• Codeforces Round #619 (Div. 2)


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


    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 /* namespace */
    17 using namespace std;
    18 /* header end */
    19 
    20 const int maxn = 110;
    21 int t;
    22 
    23 int main() {
    24     scanf("%d", &t);
    25     while (t--) {
    26         char a[maxn], b[maxn], c[maxn];
    27         scanf("%s", a + 1);
    28         scanf("%s", b + 1);
    29         scanf("%s", c + 1);
    30         int len = strlen(a + 1), flag = 1;
    31         for (int i = 1; i <= len; i++) {
    32             if (a[i] == c[i] ||  b[i] == c[i] ) continue;
    33             else {
    34                 flag = 0; break;
    35             }
    36         }
    37         if (flag) puts("YES"); else puts("NO");
    38     }
    39     return 0;
    40 }
    View Code

    B:

    k值一定是所有正数最大最小值之差除2,注意坑点是m值受相邻正数之差的影响。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define pb emplace_back
     6 #define mp make_pair
     7 #define eps 1e-8
     8 #define lson (curpos<<1)
     9 #define rson (curpos<<1|1)
    10 /* namespace */
    11 using namespace std;
    12 /* header end */
    13 
    14 const int maxn = 1e5 + 10;
    15 int t, n, a[maxn];
    16 
    17 int main() {
    18     scanf("%d", &t);
    19     while (t--) {
    20         scanf("%d", &n);
    21         for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    22         int base = 0;
    23         vector<int>v;
    24         for (int i = 1; i < n; i++) {
    25             if (a[i] == -1 && a[i + 1] != -1) v.pb(a[i + 1]);
    26             else if (a[i] != -1 && a[i + 1] == -1) v.pb(a[i]);
    27             else if (a[i] != -1 && a[i + 1] != -1) base = max(base, abs(a[i] - a[i + 1]));
    28         }
    29         if (v.empty()) {
    30             puts("0 0");
    31             continue;
    32         }
    33         sort(v.begin(), v.end());
    34         int k = (v.back() + *v.begin()) / 2;
    35         printf("%d %d
    ", max({v.back() - k, k - v[0], base}), k);
    36     }
    37     return 0;
    38 }
    View Code

    C:

    f(s)=所有子串个数-不含1的子串个数,当s长度为n时,显然f(s)=(n+1)*n/2-不含1的子串个数。对于不含1的子串个数,我们只需要找出所有连续“0”的子串,再减去他们的子串个数即可。

    现在我们有一个包含n-m个0的01串,我们希望这n-m个0能分布得尽量平均,从而使得答案尽量大。显然m个1就成为了m个隔板,n-m个0会被分为m+1组,每组至少为k=(n-m)/(m+1)个。其中前(n-m)%(m+1)组有k+1个0,剩下的组有k个0。

    所以ans=(n+1)*n/2-(k+1)*k/2*(m+1-(n-m)%(m+1))-(k+1)*(k+2)/2*((n-m)%(m+1))=(n+1)*n/2-(k+1)*k/2*g-(k+1)*(n-m)%(m+1)。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define pb emplace_back
     6 #define mp make_pair
     7 #define eps 1e-8
     8 #define lson (curpos<<1)
     9 #define rson (curpos<<1|1)
    10 /* namespace */
    11 using namespace std;
    12 /* header end */
    13 
    14 int t;
    15 ll n,m;
    16 
    17 int main() {
    18     scanf("%d",&t);
    19     while (t--){
    20         scanf("%lld%lld",&n,&m);
    21         ll ans=(n+1)*n/2, cnt=(n-m)/(m+1);
    22         ans-=cnt*(cnt+1)/2*(m+1-(n-m)%(m+1))+(cnt+1)*(cnt+2)/2*((n-m)%(m+1));
    23         printf("%lld
    ",ans);
    24     }
    25     return 0;
    26 }
    View Code

    D:

    从左上角出发,当人在第一列时,直接往下走到底再往上走到顶,然后向右走;当人不在第一列时,一直重复“DLR”直到走到底,再往上走到顶,再往右走。最后走到顶直接往左走回到左上角即可。

     1 /* basic header */
     2 #include <bits/stdc++.h>
     3 /* define */
     4 #define ll long long
     5 #define pb emplace_back
     6 #define mp make_pair
     7 #define eps 1e-8
     8 #define lson (curpos<<1)
     9 #define rson (curpos<<1|1)
    10 /* namespace */
    11 using namespace std;
    12 /* header end */
    13 
    14 int n, m, k, curx = 1, cury = 1;
    15 struct Path {
    16     int n;
    17     string s;
    18     Path() {}
    19     Path(int _n, string _s): n(_n), s(_s) {}
    20 };
    21 vector<Path>ans;
    22 
    23 int main() {
    24     ans.clear();
    25     scanf("%d%d%d", &n, &m, &k);
    26     if (k > 4 * n * m - 2 * n - 2 * m) return puts("NO"), 0;
    27     puts("YES");
    28     for (cury = 1; cury <= m; cury++) {
    29         if (!k) break;
    30         if (cury == 1) {
    31             int step = min(n - 1, k);
    32             k -= step;
    33             if (step) ans.pb(Path(step, "D"));
    34             if (k) {
    35                 int step = min(n - 1, k);
    36                 k -= step;
    37                 if (step) ans.pb(Path(step, "U"));
    38             }
    39             continue;
    40         }
    41         // 往右走一格
    42         ans.pb(Path(1, "R"));
    43         k--;
    44         if (!k) break;
    45         int cnt = 0;
    46         while (k >= 3 && curx < n) {
    47             k -= 3; curx++; cnt++;
    48         }
    49         if (cnt) ans.pb(Path(cnt, "DLR"));
    50         if (curx == n) {
    51             // 走得到下面,尽量回去第一行
    52             int step = min(k, n - 1);
    53             if (step) ans.pb(Path(step, "U"));
    54             k -= step, curx -= step;
    55         } else {
    56             // 步数不够,走不到下面,结束
    57             if (k == 1) {
    58                 ans.pb(Path(1, "D"));
    59                 k--;
    60             } else if (k == 2) {
    61                 ans.pb(Path(1, "D"));
    62                 ans.pb(Path(1, "L"));
    63                 k -= 2;
    64             }
    65             break;
    66         }
    67     }
    68     if (k) ans.pb(Path(k, "L"));
    69     printf("%d
    ", (int)ans.size());
    70     for (auto i : ans) {
    71         printf("%d %s
    ", i.n, i.s.c_str());
    72     }
    73     return 0;
    74 }
    View Code
  • 相关阅读:
    Individual Project
    最后的作业
    Reading Task 2 —— by12061154Joy
    Code Review —— by12061154Joy
    Pair Project —— Elevator Scheduler
    《移山之道》Reading Task——by12061154Joy
    Individual Project
    qa_model
    个人阅读作业2
    Personal Reading Assignment 2 -读推荐文章有感以及项目开发目前总结
  • 原文地址:https://www.cnblogs.com/JHSeng/p/12307410.html
Copyright © 2020-2023  润新知