題目傳送門
?
?
分析:一道策略游戲題,要求最大期望得分和最小期望得分。首先分析最大,很顯然是可以用一種類似于田忌賽馬的思維來做,將兩隊的實力按照從大到小(其實從小到大也可以)排序,然后就按照順序比較,可能會出現以下幾種情況:
我方最大>對方最大,則用我方最大對抗對方最大
我方最小>對方最小,則用我方最小對抗對方最小
如果以上兩種情況都不滿足,則用我方最小去對抗對方最大,為我方最大爭取機會。
這個正確性應該不難證明,那么最大的得分就這么A(shui)掉了;
再看最小得分,發現直接求最小得分并不容易,那么轉換一下思維,求最大失分,再用2n-最大失分,正確性易證。那么求最大失分思維就和上面一樣,只需轉換一下:
我方最大<對方最大,則用我方最大對抗對方最大
我方最小<對方最小,則用我方最小對抗對方最小
如果以上兩種情況都不滿足,則比較我方最大與對方最小,如果相等,則失一分,否則不失分。
然后,這題就這樣水過去了!
Code:
?
//It is made by HolseLee on 7th Apr 2018 //Luogu.org P2587 #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<iomanip> #include<algorithm> using namespace std; const int N=1e5+7; int n,a[N],b[N]; int ans,hm,tm,he,te; inline int read() {char ch=getchar();int num=0;bool flag=false;while(ch<'0'||ch>'9'){if(ch=='-')flag=true;ch=getchar();}while(ch>='0'&&ch<='9'){num=num*10+ch-'0';ch=getchar();}return flag?-num:num; } bool cmp(int x,int y) {return x>y;} int main() {n=read();for(int i=1;i<=n;i++)a[i]=read();for(int i=1;i<=n;i++)b[i]=read();sort(a+1,a+n+1,cmp);sort(b+1,b+n+1,cmp);tm=te=n;hm=he=1;while(hm<=tm){if(a[hm]>b[he])ans+=2,hm++,he++;else if(a[tm]>b[te])ans+=2,tm--,te--;else ans+=(a[tm]==b[he]),he++,tm--;}printf("%d ",ans);hm=he=1;tm=te=n;ans=0;while(hm<=tm){if(a[hm]<b[he])ans+=2,hm++,he++;else if(a[tm]<b[te])ans+=2,tm--,te--;else ans+=(a[hm]==b[te]),hm++,te--;}printf("%d",2*n-ans);return 0; }
?
?
?
?