Codeforces Edu Round 65 (Rated for Div. 2)

Posted jhseng

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 #define eps 1e-8
 8 #define int_inf (1<<30)-1
 9 #define ll_inf (1LL<<62)-1
10 #define lson curPos<<1
11 #define rson curPos<<1|1
12 
13 using namespace std;
14 
15 int t;
16 
17 int main()
18 {
19     cin>>t;
20     while(t--){
21         int n; string s; cin>>n>>s;
22         int flag=0;
23         for (int i=0;i<n-10;i++) if (s[i]==8) flag=1;
24         if (flag) puts("YES"); else puts("NO");
25     }
26     return 0;
27 }
View Code

B:

非常简单的一道交互。读入a[1]*a[2],a[2]*a[3],a[3]*a[4],a[4]*a[5]之后next_permutation枚举就完事了。

技术图片
 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 fir first
 9 #define sec second
10 #define sot(a,b) sort(a+1,a+1+b)
11 #define rep1(i,a,b) for(int i=a;i<=b;++i)
12 #define rep0(i,a,b) for(int i=a;i<b;++i)
13 #define repa(i,a) for(auto &i:a)
14 #define eps 1e-8
15 #define int_inf 0x3f3f3f3f
16 #define ll_inf 0x7f7f7f7f7f7f7f7f
17 #define lson curPos<<1
18 #define rson curPos<<1|1
19 /* namespace */
20 using namespace std;
21 /* header end */
22 
23 const int maxn = 6;
24 int a[maxn] = {4, 8, 15, 16, 23, 42}, b[6];
25 
26 int main()
27 {
28     rep0(i, 0, 4)
29     {
30         printf("? %d %d\n", i + 1, i + 2); fflush(stdout);
31         scanf("%d", &b[i]);
32     }
33     do
34     {
35         if (a[0]*a[1] == b[0] && a[1]*a[2] == b[1] && a[2]*a[3] == b[2] && a[3]*a[4] == b[3])
36             return printf("! %d %d %d %d %d %d\n", a[0], a[1], a[2], a[3], a[4], a[5]), 0;
37     } while (next_permutation(a, a + 6));
38     return 0;
39 }
View Code

C:

一眼数据结构题,DSU维护即可。

技术图片
 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 fir first
 9 #define sec second
10 #define sot(a,b) sort(a+1,a+1+b)
11 #define rep1(i,a,b) for(int i=a;i<=b;++i)
12 #define rep0(i,a,b) for(int i=a;i<b;++i)
13 #define repa(i,a) for(auto &i:a)
14 #define eps 1e-8
15 #define int_inf 0x3f3f3f3f
16 #define ll_inf 0x7f7f7f7f7f7f7f7f
17 #define lson curPos<<1
18 #define rson curPos<<1|1
19 /* namespace */
20 using namespace std;
21 /* header end */
22 
23 struct DSU: vector<int>
24 {
25     vector<int>size;
26     DSU(int n): vector<int>(n), size(n, 1)
27     {
28         rep0(i, 0, n) at(i) = i;
29     }
30     int find(int u)
31     {
32         return at(u) == u ? u : at(u) = find(at(u));
33     }
34     void merge(int u, int v)
35     {
36         u = find(u), v = find(v);
37         if (u != v)
38         {
39             at(v) = u;
40             size[u] += size[v];
41         }
42     }
43 };
44 
45 int n, m;
46 
47 int main()
48 {
49     scanf("%d%d", &n, &m);
50     DSU dsu(n + 1);
51     rep1(i, 1, m)
52     {
53         int sum; scanf("%d", &sum);
54         if (sum)
55         {
56             int u; scanf("%d", &u);
57             rep0(j, 1, sum)
58             {
59                 int v; scanf("%d", &v); dsu.merge(u, v);
60             }
61         }
62     }
63     rep1(i, 1, n) printf("%d ", dsu.size[dsu.find(i)]);
64     puts("");
65     return 0;
66 }
View Code

D:

是个很简单的贪心,但是有非常巧妙的做法。

技术图片
 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 fir first
 9 #define sec second
10 #define sot(a,b) sort(a+1,a+1+b)
11 #define rep1(i,a,b) for(int i=a;i<=b;++i)
12 #define rep0(i,a,b) for(int i=a;i<b;++i)
13 #define repa(i,a) for(auto &i:a)
14 #define eps 1e-8
15 #define int_inf 0x3f3f3f3f
16 #define ll_inf 0x7f7f7f7f7f7f7f7f
17 #define lson curPos<<1
18 #define rson curPos<<1|1
19 /* namespace */
20 using namespace std;
21 /* header end */
22 
23 int n, x = 0, y = 0;
24 string s;
25 
26 int main()
27 {
28     cin >> n >> s;
29     for (auto i : s)
30         if (i == () cout << x, x ^= 1;
31         else cout << y, y ^= 1;
32     cout << endl;
33     return 0;
34 }
View Code

E:

暂时没想到怎么做,应该是个数据结构题。

F:

可以线段树但没必要,树状数组秒杀。

技术图片
 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 fir first
 9 #define sec second
10 #define sot(a,b) sort(a+1,a+1+b)
11 #define rep1(i,a,b) for(int i=a;i<=b;++i)
12 #define rep0(i,a,b) for(int i=a;i<b;++i)
13 #define repa(i,a) for(auto &i:a)
14 #define eps 1e-8
15 #define int_inf 0x3f3f3f3f
16 #define ll_inf 0x7f7f7f7f7f7f7f7f
17 #define lson curPos<<1
18 #define rson curPos<<1|1
19 /* namespace */
20 using namespace std;
21 /* header end */
22 
23 const int mod = 1e9 + 7;
24 const int maxn = 5e5 + 10;
25 ll a[maxn], b[maxn], c[maxn], ans = 0;
26 int n;
27 
28 void addmod(ll &a, ll b)
29 {
30     a += b;
31     if (a >= mod) a -= mod;
32     if (a < 0) a += mod;
33 }
34 
35 void add(int u, int val)
36 {
37     for (; u <= n; u += u & -u) addmod(c[u], val);
38 }
39 
40 ll sum(int u)
41 {
42     ll ret = 0;
43     for (; u > 0; u -= u & -u) addmod(ret, c[u]);
44     return ret;
45 }
46 
47 int id(int x)
48 {
49     return lower_bound(b, b + n, x) - b + 1;
50 }
51 
52 ll solve()
53 {
54     rep1(i, 1, n) c[i] = 0;
55     ll ans = 0;
56     rep0(i, 0, n)
57     {
58         ll curr = sum(id(a[i]));
59         addmod(ans, (a[i] * curr % mod) * (n - i) % mod);
60         add(id(a[i]), i + 1);
61     }
62     return ans;
63 }
64 
65 int main()
66 {
67     scanf("%d", &n);
68     rep0(i, 0, n) scanf("%lld", &a[i]), b[i] = a[i];
69     sort(b, b + n);
70     rep0(i, 0, n)
71     addmod(ans, a[i] * (i + 1) % mod * (n - i) % mod);
72     addmod(ans, solve());
73     reverse(a, a + n);
74     addmod(ans, solve());
75     printf("%lld\n", ans);
76     return 0;
77 }
View Code

G:

才3个人过的题,再见。

 

以上是关于Codeforces Edu Round 65 (Rated for Div. 2)的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces Edu Round 52 A-E

Codeforces Edu Round 48 A-D

Codeforces Edu Round 59 A-D

Codeforces Edu Round 67 (Rated for Div. 2)

Codeforces Edu Round 62 A-E

Codeforces Edu Round 82 (Rated for Div. 2)