Codeforces Round #552(div.3)

Problem: http://codeforces.com/contest/1154



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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 #define lson curPos<<1
36 #define rson curPos<<1|1
37 /* namespace */
38 using namespace std;
39 /* header end */
40
41 int a[5];
42
43 int main()
44 {
45     cin >> a[1] >> a[2] >> a[3] >> a[4];
46     sot(a, 4);
47     cout << a[4] - a[1] << " " << a[4] - a[2] << " " << a[4] - a[3] << endl;
48     return 0;
49 }

B: 一开始看错题了

 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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 #define lson curPos<<1
36 #define rson curPos<<1|1
37 /* namespace */
38 using namespace std;
39 /* header end */
40
41 set<int>s;
42 int n, x;
43
44 int main()
45 {
46     s.clear();
47     cin >> n;
48     rep1(i, 1, n)
49     {
50         cin >> x;
51         s.insert(x);
52     }
53     if (s.size() == 1) puts("0");
54     else if (s.size() == 2)
55     {
56         int b[2], p = 0;
57         for (auto i : s) b[p++] = i;
58         sort(b, b + 2);
59         if ((b[1] - b[0]) % 2 == 0)
60             cout << (b[1] - b[0]) / 2 << endl;
61         else
62             cout << b[1] - b[0] << endl;
63     }
64     else if (s.size() >= 4) puts("-1");
65     else
66     {
67         int b[3], p = 0;
68         for (auto i : s) b[p++] = i;
69         sort(b, b + 3);
70         if (b[2] - b[1] == b[1] - b[0]) cout << b[1] - b[0] << endl;
71         else puts("-1");
72     }
73     return 0;
74 }

C:

 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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 #define lson curPos<<1
36 #define rson curPos<<1|1
37 /* namespace */
38 using namespace std;
39 /* header end */
40
41 int a, b, c, ans = 0;
42
43 int main()
44 {
45     scanf("%d%d%d", &a, &b, &c);
46     int week = min(a / 3, min(b / 2, c / 2));
47     a -= week * 3, b -= week * 2, c -= week * 2, ans += week * 7;
48     int pre = ans;
49     rep1(i, 1, 7)
50     {
51         int x = a, y = b, z = c, tmp = pre;
52         rep1(j, i, i + 6)
53         {
54             int curr = j > 7 ? j - 7 : j;
55             if (curr == 1 || curr == 4 || curr == 7)
56             {
57                 if (x)x--, tmp++; else break;
58             }
59             else if (curr == 2 || curr == 6)
60             {
61                 if (y) y--, tmp++; else break;
62             }
63             else if (curr == 3 || curr == 5)
64             {
65                 if (z) z--, tmp++; else break;
66             }
67         }
68         ans = max(ans, tmp);
69     }
70     printf("%d\n", ans);
71     return 0;
72 }

D:

 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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 #define lson curPos<<1
36 #define rson curPos<<1|1
37 /* namespace */
38 using namespace std;
39 /* header end */
40
41 int n, a, b;
42
43 int main()
44 {
45     scanf("%d%d%d", &n, &a, &b);
46     int ans = 0, tmp = b;
47     rep1(i, 1, n)
48     {
49         int x; scanf("%d", &x);
50         if (x == 1 && a && tmp > b)
51         {
52             ++ans, --a, b = min(++b, tmp);
53         }
54         else if (b) ++ans, --b;
55         else if (a) ++ans, --a;
56         else break;
57     }
58     printf("%d\n", ans);
59     return 0;
60 }

E:

 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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 /* namespace */
36 using namespace std;
37 /* header end */
38
39 const int maxn = 2e5 + 10;
40 int n, k, p = 1, a[maxn], l[maxn], r[maxn], ans[maxn];
41 priority_queue<int>q;
42
43 int main()
44 {
45     scanf("%d%d", &n, &k);
46     l[0] = r[0] = 0; l[n + 1] = r[n + 1] = n + 1;
47     rep1(i, 1, n)
48     {
49         int x; scanf("%d", &x);
50         q.push(x);
51         a[x] = i, l[i] = i - 1, r[i] = i + 1;
52     }
53     while (!q.empty() && p++)
54     {
55         while (!q.empty() && ans[a[q.top()]]) q.pop();
56         if (q.empty()) break;
57         int pos = a[q.top()]; q.pop();
58         ans[pos] = p % 2 + 1;
59         int lpos = pos, rpos = pos;
60         rep1(i, 1, k)
61         {
62             lpos = l[lpos], rpos = r[rpos];
63             ans[lpos] = ans[rpos] = p % 2 + 1;
64         }
65         l[r[rpos]] = l[lpos], r[l[lpos]] = r[rpos];
66     }
67     rep1(i, 1, n) printf("%d", ans[i]);
68     puts("");
69     return 0;
70 }

F: 简单dp。注释掉的部分是自己写的,但是过不了。看了一下大佬的思路

 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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 #define lson curPos<<1
