标签:algorithm queue tac scan string ret 比较 stream turn
#include <iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define maxn 2600
int a[maxn],b[maxn];
int main()
{
int N,i,j,i1,j1,sum;
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);
sort(b,b+N);
sum=0;
for(i=0,j=N-1,i1=0,j1=N-1;i1<=j1&&i<=j;)
{
if(a[i]>b[i1])
{
i++;
i1++;
sum++;
}
else if(a[i]<b[i1])
{
i++;
j1--;
sum--;
}
else if(a[j]>b[j1])
{
j--;
j1--;
sum++;
}
else if(a[j]<b[j1])
{
i++;
j1--;
sum--;
}
//现在剩余就是最快的和最慢的都相等的情况,
//则把田忌最慢的和齐王最快的比较
else if(a[i]<b[j1])
{
i++;
j1--;
sum--;
}
else
{
i++;
j1--;
}
}
printf("%d\n",sum*200);
}
return 0;
}
标签:algorithm queue tac scan string ret 比较 stream turn
原文地址:http://www.cnblogs.com/wangkun1993/p/6298307.html