ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1045. Funny Game

Why my program still WA?Please help me!Thank you!
Posted by kingfisher 22 Mar 2003 15:51
#include<stdio.h>

#define max 1001

int n,start,fly,note[max][3],use[max],airport[max];

void tidy()
{
  int i,j;
  for(i=0;i<max;i++)
    for(j=0;j<3;j++)
      note[i][j]=0;
  for(i=1;i<max;i++)airport[i]=0;
  for(i=1;i<max;i++)use[i]=0;
  fly=0;
}

void init()
{
  int i,a,b;
  scanf("%d%d",&n,&start);
  for(i=1;i<n;i++)
    {
      scanf("%d%d",&note[i][1],&note[i][2]);
    }
}

void statn()
{
  int i,j;
  for(i=1;i<n;i++)
    for(j=1;j<3;j++)
      use[note[i][j]]++;
}

void find()
{
  int i,j,k,s,p;
  p=0;
  for(i=1;i<=n;i++)
    if((i!=start)&&(use[i]==1))
      {
    p=1;if(airport[i])s=0;else s=1;
    for(j=1;j<n;j++)
      if(((note[j][1]==i)||(note[j][2]==i))&&(!note[j][0]))
        {
          if(note[j][1]==i)k=note[j][2];else k=note[j][1];
          note[j][0]=1;use[k]++;
          if(s&&(airport[k]>i))airport[k]=i;
          break;
        }
    use[i]=0;
      }
  if(p)find();
}

void work()
{
  statn();
  find();
  fly=airport[start];
}

void out()
{
  if(fly)
    {printf("First player wins flying to airport %d\n",fly);}
  else{printf("First player loses\n");}
}

void main()
{
  tidy();
  init();
  work();
  out();
}
I'v Ac now!!!!!!!!
Posted by kingfisher 22 Mar 2003 16:24
> #include<stdio.h>
>
> #define max 1001
>
> int n,start,fly,note[max][3],use[max],airport[max];
>
> void tidy()
> {
>   int i,j;
>   for(i=0;i<max;i++)
>     for(j=0;j<3;j++)
>       note[i][j]=0;
>   for(i=1;i<max;i++)airport[i]=0;
>   for(i=1;i<max;i++)use[i]=0;
>   fly=0;
> }
>
> void init()
> {
>   int i,a,b;
>   scanf("%d%d",&n,&start);
>   for(i=1;i<n;i++)
>     {
>       scanf("%d%d",&note[i][1],&note[i][2]);
>     }
> }
>
> void statn()
> {
>   int i,j;
>   for(i=1;i<n;i++)
>     for(j=1;j<3;j++)
>       use[note[i][j]]++;
> }
>
> void find()
> {
>   int i,j,k,s,p;
>   p=0;
>   for(i=1;i<=n;i++)
>     if((i!=start)&&(use[i]==1))
>       {
>     p=1;if(airport[i])s=0;else s=1;
>     for(j=1;j<n;j++)
>       if(((note[j][1]==i)||(note[j][2]==i))&&(!note[j][0]))
>         {
>           if(note[j][1]==i)k=note[j][2];else k=note[j][1];
>           note[j][0]=1;use[k]++;
>           if(s&&(airport[k]>i))airport[k]=i;
>           break;
>         }
>     use[i]=0;
>       }
>   if(p)find();
> }
>
> void work()
> {
>   statn();
>   find();
>   fly=airport[start];
> }
>
> void out()
> {
>   if(fly)
>     {printf("First player wins flying to airport %d\n",fly);}
>   else{printf("First player loses\n");}
> }
>
> void main()
> {
>   tidy();
>   init();
>   work();
>   out();
> }