Codeforces Edu Round 82 (Rated for Div. 2)

帅比萌擦擦* 提交于 2020-02-13 12:57:29

题目链接:https://codeforces.com/contest/1303


A:

白给

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 const int maxn = 110;
21 int t;
22 char s[maxn];
23 
24 int main() {
25     scanf("%d", &t);
26     while (t--) {
27         int ans = 0;
28         scanf("%s", s + 1);
29         int len = strlen(s + 1);
30         int p, q;
31         for (p = 1; p <= len; p++)
32             if (s[p] == '1') break;
33         for (q = len; q >= 1; q--)
34             if (s[q] == '1') break;
35         for (int i = p; i <= q; i++)
36             if (s[i] == '0') ans++;
37         printf("%d\n", ans);
38     }
39     return 0;
40 }
View Code

B:

写了个傻逼做法,崩了

 1 // /* basic header */
 2 // #include <bits/stdc++.h>
 3 // /* define */
 4 // #define ll long long
 5 // #define dou double
 6 // #define pb emplace_back
 7 // #define mp make_pair
 8 // #define sot(a,b) sort(a+1,a+1+b)
 9 // #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 // #define rep0(i,a,b) for(int i=a;i<b;++i)
11 // #define eps 1e-8
12 // #define int_inf 0x3f3f3f3f
13 // #define ll_inf 0x7f7f7f7f7f7f7f7f
14 // #define lson (curpos<<1)
15 // #define rson (curpos<<1|1)
16 // /* namespace */
17 // using namespace std;
18 // /* header end */
19 
20 // int t;
21 // ll n, g, b;
22 
23 // int main() {
24 //     scanf("%d", &t);
25 //     while (t--) {
26 //         scanf("%lld%lld%lld", &n, &g, &b);
27 //         ll goodNum = 0, badNum = 0, weekCount, ans = 0;
28 //         goodNum = n & 1 ? n / 2 + 1 : n / 2; badNum = n - goodNum;
29 //         weekCount = goodNum / g - 1;
30 //         goodNum -= weekCount * g, badNum -= weekCount * b;
31 //         if (goodNum < 0) goodNum = 0;
32 //         if (badNum < 0) badNum = 0;
33 //         ans = weekCount * (g + b);
34 //         while (goodNum) {
35 //             int delta = min(g, goodNum);
36 //             ans += delta; goodNum -= delta;
37 //             if (goodNum <= 0) break;
38 //             badNum -= b;
39 //             if (badNum < 0) badNum = 0;
40 //             ans += b;
41 //         }
42 //         ans += badNum;
43 //         printf("%lld\n", ans);
44 //     }
45 //     return 0;
46 // }
47 
48 /* basic header */
49 #include <bits/stdc++.h>
50 /* define */
51 #define ll long long
52 #define dou double
53 #define pb emplace_back
54 #define mp make_pair
55 #define sot(a,b) sort(a+1,a+1+b)
56 #define rep1(i,a,b) for(int i=a;i<=b;++i)
57 #define rep0(i,a,b) for(int i=a;i<b;++i)
58 #define eps 1e-8
59 #define int_inf 0x3f3f3f3f
60 #define ll_inf 0x7f7f7f7f7f7f7f7f
61 #define lson (curpos<<1)
62 #define rson (curpos<<1|1)
63 /* namespace */
64 using namespace std;
65 /* header end */
66 
67 int t;
68 
69 int main() {
70     cin >> t;
71     while (t--) {
72         ll N, n, g, b; cin >> n >> g >> b;
73         N = n, n = n + 1 >> 1;
74         ll ans = (n / g) * (g + b) + n % g;
75         if (n % g == 0 && n / g) ans -= b;
76         cout << max(ans, N) << endl;
77     }
78     return 0;
79 }
View Code

C:

建无向图dfs即可

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 int t;
21 vector<int>edge[26];
22 string s, ans;
23 bool used[26];
24 
25 void dfs(int v) {
26     if (used[v]) return;
27     ans += char('a' + v);
28     used[v] = 1;
29     for (auto to : edge[v]) {
30         if (!used[to]) dfs(to);
31     }
32 }
33 
34 int main() {
35     cin >> t;
36     while (t--) {
37         ans = "";
38         for (int i = 0; i < 26; i++) edge[i].clear();
39         memset(used, 0, sizeof(used));
40         cin >> s;
41         int n = s.size();
42         for (int i = 0; i < n - 1; i++) {
43             int a = s[i] - 'a', b = s[i + 1] - 'a';
44             edge[a].pb(b), edge[b].pb(a);
45         }
46         for (int i = 0; i < 26; i++) {
47             sort(edge[i].begin(), edge[i].end());
48             edge[i].erase(unique(edge[i].begin(), edge[i].end()), edge[i].end());
49         }
50         for (int i = 0; i < 26; i++)
51             if (!used[i] && edge[i].size() <= 1) dfs(i);
52         if (ans.size() < 26) {
53             puts("NO");
54             continue;
55         }
56         int flag = 1;
57         for (int i = 0; i < n - 1; i++) {
58             int pos1, pos2;
59             for (int j = 0; j < ans.size(); j++) {
60                 if (ans[j] == s[i]) pos1 = j;
61                 if (ans[j] == s[i + 1]) pos2 = j;
62             }
63             if (abs(pos1 - pos2) != 1) flag = 0;
64         }
65         if (!flag) puts("NO");
66         else printf("YES\n%s\n", ans.c_str());
67     }
68 }
View Code

D:

枚举2的幂,判断能否从低到高凑出n

 1 /* basic header */
 2 #include <bits/stdc++.h>
 3 /* define */
 4 #define ll long long
 5 #define dou double
 6 #define pb emplace_back
 7 #define mp make_pair
 8 #define sot(a,b) sort(a+1,a+1+b)
 9 #define rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 /* namespace */
17 using namespace std;
18 /* header end */
19 
20 ll n, sum;
21 int t, m, ans;
22 map<ll, int>cnt;
23 
24 int main() {
25     scanf("%d", &t);
26     while (t--) {
27         cnt.clear();
28         sum = 0, ans = 0;
29         scanf("%lld%d", &n, &m);
30         for (int i = 0; i < m; i++) {
31             ll x; scanf("%lld", &x);
32             sum += x; cnt[x]++;
33         }
34         if (sum < n) {
35             puts("-1");
36             continue;
37         }
38         for (int i = 0; i < 63; i++) {
39             ll j = 1ll << i;
40             if (cnt[j] < ((n >> i) & 1)) {
41                 ans++;
42                 cnt[j] += 2;
43                 cnt[j << 1] -= 1;
44             }
45             cnt[j << 1] += (cnt[j] - ((n >> i) & 1)) / 2;
46         }
47         printf("%d\n", ans);
48     }
49     return 0;
50 }
View Code

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!