zoukankan      html  css  js  c++  java
  • 《 Codeforces Round #699 (Div. 2)》

    A:把多余的步数删掉即可。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 1e4 + 5;
    const int M = 1e4 + 5;
    const LL Mod = 1e9 + 7;
    #define pi acos(-1)
    #define INF 1e12
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
            return x*f;
        }
    }
    using namespace FASTIO;
    
    int main()
    {
        int ca;ca = read();
        while(ca--){
            int px,py;px = read(),py = read();
            string s;cin >> s;
            int ri = 0,up = 0,le = 0,dw = 0,f1 = 0,f2 = 0;
            for(auto v : s){
                if(v == 'R') ri++;
                if(v == 'U') up++;
                if(v == 'L') le++;
                if(v == 'D') dw++;
            }
            if(px == 0) f1 = 1;
            if(px < 0 && le >= -px) f1 = 1;
            if(px > 0 && ri >= px) f1 = 1;
            if(py == 0) f2 = 1;
            if(py < 0 && dw >= -py) f2 = 1;
            if(py > 0 && up >= py) f2 = 1;
            printf("%s
    ",(f1 && f2) ? "YES" : "NO");
        }
      //    system("pause");
        return 0;
    }
    View Code

    B:这题需要处理好细节。

    如果不能走了,就去判断左边比它大的和右边比他大的哪个小,然后把中间一段都变成哪个更小的值。

    中间需要判断一下是否k用完了。复杂度n ^ 3。实际上找的复杂度可以单调找先维护出来,这样可以优化到n ^ 2。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 1e4 + 5;
    const int M = 1e4 + 5;
    const LL Mod = 1e9 + 7;
    #define pi acos(-1)
    #define INF 1e12
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
            return x*f;
        }
    }
    using namespace FASTIO;
    
    int h[105];
    int main()
    {
        int ca;ca = read();
        while(ca--){
            int n,k;n = read(),k = read();
            for(int i = 1;i <= n;++i) h[i] = read();
            int pos = -1;
            for(int i = 1;i < n;++i){
                if(pos != -1) break;
                if(h[i] < h[i + 1]){
                    int le = i;
                    while(le >= 2 && h[le - 1] == h[i]) le--;
                    if(le == 1){//到起点都一样
                        int len = i - le + 1;
                        LL dis = 1LL * (h[i + 1] - h[i]) * len;
                        if(k > dis) {
                            k -= dis;
                            for(int j = i;j >= le;--j) h[j] = h[i + 1];
                        }
                        else {
                            int ss = k % len;
                            if(ss == 0) pos = le;
                            else pos = i - ss + 1;
                        }
                    }
                    else {
                        int len = i - le + 1;
                        if(h[le - 1] >= h[i + 1]){
                            LL dis = 1LL * (h[i + 1] - h[i]) * len;
                            if(k > dis) {
                                k -= dis;
                                for(int j = i;j >= le;--j) h[j] = h[i + 1];
                            }
                            else {
                                int ss = k % len;
                                if(ss == 0) pos = le;
                                else pos = i - ss + 1;
                            }
                        }
                        else{
                            LL dis = 1LL * (h[le - 1] - h[i]) * len;
                            if(k > dis) {
                                k -= dis;
                                for(int j = i;j >= le;--j) h[j] = h[le - 1];
                            }
                            else {
                                int ss = k % len;
                                if(ss == 0) pos = le;
                                else pos = i - ss + 1;
                            }
                            i--;
                        }
                    }
                }
            }
            printf("%d
    ",pos);
        }
      //    system("pause");
        return 0;
    }
    /*
    10
    4 1
    4 2 1 5
    4 2
    4 2 1 5
    4 3
    4 2 1 5
    4 4
    4 2 1 5
    4 5
    4 2 1 5
    4 6
    4 2 1 5
    4 7
    4 2 1 5
    4 8
    4 2 1 5
    4 9
    4 2 1 5
    */
    View Code

    C:这题感觉比上题更水,多出来的就留着后面覆盖就行。

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef pair<int,int> pii;
    const int N = 1e5 + 5;
    const int M = 1e4 + 5;
    const LL Mod = 1e9 + 7;
    #define pi acos(-1)
    #define INF 1e12
    #define dbg(ax) cout << "now this num is " << ax << endl;
    namespace FASTIO{
        inline LL read(){
            LL x = 0,f = 1;char c = getchar();
            while(c < '0' || c > '9'){if(c == '-') f = -1;c = getchar();}
            while(c >= '0' && c <= '9'){x = (x<<1)+(x<<3)+(c^48);c = getchar();}
            return x*f;
        }
    }
    using namespace FASTIO;
    
    int a[N],b[N],c[N],ans[N],len[N],col[N],clr[N];
    struct Node{int id,pos;};
    bool cmp(Node a,Node b){
        return a.id < b.id;
    }
    vector<Node> G[N];
    vector<int> vec;
    int main()
    {
        int ca;ca = read();
        while(ca--){
            int n,m;n = read(),m = read();
            vec.clear();
            for(int i = 1;i <= n;++i){
                G[i].clear();
                len[i] = 0;
                col[i] = 0;
                clr[i] = 0;
            }
            for(int i = 1;i <= n;++i) a[i] = read();
            for(int i = 1;i <= n;++i) b[i] = read();
            for(int i = 1;i <= m;++i) c[i] = read(),clr[c[i]]++;
            for(int i = 1;i <= n;++i){
                if(a[i] != b[i]) {
                    col[b[i]]++;
                    if(col[b[i]] == 1) vec.push_back(b[i]);
                    G[b[i]].push_back(Node{0,i});
                }
                else G[b[i]].push_back(Node{1,i});
            }
            int pos = -1,f = 0;
            for(auto v : vec){
                if(col[v] > clr[v]) f = 1;
            }
            for(int i = 1;i <= n;++i) sort(G[i].begin(),G[i].end(),cmp);
            for(int i = m;i >= 1;--i){
                if(len[c[i]] == G[c[i]].size()) {
                    if(pos == -1){
                        f = 1;
                        break;
                    }
                    else ans[i] = pos;
                }
                else{
                    pos = G[c[i]][len[c[i]]].pos;
                    ans[i] = pos;
                    len[c[i]]++;
                }
            }
            if(f) printf("NO
    ");
            else{
                printf("YES
    ");
                for(int i = 1;i <= m;++i) printf("%d%c",ans[i],i == m ? '
    ' : ' ');
            }
        }
          //system("pause");
        return 0;
    }
    View Code

    D:首先如果存在u -> v == v -> u的颜色相同的情况,那么就可以构造出任意长度的aaaaaa这样长度的字符串。

    如果不存在:

    那么对于奇数长度的,可以构造出abababa这样的任意长度,显然都满足。

    对于偶数长度,如果不存在u -> v == v -> u的情况,那么对于任意三个点.

    很显然肯定存在某两个相连边的颜色是相同的。

    这样我们只需要让他们作为中间的那两个,去找起点就行。

    可以发现,任意奇数长度都能构造。

    所以对于无法构造的情况,就是n == 2且u -> v != v -> u 颜色不一样的情况。

  • 相关阅读:
    Java AJAX开发系列 5,ZK参考资料
    现代浏览器客户端Web开发 Project Silk
    Java AJAX开发系列 2,项目中使用ZK
    Java性能分析点滴
    Java AJAX开发系列 4,ZK应用实例
    Java AJAX开发系列 3, ZK MVC
    大型网站如何架构 网页资料集
    Google Analytics 进行网站流量分析
    ALM TFS/VSTS工具 的Java集成
    系统各层关注的内容【DDDD笔记】
  • 原文地址:https://www.cnblogs.com/zwjzwj/p/14389716.html
Copyright © 2011-2022 走看看