其他分享
首页 > 其他分享> > 2019 ECNU Campus Invitational Contest

2019 ECNU Campus Invitational Contest

作者:互联网

51假期无聊就跟队友一起训练了。队友手感挺好的,反而我不是很在状态。

题目链接:http://codeforces.com/gym/102190


 A:

签到题。根据长度暴力塞进去就好了。

 1 /* basic header */
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <cstdint>
 9 #include <climits>
10 #include <float.h>
11 /* STL */
12 #include <vector>
13 #include <set>
14 #include <map>
15 #include <queue>
16 #include <stack>
17 #include <algorithm>
18 #include <array>
19 #include <iterator>
20 /* define */
21 #define ll long long
22 #define dou double
23 #define pb emplace_back
24 #define mp make_pair
25 #define fir first
26 #define sec second
27 #define sot(a,b) sort(a+1,a+1+b)
28 #define rep1(i,a,b) for(int i=a;i<=b;++i)
29 #define rep0(i,a,b) for(int i=a;i<b;++i)
30 #define repa(i,a) for(auto &i:a)
31 #define eps 1e-8
32 #define int_inf 0x3f3f3f3f
33 #define ll_inf 0x7f7f7f7f7f7f7f7f
34 #define lson curPos<<1
35 #define rson curPos<<1|1
36 /* namespace */
37 using namespace std;
38 /* header end */
39 
40 const int maxn = 10;
41 char s[maxn];
42 
43 int main()
44 {
45     scanf("%s", s + 1);
46     int len = strlen(s + 1);
47     int sh = 0, th = 0, day;
48     if (len == 3)
49     {
50         sh = s[1] - '0'; th = 12 + s[2] - '0'; day = s[3] - '0';
51     }
52     else if (len == 5)
53     {
54         sh = (s[1] - '0') * 10 + s[2] - '0';
55         th = 12 + (s[3] - '0') * 10 + s[4] - '0';
56         day = s[5] - '0';
57     }
58     else
59     {
60         sh = (s[1] - '0') * 10 + s[2] - '0';
61         th = 12 + s[3] - '0';
62         day = s[4] - '0';
63         if ((sh < 2 || sh > 11) || (th < 14 || th > 23))
64         {
65             sh = s[1] - '0';
66             th = 12 + (s[2] - '0') * 10 + s[3] - '0';
67         }
68     }
69     printf("%d\n", day * (th - sh));
70     return 0;
71 }
View Code

B:

概率dp。

 1 #include <cstdio>
 2 
 3 char A[1000002], B[1000002];
 4 double f[1000002], p[1000002];
 5 
 6 int main(void)
 7 {
 8     int T;
 9     scanf("%d", &T);
10     f[0] = 0; // joker in my hand.
11     p[0] = 1; // joker in opp's hand.
12     for (int i = 1; i <= 1000000; i++)
13     {
14         // 我赢的概率 = 1 - 对手在下一个状态下赢的概率
15         f[i] = 1.0 - p[i - 1]; // 我一定会抽到一张好牌;
16         //p[i] = 1.0 / (i + 1) * (1 - p[i]) // 我抽到了对面的鬼牌。
17         //  + 1.0 * i / (i + 1) * (1 - f[i - 1]); // 我抽到了对面的好牌。
18         p[i] = (1.0 + i - 1.0 * i * f[i - 1]) / (i + 2);
19     }
20     while (T--)
21     {
22         int n;
23         scanf("%d", &n);
24         scanf(" %s", A);
25         scanf(" %s", B);
26         int cnt = 0;
27         bool myjoker = false;
28         for (int i = 0; i < n; i++)
29         {
30             if (A[i] == '1' && B[i] == '1')
31             {
32                 cnt++;
33             }
34             else if (A[i] == '1')
35             {
36                 myjoker = true;
37             }
38         }
39         //printf("both: %d, myjoker: %d \n", cnt, myjoker ? 1 : 0);
40         printf("%.10f\n", myjoker ? f[cnt] : p[cnt]);
41     }
42     return 0;
43 }
View Code

C:

队友嘴炮完(但是并没有敲完)的构造题。

D:

看了完全莫得想法的题目,感觉有点像是贪心?

E:

某个队友上来就表示这题很可写,然后被我劝去做B了,最后没搞出来。

F:

傻逼题,题意题。

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 
 4 using namespace std;
 5 
 6 map<string, int> M;
 7 vector<string> v;
 8 
 9 int main()
10 {
11     int t;
12     cin >> t;
13     while (t)
14     {
15         string x;
16         getline(cin, x);
17         if (x == "") continue;
18         string tmp = "";
19         for (int i = 0; i < x.length(); i++)
20         {
21             if ('A' <= x[i] && x[i] <= 'Z')
22             {
23                 tmp += x[i];
24             }
25         }
26         M[tmp] ++ ;
27         if (M[tmp] == 1)
28         {
29             v.push_back(tmp);
30         }
31         t--;
32     }
33     ll ans = 0;
34     for (int i = 0; i  < v.size(); i++)
35     {
36         ll x = M[v[i]];
37         ans += x * (x - 1) / 2ll;
38     }
39     cout << ans << endl;
40     return 0;
41 }
View Code

G:

