Codeforces Edu Round 82 (Rated for Div. 2)

题目链接: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 }

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 }

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 }

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 }

原文地址:https://www.cnblogs.com/JHSeng/p/12302944.html

时间: 2024-10-17 07:31:37

Codeforces Edu Round 82 (Rated for Div. 2)的相关文章

Educational Codeforces Round 82 (Rated for Div. 2)

A 1必须和1相邻,把所有1和1之间的0去掉即可,就是统计1和1之间有多少个0 #include <iostream> #include <cstdio> #include <vector> int main(){ int T; read(T); while(T--){ char s[105]; cin >> s; int len = strlen(s); std::vector<int> v; for(int i = 0; i < len

Codeforces Edu Round 64 (Rated for Div. 2)

本来在快乐写题的,突然A数据炸了,全场重测,unrated…… 昨晚的题也有点毒,不过总体来说还算简单. A: 一开始我也wa on 3了,仔细想想就会发现有重点的情况. 比如n==3, 3 1 2.答案应该是6而不是7. 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 #d

Codeforces Edu Round 65 (Rated for Div. 2)

比较简单的一场. 题目链接:https://codeforces.com/contest/1167 A: 手速快三分钟就切了. 1 #include <bits/stdc++.h> 2 #define ll long long 3 #define pb push_back 4 #define mp make_pair 5 #define sot(a,b) sort(a+1,a+1+b) 6 #define rep(i,a,b) for (int i=a;i<=b;i++) 7 #defi

Codeforces Edu Round 66 (Rated for Div. 2)

题面很短,质量很好. 题目链接:https://codeforces.com/contest/1175 A: 给定n,k,有两种操作:1) n--,2) 当n%k==0时,可以n/=k.问最少多少步把n变成0. 傻逼题. 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 #de

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars

Educational Codeforces Round 69 (Rated for Div. 2) B - Pillars There are n pillars aligned in a row and numbered from 1 to n. Initially each pillar contains exactly one disk. The i-th pillar contains a disk having radius ai. You can move these disks

Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations

原文链接:https://www.cnblogs.com/xwl3109377858/p/11405773.html Educational Codeforces Round 71 (Rated for Div. 2) D - Number Of Permutations You are given a sequence of n pairs of integers: (a1,b1),(a2,b2),…,(an,bn). This sequence is called bad if it is

Educational Codeforces Round 36 (Rated for Div. 2)

Educational Codeforces Round 36 (Rated for Div. 2) F. Imbalance Value of a Tree You are given a tree T consisting of n vertices. A number is written on each vertex; the number written on vertex i is ai. Let's denote the function I(x,?y) as the differ

Educational Codeforces Round 36 (Rated for Div. 2) 题解

Educational Codeforces Round 36 (Rated for Div. 2) 题目的质量很不错(不看题解做不出来,笑 Codeforces 920C 题意 给定一个\(1\)到\(n\)组成的数组,只可以交换某些相邻的位置,问是否可以将数组调整为升序的 解题思路 首先如果每个数都能通过交换到它应该到的位置,那么就可以调整为升序的. 但实际上交换是对称的,如果应该在的位置在当前位置前方的数都交换完成,那么整体就是排好序的,因为不可能所有不在相应位置的数都在相应位置的后方.

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://codeforces.com/contest/985/problem/E Description Mishka received a gift of multicolored pencils for his birthday! Unfortunately he lives in a monochrome w