沿传孙子的策略 , 用自己最差的马打对方最好的马。
提示:
1. 先前的一道田忌赛马有些类似 , 但是这个题时间不允许我们用
O(n2)
的算法来搞
2. 研究了一下策略满足单峰性 , 果断三分。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <stack>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <string>
using namespace std;
const int maxn = 1e5+1e2;
inline int re() { int n; scanf("%d",&n); return n; }
int n;
int a[maxn] , b[maxn];
int give(int *x , int *y , int l)
{
int res = 0;
for(int i=n-l;i<n;i++) if(x[i]<y[i-n+l]) return 0; else res+= (x[i]==y[i-n+l]?1:2);
return res;
}
int solve(int *x , int *y)
{
int l = 0 , r = n+1;
while(l+4<r)
{
int len = r-l+1;
int ml = l+len/3-1;
int mr = r-len/3+1;
if(give(x , y , ml) < give(x , y , mr)) l = ml;
else r = mr;
}
int res = -1;
for(int i=l;i<=r;i++) res = max(res , give(x , y , i));
return res;
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("bnb10.in","r",stdin);
#endif
n = re();
for(int i=0;i<n;i++) a[i] = re();
for(int i=0;i<n;i++) b[i] = re();
sort(a , a+n);
sort(b , b+n);
printf("%d %d\n",solve(a , b) , n*2-solve(b , a));
//cout<<solve(a , b)<<" "<<solve(b , a)<<endl;
return 0;
}
数据:
TestInput 1:
10
3
4
3
2
0
2
0
0
0
2
3
0
2
1
2
1
0
0
2
0
TestOutput 1:
15 9