2015 ICL, Finals, Div. 2【ABFGJK】

【题外话:我......不补了......】

2015 ICL, Finals, Div. 2http://codeforces.com/gym/100637

G. #TheDress【水】

(strstr函数真好用......)

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 char s[101];
 4 int main() {
 5     int n, i;
 6     scanf("%d ", &n);
 7     int x = 0, y = 0, z = 0;//地球人,外星人,其他人
 8     for(i = 1; i <= n; ++i) {
 9         gets(s);
10         if(strstr(s, "blue") && strstr(s, "black")) x++;
11         else if(strstr(s, "white") && strstr(s, "gold")) y++;
12         else z++;
13     }
14     printf("%.10f
", x*100.0/(x+y+z));
15     printf("%.10f
", y*100.0/(x+y+z));
16     printf("%.10f
", z*100.0/(x+y+z));
17     return 0;
18 }
View Code

F. The Pool for Lucky Ones【暴力】

题意:泳池有N个水道,假设水道人数最多的水道里的人都是不快乐的(可以有多个水道同时人数最多),现在允许你移动任意一个人到相邻水道(可以不移动),求最少的不快乐的人数。

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int a[100001], b[100001];//水道的人数 和 人数相同的水道数
 5 int main() {
 6     int n, i, j;
 7     ll ans = 0, ma = 0;
 8     scanf("%d ", &n);
 9     for(i = 1; i <= n; ++i) {
10         scanf("%d", &a[i]);
11         b[a[i]]++;
12         ma = max(1ll*a[i], ma);
13     }
14     ans = 1l * ma * b[ma];
15     for(i = 1; i <= n; ++i) {
16         if(!a[i]) continue;
17         if(i != n) {//从前往后移一个人
18             b[a[i]]--; b[a[i]-1]++;
19             b[a[i+1]]--; b[a[i+1]+1]++;
20             for(j = ma+1; j > 0; --j) {
21                 if(b[j] > 0) {
22                     ans = min(ans, 1ll*b[j]*j);
23                     break;
24                 }
25             }
26             b[a[i]]++; b[a[i]-1]--;
27             b[a[i+1]]++; b[a[i+1]+1]--;
28         }
29         if(i != 1) {//从后往前移一个人
30             b[a[i]]--; b[a[i]-1]++;
31             b[a[i-1]]--; b[a[i-1]+1]++;
32             for(j = ma+1; j > 0; --j) {
33                 if(b[j] > 0) {
34                     ans = min(ans, 1ll*b[j]*j);
35                     break;
36                 }
37             }
38             b[a[i]]++; b[a[i]-1]--;
39             b[a[i-1]]++; b[a[i-1]+1]--;
40         }
41     }
42     printf("%lld
", ans);
43     return 0;
44 }
View Code

K. Microcircuits【dp】

题意:N个点放在环上,现在要不相交的连K条线,求方案数。

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 ll dp[50][50];//dp[i][j]:i个点连j条边的方案数
 5 int main() {
 6     int n, k, i, j, p, q;
 7     scanf("%d%d", &n, &k);
 8     for(i = 0; i <= n; ++i) dp[i][0] = 1;
 9     for(i = 1; i <= n; ++i) {
10         for(j = 0; j <= k; ++j) {
11             dp[i][j] = dp[i-1][j];
12             for(p = 1; p < i; ++p) {//枚举连到哪个点
13                 for(q = 0; q < j; ++q) {//枚举子问题连边数
14                     dp[i][j] += dp[p-1][q] * dp[i-1-p][j-1-q];
15                 }
16             }
17         }
18     }
19     printf("%lld
", dp[n][k]);
20     return 0;
21 }
View Code

B. Lunch【规律题】

有个讲得很清晰的题解:https://www.cnblogs.com/jerryRey/p/4676072.html

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main() {
 5     int n, s, f, ans = 0, i, j;
 6     scanf("%d%d%d", &n, &s, &f);
 7     if(f < s) swap(s, f);
 8     if(s+1 == f) {
 9         if(s > 1 && f < n) puts("-1");
10         else puts("1");
11     }
12     else {
13         if(s > 1) ans++, s++;
14         if(f < n) ans++, f--;
15         ans += (f-s)/3 + (f-s)%3;
16         printf("%d
", ans);
17     }
18     return 0;
19 }
View Code

A. Nano alarm-clocks

参考题解:https://www.cnblogs.com/liuweimingcprogram/p/5766622.html

 

J. Superfactorial numeral system【构造】

题意:给p,q,求满足该式的a序列。a[1]≥0,其他0≤a[k]≤k。

【注意用long long......】

代码:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 int main() {
 5     ll p, q, x = 1;
 6     scanf("%lld%lld", &p, &q);
 7     while(p) {
 8         p *= x;
 9         printf("%lld ", p/q);
10         p %= q;
11         x++;
12     }
13     puts("");
14     return 0;
15 }
View Code
原文地址:https://www.cnblogs.com/GraceSkyer/p/9030655.html