【bzoj1034】 ZJOI2008—泡泡堂BNB
http://www.lydsy.com/JudgeOnline/problem.php?id=1034 (题目链接)
题意
田忌赛马。。
Solution
贪心。
1.若A队最弱的比B队最弱的强,先赢一场。
2.若A队最强的比B队最强的强,先赢一场。
3.用A队最弱的去顶B队最强的。
其中第一步与第二步可以替换。
细节
考试自信不拍,结果又写Wa了。。
代码
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 | // bzoj1034 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<cmath> #define LL long long #define inf 2147483640 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; const int maxn=100010; int a[maxn],b[maxn],n; int solve( int *a, int *b) { int al=1,bl=1,ar=n,br=n,ans=0; while (al<=ar && bl<=br) { if (a[al]>b[bl]) ans+=2,al++,bl++; else if (a[ar]>b[br]) ans+=2,ar--,br--; else ans+=(a[al]==b[br]),al++,br--; } 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+1+n);sort(b+1,b+1+n); printf ( "%d %d" ,solve(a,b),2*n-solve(b,a)); return 0; } |
This passage is made by MashiroSky.
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步