zoukankan      html  css  js  c++  java
  • Codeforces Round #363 (Div. 2) A-C

    A. Launch of Collider

    找最近的R和L之间的距离

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int, int> PII;
    using namespace std;
    
    const int maxn = 200000 + 5;
    
    char s[maxn];
    int a[maxn];
    
    int main() {
       //FIN
       int n;
       while(~scanf("%d", &n)) {
           scanf("%s", s + 1);
           int ans = INF;
           for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
           int flag = 0;
           for(int i = 1; i <= n; i++) {
               if(flag != 0) {
                    if(s[i] == 'R') flag = i;
                    else if(s[i] == 'L') ans = min(ans, a[i] - a[flag]);
               }
               else if(s[i] == 'R') flag = i;
               else continue;
           }
           if(ans == INF) printf("-1
    ");
           else printf("%d
    ", ans/2);
    
       }
       return 0;
    }
    

      

    B. One Bomb

    *是墙问可不可以用一个炸弹把所有的墙炸掉 

    炸弹可以炸当前坐标上x,y轴上的所有点 (就是一个十字

    直接在读取数据时维护一个前缀然后再扫一遍判断就可以了

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int, int> PII;
    using namespace std;
    
    const int maxn = 1000 + 5;
    
    int q1[maxn];
    int q2[maxn];
    char mp[maxn][maxn];
    
    int main() {
       //FIN
       int n, m;
       while(~scanf("%d%d", &n, &m)) {
            int cnt = 0;
            memset(q1, 0, sizeof(q1));
            memset(q2, 0, sizeof(q2));
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {
                    cin >> mp[i][j];
                    if(mp[i][j] == '*') {
                        cnt++;
                        q1[i]++;
                        q2[j]++;
                    }
                }
            }
            int flag = 0;
    
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < m; j++) {
                    int tmp = cnt;
                    if(mp[i][j] == '*') tmp++;
                    if(q1[i] + q2[j] == tmp) {
                        printf("YES
    ");
                        printf("%d %d
    ", i+1, j+1);
                        flag = 1;
                        break;
                    }
                }
                if(flag) break;
            }
            if(flag == 0) printf("NO
    ");
    
       }
    
       return 0;
    }
    

      

    C. Vacations

    1 2 代表两种活动 3表示两种活动都可以进行 0是休息 不可以连续两天进行同一个活动,问最少休息的天数是多少, 贪心

    #include <iostream>
    #include <cstring>
    #include <cstdio>
    #include <algorithm>
    #include <queue>
    #include <vector>
    #include <iomanip>
    #include <math.h>
    #include <map>
    using namespace std;
    #define FIN     freopen("input.txt","r",stdin);
    #define FOUT    freopen("output.txt","w",stdout);
    #define INF     0x3f3f3f3f
    #define INFLL   0x3f3f3f3f3f3f3f
    #define lson    l,m,rt<<1
    #define rson    m+1,r,rt<<1|1
    typedef long long LL;
    typedef pair<int, int> PII;
    using namespace std;
    
    const int maxn = 100 + 5;
    
    int a[maxn];
    
    int main() {
       //FIN
       int n;
       while(~scanf("%d", &n)) {
           for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
           int flag = -1;
           int ans = 0;
           for(int i = 1; i <= n; i++) {
                if(a[i] == 0) ans++, flag = -1;
                else if(a[i] == 1) {
                    if(flag != 1) flag = 1;
                    else flag = -1, ans++;
                }
                else if(a[i] == 2) {
                    if(flag != 2) flag = 2;
                    else flag = -1, ans++;
                }
                else {
                    if(flag == 1) flag = 2;
                    else if(flag == 2) flag = 1;
                    //else if(a[i+1] == 1) flag = 2;
                    //else flag = 1;
                }
           }
           printf("%d
    ", ans);
    
       }
       return 0;
    }
    

      

  • 相关阅读:
    最清晰易懂的Mysql CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP区别
    yield再理解--绝对够透彻
    解决pyspider框架web预览框过小问题
    python中的可哈希与不可哈希
    python json.dumps 中的ensure_ascii 参数引起的中文编码问题
    LeetCode 297. 二叉树的序列化与反序列化 | Python
    LeetCode 1300. 转变数组后最接近目标值的数组和 | Python
    LeetCode 30. 串联所有单词的子串 | Python
    LeetCode 739. 每日温度 | Python
    LeetCode 128. 最长连续序列 | Python
  • 原文地址:https://www.cnblogs.com/Hyouka/p/7397033.html
Copyright © 2011-2022 走看看