Codeforces Round #268 (Div. 2) ABCD

CF469

Codeforces Round #268 (Div. 2)

http://codeforces.com/contest/469

 

开学了,时间少,水题就不写题解了,不水的题也不写这么详细了。

A

水题

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define mf1(array) memset(array, -1, sizeof(array))
17 #define minf(array) memset(array, 0x3f, sizeof(array))
18 #define REP(i,n) for(i=0;i<(n);i++)
19 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
20 #define RD(x) scanf("%d",&x)
21 #define RD2(x,y) scanf("%d%d",&x,&y)
22 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
23 #define WN(x) printf("%d\n",x);
24 #define RE  freopen("D.in","r",stdin)
25 #define WE  freopen("huzhi.txt","w",stdout)
26 #define mp make_pair
27 #define pb push_back
28 
29 bool a[111];
30 
31 int main(){
32     int n,m,i,x;
33     RD(n);
34     RD(m);
35     mz(a);
36     REP(i,m){RD(x);a[x]=1;}
37     RD(m);
38     REP(i,m){RD(x);a[x]=1;}
39     bool flag=1;
40     FOR(i,1,n){
41         if(a[i]==0){flag=0;break;}
42     }
43     if(flag)puts("I become the guy.");
44     else puts("Oh, my keyboard!");
45     return 0;
46 }
View Code

B

模拟,狂撸

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define mf1(array) memset(array, -1, sizeof(array))
17 #define minf(array) memset(array, 0x3f, sizeof(array))
18 #define REP(i,n) for(i=0;i<(n);i++)
19 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
20 #define RD(x) scanf("%d",&x)
21 #define RD2(x,y) scanf("%d%d",&x,&y)
22 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
23 #define WN(x) printf("%d\n",x);
24 #define RE  freopen("D.in","r",stdin)
25 #define WE  freopen("huzhi.txt","w",stdout)
26 #define mp make_pair
27 #define pb push_back
28 
29 int a[55],b[55],c[55],d[55];
30 int p,q,l,r;
31 
32 bool gank(int x){
33     int i,j;
34     j=0;
35     d[q]=111111;
36     REP(i,p){
37         while(d[j]+x<a[i])j++;
38         if(j>=q)return 0;
39         if(c[j]+x<=b[i])return 1;
40     }
41     return 0;
42 }
43 
44 int main(){
45     int i;
46     RD3(p,q,l);
47     RD(r);
48     REP(i,p)RD2(a[i],b[i]);
49     REP(i,q)RD2(c[i],d[i]);
50     int ans=0;
51     FOR(i,l,r){
52         if(gank(i)){
53            // printf("%d!",i);
54             ans++;
55         }
56     }
57     WN(ans);
58     return 0;
59 }
View Code

C

找规律,发现4一种5一种,更高的可以两个相邻相减搞成1,随便搞。

 1 //#pragma comment(linker, "/STACK:102400000,102400000")
 2 #include<cstdio>
 3 #include<cmath>
 4 #include<iostream>
 5 #include<cstring>
 6 #include<algorithm>
 7 #include<cmath>
 8 #include<map>
 9 #include<set>
10 #include<stack>
11 #include<queue>
12 using namespace std;
13 #define ll long long
14 #define usll unsigned ll
15 #define mz(array) memset(array, 0, sizeof(array))
16 #define mf1(array) memset(array, -1, sizeof(array))
17 #define minf(array) memset(array, 0x3f, sizeof(array))
18 #define REP(i,n) for(i=0;i<(n);i++)
19 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
20 #define RD(x) scanf("%d",&x)
21 #define RD2(x,y) scanf("%d%d",&x,&y)
22 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
23 #define WN(x) printf("%d\n",x);
24 #define RE  freopen("D.in","r",stdin)
25 #define WE  freopen("huzhi.txt","w",stdout)
26 #define mp make_pair
27 #define pb push_back
28 
29 void farm(int n) {
30     if(n<=3) {
31         puts("NO");
32         return;
33     }
34     puts("YES");
35     while(n>5) {
36         printf("%d - %d = 1\n",n,n-1);
37         puts("4 * 1 = 4");
38         n-=2;
39     }
40     if(n==4) {
41         puts("4 * 3 = 12\n1 * 2 = 2\n2 * 12 = 24");
42     } else {
43         puts("5 - 3 = 2\n2 * 4 = 8\n2 + 1 = 3\n3 * 8 = 24");
44     }
45 }
46 
47 int main() {
48     int n;
49     RD(n);
50     farm(n);
51     return 0;
52 }
View Code

D

过初审,爆炸了,还不会


