codeforeces GYM 101142 C

Posted %%%%%

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforeces GYM 101142 C相关的知识,希望对你有一定的参考价值。

CodeCoder vs TopForces

思路:排序+DFS

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 ("\n")
#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\n",ans[i]);
    return 0;
}

 

以上是关于codeforeces GYM 101142 C的主要内容,如果未能解决你的问题,请参考以下文章

Gym 101142C CodeCoder vs TopForces (搜索)

Gym 101142 I.Integral Polygons 计算几何 奇偶性 前缀和

Gym101142C CodeCoder vs TopForces

Codeforces Gym 101142 C. CodeCoder vs TopForces(思维+图论)

Gym 101142G: Gangsters in Central City(DFS序+LCA+set)

Codeforces Gym 101142 G Gangsters in Central City (lca+dfs序+树状数组+set)