• Educational Codeforces Round 41 (Rated for Div. 2)


    这场没打又亏疯了!!!

    A - Tetris :

    类似俄罗斯方块,模拟一下就好啦。

     1 #include<bits/stdc++.h>
     2 #define fi first
     3 #define se second
     4 #define mk make_pair
     5 #define pii pair<int,int>
     6 using namespace std;
     7 
     8 typedef long long ll;
     9 const int inf=0x3f3f3f3f;
    10 const ll INF=0x3f3f3f3f3f3f3f3f;
    11 const int N=1000+7;
    12 const int M=12;
    13 
    14 int n, m;
    15 
    16 int cnt[N];
    17 int main() {
    18 
    19     int ans = 0;
    20     scanf("%d%d", &n, &m);
    21     for(int i = 1; i <= m; i++) {
    22         int x; scanf("%d", &x);
    23         cnt[x]++;
    24 
    25         bool flag = true;
    26         for(int j = 1; j <= n; j++) {
    27             if(cnt[j] == 0)
    28                 flag = false;
    29         }
    30 
    31         if(flag) {
    32             ans++;
    33             for(int j = 1; j <= n; j++) {
    34                 cnt[j] -= 1;
    35             }
    36         }
    37     }
    38 
    39     printf("%d
    ", ans);
    40     return 0;
    41 }
    42 /*
    43 */
    View Code

    B - Lecture Sleep

    瞎模拟一下就好啦。

     1 #include<bits/stdc++.h>
     2 #define fi first
     3 #define se second
     4 #define mk make_pair
     5 #define pii pair<int,int>
     6 using namespace std;
     7 
     8 typedef long long ll;
     9 const int inf=0x3f3f3f3f;
    10 const ll INF=0x3f3f3f3f3f3f3f3f;
    11 const int N=1e5+7;
    12 const int M=12;
    13 
    14 int n, k, a[N], t[N],sum1[N], sum2[N];
    15 
    16 int main() {
    17 
    18     scanf("%d%d", &n, &k);
    19 
    20     for(int i = 1; i <= n; i++) {
    21         scanf("%d", &a[i]);
    22         sum1[i] = sum1[i-1] + a[i];
    23     }
    24 
    25     for(int i = 1; i <= n; i++) {
    26         scanf("%d", &t[i]);
    27         sum2[i] = sum2[i-1];
    28         if(t[i])
    29             sum2[i] += a[i];
    30     }
    31 
    32     int ans = sum2[n];
    33 
    34     for(int i = 1; i + k -1 <= n; i++) {
    35         ans = max(ans, sum2[n] + (sum1[i+k-1] - sum1[i-1]) - (sum2[i+k-1] - sum2[i-1]));
    36     }
    37 
    38     printf("%d
    ",ans);
    39     return 0;
    40 }
    41 /*
    42 */
    View Code

    C - Chessboard

    每个块只有两种情况,第一种是第一个数字为0,第二种是第一个数字为1,把每个块这两种情况需要修改的个数记录下来,

    然后暴力枚举就好啦 。

     1 #include<bits/stdc++.h>
     2 #define fi first
     3 #define se second
     4 #define mk make_pair
     5 #define pii pair<int,int>
     6 using namespace std;
     7 
     8 typedef long long ll;
     9 const int inf=0x3f3f3f3f;
    10 const ll INF=0x3f3f3f3f3f3f3f3f;
    11 const int N=1e5+7;
    12 const int M=12;
    13 
    14 int n, a[4][2], s[101][101],id[4];
    15 int main() {
    16 
    17     scanf("%d", &n);
    18 
    19     for(int k = 0; k < 4; k++) {
    20         for(int i = 0; i < n; i++) {
    21             for(int j = 0; j < n; j++) {
    22                 scanf("%1d", &s[i][j]);
    23             }
    24         }
    25 
    26         int flag = 0;
    27         for(int i = 0; i < n; i++) {
    28             for(int j = 0; j < n; j++) {
    29                 if(flag != s[i][j])
    30                     a[k][0]++;
    31                 flag ^= 1;
    32             }
    33         }
    34 
    35         flag = 1;
    36         for(int i = 0; i < n; i++) {
    37             for(int j = 0; j < n; j++) {
    38                 if(flag !=s[i][j])
    39                     a[k][1]++;
    40                 flag ^= 1;
    41             }
    42         }
    43     }
    44     for(int i = 0; i < 4; i++)
    45         id[i] = i;
    46 
    47     int ans = inf;
    48     do
    49     {
    50         ans = min(ans, a[id[0]][0] + a[id[1]][1] + a[id[2]][0] + a[id[3]][1]);
    51     }while(next_permutation(id, id + 4));
    52 
    53     for(int i = 0; i < 4; i++)
    54         id[i] = i;
    55 
    56     do
    57     {
    58         ans = min(ans, a[id[0]][1] + a[id[1]][0] + a[id[2]][1] + a[id[3]][0]);
    59     }while(next_permutation(id, id + 4));
    60 
    61     printf("%d
    ", ans);
    62     return 0;
    63 }
    64 /*
    65 */
    View Code

    D - Pair Of Lines

    题意:给你若干个点,问你能不能最多划两条直线覆盖所有点。

    思路:先找到三个不共线的点组成一个三角形,其中一条边一定是需要划的直线,枚举一下这三条边,然后check一下剩下的

    点在不在一条直线上。

      1 #include<bits/stdc++.h>
      2 #define fi first
      3 #define se second
      4 #define mk make_pair
      5 #define pii pair<int,int>
      6 using namespace std;
      7 
      8 typedef long long LL;
      9 const int inf=0x3f3f3f3f;
     10 const LL INF=0x3f3f3f3f3f3f3f3f;
     11 const int N=1e5+7;
     12 const int M=12;
     13 
     14 struct point {
     15     LL x, y;
     16 }p[N];
     17 
     18 LL aross(point a, point b, point c) {
     19     return (b.x - a.x) * (c.y - a.y) - (c.x - a.x) * (b.y - a.y);
     20 }
     21 
     22 vector<point> v;
     23 int n;
     24 int main() {
     25 
     26     scanf("%d", &n);
     27 
     28     if(n <= 4) {
     29         puts("YES");
     30         return 0;
     31     }
     32     for(int i = 0; i < n; i++) {
     33         scanf("%lld", &p[i].x);
     34         scanf("%lld", &p[i].y);
     35     }
     36 
     37     int pos = 2;
     38 
     39     while(pos < n && !aross(p[0], p[1], p[pos]))
     40         pos++;
     41 
     42     if(pos == n) {
     43         puts("YES");
     44         return 0;
     45     } else {
     46 
     47         for(int i = 0; i < n; i++) {
     48             if(aross(p[0], p[1], p[i]) != 0)
     49                 v.push_back(p[i]);
     50         }
     51 
     52         if(v.size() <= 2) {
     53             puts("YES");
     54             return 0;
     55         }
     56 
     57         bool flag = true;
     58 
     59         for(int i = 2; i < v.size(); i++) {
     60             if(aross(v[0], v[1], v[i]) !=0) {
     61                 flag = false;
     62                 break;
     63             }
     64         }
     65 
     66         if(flag) {
     67             puts("YES");
     68             return 0;
     69         }
     70 
     71         v.clear();
     72         for(int i = 0; i < n; i++) {
     73             if(aross(p[0], p[pos], p[i]) != 0)
     74                 v.push_back(p[i]);
     75         }
     76 
     77         if(v.size() <= 2) {
     78             puts("YES");
     79             return 0;
     80         }
     81 
     82         flag = true;
     83 
     84         for(int i = 2; i < v.size(); i++) {
     85             if(aross(v[0], v[1], v[i]) !=0) {
     86                 flag = false;
     87                 break;
     88             }
     89         }
     90 
     91         if(flag) {
     92             puts("YES");
     93             return 0;
     94         }
     95 
     96         
     97         v.clear();
     98         for(int i = 0; i < n; i++) {
     99             if(aross(p[1], p[pos], p[i]) != 0)
    100                 v.push_back(p[i]);
    101         }
    102 
    103         if(v.size() <= 2) {
    104             puts("YES");
    105             return 0;
    106         }
    107 
    108         flag = true;
    109 
    110         for(int i = 2; i < v.size(); i++) {
    111             if(aross(v[0], v[1], v[i]) !=0) {
    112                 flag = false;
    113                 break;
    114             }
    115         }
    116 
    117         if(flag) {
    118             puts("YES");
    119             return 0;
    120         }
    121 
    122         puts("NO");
    123     }
    124     return 0;
    125 }
    126 /*
    127 */
    View Code

    E - Tufurama

    裸的主席树,没啥好说的,数组开小了两次一次WA,一次RE。。。

     1 #include<bits/stdc++.h>
     2 #define ll long long
     3 #define fi first
     4 #define se second
     5 #define mk make_pair
     6 #define pii pair<int,int>
     7 using namespace std;
     8 
     9 typedef long long LL;
    10 const int inf=0x3f3f3f3f;
    11 const LL INF=0x3f3f3f3f3f3f3f3f;
    12 const int N=4e5+7;
    13 const int M=12;
    14 
    15 int root[N],hs[N],a[N],tot;
    16 struct Chairman_tree
    17 {
    18     int cnt;
    19     struct node{
    20         int l,r;
    21         ll sum;
    22     }a[20*N];
    23     void update(int l,int r,int &x,int y,int pos,int v)
    24     {
    25         a[++cnt]=a[y];
    26         x=cnt; a[x].sum+=v;
    27         if(l==r) return;
    28         int mid=(l+r)>>1;
    29         if(pos<=mid)
    30             update(l,mid,a[x].l,a[y].l,pos,v);
    31         else
    32             update(mid+1,r,a[x].r,a[y].r,pos,v);
    33     }
    34     ll query(int l,int r,int L,int R,int x)
    35     {
    36         if(l >= L && r <= R)
    37             return a[x].sum;
    38         ll ans = 0;
    39         int mid = (l + r) >> 1;
    40         if(L <= mid)
    41             ans += query(l,mid,L,R,a[x].l);
    42         if(R > mid)
    43             ans += query(mid + 1,r,L,R,a[x].r);
    44         return ans;
    45     }
    46 }seg;
    47 
    48 int n;
    49 int main() {
    50 
    51     scanf("%d", &n);
    52 
    53     for(int i = 1; i <= n; i++) {
    54         scanf("%d", &a[i]);
    55         hs[++tot] = a[i];
    56         hs[++tot] = i;
    57     }
    58 
    59     sort(hs + 1, hs + tot + 1);
    60     tot = unique(hs + 1, hs + tot + 1) - hs - 1;
    61 
    62     for(int i = 1; i <= n; i++) {
    63         int pos = lower_bound(hs+1,hs+1+tot,a[i])-hs;
    64         seg.update(1,tot,root[i],root[i-1],pos,1);
    65     }
    66 
    67     ll ans = 0;
    68     for(int i = 1; i <= n; i++) {
    69         int item = lower_bound(hs+1,hs+1+tot,i)-hs;
    70         int pos = min(i - 1, a[i]);
    71         ans += seg.query(1, tot, item, tot, root[pos]);
    72     }
    73 
    74     printf("%lld
    ",ans);
    75     return 0;
    76 }
    77 /*
    78 */
    View Code
  • 相关阅读:
    使用字符流(Writer、Reader)完成对文件的读写操作
    Java中File类重修
    适配器模式学习
    oracle 新建数据库 ,新建用户
    8.19 extjs jar 包使用。
    8.15 session 有效时间, session在数据查询中最后不用
    8.15 自定义tr行 滚动 信息行的滚动
    8.15jsp document 头部声明 区别
    8.14 图片滚动无缝
    8.13Oracle新建用户、角色,授权
  • 原文地址:https://www.cnblogs.com/CJLHY/p/8724053.html
Copyright © 2020-2023  润新知