• Codeforces Round #568 (div. 2)


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


    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 int a[4], d;
    22 
    23 int main() {
    24     cin >> a[1] >> a[2] >> a[3] >> d;
    25     sot(a, 3);
    26     cout << (d - (a[2] - a[1]) >= 0 ? d - (a[2] - a[1]) : 0) + (d - (a[3] - a[2]) >= 0 ? d - (a[3] - a[2]) : 0) << endl;
    27     return 0;
    28 }
    View Code

    B:

    扫一遍完事。

     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 int n;
    22 
    23 int main() {
    24     cin >> n;
    25     while (n--) {
    26         string a, b; cin >> a >> b;
    27         int i = 0, j = 0, aLen = a.size(), bLen = b.size();
    28         while (i < aLen || j < bLen) {
    29             if (a[i] == b[j]) i++, j++;
    30             else if (j && b[j] == b[j - 1]) j++;
    31             else break;
    32         }
    33         if (i == aLen && j == bLen) puts("YES");
    34         else puts("NO");
    35     }
    36     return 0;
    37 }
    View Code

    C1:

    贪心。每读一个就sort一次,然后扫一遍维护ans[i]和sum。

     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 = 2e5 + 10;
    22 int n, m, a[maxn] = {0}, b[maxn] = {0};
    23 
    24 int main() {
    25     scanf("%d%d", &n, &m);
    26     rep0(i, 0, n) {
    27         cin >> a[i];
    28         sort(a, a + i);
    29         ll sum = 0;
    30         rep1(j, 0, i)
    31         if (sum + a[i] + a[j] > m) {
    32             b[i] = i - j;
    33             break;
    34         } else sum += a[j];
    35     }
    36     rep0(i, 0, n) printf("%d ", b[i]);
    37     puts("");
    38     return 0;
    39 }
    View Code

    C2:

    贪心+枚举时间戳。

     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 = 2e5 + 10;
    22 int n, m, a[maxn], b[maxn], time[110];
    23 
    24 int main() {
    25     scanf("%d%d", &n, &m);
    26     rep0(i, 0, n) scanf("%d", &a[i]);
    27     rep0(i, 0, 110) time[i] = 0;
    28     int s = 0, sum = 0, ss = 0, delta1 = 0, delta2 = 0;
    29     rep0(i, 0, n) {
    30         s += a[i];
    31         if (s > m) {
    32             delta1 = s - m;
    33             ss = 0;
    34             for (int j = 100; j >= 1; j--) // enum each time slot
    35                 if (time[j]) {
    36                     sum += j * time[j];
    37                     ss += time[j];
    38                     if (sum > delta1) {
    39                         delta2 = sum - delta1;
    40                         ss -= delta2 / j;
    41                         break;
    42                     }
    43                 }
    44             b[i] = ss;
    45             sum = 0;
    46         } else b[i] = 0;
    47         time[a[i]]++;
    48     }
    49     rep0(i, 0, n) printf("%d ", b[i]);
    50     puts("");
    51     return 0;
    52 }
    View Code

    D:

    暴力。n==2时必定成立。sort一遍,枚举三种状态即可:删了最小的、删了最大的、删了中间某个。然后分别检查是否成立即可。

     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 = 2e5 + 10;
    22 struct Node {
    23     Node() {}
    24     int val, posi;
    25     bool operator<(const Node &rhs)const {
    26         return val < rhs.val;
    27     }
    28 } a[maxn];
    29 int n;
    30 vector<Node>b;
    31 
    32 int main() {
    33     scanf("%d", &n);
    34     rep1(i, 1, n) {
    35         scanf("%d", &a[i].val);
    36         a[i].posi = i;
    37     }
    38     if (n == 2) return puts("1"), 0;
    39     sot(a, n);
    40     int s = a[n].val - a[1].val, pos = 1, d = s / (n - 2), cnt = 0;
    41     rep1(i, 1, n)
    42     if (a[i].val != a[1].val + d * (i - cnt - 1)) {
    43         pos = a[i].posi;
    44         cnt++;
    45     }
    46     if (cnt == 1) return printf("%d
    ", pos), 0;
    47     s = a[n - 1].val - a[1].val; d = s / (n - 2);
    48     int flag = 0;
    49     rep1(i, 1, n - 1)
    50     if (a[i].val != a[1].val + d * (i - 1))
    51         flag = 1;
    52     if (!flag) return printf("%d
    ", a[n].posi), 0;
    53     flag = 0; s = a[n].val - a[2].val; d = s / (n - 2);
    54     rep1(i, 2, n)
    55     if (a[i].val != a[2].val + d * (i - 2))
    56         flag = 1;
    57     if (!flag) return printf("%d
    ", a[1].posi), 0;
    58     puts("-1");
    59     return 0;
    60 }
    View Code

    E:

    大模拟,不是很好写,我实在是写不动这种东西……

    F:

    位运算暴力题。

    G1 && G2:

    这个就真的不会了.

  • 相关阅读:
    Unity3D游戏制作(四)——Asset Server搭建
    查询开户银行的现代化支付行号
    专业版Unity技巧分享:使用定制资源配置文件
    如何建立一个完整的游戏AI
    实现简易而强大的游戏AI——FSM,有限状态机
    iOS 开发 初级:应用内购买 In-App Purchase
    linux每日命令(14):less命令
    flask上传excel文件,无须存储,直接读取内容
    linux每日命令(13):more命令
    linux每日命令(12):nl命令
  • 原文地址:https://www.cnblogs.com/JHSeng/p/11204093.html
Copyright © 2020-2023  润新知