Codeforces Round #443 (Div. 2) 【A、B、C、D】

Codeforces Round #443 (Div. 2)

 

codeforces 879 A. Borya's Diagnosis【水题】

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main(){
 6     int n, t = 0, s, d;
 7     scanf("%d", &n);
 8     while(n--) {
 9         scanf("%d%d", &s, &d);
10         while(s <= t) {s += d;}
11         t = s;
12     }
13     printf("%d\n", t);
14     return 0;
15 }
78ms

codeforces 879 B. Table Tennis【模拟】

题意:一排n个人,给出每个人的a值,从第一个人开始,每次和后面人比赛,a值大的人赢,输的人走到最后位置去,求先连赢k场的人的a值。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int main(){
 6     long long k;
 7     int n, t = 0, a, ans = 0, cnt = 0, f = 0;
 8     scanf("%d%lld", &n, &k);
 9     while(n--) {
10         scanf("%d", &a);
11         if(a < ans) cnt++;
12         else cnt = 1;
13         ans = max(ans, a);
14         if(!f) {cnt = 0;f = 1;}
15         if(cnt >= k) break;
16     }
17     printf("%d\n", ans);
18     return 0;
19 }
31ms

codeforces 878 A. Short Program【位运算】

题意:给出一系列与、或、异或这三种逻辑运算表达式,要对未知数x顺序做这些运算,要你合并运算,输出不超过5行的化简的运算式子。

 

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 int n;
 6 int main(){
 7     int i, j, k, f, x;
 8     int cnt = 0;
 9     int a = 0, b = 1023, c = 0;
10     char s;
11     scanf("%d", &n);
12     for(i = 1; i <= n; ++i) {
13         getchar();
14         scanf("%c %d", &s, &x);
15         if(s == '|') {a |= x; b |= x; c &= (1023-x);}
16         else if(s == '&') {b &= x; c &= x;}
17         else if(s =='^') {c ^= x; }
18     }
19     if(a) cnt++;
20     if(b != 1023) cnt++;
21     if(c) cnt++;
22     printf("%d\n", cnt);
23     if(a) printf("| %d\n", a);
24     if(b != 1023) printf("& %d\n", b);
25     if(c) printf("^ %d\n", c);
26     return 0;
27 }
156ms

codeforces 878 B. Teams Formation【模拟】

题意:长为n的数组a,重复m次形成一个序列,每次动态消去相邻k个相同的数,直到不能消去为止,求最后剩下几个数。

题解:先将长为n的一列数消除,然后考虑两段连接中间消除。

 

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 using namespace std;
 6 const int N = 100002;
 7 typedef long long ll;
 8 int n, k, m, cnt;
 9 int a[N], b[N], c[N];
10 ll ans = 0;
11 int main() {
12     cnt = 0;
13     int i, j, o, sum = 0;
14     int l, r;
15     scanf("%d%d%d", &n, &k, &m);
16     for(i = 1; i <= n; ++i) scanf("%d", &a[i]);
17     for(i = 1; i <= n; ++i) {//第一段序列
18         if(a[i] != b[cnt]) { b[++cnt] = a[i]; c[cnt] = 1; }
19         else { c[cnt]++; if(c[cnt] == k) cnt--; }
20     }
21     if(!cnt) {puts("0"); return 0;}
22     for(i = 1; i <= cnt; ++i) sum += c[i];
23     for(o = 0, i = 1; i < cnt+1-i; ++i) {//相当于两段序列之间
24         if(b[i] == b[cnt+1-i] && c[i] + c[cnt+1-i] == k) o += k;
25         else break;
26     }
27     if(i<cnt+1-i) {
28         if(b[i] == b[cnt+1-i] && c[i] + c[cnt+1-i] > k) o += k;
29         ans = 1ll * sum * m - 1ll * o * (m-1);
30     }
31     else {//剩一种数字
32         ans = 1ll * c[i] * m % k;
33         if(ans) ans += sum - c[i];//两端的数
34     }
35     printf("%lld\n", ans);
36     return 0;
37 }
31ms

 

posted @ 2017-10-27 19:28  GraceSkyer  阅读(574)  评论(0编辑  收藏  举报

~~~~~~ACM大牛语录,激励一下~~~~~~

为了世界的和平,为了女生的安全,我拼命做题,做题,做题!

用最短的时间,刷最多的题!

给我一滴泪,我就看到了你全部的海洋!

seize the hour, seize the day.

人生难免有无奈,幸福走远了,或是感叹幸福来迟了.其实我一直相信,无论手中的幸福是多么微不足道的感觉,我会把握住那每一分,每一秒,当幸福依旧像那百鸟般飞逝,终究无法掌握时,我会感谢它,曾经降临过!

A自己的题,让别人郁闷去吧

WA肠中过,AC心中留 TLE耳边过,AC特别牛

天然的悲苦和伤逝,过去有过,以后还会有

^*^一步一步往上爬^*^

AC就像练级,比赛就像PK. 练级不如PK好玩

其实,世上本没有ACM,AC的人多了,也便有了!

AC无止尽~ Seek you forever~

找呀找呀找水题,找到一个AC一个呀!

AC是检验程序的唯一标准。

真的猛士,敢于直面惨淡的人生,敢于正视淋漓的鲜血……