• Codeforces Round #562 (Div. 2)


    前天晚上没做 昨晚上回去补了两道题

    A题:

    有两条地铁线路 一条正向1, 2, 3, ..., n 另一条逆向n, n-1, n-2, ..., 1 有两个人分别沿正向和逆向出发 给出总站数 还有两人的起点和终点 问两人是否能相遇

    模拟+简单数学题啦

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 typedef unsigned long long ull;
     5 
     6 namespace io {
     7     const int SIZE = 1e7 + 10;
     8     char inbuff[SIZE];
     9     char *l, *r;
    10     inline void init() {
    11         l = inbuff;
    12         r = inbuff + fread(inbuff, 1, SIZE, stdin);
    13     }
    14     inline char gc() {
    15         if (l == r) init();
    16         return (l != r) ? *(l++) : EOF;
    17     }
    18     void read(int &x) {
    19         x = 0; char ch = gc();
    20         while(!isdigit(ch)) ch = gc();
    21         while(isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
    22     }
    23 } using io::read;
    24 
    25 int main(){
    26     int n, a, x, b, y;
    27     cin>>n>>a>>x>>b>>y;
    28     bool flag = false;
    29     for (int i = 0;; i++){
    30         if (a == b) flag = true;
    31         a++;
    32         b--;
    33         if (a == n + 1) a = 1;
    34         if (b == 0) b = n;
    35         if (a == x || b == y) break;
    36     }
    37     if (a == b) flag = true;
    38     if (flag) cout<<"YES"<<endl;
    39     else cout<<"NO"<<endl;
    40     return 0;
    41 }

     

    B题 给出m对在1~n之间的数 现在问 是否能找出两个不相等的数x y 使得每一对数至少有一个数等于x或y

    假设一对数(a, b)中至少有一个数为x或y 下一对(c, d)中 若(c, d) != (a, b) 则(c, d)中也至少存在一个数为x或y 即(x, y)为(a, c) || (a, d) || (b, c) || (b, d) 就只需要判断这m对数是否满足这个条件就行啦 若(c, d) == (a, b) 那(a, b)中就一个数为x 另一个数为y

    AC代码:

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 typedef unsigned long long ull;
     5 
     6 namespace io {
     7     const int SIZE = 1e7 + 10;
     8     char inbuff[SIZE];
     9     char *l, *r;
    10     inline void init() {
    11         l = inbuff;
    12         r = inbuff + fread(inbuff, 1, SIZE, stdin);
    13     }
    14     inline char gc() {
    15         if (l == r) init();
    16         return (l != r) ? *(l++) : EOF;
    17     }
    18     void read(int &x) {
    19         x = 0; char ch = gc();
    20         while(!isdigit(ch)) ch = gc();
    21         while(isdigit(ch)) x = x * 10 + ch - '0', ch = gc();
    22     }
    23 } using io::read;
    24 
    25 pair<int, int> p[300005];
    26 int n, m;
    27 
    28 bool judge(int a, int b){
    29     for (int i = 0; i < m; i++)
    30         if (p[i].first != a && p[i].first != b &&
    31             p[i].second != a && p[i].second != b)
    32             return false;
    33     return true;
    34 }
    35 
    36 int main(){
    37     cin>>n>>m;
    38     int a, b;
    39     int c = 0, d = 0;
    40     bool flag = false;
    41     cin>>p[0].first>>p[0].second;
    42     a = p[0].first;
    43     b = p[0].second;
    44     for (int i = 1; i < m; i++){
    45         cin>>p[i].first>>p[i].second;
    46         if (p[i].first != a && p[i].first != b &&
    47             p[i].second != a && p[i].second != b){
    48             c = p[i].first;
    49             d = p[i].second;
    50         }
    51     }
    52     if (judge(a, b) || judge(a, c) || judge(a, d) || judge(b, c) || judge(b, d))
    53         flag = true;
    54     if (flag) cout<<"YES"<<endl;
    55     else cout<<"NO"<<endl;
    56     return 0;
    57 }
  • 相关阅读:
    phonegap开发入门
    [转] jQuery源码分析-如何做jQuery源码分析
    【转】HTML,CSS,font-family:中文字体的英文名称 (宋体 微软雅黑)
    iframe子页面与父页面通信
    5.10团队冲刺
    5.10日
    5.9日团队冲刺
    5.9日自学成果
    5.8日团队冲刺
    5.7日团队冲刺
  • 原文地址:https://www.cnblogs.com/Misuchii/p/10935273.html
Copyright © 2020-2023  润新知