标签:include == tchar 文件 lan 输入 printf 之间 sig
1 #include <bits/stdc++.h> 2 #define il inline 3 #define RG register 4 #define ll long long 5 #define rhl (2573287) 6 #define M (5000010) 7 #define N (40010) 8 9 using namespace std; 10 11 struct edge{ int nt,to; }g[M]; 12 struct data{ int x,y,z; }q[N]; 13 14 int a[N][135],mt[N],q1[M],q2[M],vis[M],head[rhl],n,m,l,num,cnt,res,flg; 15 char ch; 16 17 il int cmp(const data &a,const data &b){ 18 if (a.x==b.x) return a.y<b.y; return a.x<b.x; 19 } 20 21 il int insert(RG int to){ 22 RG int from=to%rhl; 23 for (RG int i=head[from];i;i=g[i].nt) if (g[i].to==to) return i; 24 g[++num]=(edge){head[from],to},head[from]=num; return num; 25 } 26 27 il int eql(RG int x,RG int y){ 28 ++flg; RG int mch=0; 29 for (RG int i=1;i<=l;++i) vis[a[x][i]]=flg; 30 for (RG int i=1;i<=l;++i) mch+=vis[a[y][i]]==flg; 31 return mch==(l>>1); 32 } 33 34 il int solve(){ 35 random_shuffle(q1+1,q1+num+1),random_shuffle(q2+1,q2+num+1),cnt=0; RG int mch=0; 36 for (RG int i=1;i<=n;++i){ 37 if (mt[i]) continue; ++cnt,q[cnt].x=q1[a[i][1]],q[cnt].y=q2[a[i][1]],q[cnt].z=i; 38 for (RG int j=2;j<=l;++j) q[cnt].x=min(q[cnt].x,q1[a[i][j]]),q[cnt].y=min(q[cnt].y,q2[a[i][j]]); 39 } 40 sort(q+1,q+cnt+1,cmp); 41 for (RG int i=1,j;i<cnt;++i){ 42 if (mt[q[i].z]) continue; 43 for (j=i;j<cnt && q[j+1].x==q[j].x && q[j+1].y==q[j].y;++j); 44 for (RG int u=i;u<j;++u){ 45 if (mt[q[u].z]) continue; 46 for (RG int v=u+1;v<=j;++v) 47 if (!mt[q[v].z] && eql(q[u].z,q[v].z)){ 48 mt[q[u].z]=q[v].z,mt[q[v].z]=q[u].z,++mch; break; 49 } 50 } 51 } 52 return mch; 53 } 54 55 int main(){ 56 #ifndef ONLINE_JUDGE 57 freopen("pairing.in","r",stdin); 58 freopen("pairing.out","w",stdout); 59 #endif 60 srand(19260817),cin>>n>>m>>l,n<<=1; while (ch<‘!‘) ch=getchar(); 61 for (RG int i=1;i<=n;++i) 62 for (RG int j=1,x=0;j<=l;++j,x=0){ 63 for (RG int k=1;k<=4;++k,ch=getchar()) x=(x<<7)+(int)ch; 64 a[i][j]=insert(x); 65 } 66 for (RG int i=1;i<=num;++i) q1[i]=q2[i]=i; 67 res=n>>1; while (res) res-=solve(); 68 for (RG int i=1;i<=n;++i) printf("%d\n",mt[i]); return 0; 69 }
标签:include == tchar 文件 lan 输入 printf 之间 sig
原文地址:http://www.cnblogs.com/wfj2048/p/7612449.html