Codeforces Round #345

Joysticks

题意:讲的是放电要2,充电要1,问两个持续时间最长是多少。

水题,注意的是当a,b同时等于1的时候,直接游戏结束。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int a,b;
int main(){
    while(scanf("%d%d",&a,&b)!=EOF){
            int num=0;
            if(a==1&&b==1){
                    printf("0
");
                    break;
            }
        while(a>0&&b>0){
            if(a>b)swap(a,b);
            a++;b-=2;
            //printf("%d %d
",a,b);
            num++;
        }
    printf("%d
",num);
    }

return 0;
}
View Code

Beautiful Paintings

二水,求的是a i+1 >a i的对数最大有多少,所以实际只需要求一共有多少个相同值,然后用总数减去这个值即可。原因是,我们既然排序,那最好肯定的是按照从小到大排序,但是可能有重复的,所以不符合条件,所以要重新单独拍,那么就和前面的断了,所以只要用总数减去断的个数即可。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int a[1005],k,n;
int main(){
    while(scanf("%d",&n)!=EOF){
            memset(a,0,sizeof(a));
            int num=0;
            int maxx=0;
        for(int i=0;i<n;i++){
            scanf("%d",&k);
                    a[k]++;
            if(a[k]>maxx)maxx=a[k];
        }
       // printf("%d
",maxx);
        printf("%d
",n-maxx);
    }

return 0;
}
View Code

Watchmen

思路:简单容斥;只需要求xi=xj和yi=yj的情况分别有多少种两两组合方式,然后减去xi=xj且yi=yj情况下的两两组合方式即可。使用的是map。

#include<cstdio>
#include<cstring>
#include<map>
#include<iostream>
using namespace std;
typedef long long LL;
map<pair<LL,LL>,LL> map1;
map<LL ,LL> map2,map3;
int main(){
    int n;
    LL a,b;
    while(scanf("%d",&n)!=EOF){
            map1.clear();
            map2.clear();
            map3.clear();
        for(int i=0;i<n;i++){
            scanf("%I64d%I64d",&a,&b);
            map1[make_pair(a,b)]++;
            map2[a]++;
            map3[b]++;
        }
        /*printf("%d
",map1.size());
        printf("%d
",map2.size());
        printf("%d
",map3.size());*/
        map<pair<LL,LL>,LL>::iterator it1;
        LL sum=0;
        for(it1=map1.begin();it1!=map1.end();it1++){
            //if(it1->second!=1)
            sum+=it1->second*(it1->second-1)/2;
            // else sum++;
        }
        LL sum1=0;
        map<LL,LL>::iterator it2;
        for(it2=map2.begin();it2!=map2.end();it2++){
                //if(it2->second!=1)
            sum1+=it2->second*(it2->second-1)/2;
        //else sum1++;
        }
        map<LL,LL>::iterator it3;
        for(it3=map3.begin();it3!=map3.end();it3++){
                //if(it3->second!=1)
            sum1+=it3->second*(it3->second-1)/2;
            //else sum1++;
        }
        printf("%I64d
",sum1-sum);
    }
return 0;
}
View Code

未完待续~后面题还不会写~orz

原文地址:https://www.cnblogs.com/Yvettey-me/p/5256503.html