• Codeforces Round #395 (Div. 2)


      现场打的。出了ABC,结果B被rejudge。。

      A题,水题,找找lcm就行,都不会爆int。

      B题,也是水题,我找的一个规律是没错,但是写挫了= =,结果又麻烦,又WA。。其实有更好的规律,只要每隔两个位置swap一下即可。

      C题,看别人AC代码很短,,但是不是很理解。。我觉得自己的方法也可以接受。我的方法是找两个点,这两个点的颜色不同,把它们中不为叶子的节点加入待测数组need中。然后一一的检测是不是即可。现场时因为dfs写错了导致WA了一发= =。但是这方法是确实可行的。代码如下:

     1 #include <stdio.h>
     2 #include <algorithm>
     3 #include <string.h>
     4 #include <iostream>
     5 #include <map>
     6 #include <vector>
     7 #include <set>
     8 #include <queue>
     9 using namespace std;
    10 const int N = 100000 + 5;
    11 typedef long long ll;
    12 typedef pair<int,int> pii;
    13 
    14 vector<int> G[N];
    15 int n;
    16 int color[N];
    17 vector<int> need;
    18 void dfs(int u,int fa)
    19 {
    20     for(int i=0;i<G[u].size();i++)
    21     {
    22         int v = G[u][i];
    23         if(v == fa) continue;
    24         if(color[u] != color[v])
    25         {
    26             if(G[u].size() > 1) need.push_back(u);
    27             if(G[v].size() > 1) need.push_back(v);
    28             //printf("%d == %d
    ",u,v);
    29             return;
    30         }
    31         dfs(v,u);
    32     }
    33 }
    34 bool dfs2(int u,int col,int fa)
    35 {
    36     if(color[u] != col) return 0;
    37     for(int i=0;i<G[u].size();i++)
    38     {
    39         int v = G[u][i];
    40         if(v == fa) continue;
    41         if(dfs2(v,col,u) == false)  return false;
    42     }
    43     return 1;
    44 }
    45 bool can(int u)
    46 {
    47     for(int i=0;i<G[u].size();i++)
    48     {
    49         int v = G[u][i];
    50         if(dfs2(v,color[v],u) == false) return false;
    51     }
    52     return 1;
    53 }
    54 
    55 int main()
    56 {
    57     cin >> n;
    58     for(int i=1;i<n;i++)
    59     {
    60         int u,v;scanf("%d%d",&u,&v);
    61         G[u].push_back(v);
    62         G[v].push_back(u);
    63     }
    64     for(int i=1;i<=n;i++) scanf("%d",color+i);
    65     dfs(1,-1);
    66     //for(int i=0;i<need.size();i++) printf("--%d--
    ",need[i]);
    67     if(need.size() == 0)
    68     {
    69         puts("YES
    1");
    70     }
    71     else if(need.size() == 1)
    72     {
    73         int now = need[0];
    74         if(can(now)) printf("YES
    %d
    ",now);
    75         else puts("NO");
    76     }
    77     else
    78     {
    79         if(can(need[0])) printf("YES
    %d
    ",need[0]);
    80         else if(can(need[1])) printf("YES
    %d
    ",need[1]);
    81         else puts("NO");
    82     }
    83     return 0;
    84 }
    C

      D题。很神奇的题目。由四色定理,答案肯定是YES。然后题目有个神奇的设定:所有矩形的变长为奇数。那么,左下点的两个坐标的奇偶性都相同的点显然是不会碰触的,因此他们颜色可以相同。然后对左下点的x和y的奇偶性做分类,发现恰好有4种点,那么每种点分别使用一种颜色即可。神奇的题目!代码如下:

     1 #include <stdio.h>
     2 #include <algorithm>
     3 #include <string.h>
     4 #include <iostream>
     5 #include <map>
     6 #include <vector>
     7 #include <set>
     8 #include <queue>
     9 using namespace std;
    10 const int N = 200000 + 5;
    11 typedef long long ll;
    12 typedef pair<int,int> pii;
    13 
    14 int n;
    15 
    16 int main()
    17 {
    18     cin >> n;
    19     puts("YES");
    20     for(int i=1;i<=n;i++)
    21     {
    22         int x,y,xx,yy;
    23         scanf("%d%d%d%d",&x,&y,&xx,&yy);
    24         if(x % 2) x = 1; else x = 0;
    25         if(y % 2) y = 1; else y = 0;
    26         int ans = x + (y << 1) + 1;
    27         printf("%d
    ",ans);
    28     }
    29     return 0;
    30 }
    D

      E题做出来的人好少啊= =。待补。

      发现CF的1A率和手速真的很重要,名次可以差得很远!这两点一定要多训练来提高!

  • 相关阅读:
    【Spring】注解的循环依赖问题
    【网络】计算机网络自顶向下读书笔记
    【JUC】并发编程的艺术笔记
    【JUC】多线程手撕代码面试题
    【操作系统】王道操作系统全盘汇总
    【Spring】IoC源码分析以及实现
    【Spring】用例子来初次理解IoC
    拼音工具类
    chr(10)与chr(13)的区别
    List 集合转String 逗号拼接
  • 原文地址:https://www.cnblogs.com/zzyDS/p/6362517.html
Copyright © 2020-2023  润新知