zoukankan      html  css  js  c++  java
  • codeforeces GYM 101142 C

    CodeCoder vs TopForces

    思路:排序+DFS 先按cc排序,排序后每个点于它前一个点建单向边,表示i能打败i-1(同一个oj没有相同的ranting,所以相邻2点之间一定可以建这样的边),然后按tf排序,同样建边,然后对每个点经行dfs,在所有的dfs过程中每个点只走一次,也就是说vis只标记一次,而且不取消标记,每次对一个点dfs结束以后更新这个点的答案,因为可知,排序后(无论按哪个排序的),前面点可到的点后面的点一点也可到达,比如第2个点可以到1,那么第3个点一定可以到1和2

    AC代码:

    #include "iostream"
    #include "iomanip"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #pragma comment(linker, "/STACK:102400000,102400000")
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a,x) memset(a,x,sizeof(a))
    #define step(x) fixed<< setprecision(x)<<
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    #define ll long long
    #define endl ("
    ")
    #define ft first
    #define sd second
    #define lrt (rt<<1)
    #define rrt (rt<<1|1)
    using namespace std;
    const ll mod=1e9+7;
    const ll INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const double PI=acos(-1.0);
    const double eps=1e-9;
    const int N=1e5+100;
    
    struct Node{
        int cc, tf, id;
    }p[N];
    
    bool cmp_cc(Node a, Node b){
        return a.cc<b.cc;
    }
    
    bool cmp_tf(Node a, Node b){
        return a.tf<b.tf;
    }
    vector<int> G[N];
    int ans[N],vis[N],sum;
    void dfs(int u){
        if(vis[u]) return;
        sum++; vis[u]=1;
        for(auto v : G[u]){
            dfs(v);
        }
    }
    
    int main(){
        freopen("codecoder.in","r",stdin);
        freopen("codecoder.out","w",stdout);
        int n; scanf("%d",&n);
        for(int i=0; i<n; ++i){
            scanf("%d %d", &p[i].cc, &p[i].tf);
            p[i].id=i;
        }
        sort(p,p+n,cmp_cc);
        for(int i=1; i<n; ++i){
            G[p[i].id].pb(p[i-1].id);
        }
        sort(p,p+n,cmp_tf);
        for(int i=1; i<n; ++i){
            G[p[i].id].pb(p[i-1].id);
        }
        for(int i=0; i<n; ++i){
            dfs(p[i].id); ans[p[i].id]=sum-1;
        }
        for(int i=0; i<n; ++i) printf("%d
    ",ans[i]);
        return 0;
    }
  • 相关阅读:
    Linux内核配置过程
    Linux内核最顶层文档
    LeetCode 11月第2周题目汇总
    Chapter0
    序列加法的讨论
    ch2-基本工具介绍
    ch1-数据科学概述
    在Linux下制作Linux&windows启动盘
    VMware Workstation 与 Device/Credential Guard 不兼容?
    Linux mint 19.3配置CUDA+安装Tensorflow
  • 原文地址:https://www.cnblogs.com/max88888888/p/7800199.html
Copyright © 2011-2022 走看看