码迷,mamicode.com
首页 > 其他好文 > 详细

Codeforces Round #567 (div. 2)

时间:2019-07-17 00:12:16      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:c++   color   leader   already   hid   turn   hat   notice   org   

题目链接:https://codeforces.com/contest/1181


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 rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 #define mid (curl+curr>>1)
17 /* namespace */
18 using namespace std;
19 /* header end */
20 
21 ll x, y, z;
22 
23 int main() {
24     cin >> x >> y >> z;
25     cout << (x + y) / z << " ";
26     ll a = (x + y) % z, b = y / z, c = x / z;
27     if (x % z + y % z == a) return puts("0"), 0; // the most balanced state
28     if (x % z) c++; if (y % z) b++;
29     cout << min(b * z - y, c * z - x) << endl;
30     return 0;
31 }
View Code

B:

没啥好说的,就是O(n)暴力。

技术图片
 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 rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 #define mid (curl+curr>>1)
17 /* namespace */
18 using namespace std;
19 /* header end */
20 
21 const int maxn = 1e5 + 10;
22 int a[maxn], b[maxn], c[maxn], tmp[maxn], s[maxn];
23 int sLen = maxn, n;
24 
25 void calc(int p) {
26     if (!a[p + 1]) return; // leader zero in array c
27     int bLen = p, cLen = n - p;
28     for (int i = 0; i < maxn; i++) b[i] = 0;
29     for (int i = 0; i < maxn; i++) c[i] = 0;
30     for (int i = 0; i < maxn; i++) tmp[i] = 0;
31     rep1(i, 1, bLen) b[bLen - i + 1] = a[i];
32     rep1(i, 1, cLen) c[cLen - i + 1] = a[p + i];
33     int tmpLen = max(bLen, cLen);
34     rep1(i, 1, tmpLen) {
35         tmp[i] += b[i] + c[i];
36         if (tmp[i] > 9) {
37             tmp[i] -= 10;
38             tmp[i + 1]++;
39         }
40     }
41     if (tmp[tmpLen + 1]) ++tmpLen;
42     if (tmpLen < sLen) {
43         sLen = tmpLen;
44         memcpy(s, tmp, sizeof(s));
45     } else if (tmpLen == sLen) {
46         int flag = 0;
47         for (int i = tmpLen; i; i--)
48             if (tmp[i] < s[i]) {
49                 flag = 1;
50                 break;
51             } else if (tmp[i] > s[i]) break;
52         if (flag) memcpy(s, tmp, sizeof(s));
53     }
54 }
55 
56 int main() {
57     scanf("%d", &n);
58     rep1(i, 1, n) scanf("%1d", &a[i]);
59     for (int i = (n >> 1); i && sLen == maxn; i--) { // solution exists when sLen!=maxn
60         calc(i); calc(n - i);
61     }
62     for (int i = sLen; i; i--) printf("%d", s[i]);
63     puts("");
64     return 0;
65 }
View Code

C:

看起来不是很好做,其实算是大模拟。

技术图片
 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 rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 #define mid (curl+curr>>1)
17 /* namespace */
18 using namespace std;
19 /* header end */
20 
21 const int maxn = 1e3 + 10;
22 int n, m, a[maxn][maxn];
23 char s[maxn][maxn];
24 ll ans;
25 
26 int main() {
27     scanf("%d%d", &n, &m);
28     rep1(i, 1, n) scanf("%s", s[i] + 1);
29     rep1(j, 1, m) {
30         for (int i = n; i; i--) {
31             // a[i][j] means a[i][j] blocks‘ color are same with current one below, including current block
32             if (s[i][j] != s[i + 1][j]) a[i][j] = 1;
33             else a[i][j] = a[i + 1][j] + 1;
34         }
35     }
36     rep1(i, 1, n) {
37         rep1(j, 1, m) {
38             int num = a[i][j];
39             if (num * 3 + i - 1 > n) continue; // judge the length of the flag
40             ll cnt = 0;
41             // if current condition satisfly to form a flag
42             while (a[i + num][j] == num && a[i + 2 * num][j] >= num) {
43                 cnt++; j++;
44                 if (a[i][j] != num) {
45                     j--; break;
46                 }
47                 if (s[i][j] != s[i][j - 1]) {
48                     j--; break;
49                 }
50                 if (s[i + num][j] != s[i + num][j - 1]) {
51                     j--; break;
52                 }
53                 if (s[i + 2 * num][j] != s[i + 2 * num][j - 1]) {
54                     j--; break;
55                 }
56             }
57             ans += (cnt + 1) * cnt / 2;
58         }
59     }
60     printf("%lld\n", ans);
61     return 0;
62 }
View Code

D:

一开始以为要离线做,其实特殊处理一下之后在线也可以做。官方题解写得很好:

Let‘s solve all the queries simultaneously. For this purpose sort them all in increasing order. Sort all the countries based on the number of hosted competitions in the first n years.

How this diagram changes after several more years of the competition? The cells are filled from lower rows to the higher, while inside one row we order cells based on the country number.

Let‘s fill this table from bottom upwards.

For the queries which won‘t be replied in the current row, it is not important in which order the cells in the current row are colored, only the quantity is important. So for such queries we can simply accumulate the number of already painted cells so far.

Now let‘s discuss the queries, which need to be answered in the current row. If we subtract from k (the query parameter) the number S of cells painted in previous rows, then we simply need to return the ks th element in this set. So in other words we need to add countries in the set and sometimes compute i-th element in it. One can use cartesian tree "treap" or a segment tree to do that.

It may also turn out, that after we fill all the diagram, there are some questions unanswered yet. In this case we can notice, that all the subsequent rows look like the whole set of countries. So the answer is simply the remainder of kS modulo m.

Since we only need to consider at most nn lines until the diagram is filled-up, the solution works in O((q+n+m)log)

技术图片
 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 rep1(i,a,b) for(int i=a;i<=b;++i)
10 #define rep0(i,a,b) for(int i=a;i<b;++i)
11 #define eps 1e-8
12 #define int_inf 0x3f3f3f3f
13 #define ll_inf 0x7f7f7f7f7f7f7f7f
14 #define lson (curpos<<1)
15 #define rson (curpos<<1|1)
16 #define mid (curl+curr>>1)
17 /* namespace */
18 using namespace std;
19 /* header end */
20 
21 const int maxn = 5e5 + 10;
22 int n, m, q, times[maxn];
23 ll a[maxn];
24 
25 int main() {
26     scanf("%d%d%d", &n, &m, &q);
27     rep1(i, 1, n) {
28         int x; scanf("%d", &x);
29         a[i] = (ll)(times[x]++) * m + x;
30     }
31     sot(a, n);
32     rep1(i, 1, n) a[i] -= i;
33     while (q--) {
34         ll k; scanf("%lld", &k);
35         k += lower_bound(a + 1, a + 1 + n, k - n) - a - 1 - n;
36         printf("%lld\n", (k - 1) % m + 1);
37     }
38     return 0;
39 }
View Code

E1 && E2:

不会,溜了(

 

Codeforces Round #567 (div. 2)

标签:c++   color   leader   already   hid   turn   hat   notice   org   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!