luogu p2587 [zjoi2008]泡泡堂

神仙贪心

田忌赛马的策略会gg

1.判断我方最菜能否胜对方最菜,不能就跳2(用最菜虐对方最菜和用更犇的去虐价值都是2)

2.判断我方最犇能否胜对方最犇,不能就跳3(虐得过就没必要送人头)

3.判断我方最菜和对方最犇是否平手(平手总比白送强)

代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

#include<algorithm>
#include<cstring>
using namespace std;
namespace io{
#define re register
#define ll long long
#define inf 0x3f3f3f3f
#define il inline
#define in1(a) read(a)
#define in2(a,b) in1(a),in1(b)
#define in3(a,b,c) in2(a,b),in1(c)
#define in4(a,b,c,d) in2(a,b),in2(c,d)
il void (ll &x){
x=0;ll f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
x*=f;
}
il void read(int &x){
x=0;int f=1;char c=getchar();
while(c<'0'||c>'9'){if(c=='-')f=-f;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
x*=f;
}
}using namespace io;
#define N 100005
int n;
int a[N],b[N];
int main(){
read(n);
for(re int i=1;i<=n;i++) read(a[i]);
sort(a+1,a+n+1);
for(re int i=1;i<=n;i++) read(b[i]);
sort(b+1,b+n+1);
int s=1,t=n,l=1,r=n,ans=0;
while(s<=t&&l<=r){
if(a[s]>b[l]) ans+=2,s++,l++;
else if(a[t]>b[r]) ans+=2,t--,r--;
else ans+=a[s]==b[r],s++,r--;
}
printf("%d ",ans);
swap(a,b);
s=l=1,t=r=n,ans=0;
while(s<=t&&l<=r){
if(a[s]>b[l]) ans+=2,s++,l++;
else if(a[t]>b[r]) ans+=2,t--,r--;
else ans+=a[s]==b[r],s++,r--;
}
printf("%d",n*2-ans);
return 0;
}