Codeforces Round #556 (Div. 2)

没想到平成年代最后一场cf居然是手速场,幸好拿了个小号娱乐不然掉分预定 (逃



A:

傻题。

 1 /* basic header */
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <cstdint>
 9 #include <climits>
10 #include <float.h>
11 /* STL */
12 #include <vector>
13 #include <set>
14 #include <map>
15 #include <queue>
16 #include <stack>
17 #include <algorithm>
18 #include <array>
19 #include <iterator>
20 /* define */
21 #define ll long long
22 #define dou double
23 #define pb emplace_back
24 #define mp make_pair
25 #define fir first
26 #define sec second
27 #define sot(a,b) sort(a+1,a+1+b)
28 #define rep1(i,a,b) for(int i=a;i<=b;++i)
29 #define rep0(i,a,b) for(int i=a;i<b;++i)
30 #define repa(i,a) for(auto &i:a)
31 #define eps 1e-8
32 #define int_inf 0x3f3f3f3f
33 #define ll_inf 0x7f7f7f7f7f7f7f7f
34 #define lson curPos<<1
35 #define rson curPos<<1|1
36 /* namespace */
37 using namespace std;
38 /* header end */
39
40 const int maxn = 1e2 + 10;
41 int n, m, r, minn = 2000, maxx = 0;
42
43 int main()
44 {
45     scanf("%d%d%d", &n, &m, &r);
46     rep1(i, 1, n)
47     {
48         int x; scanf("%d", &x); minn = min(minn, x);
49     }
50     rep1(i, 1, m)
51     {
52         int x; scanf("%d", &x); maxx = max(maxx, x);
53     }
54     if (maxx > minn) printf("%d\n", maxx * (r / minn) + r % minn);
55     else printf("%d\n", r);
56     return 0;
57 }

B:

乍一看以为要搜,其实根本不需要,n^2填进去判断就完事了 (看通过人数就能猜到根本不用搜。

至于为什么可以这样,是因为跟紧密填充相关吗?

 1 /* basic header */
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <cstdint>
 9 #include <climits>
10 #include <float.h>
11 /* STL */
12 #include <vector>
13 #include <set>
14 #include <map>
15 #include <queue>
16 #include <stack>
17 #include <algorithm>
18 #include <array>
19 #include <iterator>
20 /* define */
21 #define ll long long
22 #define dou double
23 #define pb emplace_back
24 #define mp make_pair
25 #define fir first
26 #define sec second
27 #define sot(a,b) sort(a+1,a+1+b)
28 #define rep1(i,a,b) for(int i=a;i<=b;++i)
29 #define rep0(i,a,b) for(int i=a;i<b;++i)
30 #define repa(i,a) for(auto &i:a)
31 #define eps 1e-8
32 #define int_inf 0x3f3f3f3f
33 #define ll_inf 0x7f7f7f7f7f7f7f7f
34 #define lson curPos<<1
35 #define rson curPos<<1|1
36 /* namespace */
37 using namespace std;
38 /* header end */
39
40 const int maxn = 55;
41 int a[maxn][maxn], n, solved = 0;
42 char s[maxn];
43
44 int check()
45 {
46     rep1(i, 1, n)
47     rep1(j, 1, n)
48     if (!a[i][j]) return 0;
49     return 1;
50 }
51
52 int putable(int x, int y)
53 {
54     if (x == 1 || x == n || y == 1 || y == n) return 0;
55     if (a[x - 1][y] || a[x + 1][y] || a[x][y - 1] || a[x][y + 1] || a[x][y]) return 0;
56     return 1;
57 }
58
59 int main()
60 {
61     scanf("%d", &n);
62     rep1(i, 1, n)
63     {
64         scanf("%s", s + 1);
65         rep1(j, 1, n)
66         if (s[j] == ‘#‘) a[i][j] = 1; else a[i][j] = 0;
67     }
68     rep1(i, 2, n - 1)
69     {
70         rep1(j, 2, n - 1)
71         if (putable(i, j))
72         {
73             a[i - 1][j] = a[i + 1][j] = a[i][j - 1] = a[i][j + 1] = a[i][j] = 1;
74         }
75     }
76     if (check()) puts("YES");
77     else puts("NO");
78     return 0;
79 }

C:

2e5质数筛贪心就完事了,优先满足最近的质数,先塞2再塞1,也有大佬说不用筛。

 1 /* basic header */
 2 #include <iostream>
 3 #include <cstdio>
 4 #include <cstdlib>
 5 #include <string>
 6 #include <cstring>
 7 #include <cmath>
 8 #include <cstdint>
 9 #include <climits>
10 #include <float.h>
11 /* STL */
12 #include <vector>
13 #include <set>
14 #include <map>
15 #include <queue>
16 #include <stack>
17 #include <algorithm>
18 #include <array>
19 #include <iterator>
20 /* define */
21 #define ll long long
22 #define dou double
23 #define pb emplace_back
24 #define mp make_pair
25 #define fir first
26 #define sec second
27 #define sot(a,b) sort(a+1,a+1+b)
28 #define rep1(i,a,b) for(int i=a;i<=b;++i)
29 #define rep0(i,a,b) for(int i=a;i<b;++i)
30 #define repa(i,a) for(auto &i:a)
31 #define eps 1e-8
32 #define int_inf 0x3f3f3f3f
33 #define ll_inf 0x7f7f7f7f7f7f7f7f
34 #define lson curPos<<1
35 #define rson curPos<<1|1
36 /* namespace */
37 using namespace std;
38 /* header end */
39
40 const int maxn = 2e5 + 10;
41 int c1 = 0, c2 = 0, n, prime[maxn], p = 1, tot;
42 vector<int>ans;
43
44 bool valid[maxn];
45 void getPrime(int n, int &tot, int ans[maxn])
46 {
47     tot = 0;
48     memset(valid, 1, sizeof(valid));
49     for (int i = 2; i <= n; i++)
50     {
51         if (valid[i]) ans[++tot] = i;
52         for (int j = 1; (j <= tot) && (i * ans[j] <= n); j++)
53         {
54             valid[i * ans[j]] = false;
55             if (i % ans[j] == 0) break;
56         }
57     }
58 }
59
60 int main()
61 {
62     getPrime(2e5, tot, prime);
63     ans.clear();
64     scanf("%d", &n);
65     rep1(i, 1, n)
66     {
67         int x; scanf("%d", &x);
68         if (x & 1) c1++; else c2++;
69     }
70     int curr = 0;
71     while (c1 || c2)
72     {
73         if (prime[p] - curr > 2 && c2)
74         {
75             ans.pb(2); c2--; curr += 2;
76         }
77         else if (prime[p] - curr == 2 && c2)
78         {
79             ans.pb(2); c2--; p++; curr += 2;
80         }
81         else if (prime[p] - curr == 1 && c1)
82         {
83             ans.pb(1); c1--; p++; curr += 1;
84         }
85         else
86         {
87             if (c2)
88             {
89                 ans.pb(2); c2--; curr += 2;
90             }
91             else if (c1)
92             {
93                 ans.pb(1); c1--; curr += 1;
94             }
95         }
96     }
97     for (auto i : ans) printf("%d ", i);
98     return 0;
99 }

D:

把全场人卡死的dp,直到比赛结束都只有不到20个人过了,待补。

E:

看了一眼感觉其实比D简单(我口胡的),待补。

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

时间: 2024-10-08 03:07:11

Codeforces Round #556 (Div. 2)的相关文章

Codeforces Round #556 (Div. 2) - C. Prefix Sum Primes(思维)

Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 1000 mSec Problem Description Input Output Sample Input 51 2 1 2 1 Sample Output 1 1 1 2 2 题解:这个题有做慢了,这种题做慢了和没做出来区别不大... 读题的时候脑子里还意识到素数除了2都是奇数,读完之后就脑子里就只剩欧拉筛了,贪心地构造使得前缀和是连续的素数,那

Codeforces Round #556 (Div. 2) - D. Three Religions(动态规划)

Problem  Codeforces Round #556 (Div. 2) - D. Three Religions Time Limit: 3000 mSec Problem Description Input Output Sample Input 6 8abdabc+ 1 a+ 1 d+ 2 b+ 2 c+ 3 a+ 3 b+ 1 c- 2 Sample Output YESYESYESYESYESYESNOYES 题解:动态规划,意识到这个题是动态规划之后难点在于要优化什么东西,本题

Codeforces Round #556 (Div. 2) C. Prefix Sum Primes

题目大意让你改变数组的排序,使前缀和的素数最多: 这是一道模拟题,让你通过判断1和2的个数来解决, 只要特判一下1的个数是零的时候,2的个数是零的时候,或者1只有一个而2的个数又不是0个的时候,剩下的情况我们只有把1的个数分奇数和偶数来考虑,大致思路是这样,接下来就看代码吧 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std

Codeforces Round #428 (Div. 2)

Codeforces Round #428 (Div. 2) A    看懂题目意思就知道做了 #include<bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") #define rep(i,a,b) for (int i=a; i<=b; ++i) #define per(i,b,a) for (int i=b; i>=a; --i

Codeforces Round #424 (Div. 2) D. Office Keys(dp)

题目链接:Codeforces Round #424 (Div. 2) D. Office Keys 题意: 在一条轴上有n个人,和m个钥匙,门在s位置. 现在每个人走单位距离需要单位时间. 每个钥匙只能被一个人拿. 求全部的人拿到钥匙并且走到门的最短时间. 题解: 显然没有交叉的情况,因为如果交叉的话可能不是最优解. 然后考虑dp[i][j]表示第i个人拿了第j把钥匙,然后 dp[i][j]=max(val(i,j),min(dp[i-1][i-1~j]))   val(i,j)表示第i个人拿

Codeforces Round #424 (Div. 2) C. Jury Marks(乱搞)

题目链接:Codeforces Round #424 (Div. 2) C. Jury Marks 题意: 给你一个有n个数序列,现在让你确定一个x,使得x通过挨着加这个序列的每一个数能出现所有给出的k个数. 问合法的x有多少个.题目保证这k个数完全不同. 题解: 显然,要将这n个数求一下前缀和,并且排一下序,这样,能出现的数就可以表示为x+a,x+b,x+c了. 这里 x+a,x+b,x+c是递增的.这里我把这个序列叫做A序列 然后对于给出的k个数,我们也排一下序,这里我把它叫做B序列,如果我

[Codeforces] Round #352 (Div. 2)

人生不止眼前的狗血,还有远方的狗带 A题B题一如既往的丝帛题 A题题意:询问按照12345678910111213...的顺序排列下去第n(n<=10^3)个数是多少 题解:打表,输出 1 #include<bits/stdc++.h> 2 using namespace std; 3 int dig[10],A[1005]; 4 int main(){ 5 int aa=0; 6 for(int i=1;;i++){ 7 int x=i,dd=0; 8 while(x)dig[++dd

Codeforces Round #273 (Div. 2)

Codeforces Round #273 (Div. 2) 题目链接 A:签到,仅仅要推断总和是不是5的倍数就可以,注意推断0的情况 B:最大值的情况是每一个集合先放1个,剩下都丢到一个集合去,最小值是尽量平均去分 C:假如3种球从小到大是a, b, c,那么假设(a + b) 2 <= c这个比較明显答案就是a + b了.由于c肯定要剩余了,假设(a + b)2 > c的话,就肯定能构造出最优的(a + b + c) / 3,由于肯定能够先拿a和b去消除c,而且控制a和b成2倍关系或者消除

Codeforces Round #339 (Div. 2) B. Gena&#39;s Code

B. Gena's Code It's the year 4527 and the tanks game that we all know and love still exists. There also exists Great Gena's code, written in 2016. The problem this code solves is: given the number of tanks that go into the battle from each country, f