36 #define rson curPos<<1|1
37 /* namespace */
38 using namespace std;
39 /* header end */
40
41 const int maxn = 2e3 + 10;
42 const int maxm = 2e5 + 10;
43 int n, m, k, a[maxm], off[maxn], dp[maxn], s[maxn];
44
45 int calc(int num)
46 {
47     // if (num > k) return 0;
48     // ll ret = 1e17;
49     // rep1(i, 1, k)
50     // {
51     //     if (!off[i]) continue;
52     //     ret = min(ret, calc(num - i) + s[num] - s[num - i + off[i]]);
53     // }
54     // ret = min(ret, s[num]);
55     // return dp[num] = ret;
56     if (num > k) return 0;
57     int &ans = dp[num];
58     if (~ans) return ans;
59     ans = int_inf;
60     ans = min(ans, calc(num + 1) + a[num]);
61     rep1(i, 1, k)
62     {
63         int x = i, y = off[i];
64         if (!y) continue;
65         if (num + x <= k + 1)
66             ans = min(ans, calc(num + x) + s[num + x - 1] - s[num + y - 1]);
67     }
68     return ans;
69 }
70
71 int main()
72 {
73     scanf("%d%d%d", &n, &m, &k);
74     rep1(i, 1, n) scanf("%d", &a[i]);
75     sot(a, n);
76     rep1(i, 1, k)
77     {
78         dp[i] = -1;
79         s[i] = s[i - 1] + a[i];
80     }
81     rep1(i, 1, m)
82     {
83         int num, y; scanf("%d%d", &num, &y);
84         if (num > k) continue;
85         off[num] = max(off[num], y);
86     }
87     printf("%d\n", calc(1));
88     return 0;
89 }

G: 枚举gcd

 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 init(a,b) fill(begin(a),end(a),b)
28 #define sot(a,b) sort(a+1,a+1+b)
29 #define rep1(i,a,b) for(int i=a;i<=b;++i)
30 #define rep0(i,a,b) for(int i=a;i<b;++i)
31 #define repa(i,a) for(auto &i:a)
32 #define eps 1e-8
33 #define int_inf 0x3f3f3f3f
34 #define ll_inf 0x7f7f7f7f7f7f7f7f
35 #define lson curPos<<1
36 #define rson curPos<<1|1
37 /* namespace */
38 using namespace std;
39 /* header end */
40
41 const int maxn = 1e7 + 10;
42 int n, vis[maxn], qu[5];
43 ll ansLcm = ll_inf, a, b;
44
45 int main()
46 {
47     scanf("%d", &n);
48     rep1(i, 1, n)
49     {
50         int x; scanf("%d", &x);
51         if (vis[x])
52         {
53             if (ansLcm > x)
54             {
55                 ansLcm = x;
56                 a = vis[x];
57                 b = i;
58             }
59         }
60         else vis[x] = i;
61     }
62     rep1(i, 1, 1e7)
63     {
64         int len = 0;
65         for (int j = i; j <= 1e7; j += i)
66         {
67             if (vis[j]) qu[len++] = j;
68             if (len == 2) break;
69         }
70         if (len == 2)
71         {
72             ll num1 = qu[0], num2 = qu[1], tmpLcm = num1 * num2 / i;
73             if (tmpLcm < ansLcm)
74             {
75                 ansLcm = tmpLcm, a = vis[num1], b = vis[num2];
76             }
77         }
78     }
79     if (a > b) swap(a, b);
80     printf("%lld %lld\n", a, b);
81     return 0;
82 }

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

时间: 2024-08-30 13:51:19

Codeforces Round #552(div.3)的相关文章

Codeforces Round #552 (Div. 3) C题

题目网址:http://codeforces.com/contest/1154/problem/C 题目意思:小猫吃三种食物,A,B,C,一周吃食物的次序是,A,B,C,A,C,B,A,当小猫该天无食物可吃时,就会饿死,现给出a,b,c三个数,表示A,B,C的食物数量, 选择一天开始,问小猫最多可以活到多少天. 题解:首先,在一周时间,A要吃三天,B要吃两天,C要吃两天,先随便选一天开始,当剩下食物不足以撑过一周时停止,再细分剩下的食物数量,看小猫饿 死是经过的最多天数.选择的天数用暴力写即可.

Codeforces Round #552 (Div. 3) Editorial 1154C - Gourmet Cat

链接:https://codeforces.com/contest/1154/problem/C 题意:一只旅行的小猫在特定的星期里吃特定的食物,一四七a,二六b,三五c,现在给三种食物的数量,问小猫最多能活几天. 思路:先看小猫能活几个整星期,因为a在一个星期里占三天,b和c各占两天,所以取min(a/3,b/2,c/2),然后求剩下的,这个时候就可以枚举日子了,从周一枚举到周日,然后模拟一哈就行了,虽然是个水题但我还是没做粗来 代码: 1 //#include<bits/stdc++.h>

Codeforces Round #552 (Div. 3)-D-Walking Robot-(贪心)

http://codeforces.com/contest/1154/problem/D 解题: 1.无光的时候优先使用太阳能电池. 2.有光的时候 (1)太阳能电池没满电,让它充,使用普通电池 (2)太阳能电池满电,使用太阳能电池 #include<stdio.h> #include<math.h> #include<string.h> #include<algorithm> #include<string> #include<vecto

Codeforces Round #552 (Div. 3)-1154E-Two Teams-(模拟+双指针)

http://codeforces.com/contest/1154/problem/E 解题: 举例n=10,k=1 1,2,10,4,7,6,9,8,5,3 第一次,1队先挑2,10,4这三个人 1,2,10,4,7,6,9,8,5,3 第二次,2队挑6,9,8三个人 1,2,10,4,7,6,9,8,5,3 第三次,1队挑1,7,5三个人 1,2,10,4,7,6,9,8,5,3 第四次,2队挑3一个人 1,2,10,4,7,6,9,8,5,3 显然需要实现的有两点 (1)挑完后的“连接”

Codeforces Round #552 (Div. 3) E C++

题目: E. Two Teams time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output There are nn students standing in a row. Two coaches are forming two teams — the first coach chooses the first team and the

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