zoukankan      html  css  js  c++  java
  • Codeforces Edu Round 68 (Rated for Div. 2)

    比较水的一场。

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


    A:

    秒懂跟x没关系,答案就是2n。

    B:

    因为n*m<=4e5,统计每行每列点的数量后直接O(nm)暴力枚举维护最小值即可。

     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 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int main() {
    21     int t; cin >> t;
    22     while (t--) {
    23         int n, m, ans = int_inf; cin >> n >> m;
    24         char s[n + 1][m + 1];
    25         int row[n + 1] = {0}, col[m + 1] = {0};
    26         rep1(i, 1, n) {
    27             scanf("%s", s[i] + 1);
    28             rep1(j, 1, m) {
    29                 if (s[i][j] == '.') row[i]++, col[j]++;
    30             }
    31         }
    32         rep1(i, 1, n) {
    33             rep1(j, 1, m) {
    34                 int k = row[i] + col[j];
    35                 if (s[i][j] == '.') k--;
    36                 ans = min(ans, k);
    37             }
    38         }
    39         printf("%d
    ", ans);
    40     }
    41     return 0;
    42 }
    View Code

    C:

    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 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 110;
    21 int q;
    22 
    23 int main() {
    24     scanf("%d", &q);
    25     while (q--) {
    26         string s, t, p; cin >> s >> t >> p;
    27         int len1 = s.size(), len2 = t.size(), len3 = p.size(), ans = 1;
    28         int a[26] = {0};
    29         for (auto c : p) a[c - 'a']++;
    30         int i = 0, j = 0;
    31         for (; i < len2; i++) {
    32             if (j < len1 && t[i] == s[j]) j++;
    33             else if (a[t[i] - 'a']) a[t[i] - 'a']--;
    34             else {
    35                 ans = 0;
    36                 break;
    37             }
    38         }
    39         if (j != len1) ans = 0;
    40         if (ans) puts("YES"); else puts("NO");
    41     }
    42     return 0;
    43 }
    View Code

    D:

    一看就是SG函数相关的题,打个表找规律发现循环节长度为3。简单推一下必胜必败点也可以猜出来。

     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 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 int t;
    21 
    22 int main() {
    23     scanf("%d", &t);
    24     while (t--) {
    25         int n, k; scanf("%d%d", &n, &k);
    26         if (k % 3 == 0) {
    27             int p = n % (k + 1) + 1;
    28             if (p == k + 1) {
    29                 puts("Alice");
    30                 continue;
    31             } else {
    32                 if (p % 3 == 1) puts("Bob");
    33                 else puts("Alice");
    34             }
    35         } else {
    36             if (n % 3 == 0) puts("Bob");
    37             else puts("Alice");
    38         }
    39     }
    40     return 0;
    41 }
    View Code

    E:

    树状数组+扫描线。

     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 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 1e4 + 10;
    21 int n, m, tot1 = 0, tot2 = 0, c[maxn], vis[maxn];
    22 ll ans = 0;
    23 
    24 struct Vert {
    25     int x, y, xx;
    26     bool operator<(const Vert &rhs)const {
    27         return y < rhs.y;
    28     }
    29 } v[maxn];
    30 
    31 struct Hori {
    32     int x, y, yy;
    33     bool operator<(const Hori &rhs)const {
    34         return yy < rhs.yy;
    35     }
    36 } h[maxn];
    37 
    38 int lowbit(int x) {
    39     return x & -x;
    40 }
    41 
    42 int find(int x) {
    43     int ret = 0;
    44     while (x > 0) {
    45         ret += c[x];
    46         x -= lowbit(x);
    47     }
    48     return ret;
    49 }
    50 
    51 void add(int x, int val) {
    52     while (x <= 10001) {
    53         c[x] += val;
    54         x += lowbit(x);
    55     }
    56 }
    57 
    58 int main() {
    59     scanf("%d", &n);
    60     rep1(i, 1, n) {
    61         int x, y, xx, yy; scanf("%d%d%d%d", &x, &y, &xx, &yy);
    62         x += 5001, y += 5001, xx += 5001, yy += 5001;
    63         if (x == xx) h[++tot2] = (Hori) {
    64             x, min(y, yy), max(y, yy)
    65         };
    66         else v[++tot1] = (Vert) {
    67             min(x, xx), y, max(x, xx)
    68         };
    69     }
    70     sot(v, tot1); sot(h, tot2);
    71     sort(v + 1, v + 1 + tot1);
    72     sort(h + 1, h + 1 + tot2);
    73     rep1(i, 1, tot1) {
    74         rep0(j, 0, maxn) c[j] = 0;
    75         rep1(j, 1, tot2) {
    76             if (h[j].y <= v[i].y && h[j].yy >= v[i].y) {
    77                 add(h[j].x, 1);
    78                 vis[j] = 1;
    79             } else vis[j] = 0;
    80         }
    81         int k = 1;
    82         rep1(j, i + 1, tot1) {
    83             while (k <= tot2 && h[k].yy < v[j].y) {
    84                 if (vis[k]) add(h[k].x, -1);
    85                 k++;
    86             }
    87             int l = max(v[i].x, v[j].x) - 1, r = min(v[i].xx, v[j].xx);
    88             if (l < r) {
    89                 int x = find(r) - find(l);
    90                 ans += 1LL * x * (x - 1) / 2;
    91             }
    92         }
    93     }
    94     printf("%lld
    ", ans);
    95     return 0;
    96 }
    View Code

    F && G:

    不会,溜了(

  • 相关阅读:
    你自己不优秀,就算认识再多优秀人又有何用
    史玉柱和他老同学的一段故事
    哪有雪中送碳,都是锦上添花
    围城之困
    心已死,梦前行
    一位销售高手逼单经历!
    Python--函数return多个值
    Python--内置函数
    Python--小程序
    Python--递归
  • 原文地址:https://www.cnblogs.com/JHSeng/p/11190004.html
Copyright © 2011-2022 走看看