• cfER76 abcd


    https://codeforces.com/contest/1257

    A題 取個max(b-a+x, n-1)

    B題 儅x>3 時就可以變成任意y, 儅 n <= 3 時 討論下

    C題 用數組記錄下沒個數的出現位置, 取與上一次位置的最小距離為答案

    1 1 1 2 2 2  也可以, ans = 2,

    D題 儅怪物中力量最大的大於勇士 則輸出 -1, 否則 貪心 將每個耐力值取最大力量, 用一個數組存  耐力值的最大力量()

    hero[1] 存的是 耐心值>=1 的最大力量, hero[2] 存的是 耐心值>=2 的最大力量, 每次從hero[1] 貪心取到最大的耐心值

    /*
    6
    1 1 1 2 2 2
    */
    
    #include <bits/stdc++.h>
    using namespace std;
    #define _for(i,a,b) for(int i = (a); i < (b); i++)
    #define _rep(i,a,b) for(int i = (a); i <= (b); i++)
    #define ll long long
    void taskA(){
        int t, n,x,a,b;
        cin >> t;
        while(t--) {
            cin >> n >> x >> a >> b;
            if(a > b) swap(a, b);
            int ma = b-a;
            if(abs(b-a) < n) 
                ma = min(n-1, ma+x);
            cout << ma << endl;
        }
    }
    void taskB(){
        ll t, x, y;
        cin >> t;
        while(t--) {
            int flag = 1;
            cin >> x >> y;
            //if(x%2==0 && x/2*3==x && x!=y) flag = 0;
            if(((x==3 && y>3) || (x==1 && y>1) || (x==2 && y>3))) 
                flag = 0;
            if(flag) cout << "YES
    ";
            else cout << "NO
    ";
        }
    }
    void taskC(){
        int t; cin >> t;
        while(t--) {
            int n; cin >> n;
            int ma = 0, k, ans = n+5, x;
            vector<int> lst(n+1, 0);
            _rep(i,1,n) {
                cin >> x;
                if(lst[x])  ans = min(ans, i-lst[x]+1);
                lst[x] = i;
            } if(ans > n) ans = -1;
            cout << ans << endl;
        }
    }
    void taskD(){
        int t; cin>> t;
        while(t--) {
            int n; cin >> n;
            //vector<int> mon, hero;
            vector<int> mon(n), hero(n+1, 0);
            int mxm = 0;
            _for(i,0,n) {
                cin >> mon[i];
                mxm = max(mon[i], mxm);
            }
            int m, mxp = 0; cin >> m;
    
            _for(i,0,m) {
                int x,y;
                cin >> x >> y;
                mxp = max(mxp, x);
                hero[y] = max(hero[y], x);
            }
            if(mxp < mxm) {
                cout<<"-1
    "; continue;
            }
            for(int i = n-1; i > 0; --i) 
                hero[i] = max(hero[i], hero[i+1]);
    
            int ans = 0, pos = 0;
            while(pos < n) {
                ans++;
                int npos = pos;
                int mx = 0;
                while(1) {
                    mx = max(mx, mon[npos]);
                    if(mx > hero[npos-pos+1]) break;
                    npos++;
                }
                //if(npos == pos) break;
                pos = npos;
            }
            cout << ans << endl;
        }
    }  
    int main(){
        ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
        //freopen("output.txt", "w", stdout);
        //taskA();
        //taskB();
        //taskC();
        taskD();
        return 0;
    }
  • 相关阅读:
    js大文件上传(切片)
    前端大文件上传(切片)
    vue大文件上传(切片)
    网页大文件上传(切片)
    web大文件上传(切片)
    FCKEditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
    umeditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
    百度web编辑器 实现ctrl+v粘贴图片并上传、word粘贴带图片
    百度编辑器 实现ctrl+v粘贴图片并上传、word粘贴带图片
    百度ueditor 实现ctrl+v粘贴图片并上传、word粘贴带图片
  • 原文地址:https://www.cnblogs.com/163467wyj/p/11870076.html
Copyright © 2020-2023  润新知