zoukankan      html  css  js  c++  java
  • Codeforces Round #656 (Div. 3)

    A

    根据性质,(a,b,c) 中的最大值一定会在 $x,y,z $ 中出现两次

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int t;
        cin >> t;
        int a[3];
        while(t --) {
            memset(a,0,sizeof a);
            for(int i = 0;i < 3; ++i) cin >> a[i];
            sort(a,a + 3);
            if(a[1] != a[2]) cout << "NO" << endl;
            else {
                cout << "YES
    " << a[0] << ' ' << a[0] << ' ' << a[1] << endl; 
            }
        }
        return 0;
    }
    

    C

    题意 :去除一个数组的最短前缀使得余下的数组每次从首或尾部取元素可以排为非降序列

    每次从首尾取元素,组成非降序列的话,首位肯定是最小的,中间肯定是最大的,

    所以,只要从尾部开始找到一组形如 $a_1leq a_2leq dotsleq a_{max}geq dotsgeq a_{k-1}geq a_k $ 这样的序列即可

    #include <bits/stdc++.h>
    using namespace std;
    int main() {
        int t;
        cin >> t;
        int n;
        while(t --) {
            cin >> n;
            vector<int> a(n);
            int pos = n - 1;
            for(int i = 0;i < n; ++i) cin >> a[i];
            while(pos > 0 && a[pos - 1] >= a[pos]) -- pos;
            while(pos > 0 && a[pos - 1] <= a[pos]) -- pos;
            cout << pos << endl;
        }
        return 0;
    }
    

    参考

    Kanoon

    https://codeforces.com/blog/entry/80257

    D

    • string 递归拷贝的时候,要加 const

    每次都是对半分字符递增,计算每个半区域有多少不同的字符即可,然后左右两边取 (min) 返回

    #include <bits/stdc++.h>
    using namespace std;
    int calc(const string &s,char c) {
        if(s.size() == 1) return s[0] != c;
        int mid = s.size() / 2;
        int cntl = calc(string(s.begin(), s.begin() + mid), c + 1);
        cntl += mid - count(s.begin() + mid,s.end(),c);
        int cntr = calc(string(s.begin() + mid, s.end()), c + 1);
        cntr += mid - count(s.begin(),s.begin() + mid,c);
        return min(cntl,cntr);
    }
    int main() {
        int t;
        cin >> t;
        while(t --) {
            string s;
            int n;
            cin >> n >> s;
            cout << calc(s,'a') << endl;
        }
        return 0;
    }
    

    参考

    https://codeforces.com/blog/entry/80257

    E

    先把有向边连上,跑一遍topsort,在这个过程中,记录每个点的优先级大小,因为无向边没有连,所以他们也会进队跑一遍,

    但是不用担心,因为这些无向边都是一组的,不管怎么跑,永远不可能比有向边的权值大,如果最后topsort跑成环,输出 (NO)

    否则,就按权值大小,小的点连到大的点上即可

    #include <bits/stdc++.h>
    using namespace std;
    const int N = 2e5 + 10;
    typedef pair<int,int> PII;
    int e[N],ne[N],h[N],idx,d[N],n,m,top[N],cnt;
    void add(int a,int b) {
        e[idx] = b;
        ne[idx] = h[a];
        h[a] = idx ++;
    }
    bool topsort() {
        queue<int> q;
        int t;
        for(int i = 1;i <= n; ++i) {
            if(d[i] == 0) q.push(i);
        }
        while(q.size()) {
            t = q.front();
            top[t] = cnt ++;// 记录每个topsort的优先值大小
            q.pop();
            for(int i = h[t]; ~i;i = ne[i]) {
                int j = e[i];
                d[j] --;
                if(d[j] == 0) q.push(j);
            }
        }
        if(cnt < n) return 0;
        else return 1;
    }
    int main() {
        // freopen("in.txt","r",stdin);
        int t;
        cin >> t;
        while(t --) {
            idx = 0;
            cnt = 1;
            memset(h,-1,sizeof h);
            memset(e,0,sizeof e);
            memset(ne,0,sizeof ne);
            memset(d,0,sizeof d);
            memset(top,0,sizeof top);
            int op,u,v;
            cin >> n >> m;
            vector<PII> vec;
            for(int i = 0;i < m; ++i) {
                cin >> op >> u >> v;
                vec.push_back({u,v});
                if(op == 1) {
                    add(u,v);
                    d[v] ++;
                }
            }
            if(topsort() == 0) {
                cout << "NO" << endl;
            }
            else {
                cout << "YES" << endl;
                for(int i = 0;i < m; ++i) {
                    int &u = vec[i].first,&v = vec[i].second;
                    if(top[u] > top[v]) swap(u,v);
                    cout << u << ' ' << v << endl;
                }
            }
        }
        return 0;
    }
    

    参考

    Half-Blood Prince

  • 相关阅读:
    在OpenEuler中安装轻量化调试工具CGDB
    nginx服务器 server location映射路径配置
    hadoop HDFS文件系统角色及文件读写流程
    Linux系统Tomcat服务自启动脚本
    Linux系统软件安装的三种方式
    linux基础命令
    Java多线程解析
    多线程的典型应用场景---多个生产者多个消费者对共享资源的处理
    10.16变量的作用域和生存周期
    10.15sizeof用法
  • 原文地址:https://www.cnblogs.com/lukelmouse/p/13336745.html
Copyright © 2011-2022 走看看