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 <iostream> #include <string> #include <queue> #include <map> #include <memory> using namespace std; struct node { int color; int axi; struct node* next; }; struct combine { long int num; struct node *top; struct node *last; }couple[3][31]; long int n,paired; int output[31]={0};//1表示老公,2表示老婆 int bfs(int level) { if(level>n-1) return 1;//1表示找到了 int temp[3]={0}; temp[1]=couple[1][level].num>couple[2][level].num?1:2; temp[2]=temp[1]!=1?1:2; int i,flag=1; for(i=1;i<=2;i++) { output[level]=temp[i]; struct node* p=couple[temp[i]][level].top; while(p->next!=NULL) { if(output[p->axi]==p->color) { flag=0; break; } p=p->next; } if(flag==1) { if(bfs(level+1)==1) return 1; } output[level]=0; flag=1; } return 0; } int assign(int first,int second,int sex1,int sex2) { couple[sex1][first].last->next=new struct node; couple[sex1][first].last->axi=second; couple[sex1][first].last->color=sex2; couple[sex1][first].last=couple[sex1][first].last->next; couple[sex1][first].last->axi=couple[sex1][first].last->color=0; couple[sex1][first].last->next=NULL; couple[sex1][first].num++; return 0; } int main() { cin>>n>>paired; while(n!=0) { output[0]=1; long int i; for(i=0;i<=30;i++) { couple[1][i].num=couple[2][i].num=0; couple[1][i].top=couple[1][i].last=new struct node; couple[2][i].top=couple[2][i].last=new struct node; couple[1][i].last->axi=couple[1][i].last->color=couple[2][i].last->axi=couple[2][i].last->color=0; couple[1][i].last->next=couple[2][i].last->next=NULL; } for(i=1;i<=paired;i++) { string a,b; cin>>a>>b; string::iterator iter1,iter2; iter1=a.begin(),iter2=b.begin(); int first,second,sex1,sex2; first=(*iter1)-48,second=(*iter2)-48; iter1++,iter2++; if(*iter1=='h') sex1=1; else sex1=2; if(*iter2=='h') sex2=1; else sex2=2; assign(first,second,sex1,sex2); assign(second,first,sex2,sex1); } if(bfs(1)) { for(i=1;i<=n-1;i++) { if(output[i]==1) cout<<i<<'w'<<" "; else cout<<i<<'h'<<" "; } cout<<endl; } else { cout<<"bad luck"<<endl; } memset(output,0,31*sizeof(int)); cin>>n>>paired; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator