首页 > 代码库 > 贪心/hdu 1052 Tian Ji -- The Horse Racing

贪心/hdu 1052 Tian Ji -- The Horse Racing

 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int n; 6 int tian[1010],king[1010]; 7 bool cmp(int x,int y) 8 { 9     return x>y;10 }11 int main()12 {13     scanf("%d",&n);14     while (n!=0)15     {16         for (int i=1;i<=n;i++) scanf("%d",&tian[i]);17         for (int i=1;i<=n;i++) scanf("%d",&king[i]);18         sort(tian+1,tian+n+1,cmp);19         sort(king+1,king+n+1,cmp);20         int tot=n;21         int tian1=1,tiann=n;22         int king1=1,kingn=n;23         int win=0;24         while (tot>0)25         {26             if (tian[tiann]>king[kingn])27             {28                 win++;29                 tiann=tiann-1;30                 kingn=kingn-1;31                 tot--;32                 if (tot<=0) break;33             }34             else if (tian[tiann]<king[kingn])35             {36                 win--;37                 tiann=tiann-1;38                 king1=king1+1;39                 tot--;40                 if (tot<=0) break;41             }42             else if (tian[tiann]==king[kingn])43             {44                 if (tian[tian1]>king[king1])45                 {46                     win++;47                     tian1=tian1+1;48                     king1=king1+1;49                     tot--;50                     if (tot<=0) break;51                 }52                 else if (tian[tian1]<king[king1])53                 {54                     win--;55                     tiann=tiann-1;56                     king1=king1+1;57                     tot--;58                     if (tot<=0) break;59                 }60                 else if (tian[tian1]==king[king1])61                 {62                     if (tian[tiann]>king[king1])63                     {64                         win++;65                         tiann=tiann-1;66                         king1=king1+1;67                         tot--;68                         if (tot<=0) break;69                     }70                     else if (tian[tiann]<king[king1])71                     {72                         win--;73                         tiann=tiann-1;74                         king1=king1+1;75                         tot--;76                         if (tot<=0) break;77                     }78                     else if (tian[tiann]==king[king1])79                     {80                         tiann=tiann-1;81                         king1=king1+1;82                         tot--;83                         if (tot<=0) break;84                     }85                 }86             }87         }88         printf("%d\n",(win)*200);89         scanf("%d",&n);90     }91     return 0;92 }

 

贪心/hdu 1052 Tian Ji -- The Horse Racing