Codeforces Global Round 22

A

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#define endl '\n'
using namespace std;
const int N=1e6+10;
int t;
int n;
int mark[N];
priority_queue<long long> a,b;
inline void solve(){
    int cnt0=0,cnt1=0;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>mark[i];
    int s;
    for(int i=1;i<=n;i++){
        cin>>s;
        if(mark[i]){
            a.push(s);
        }
        else{
            b.push(s);
        }
    }
    long long  ans=0;
    while(a.size()&&b.size()){
        ans+=a.top()*2+b.top()*2;
        if(a.size()==1&&b.size()==1){
            ans-=min(a.top(),b.top());
        }
        a.pop(),b.pop();
    }
    while(a.size()){
        ans+=a.top();
        a.pop();
    }
    while(b.size()){
        ans+=b.top();
        b.pop();
    }
    cout<<ans<<endl;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
    while(t--){
        solve();
    }
	return 0;
}

昨天差点寄在a题上了,赛时想了半个小时终于想出来了,原本很弱智的一道题,不想多说了,代码就能理解

B

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define int long long
#define endl '\n'
using namespace std;
const int N=1e5+10;
int t;
int n,k;
int c[N];
double b[N];
inline void solve(){
    cin>>n>>k;
    for(int i=1;i<=k;i++)cin>>c[i];
    b[1]=c[1];
    for(int i=2;i<=k;i++){
        b[i]=c[i]-c[i-1];
    }
        b[1]=b[1]/(n-k+1);
    for(int i=k;i>1;i--){
        if(b[i]<b[i-1]){
            cout<<"No"<<endl;
            return;
        }
    }
    cout<<"Yes"<<endl;
}
main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
    while(t--){
        solve();
    }
	return 0;	
}

B题又被hack了,一直纠结正数上取整还是负数下取整,其实只需要用double就行了。

C

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#define endl '\n'
using namespace std;
const int N=110;
int t;
int n;
inline void solve(){
    cin>>n;
    int s=0;
    int cnt=0;
    for(int i=1;i<=n;i++){
        cin>>s;
        if(s&1)cnt++;
    }
    if(cnt&1){
        if(n&1){
            int t=(cnt+1)/2;
            if(t&1)cout<<"Bob"<<endl;
            else cout<<"Alice"<<endl;
        }
        else cout<<"Alice"<<endl;
    }
    else{
        int t=cnt/2;
        if(t&1)cout<<"Bob"<<endl;
        else cout<<"Alice"<<endl;
    }
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	cin>>t;
    while(t--){
        solve();
    }
	return 0;
}

c题的赛时代码,和前天的c一摸一样类型的题,可以找数学关系,从而巧妙得出结论,也可以dp推导。