POJ 2287

来源:互联网 发布:飞升游戏升级数据 编辑:程序博客网 时间:2024/05/29 04:38

 把双方的马从大到小排序 然后从前往后比较 老田赢了呢 就继续往下比 老田比不过呢 就拉老田最慢的马跟这个比 这里好理解

还有比平的情况 比平了还是从后面找一匹马

找的时候 要是老田后面的马可以赢对应位置的马 就接着往前比 然后找到的那匹就跟前面这匹马比

不能理解的话看下面这组测试数据

2

4  2

4  1

应该输出 200

2

4 1

4 2

输出 0

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define M 1005
using namespace std;
int a[M],b[M];

bool cmp(int a,int b)
{return a>b;}

int main()
{
 int n;
 int i;
 int ap,at,bp,bt;
 int ans;
 while(scanf("%d",&n)&&n)
 {
  for(i=0;i<n;i++)
      scanf("%d",&a[i]);
  for(i=0;i<n;i++)
      scanf("%d",&b[i]);
  sort(a,a+n,cmp);
  sort(b,b+n,cmp);
  ap=bp=0;
  at=bt=n-1;
  ans=0;
  while(ap<=at&&bp<=bt)
  {
   if(a[ap]>b[bp])
   {
    ans+=200;
    ap++;
    bp++;
   }
   else if(a[ap]<b[bp])
   {
    ans-=200;
    bp++;
    at--;
   }
   else
   {
    while(ap<=at&&bp<=bt)
    {
     if(a[at]>b[bt])
     {
      ans+=200;
      at--;
      bt--;
     }
     else
     {
      if(a[at]<b[bp])
       ans-=200;
      at--;
      bp++;
      break;
     }
    }
   }
  }
  printf("%d\n",ans);
 }
 return 0;
}


 

原创粉丝点击