标签:size iostream codec mat linker ace ons pair cond
思路:排序+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; }
标签:size iostream codec mat linker ace ons pair cond
原文地址:http://www.cnblogs.com/max88888888/p/7800199.html