• 2019-2020 ICPC Northwestern European Regional Programming Contest (NWERC 2019)


    2019-2020 ICPC Northwestern European Regional Programming Contest (NWERC 2019)

    I-Inverted Deck

    #include<bits/stdc++.h>
    using namespace std;
    
    const int N=1e6+10;
    int n;
    int v[N],v1[N];
    
    
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;++i) scanf("%d",v+i),v1[i]=v[i];
        int rec1=0,rec2=0;
        sort(v1+1,v1+1+n);
        for(int i=1;i<=n;++i){
            if(v[i]!=v1[i]){
                rec1=i;
                break;
            }
        }
        for(int i=n;i>=1;i--){
            if(v[i]!=v1[i]){
                rec2=i;
                break;
            }
        }
        if(rec1==0 && rec2==0){
            printf("1 1
    ");
            return 0;
        }
        int f=0;
        for(int i=rec1;i<rec2;++i){
            if(v[i]<v[i+1]){
                f=1;
                break;
            }
        }
        if(f){
            printf("impossible
    ");
        }else{
            printf("%d %d
    ",rec1,rec2);
        }
        return 0;
    }
    

    G-Gnoll Hypothesis

    #include<bits/stdc++.h>
    using namespace std;
    
    const int N = 1010;
    int n, k;
    long double s[N], sum[N];
    
    int main()
    {
        //ios::sync_with_stdio(false);
        //cin.tie(0);
        //scanf("%d%d", &n, &k);
        cin >> n >> k;
        for (int i = 1; i <= n; ++i) {
            //scanf("%lf", s + i);
            cin >> s[i];
            s[i + n] = s[i];
        }
        if (n == k) {
            for (int i = 1; i <= n; ++i) printf("%.12Lf ", s[i]);
            return 0;
        }
        if (k == 1) {
            long double ss = 100.0;
            for (int i = 1; i <= n; ++i) printf("%.12Lf ", ss / ((long double)n));
            return 0;
        }
        for (int i = 1; i <= 2 * n; ++i) sum[i] = sum[i - 1] + s[i];
        long double t = 1.0;
        for (long double i = k, j = n; i >= 1; --i, --j) {
            t *= (j / i);
        }
        //double t1=0;
        long double t2 = 1.0;
        for (long double i = n - k, j = n - 2; i >= 1; --i, --j) t2 *= (j / i);
        for (int i = 1; i <= n; ++i) {
            long double tmpAns = 0.0, tmp = t2;
            for (int j = 1; j <= (n - k + 1); ++j) {
                if (j == (n - k + 1)) {
                    tmpAns += (long double)(sum[n + i] - sum[n + i - j]);
                    break;
                }
                tmpAns += (long double)(tmp * (sum[n + i] - sum[n + i - j]));
                tmp *= (long double)(((n - k - j + 1) * 1.0) / ((n - j - 1) * 1.0));
            }
            printf("%.12Lf ", tmpAns / t);
        }
        return 0;
    }
    

    F-Firetrucks Are Red

    #include<bits/stdc++.h>
    using namespace std;
     
    const int N = 2e5 + 10;
    int n, m;
    int fa[N];
    map<int, vector<int>>mp;
    struct edge {
        int v, w;
    };
    vector<edge>e[N];
     
    int find(int x)
    {
        if (x == fa[x]) return x;
        return fa[x] = find(fa[x]);
    }
     
    struct node {
        int u, v, w;
    };
    queue<node>q;
     
    // void solve(int u)
    // {
    //     int len = e[u].size();
    //     for (int i = 0; i < len; ++i) {
    //         int v = e[u][i].v, w = e[u][i].w;
    //         int x = find(u);
    //         int y = find(v);
    //         if (x == y) continue;
    //         fa[x] = y;
    //         q.push(node{ u,v,w });
    //         solve(v);
    //     }
    // }
     
    bool checkF(int u, int v)
    {
        int x=find(u);
        int y=find(v);
        if(x==y)
            return  false;
        else{
            fa[x]=y;
            return true;
        }
    }
     
     
    int main()
    {
        scanf("%d", &n);
        for (int i = 1; i <= n; ++i) {
            fa[i] = i;
            scanf("%d", &m);
            for (int j = 0; j < m; ++j) {
                int t;
                scanf("%d", &t);
                mp[t].push_back(i);
                // if (mp[t].empty()) {
                //     mp[t].push_back(i);
                // }
                // else {
                //     int len = mp[t].size();
                //     for (int k = 0; k < len; ++k) {
                //         e[i].push_back(edge{ mp[t][k],t });
                //         e[mp[t][k]].push_back(edge{ i,t });
                //         mp[t].push_back(i);
                //     }
                // }
            }
        }
        // mp.clear();
        // solve(1); 
        // if (q.size() != n - 1) {
        //     printf("impossible
    ");
        //     return 0;
        // }
        // while (!q.empty()) {
        //     printf("%d %d %d
    ", q.front().u, q.front().v, q.front().w);
        //     q.pop();
        // }
        for(auto i : mp){
            for(int j=0;j<i.second.size()-1;++j){
                if(checkF(i.second[j],i.second[j+1]))
                    q.push(node{i.second[j],i.second[j+1],i.first});
            }
        }
        if (q.size() != n - 1) {
            printf("impossible
    ");
            return 0;
        }
        while (!q.empty()) {
            printf("%d %d %d
    ", q.front().u, q.front().v, q.front().w);
            q.pop();
        }
        return  0;
    }
    
  • 相关阅读:
    异常
    带参数的方法
    变量,基本类型,数据类型和运算符
    数据类型转换(针对数字类型)
    this关键字
    面向对象DAO模式
    常见类 Object
    方法和包
    final关键字
    abstract关键字
  • 原文地址:https://www.cnblogs.com/DrumWashingMachine-Lhy-NoobInCsu/p/13775992.html
Copyright © 2020-2023  润新知