1. 程式人生 > 實用技巧 >QFNU 10-02 19 training

QFNU 10-02 19 training

B - Yet Another Crosses Problem

CodeForces - 1194B

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=5e4+10;

string a[MAXN];
int aa[MAXN],bb[MAXN];

int main(){
    ll n;
    cin>>n;
    while(n--){
        int x,y;
        cin>>x>>y;
        for
(int i=0;i<MAXN;i++) aa[i]=0; for(int i=0;i<MAXN;i++) bb[i]=0; for(int i=0;i<x;i++) cin>>a[i]; for(int i =0;i<x;i++){ for(int j=0;j<y;j++){ if(a[i][j]=='*'){ bb[i]++; aa[j]
++; } } } int ans=1e9; for(int i =0;i<x;i++){ for(int j=0;j<y;j++){ // cout<<aa[j]<<bb[i]<<endl; if(a[i][j]=='.'){ ans=min(ans,(x+y-bb[i]-aa[j]-1)); }
else ans=min(ans,(x+y-bb[i]-aa[j])); } } cout<<ans<<endl; } return 0; }

E - Buying a TV Set

CodeForces - 1041B

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;

int main(){
    ll w,h,x,y;
    cin>>w>>h>>x>>y;
    ll t=__gcd(x,y);
    x=x/t;
    y=y/t;
    ll a=w/x;
    ll b=h/y;
    
    cout<<min(a,b)<<endl;
    
    return 0;
}

F - Coffee Break

CodeForces - 1041C

使用最小優先佇列,每次用最小的和當前元素對比,是不是可以在同一天休息。不可以就再來一天。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=1e5+10;
int n,m,d,ans=1,x;
map<int,int> mp;
vector<int> a,b;
priority_queue<int,vector<int>,greater<int> > q;

int main(){
    cin>>n>>m>>d;
    for(int i =0;i<n;i++){
        cin>>x;
        a.push_back(x);
        b.push_back(x);
    }
    sort(a.begin(),a.end());
    mp[a[0]]=1;
    
    q.push(0);
    for(int i =1;i<n;i++){
//        cout<<ans<<endl;
        int ii = q.top();
        if(a[i]-a[ii]>d){
            mp[a[i]]=mp[a[ii]];
            q.pop();
        }
        else{
            ans++;
            mp[a[i]]=ans;
        }
        q.push(i);
    }
    cout<<ans<<endl;
    for(int i =0;i<n;i++)
        cout<<mp[b[i]]<<" ";
    
    
    return 0;
}