首页 > 代码库 > Codeforces Round #413 Div.2

Codeforces Round #413 Div.2

A 一个if(但是我太弱了 写了一个迷之dfs

技术分享
 1 #include<cstdio>
 2 #include<cmath>
 3 #include<iostream>
 4 using namespace std;
 5 
 6 int ans1, ans2;
 7 int t1, t2;
 8 int n, t, k, d;
 9 
10 void dfs1(int ticks) {
11     if (ans1 >= n) {
12         t1 = ticks;
13         return ;
14     }
15     if (ticks % t == 0) {
16         ans1 += k;
17     }
18     dfs1(ticks + 1);
19 }
20 
21 
22 void dfs2(int ticks) {
23     if (ans2 >= n) {
24         t2 = ticks;
25         return ;
26     }
27     if (ticks % t == 0) {
28         ans2 += k;
29     }
30     if (ticks - d > 0 and (ticks - d) % t == 0) {
31         ans2 += k;
32     }
33     dfs2(ticks + 1);
34 }
35 
36 
37 int main() {
38     scanf("%d %d %d %d", &n, &t, &k, &d);
39     dfs1(1); dfs2(1);
40     puts(t1 <= t2 ? "NO" : "YES");
41     return 0;
42 }
View Code

B 对颜色开堆

技术分享
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<queue>
 4 #include<algorithm>
 5 #include<iostream>
 6 using namespace std;
 7 
 8 inline void read(int &ans) {
 9     static char ch = getchar();
10     register int neg = 1;
11     ans = 0;
12     for (; !isdigit(ch); ch = getchar())
13         if (ch == -) neg = -1;
14     for (; isdigit(ch); ch = getchar())
15         ans = ans * 10 + ch - 0;
16     ans *= neg;
17 }
18 const int N = 200010;
19 bool exist[N];
20 struct Node {
21     int p, id;
22 
23     bool operator< (const Node &rhs) const {
24         return p > rhs.p;
25     }
26 
27     inline void init(const int &i) {
28         read(p); id = i;
29     }
30 
31 } a[N];
32 priority_queue < Node > q[4];
33 int main() {
34     int n; read(n); memset(exist, true, sizeof(exist));
35     for (int i = 1; i <= n; ++i) a[i].init(i);
36     for (int c, i = 1; i <= n; ++i) read(c), q[c].push(a[i]);
37     for (int c, i = 1; i <= n; ++i) read(c), q[c].push(a[i]);
38     int m; read(m);
39     for (int c, i = 1; i <= m; ++i) {
40         read(c);
41         if (q[c].empty()) {
42             printf("-1 "); continue;
43         }
44         Node h;
45         do {
46             h = q[c].top(); q[c].pop();
47         }
48         while (!q[c].empty() and !exist[h.id]);
49         if (exist[h.id]) printf("%d ", h.p);
50         else printf("-1 ");
51         exist[h.id] = false;
52     }
53     return 0;
54 }
View Code

CDE 太弱了 不会

 

人生第一次涨rating 激动

Codeforces Round #413 Div.2