首页 > 代码库 > UVALive 6662 TheLastAnt

UVALive 6662 TheLastAnt

 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 struct xxx 7 { 8     int p,d; 9 }a[22];10 int n,l;11 bool f[22];12 int main()13 {14     while (~scanf("%d%d",&n,&l))15     {16         if (n==0&&l==0) break;17         for (int i=1;i<=n;i++)18         {19             char s[5];20             scanf("%s",s);21             scanf("%d",&a[i].p);22             if (s[0]==R) a[i].d=1;23             else a[i].d=0;24         }25         int ti=0,tot=n;26         memset(f,0,sizeof(f));27         int ans;28         while (tot)29         {30             ti++;31             for (int i=1;i<=n;i++)32                 if (!f[i])33                 {34                     if (a[i].d==1) a[i].p++;35                     else a[i].p--;36                 }37             for (int i=1;i<=n;i++)38                 if (!f[i])39                 {40                     if (a[i].p>=l)41                     {42                         ans=i;43                         f[i]=1;44                         tot--;45                     }46                 }47             for (int i=1;i<=n;i++)48                 if (!f[i])49                 {50                     if (a[i].p<1)51                     {52                         ans=i;53                         f[i]=1;54                         tot--;55                     }56                 }57             for (int i=1;i<=n;i++)58                 for (int j=i+1;j<=n;j++)59                     if (a[i].p==a[j].p)60                     {61                         a[i].d^=1;62                         a[j].d^=1;63                     }64         }65         printf("%d %d\n",ti,ans);66     }67     return 0;68 }
View Code