Codeforces Round #435 (Div. 2)

来源:互联网 发布:手机考试软件 编辑:程序博客网 时间:2024/05/16 09:04

http://codeforces.com/contest/862
A. Mahmoud and Ehab and the MEX
……………………简单题

B Mahmoud and Ehab and the bipartiteness
给一棵树,问最多加多少条边使其仍是二分图。
其实不难想,我们把树上的点DFS序一下,之后按奇数偶数分别统计个数,之后我们就能知道最多多少边了,之后减去(n-1) 即可

C
Mahmoud and Ehab and the xor
这个是给你一个x,一个n,让你找到n个不重复的数使其^和为x。并且每个数不超过1e6
这个题有些意思,出题人给了数据范围不超过1e6,又说x<1e5,所以我们找到了2个神奇的数1<<17 ,1<<18,这两个数正好在1e5~1e6之间,这就给了我们很大的帮助。我们分类讨论n和x的情况即可。具体看代码

#include <bits/stdc++.h>#define maxs 202020#define mme(i,j) memset(i,j,sizeof(i))#define ll long long int;using namespace std;int main(){    int n,x;    while(~scanf("%d",&n))    {        scanf("%d",&x);        if(n==2&&x==0){            printf("NO\n");            continue;        }        printf("YES\n");        if(n==1){            printf("%d\n",x);            continue;        }        if(n==2){            printf("0 %d\n",x);            continue;        }        if(n==3){            printf("%d %d %d\n",(1<<17),x^(1<<17)^(1<<18),(1<<18));         //   printf("ans is %d\n", ((1<<17)|x)^ ( (1<<17)|(1<<18))^(1<<18));            continue;        }        if(n>3){            int tmp=0;            for(int i=1;i<=n-3;i++){                tmp^=i;                printf("%d ",i);            }            x=x^tmp;            printf("%d %d %d\n",(1<<17),(1<<17)^(1<<18)^x,(1<<18));          //  printf("ans is %d\n", tmp^((1<<17)|x)^( (1<<17)|(1<<18))^(1<<18));        }    }    return 0;}
原创粉丝点击