Codeforces Round #441 (Div. 2, by Moscow Team Olympiad)

好久没打cf了,又打了一把。终于又涨rating了,很开心。

A 贪心

 1 #include<cstdio>
 2 #include<iostream>
 3 using namespace std;
 4 int main() {
 5     int n, a, b, c, ans = 0;
 6     scanf("%d%d%d%d", &n, &a, &b, &c);
 7     int mn = min(a, min(b, c));
 8     if (a == mn || b == mn) {
 9         ans = (n - 1) * mn;
10     } else if (n > 1) {
11         ans = min(a, b);
12         if (n > 2) ans += (n - 2) * c; 
13     } printf("%d\n", ans);
14     return 0;
15 }
View Code

B  

所以把模m的余数相同的丢一起就行了

 1 #include<cstdio>
 2 #include<vector>
 3 #include<iostream>
 4 using namespace std;
 5 inline char nc() {
 6     static char b[100000],*s=b,*t=b;
 7     return s==t&&(t=(s=b)+fread(b,1,100000,stdin),s==t)?-1:*s++;
 8 }
 9 inline void read(int &x) {
10     char b = nc(); x = 0;
11     for (; !isdigit(b); b = nc());
12     for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
13 }
14 int n, k, m;
15 vector < int > a[100010];
16 
17 int check() {
18     for (int i = 0; i < m; ++i) {
19         if (a[i].size() >= k) return i;
20     } return -1;
21 }
22 
23 int main() {
24     read(n); read(k); read(m);
25     for (int t, i = 1; i <= n; ++i) {
26         read(t); a[t%m].push_back(t);
27     } int p = check();
28     if (p == -1) puts("No");
29     else {
30         puts("Yes");
31         for (int i = 0; i < k; ++i) printf("%d ", a[p][i]);
32         puts("");
33     }
34     return 0;
35 }
View Code

C 暴力

 1 #include<stack>
 2 #include<cstdio>
 3 #include<iostream>
 4 using namespace std;
 5 
 6 int calc(int x) {
 7     int res = 0;
 8     for (; x; x /= 10) res += x % 10;
 9     return res;
10 }
11 stack < int > ans;
12 int main() {
13     int n, j = 0;
14     scanf("%d", &n);
15     for (int i = n - 1; i >= 0; --i) {
16         if (i + calc(i) == n) ans.push(i);
17         if (++j > 1e7) break;
18     } printf("%lu\n", ans.size());
19     while (!ans.empty()) {
20         printf("%d\n", ans.top()); ans.pop();
21     }
22     return 0;
23 }
View Code

D 找出没有和右端点相连的个数即可

 1 #include<cstdio>
 2 #include<vector>
 3 #include<queue>
 4 #include<iostream>
 5 #define lowbit(x) ((x)&(-x))
 6 using namespace std;
 7 inline char nc() {
 8     static char b[100000],*s=b,*t=b;
 9     return s==t&&(t=(s=b)+fread(b,1,100000,stdin),s==t)?-1:*s++;
10 }
11 inline void read(int &x) {
12     char b = nc(); x = 0;
13     for (; !isdigit(b); b = nc());
14     for (; isdigit(b); b = nc()) x = x * 10 + b - '0';
15 }
16 const int N = 300010;
17 int n;
18 priority_queue < int > q;
19 int main() {
20     read(n); int lst = n; 
21     putchar('1');
22     for (int t, i = 1; i <= n; ++i) {
23         read(t); q.push(t);
24         while (!q.empty() && q.top() == lst) {
25             lst = q.top() - 1; q.pop();
26         } printf(" %d", q.size() + 1);
27     }
28     return 0;
29 }
View Code

EF没做

posted @ 2017-10-17 19:58  p0ny  阅读(152)  评论(0编辑  收藏  举报