发现我居然过了,不过我也不记得是啥题了怎么做的了,贴代码好了

  1 //#pragma comment(linker, "/STACK:102400000,102400000")
  2 #include<cstdio>
  3 #include<cmath>
  4 #include<iostream>
  5 #include<cstring>
  6 #include<algorithm>
  7 #include<cmath>
  8 #include<map>
  9 #include<set>
 10 #include<stack>
 11 #include<queue>
 12 using namespace std;
 13 #define ll long long
 14 #define usll unsigned ll
 15 #define mz(array) memset(array, 0, sizeof(array))
 16 #define mf1(array) memset(array, -1, sizeof(array))
 17 #define minf(array) memset(array, 0x3f, sizeof(array))
 18 #define REP(i,n) for(i=0;i<(n);i++)
 19 #define FOR(i,x,n) for(i=(x);i<=(n);i++)
 20 #define RD(x) scanf("%d",&x)
 21 #define RD2(x,y) scanf("%d%d",&x,&y)
 22 #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
 23 #define WN(x) printf("%d\n",x);
 24 #define RE  freopen("D.in","r",stdin)
 25 #define WE  freopen("huzhi.txt","w",stdout)
 26 #define mp make_pair
 27 #define pb push_back
 28 
 29 int d[111111];
 30 int c[111111];
 31 int f[111111];
 32 int n,ab[2];
 33 
 34 map<int,int>S;
 35 
 36 int getfather(int x){
 37     int t=f[x]!=x?getfather(f[x]):x;
 38     f[x]=t;
 39     return t;
 40 }
 41 void comb(int x,int y){
 42     f[getfather(y)]=getfather(x);
 43 }
 44 
 45 
 46 int gank(int x) {
 47     int q=d[x];
 48     int xa=S[ab[0]-q];
 49     int xb=S[ab[1]-q];
 50     if(xa!=0 && xb!=0){
 51         int fx=getfather(x);
 52         int fxa=getfather(xa);
 53         int fxb=getfather(xb);
 54         if(fx>n && fxa>n && fx!=fxa)return -1;
 55         if(fx!=fxa) fx>fxa?comb(fx,fxa):comb(fxa,fx);
 56         fx=getfather(x);
 57         if(fx>n && fxb>n && fx!=fxb)return -1;
 58         if(fx!=fxb) fx>fxb?comb(fx,fxb):comb(fxb,fx);
 59     }else if(xa!=0){
 60         int fx=getfather(x);
 61         int fxa=getfather(xa);
 62         if(fx==n+2 || fxa==n+2)return -1;
 63         if(fx!=n+1)comb(n+1,fx);
 64         if(fxa!=n+1)comb(n+1,fxa);
 65     }else if(xb!=0){
 66         int fx=getfather(x);
 67         int fxb=getfather(xb);
 68         if(fx==n+1 || fxb==n+1)return -1;
 69         if(fx!=n+2)comb(n+2,fx);
 70         if(fxb!=n+2)comb(n+2,fxb);
 71     }else return -1;
 72     return 0;
 73 }
 74 
 75 bool farm() {
 76     if(ab[0]==ab[1])ab[1]=1e9*2+7;
 77     int i,j;
 78     mf1(c);
 79     FOR(i,1,n+2)f[i]=i;
 80     ///n+1��setA��n+2��setB
 81     FOR(i,1,n) {
 82         if(gank(i)==-1)return 0;
 83         //printf("%d f[1]=%d\n",i,getfather(1));
 84     }
 85     set<int>A;
 86     int b[5],r=0;
 87     A.clear();
 88     int cnt=0;
 89     FOR(i,1,n){
 90         int fi=getfather(i);
 91         if(fi!=n+1 && fi!=n+2){
 92             int xa=S[ab[0]-d[i]];
 93             int xb=S[ab[1]-d[i]];
 94             if(xb!=0 && (getfather(xb)==n+2 || i==xa))comb(n+2,fi);
 95             else if(xa!=0 && (getfather(xa)==n+1 || i==xb)) comb(n+1,fi);
 96             else return 0;
 97         }
 98         //printf("f[%d] = %d\n",i,f[i]);
 99     }
100     return 1;
101 }
102 
103 int main() {
104     int i;
105     RD3(n,ab[0],ab[1]);
106     FOR(i,1,n) {
107         RD(d[i]);
108         S[d[i]]=i;
109     }
110     if(farm()) {
111         puts("YES");
112         if(n>0)printf("%d",getfather(1)-n-1);
113         FOR(i,2,n)printf(" %d",getfather(i)-n-1);
114     } else puts("NO");
115     return 0;
116 }
View Code

 

转载于:https://www.cnblogs.com/yuiffy/p/3984752.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值