一道很有意思的交互。从n==5的情况出发,先构造出有解的情况,之后再不停地加点上去就可以了。

 1 #include <cstdio>
 2 
 3 int main(void)
 4 {
 5     int T;
 6     scanf("%d", &T);
 7     while (T--)
 8     {
 9         int n, st;
10         int st1, st2, st3;
11         scanf("%d", &n);
12         printf("1 2 2 3\n");
13         fflush(stdout);
14         scanf("%d", &st1);
15         printf("3 4 4 5\n");
16         fflush(stdout);
17         scanf("%d", &st2);
18         if (st1 == st2)
19         {
20             printf("5 1 1 4\n");
21             fflush(stdout);
22             scanf("%d", &st3);
23             if (st1 == st3)
24             {
25                 printf("1 3 3 5\n");
26                 fflush(stdout);
27                 scanf("%d", &st);
28             }
29             else
30             {
31                 printf("2 5 5 3\n");
32                 fflush(stdout);
33                 scanf("%d", &st);
34             }
35         }
36         else
37         {
38             printf("5 3 3 1\n");
39             fflush(stdout);
40             scanf("%d", &st3);
41             if (st1 == st3)
42             {
43                 printf("1 5 5 2\n");
44                 fflush(stdout);
45                 scanf("%d", &st);
46             }
47             else
48             {
49                 printf("1 5 1 4\n");
50                 fflush(stdout);
51                 scanf("%d", &st);
52             }
53         }
54         for (int i = 6; i <= n; i++)
55         {
56             printf("%d 1 %d 2\n", i, i);
57             fflush(stdout);
58             scanf("%d", &st);
59         }
60     }
61     return 0;
62 }
View Code

H:

分情况讨论就可以了。

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 typedef long long ll;
 6 
 7 ll gcd(ll a, ll b)
 8 {
 9     if (a % b == 0) return b;
10     else return gcd(b, a % b);
11 }
12 
13 int main()
14 {
15     ll h, m;
16     cin >> h >> m;
17     if (h <= m)
18     {
19         ll x1 = h;
20         ll x2 = 2ll * m - h + 1;
21         ll a = x1 * x2 / 2ll;
22         ll b = h * m;
23         ll g = gcd(a, b);
24         a /= g; b /= g;
25         cout << a << '/' << b << endl;
26     }
27     else
28     {
29         ll a = m * (m + 1) / 2ll;
30         ll b = h * m;
31         ll g = gcd(a, b);
32         a /= g; b /= g;
33         cout << a << '/' << b << endl;
34     }
35 
36     return 0;
37 }
View Code

I:

队友没发现输入并不保证正确,wa了好多发……

解法倒是非常傻,floyd就完事了。

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 
 5 const int maxn = 2000;
 6 const int INF = 1e5;
 7 
 8 int A[maxn][maxn];
 9 int f[maxn][maxn];
10 
11 int main()
12 {
13     int T;
14     scanf("%d", &T);
15     while (T--)
16     {
17         int n, fg = 0;
18         scanf("%d", &n);
19         for (int i = 1; i <= n; i++)
20             for (int j = 1; j <= n; j++)
21             {
22                 scanf("%d", &A[i][j]);
23                 f[i][j] = A[i][j]; //copy
24             }
25         for (int i = 1; i <= n; i++)
26         {
27             f[i][i] = 0; //dui jiao must be zero
28             for (int j = 1; j <= n; j++)
29             {
30                 if (f[i][j] != -1 && f[j][i] != -1 && f[i][j] != f[j][i])
31                 {
32                     fg = 1; goto mark;
33                 }
34                 if (f[i][j] == -1 && f[j][i] != -1)
35                     f[i][j] = f[j][i];
36                 else if (f[i][j] == -1) f[i][j] = INF;
37             }
38         }
39         //floyd
40         for (int k = 1; k <= n; k++)
41             for (int i = 1; i <= n; i++)
42                 for (int j = 1; j <= n; j++)
43                     f[i][j] = min(f[i][k] + f[k][j], f[i][j]);
44         for (int i = 1; i <= n; i++)
45             for (int j = 1; j <= n; j++)
46             {
47                 if (A[i][j] != -1 && f[i][j] != A[i][j])
48                 {
49                     fg = 1;
50                     goto mark;
51                 }
52             }
53 mark:;
54         if (fg) printf("NO\n");
55         else
56         {
57             printf("YES\n");
58             for (int i = 1; i <= n; i++)
59             {
60                 for (int j = 1; j <= n; j++)
61                 {
62                     if (j == 1) printf("%d", f[i][j]);
63                     else
64                     {
65                         printf(" %d", f[i][j]);
66                     }
67                 }
68                 printf("\n");
69             }
70         }
71     }
72     return 0;
73 }
View Code

J && K:

没看。

L:

还没看就被队友秒了,说是sb贪心(还抢了gym的一血

 1 #include<bits/stdc++.h>
 2 
 3 using namespace std;
 4 int A[20];
 5 
 6 int main()
 7 {
 8     int T;
 9     scanf("%d", &T);
10     while (T--)
11     {
12         for (int i = 1; i <= 6; i++)
13             scanf("%d", &A[i]);
14         int ans = A[6];
15         A[6] = 0;
16         ans += A[5];
17         A[1] -= A[5];
18         ans += A[4];
19         if (A[2] <= A[4])
20         {
21             A[4] -= A[2];
22             A[2] = 0;
23             A[1] -= A[4] * 2;
24         }
25         else
26         {
27             A[2] -= A[4];
28         }
29         ans += A[3] / 2;
30         A[3] %= 2;
31         if (A[3] == 1)
32         {
33             ans ++;
34             int x = 3;
35             if (A[2] >= 1)
36             {
37                 A[2] --;
38                 x -= 2;
39             }
40             A[1] -= x;
41         }
42         ans += A[2] / 3;
43         A[2] %= 3;
44         if (A[2] >= 1)
45         {
46             ans ++;
47             A[1] -= 6 - A[2] * 2;
48         }
49         if (A[1] >= 1) ans += (A[1] + 5) / 6;
50         printf("%d\n", ans);
51     }
52     return 0;
53 }
View Code

 

标签:Invitational,Contest,int,scanf,2019,printf,fflush,include,define
来源: https://www.cnblogs.com/JHSeng/p/10803149.html