| ||||||||||
| 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 | |||||||||
难道一行可以射多个点?In Reply To:狂wa。哪位给在下看一下?每一列选且只选一个白点,每一行最多选一个白点,是吗? Posted by:tengshengbo at 2005-08-08 23:37:15 > #include <cstdio>
> #include <iostream>
> using namespace std;
> bool map[1005][1005];
> int chk[1005];
> int match[1005];
> int result,m,n;
> int Dfs(int p)
> {
> int i,t;
> for(i=0;i<m;i++)
> if((map[i][p]==1) && (chk[i]==0))
> {
> chk[i]=1;
> t=match[i];
> match[i]=p;
> if((t==-1 )||( Dfs(t)==1))
> return 1;
> match[i]=t;
> }
> return 0;
> }
>
> int pro()
> {
> int i,res=0;
> for(i=0;i<n;i++)
> {
> for(int j=0;j<m;j++)
> chk[j]=0;
> if(Dfs(i)==1) res++;
> }
> return res;
> }
>
> int main()
> {
> int c;
> scanf("%d",&c);
> while(c--)
> {
> scanf("%d%d",&m,&n);
> int i,j,k;
> for(i=0;i<m;i++)
> for(j=0;j<n;j++)
> map[i][j]=0;
> for(i=0;i<m;i++)
> match[i]=-1;
>
> for(i=0;i<n;i++)
> {
> int a,b;
> scanf("%d%d",&a,&b);
> map[a-1][i]=1;
> map[b-1][i]=1;
> }
>
> result=pro();//匈牙利匹配
> int temp[1005];
> for(i=0;i<n;i++)
> temp[i]=0;
> if(result==n)
> {
> int i;
> for(i=0;i<m;i++)
> {
> if(match[i]>=0) temp[match[i]]=i;//转换match到另一边
> }
> for(i=0;i<n-1;i++)
> cout<<temp[i]+1<<" ";
> cout<<temp[n-1]+1<<endl;
> }
> else cout<<"NO"<<endl;
> }
> return 0;
>
> }
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator