codeforces #516---ABC

A---golden plate

http://codeforces.com/contest/1072/problem/A

题意:给一个n*m的格子,从最外层往里涂色,每次尽量涂最外面的那一圈,两圈涂色之间要间隔一格。问最多涂多少颜色。

思路:最外面一圈是2*n + 2(m - 2),然后行和列都减4就行了。里面的if都可以不用写,因为数据范围已经保证了

 1 #include <iostream>
 2 #include <set>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <map>
 9 using namespace std;
10 typedef long long LL;
11 #define inf 0x7f7f7f7f
12 
13 int w, h, k;
14 
15 int main()
16 {
17     while(scanf("%d%d%d", &w, &h, &k) != EOF){
18 
19         int ans = 0;
20         for(int i = 0; i < k; i++){
21             if(w <= 0 || h <= 0)break;
22             if(h >= 2){
23                 ans += 2 * w + 2 * (h - 2);
24             }
25             else if(h >= 1){
26                 ans += w;
27             }
28             w -= 4; h -= 4;
29 
30         }
31         printf("%d\n", ans);
32     }
33     return 0;
34 }
View Code

好的这是我这次比赛唯一过了的题目 吐血又猛的掉分了。

 

B---Curiosity Has No Limits

题意:给两个数量为n-1的数列a,b

a[i] = t[i] | t[i+1],  b[i] = t[i] & t[i+1],问是否可以找到这样的数列c

思路:因为a和b的数保证是在0~3.所以只有三种情况,对于所有的i,可以知道有可能的t[i]和t[i+1]

枚举最开始的数的两种可能,然后暴力跑一遍看看能不能符合。

一直WA在了第8组是因为,当a=3,b=0时,t可以是0/3, 也可以是1/2, 所以每当是这样的情况的时候要多考虑一下

  1 #include <iostream>
  2 #include <set>
  3 #include <cmath>
  4 #include <stdio.h>
  5 #include <cstring>
  6 #include <algorithm>
  7 #include <vector>
  8 #include <map>
  9 using namespace std;
 10 typedef long long LL;
 11 #define inf 0x7f7f7f7f
 12 
 13 int n;
 14 const int maxn = 1e5 + 5;
 15 int a[maxn], b[maxn], c[maxn];
 16 
 17 int check()
 18 {
 19     for(int i = 2; i <= n - 1; i++){
 20         if(a[i] == 0 && b[i] != 0){
 21             return -1;
 22         }
 23         else if(b[i] == 3 && a[i] != 3){
 24             return -1;
 25         }
 26         else if(b[i] == 2 && a[i] == 1){
 27             return -1;
 28         }
 29         else if(b[i] == 1 && a[i] == 2){
 30             return -1;
 31         }
 32         else{
 33             int x, y, l, k;
 34             if(b[i] == 0){
 35                 x = 0;
 36                 y = a[i];
 37                 if(a[i] == 3){
 38                     l = 1;
 39                     k = 2;
 40                 }
 41             }
 42             else if(b[i] == 3){
 43                 x = y = 3;
 44             }
 45             else if(b[i] == 1){
 46                 if(a[i] == 1){
 47                     x = y = 1;
 48                 }
 49                 else{
 50                     x = 1;
 51                     y = 3;
 52                 }
 53             }
 54             else if(b[i] == 2){
 55                 if(a[i] == 2){
 56                     x = y = 2;
 57                 }
 58                 else{
 59                     x = 2;
 60                     y = 3;
 61                 }
 62             }
 63             if(c[i] == x){
 64                 c[i + 1] = y;
 65             }
 66             else if(c[i] == y){
 67                 c[i + 1] = x;
 68             }
 69             else if(b[i] == 0 && a[i] == 3){
 70                 if(c[i] == l){
 71                     c[i + 1] = k;
 72                 }
 73                 else if(c[i] == k){
 74                     c[i + 1] = l;
 75                 }
 76                 else return 0;
 77             }
 78             else{
 79                 return 0;
 80             }
 81         }
 82     }
 83     return 1;
 84 }
 85 
 86 int main()
 87 {
 88     while(scanf("%d", &n) != EOF){
 89         for(int i = 1; i <= n - 1; i++){
 90             scanf("%d", &a[i]);
 91         }
 92         for(int i = 1; i <= n - 1; i++){
 93             scanf("%d", &b[i]);
 94         }
 95 
 96         bool flag = true;
 97         int tmp1, tmp2, tmp3, tmp4;
 98         if(a[1] == 0 && b[1] != 0){
 99             flag = false;
100         }
101         else if(b[1] == 3 && a[1] != 3){
102             flag = false;
103         }
104         else if(b[1] == 2 && a[1] == 1){
105             flag = false;
106 
107         }
108         else if(b[1] == 1 && a[1] == 2){
109             flag = false;
110 
111         }
112         else if(b[1] == 0){
113             tmp1 = 0;
114             tmp2 = a[1];
115             if(a[1] == 3){
116                 tmp3 = 1;
117                 tmp4 = 2;
118             }
119         }
120         else if(b[1] == 3){
121             tmp1 = tmp2 = 3;
122         }
123         else if(b[1] == 1){
124             if(a[1] == 1){
125                 tmp1 = tmp2 = 1;
126             }
127             else{
128                 tmp1 = 1;
129                 tmp2 = 3;
130             }
131         }
132         else if(b[1] == 2){
133             if(a[1] == 2){
134                 tmp1 = tmp2 = 2;
135             }
136             else{
137                 tmp1 = 2;
138                 tmp2 = 3;
139             }
140         }
141 
142         if(!flag){
143             printf("NO\n");
144             continue;
145         }
146         /*if(n == 2){
147             printf("YES\n%d %d\n", tmp1, tmp2);
148             continue;
149         }*/
150         c[1] = tmp1;
151         c[2] = tmp2;
152         int f = check();
153         if(f == -1){
154             printf("NO\n");
155         }
156         else if(f == 0){
157             c[1] = tmp2;
158             c[2] = tmp1;
159             int x = check();
160             if(x == 1){
161                 printf("YES\n");
162                 printf("%d", c[1]);
163                 for(int i = 2; i <= n; i++){
164                     printf(" %d", c[i]);
165                 }
166                 printf("\n");
167             }
168             else if(x == 0){
169                 if(b[1] == 0 && a[1] == 3){
170                     c[1] = tmp3;
171                     c[2] = tmp4;
172                     int y = check();
173                     if(y == 1){
174                         printf("YES\n");
175                         printf("%d", c[1]);
176                         for(int i = 2; i <= n; i++){
177                             printf(" %d", c[i]);
178                         }
179                         printf("\n");
180 
181                     }
182                     else if(y == 0){
183                         c[1] = tmp4;
184                         c[2] = tmp3;
185                         int z = check();
186                         if(z == 1){
187                             printf("YES\n");
188                             printf("%d", c[1]);
189                             for(int i = 2; i <= n; i++){
190                                 printf(" %d", c[i]);
191                             }
192                             printf("\n");
193 
194                         }
195                         else{
196                             printf("NO\n");
197                         }
198                     }
199                 }
200                 else{
201                     printf("NO\n");
202                 }
203             }
204         }
205         else if(f == 1){
206             printf("YES\n");
207             printf("%d", c[1]);
208             for(int i = 2; i <= n; i++){
209                 printf(" %d", c[i]);
210             }
211             printf("\n");
212         }
213     }
214     return 0;
215 }
View Code

 

C---Cram Time

题意:告诉你两天的时间长度a,b,学第i门课需要i个小时,并且不可以拆分到两天学。现在想要尽量多学习,问每天应该学习哪几门课。

思路:因为要尽量多的学,所以应该尽量选择前面的课程。我们先找出前x个之和小于等于a+b的最大的x,他就是总的学习科目数。

从大到小给第一天尽量去分配,当a学习第i个不够时,就跳过i给他挑一个小一些的刚好填进去的。

剩下的都是给b的。

注意要用longlong

 1 #include <iostream>
 2 #include <set>
 3 #include <cmath>
 4 #include <stdio.h>
 5 #include <cstring>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <map>
 9 using namespace std;
10 typedef long long LL;
11 #define inf 0x7f7f7f7f
12 #define lld I64d
13 
14 LL a, b;
15 const int maxn = 1e5 + 5;
16 bool vis[maxn];
17 
18 int main()
19 {
20     while(scanf("%lld%lld", &a, &b) != EOF){
21         memset(vis, 0, sizeof(vis));
22         LL ans = (sqrt(1 + 8 * (a + b)) - 1) / 2;
23         //cout<<ans<<endl;
24         LL n = 0;
25         for(LL i = ans; i >= 1; i--){
26             if(a - i >= 0){
27                 vis[i] = true;
28                 a -= i;
29                 n++;
30             }
31         }
32         printf("%lld\n", n);
33         bool flag = false;
34         for(LL i = ans; i >= 1; i--){
35 
36             if(vis[i]){
37                 if(flag){
38                     printf(" ");
39                 }
40                 else{
41                     flag = true;
42                 }
43                 printf("%lld", i);
44             }
45         }
46         printf("\n");
47 
48         printf("%lld\n", ans - n);
49         flag = false;
50         for(LL i = 1; i <= ans; i++){
51             if(!vis[i]){
52                 if(flag){
53                     printf(" ");
54                 }
55                 else{
56                     flag = true;
57                 }
58                 printf("%lld", i);
59             }
60         }
61         printf("\n");
62 
63     }
64     return 0;
65 }
View Code

 

posted @ 2018-10-21 21:28  wyboooo  阅读(238)  评论(0编辑  收藏  举报