zoukankan      html  css  js  c++  java
  • 牛客OI周赛7-普及组

    https://ac.nowcoder.com/acm/contest/372#question

    A.救救猫咪

    #include <bits/stdc++.h>
    using namespace std;
     
    const int maxn = 1e5 + 10;
    int N;
     
    struct Node {
        int x;
        int y;
        int cnt;
    }node[maxn];
     
    int main() {
        scanf("%d", &N);
        for(int i = 0; i < N; i ++)
            scanf("%d%d", &node[i].x, &node[i].y);
     
        for(int i = 0; i < N; i ++) {
            for(int j = 0; j < N; j ++) {
                if(node[j].x > node[i].x && node[j].y > node[i].y)
                    node[i].cnt ++;
            }
        }
     
        for(int i = 0; i < N; i ++)
            printf("%d
    ", node[i].cnt);
        return 0;
    }
    View Code

    B.救救兔子

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e5 + 10;
    int N, M;
    int num[maxn];
    
    int main() {
        scanf("%d", &N);
        for(int i = 0; i < N; i ++)
            scanf("%d", &num[i]);
    
        sort(num, num + N);
        scanf("%d", &M);
        while(M --) {
            int x;
            scanf("%d", &x);
            int l = 0, r = N - 1, mid;
            while(l <= r) {
                mid = (l + r) / 2;
                if(x > num[mid]) l = mid + 1;
                else if(x == num[mid]) break;
                else r = mid - 1;
            }
            if(num[mid] == x)
                printf("%d
    ", num[mid]);
            else if(num[mid] > x) {
                if(mid == 0) printf("%d
    ", num[mid]);
                else if((num[mid] - x) >= (x - num[mid - 1]))
                    printf("%d
    ", num[mid - 1]);
                else printf("%d
    ", num[mid]);
            }
            else {
                if(mid == N - 1)
                    printf("%d
    ", num[mid]);
                else if((num[mid + 1] - x) >= (x - num[mid]))
                    printf("%d
    ", num[mid]);
                else printf("%d
    ", num[mid + 1]);
            }
    
        }
        return 0;
    }
    View Code

    C.救救企鹅

    #include <bits/stdc++.h>
    using namespace std;
     
    string s, a, b;
     
    int main() {
        cin >> s >> a >> b;
        int sign;
        sign = s.find(a, 0);
        while(sign != string::npos) {
            s.replace(sign, a.size(), b);
            sign = s.find(a, sign + 1);
        }
        cout << s;
        return 0;
    }
    View Code

    D.数糖纸

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn = 1e6 + 10;
    int N;
    int num[maxn];
    map<int, int> mp;
    
    int main() {
        scanf("%d", &N);
        for(int i = 0; i < N; i ++)
            scanf("%d", &num[i]);
    
        set<int> s;
        int L = 0, R = 0, ans = 0;
        while(R < N) {
            while(R < N && !s.count(num[R])) {
                s.insert(num[R]);
                //mp[num[R]] ++;
                R ++;
            }
            ans = max(ans, R - L);
            s.erase(num[L]);
            //mp[num[L]] = 0;
            L ++;
        }
        printf("%d
    ", ans);
        return 0;
    }
    View Code

    D 题用 map 会超时

  • 相关阅读:
    自己没有记住的一点小知识(ORM查询相关)
    博客系统(设计表时需要注意的)
    ajax补充--------FormData等...
    需要知道的小知识。。。
    apache服务器多端口支持
    oracle中database links的使用
    在linux下安装mysql
    linux下停止tomcat
    vsftpd 本地用户无法登陆 530 Login incorrect
    angularjs库及ionic库下载地址
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10426046.html
Copyright © 2011-2022 走看看