P1650 田忌赛马(贪心)
作者:互联网
同 泡泡堂
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
const int N=20005;
int a[N],b[N],n;
int solve(){
int ans=0;
int s=1,t=n,l=1,r=n;
while(s<=t&&l<=r){
if(a[s]>b[l]){
s++; l++;
ans+=200;
}
else if(a[t]>b[r]){
t--; r--;
ans+=200;
}
else{
if(a[s]!=b[r]) ans-=200;
s++,r--;
}
}
return ans;
}
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n;i++) scanf("%d",&b[i]);
sort(a+1,a+n+1); sort(b+1,b+n+1);
printf("%d",solve());
return 0;
}
标签:200,田忌赛马,int,P1650,++,--,ans,include,贪心 来源: https://www.cnblogs.com/New-ljx/p/15370198.html