Codeforces Round #532 (Div. 2) Solution
阿新 • • 發佈:2019-01-14
A. Roman and Browser
簽到.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 int n, k, a[110]; 5 6 int get(int b) 7 { 8 int vis[110]; 9 memset(vis, 0, sizeof vis); 10 int c = b; 11 while (c <= n) 12 { 13 vis[c] = 1; 14 c += k; 15 }View Code16 c = b - k; 17 while (c >= 1) 18 { 19 vis[c] = 1; 20 c -= k; 21 } 22 int l = 0, r = 0; 23 for (int i = 1; i <= n; ++i) if (!vis[i]) 24 { 25 if (a[i] == 1) ++l; 26 else ++r; 27 } 28 return abs(l - r); 29 } 30 31 int main() 32 {33 while (scanf("%d%d", &n, &k) != EOF) 34 { 35 for (int i = 1; i <= n; ++i) scanf("%d", a + i); 36 int res = 0; 37 for (int i = 1; i <= n; ++i) res = max(res, get(i)); 38 printf("%d\n", res); 39 } 40 return 0; 41 }
B. Build a Contest
簽到.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 #define N 100010 5 int n, m, a[N]; 6 int cnt[N]; 7 8 int main() 9 { 10 while (scanf("%d%d", &n, &m) != EOF) 11 { 12 for (int i = 1; i <= m; ++i) scanf("%d", a + i); 13 int need = n; 14 memset(cnt, 0, sizeof cnt); 15 for (int i = 1; i <= m; ++i) 16 { 17 if (cnt[a[i]] == 0) 18 --need; 19 ++cnt[a[i]]; 20 if (need) putchar('0'); 21 else 22 { 23 putchar('1'); 24 for (int j = 1; j <= n; ++j) 25 { 26 --cnt[j]; 27 if (!cnt[j]) 28 ++need; 29 } 30 } 31 } 32 puts(""); 33 } 34 return 0; 35 }View Code
C. NN and the Optical Illusion
簽到.
1 #include <bits/stdc++.h> 2 using namespace std; 3 4 const double eps = 1e-8; 5 const double PI = acos(-1.0); 6 7 int main() 8 { 9 int n; double r; 10 while (scanf("%d%lf", &n, &r) != EOF) 11 { 12 double ang1 = 2.0 * PI / n; 13 double ang2 = (PI - ang1) / 2; 14 double R = (r * sin(ang1) * 1.0) / (2 * sin(ang2) - sin(ang1)); 15 printf("%.10f\n", R); 16 } 17 return 0; 18 }View Code
E. Andrew and Taxi
Unsolved.
題意:
給出一張有向圖,求改變一些邊使得它沒有環
改變一條邊的花費是它的邊權,要使得最大花費最小
輸出最大花費和需要改變的邊數
再輸出相應的邊