1. 程式人生 > >Codeforces Round #443 (Div. 2) 【A、B、C、D】

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

log ram har bre 個人 algorithm -a 的人 lan

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

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