| ||||||||||
| 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 | |||||||||
为什么这样会wa#include <iostream>
#include <string>
using namespace std;
int que[5000000];
int fa(char ch,char *a)
{
for(int i=0;;i++)
if(ch == a[i]) return i;
}
int main()
{
int cas,i,num;
char ma[200],fe[200],c,pre[200];
char ma_rela[200][200],fe_rela[200][200];
char engaged[200];
int ok[200];
scanf("%d",&cas);
int ff = cas;
while(cas--)
{
if(ff != cas + 1) cout<<endl;
scanf("%d",&num);
for(i = 0;i < num;i++)
engaged[i] = '*';
for(i = 0;i < num;i++)
cin>>fe[i];
for(i = 0;i < num;i++)
cin>>ma[i];
for(i = 0;i < num;i++)
cin>>fe_rela[i];
for(i = 0;i < num;i++)
cin>>ma_rela[i];
for(i = 0;i < num;i++)
ok[i] = 2;
for(i = 0;i < num;i++)
que[i]=i;
int head=0; int tail=num-1;
while(tail >= head)
{
int m = que[head];
int w = fa(ma_rela[m][ok[m]],fe); //w编号
ok[m]++;
if(engaged[w] != '*')
{
int m1 = fa(ma[m],fe_rela[w]);
int m2 = fa(engaged[w],fe_rela[w]);
if(m1 < m2)
{
int fm = fa(engaged[w],ma);
engaged[w] = ma[m];
head++;
que[++tail] = fm;
}
}
else
{
engaged[w] = ma[m];
head++;
}
}
for(i = 0;i < num;i++)
cout<<fe[i]<<" "<<engaged[i]<<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