Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我傻叉了。贴代码、#include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> #define N 200000 using namespace std; int rank[N],fa[N],n,cnt,m,bh; bool jo[N]; struct P { int id,q,h; }p[N]; inline bool cmp_q(const P &a,const P &b) { return a.q<b.q; } inline bool cmp_id(const P &a,const P &b) { if(a.id!=b.id) return a.id<b.id; else return a.h<b.h; } int findfa(int x) { if(fa[x]!=x) { findfa(fa[x]); rank[x]+=rank[fa[x]]; fa[x]=findfa(fa[x]); } return fa[x]; } void read() { cnt=0;char str[5]; scanf("%d",&m); for(int i=1;i<=m;i++) { scanf("%d",&p[++cnt].q); p[cnt].q--; p[cnt].id=i; scanf("%d",&p[++cnt].q); p[cnt].id=i; scanf("%s",str); if(str[0]=='o') jo[i]=1;//奇数 else jo[i]=0;//偶数 } } void lsh() { sort(p+1,p+1+cnt,cmp_q); p[1].h=1; bh=1; for(int i=2;i<=cnt;i++) { if(p[i].q==p[i-1].q) p[i].h=bh; else p[i].h=++bh; } sort(p+1,p+1+cnt,cmp_id); } void go() { for(int i=0;i<N;i++) fa[i]=i,rank[i]=0; for(int i=1;i<=cnt;i+=2) { if(findfa(p[i].h)!=findfa(p[i+1].h)) { if(((rank[p[i].h]+rank[p[i+1].h])&1)==jo[p[i].id]) { rank[fa[p[i+1].h]]=0; fa[fa[p[i+1].h]]=fa[p[i].h]; } else { rank[fa[p[i+1].h]]=1; fa[fa[p[i+1].h]]=fa[p[i].h]; } } else { if(((rank[p[i].h]+rank[p[i+1].h])&1)!=jo[p[i].id]) { printf("%d\n",p[i].id-1); return; } } } printf("%d\n",m); } int main() { scanf("%d",&n); read(); lsh(); go(); system("pause"); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator