bzoj 1034 泡泡堂BNB
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1034
题解:
很明显的贪心,读过田忌赛马的典故就很容易能想出来,分成三种情况讨论:
<1>如果A队实力最强的选手比B队实力最强的选手强,就比一场;
<2>如果A队实力最弱的选手比B队实力最弱的选手强,就比一场;
<3>如果上述情况都不行,就直接用A队实力最弱的选手和B队实力最强的选手比一场;
先把浙江队当成A队,对手当成B队,算出最大得分;
再反过来算出最小得分即可
1 #include<cstdio> 2 #include<algorithm> 3 using namespace std; 4 #define MAXN 100010 5 int n,a[MAXN],b[MAXN],ans; 6 int main() 7 { 8 scanf("%d",&n); 9 for(int i=1;i<=n;i++)scanf("%d",&a[i]); 10 for(int i=1;i<=n;i++)scanf("%d",&b[i]); 11 sort(a+1,a+1+n); 12 sort(b+1,b+1+n); 13 int l1=1,l2=1,r1=n,r2=n; 14 while(l1<=r1&&l2<=r2) 15 { 16 if(a[l1]>b[l2]) 17 { 18 ans+=2; 19 l1++; 20 l2++; 21 } 22 else if(a[r1]>b[r2]) 23 { 24 ans+=2; 25 r1--; 26 r2--; 27 } 28 else 29 { 30 if(a[l1]==b[r2])ans++; 31 l1++; 32 r2--; 33 } 34 } 35 printf("%d ",ans); 36 ans=0; 37 l1=1; 38 l2=1; 39 r1=n; 40 r2=n; 41 while(l1<=r1&&l2<=r2) 42 { 43 if(b[l1]>a[l2]) 44 { 45 ans+=2; 46 l1++; 47 l2++; 48 } 49 else if(b[r1]>a[r2]) 50 { 51 ans+=2; 52 r1--; 53 r2--; 54 } 55 else 56 { 57 if(b[l1]==a[r2])ans++; 58 l1++; 59 r2--; 60 } 61 } 62 printf("%d\n",2*n-ans); 63 return 0; 64 }