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 }

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 }

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 }

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 }

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 }

G:

才3个人过的题,再见。

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

时间: 2024-08-01 16:26:11

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

[ Educational Codeforces Round 65 (Rated for Div. 2)][二分]

https://codeforc.es/contest/1167/problem/E E. Range Deleting time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an array consisting of nn integers a1,a2,…,ana1,a2,…,an and an in

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 r

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 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 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 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) 题目的质量很不错(不看题解做不出来,笑 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