bzoj4396[usaco2015 Dec]high Card Wins
Test instructions
There are a total of 2n cards, Alice has n Zhang, Bob has n Zhang, each bureau points big win. Knowing Bob's Order of cards, Alice can win a few innings. n≤50000.
Exercises
Greedy. Sort Alice and Bob's cards by the number of points, and then if Alice's current card wins Bob's current card, it ans++ to adjust Bob's current card until Alice's current card wins Bob's current card.
Code:
1#include <cstdio>2#include <cstring>3#include <algorithm>4 #defineInc (I,J,K) for (int i=j;i<=k;i++)5 #defineMAXN 500106 using namespacestd;7 8InlineintRead () {9 CharCh=getchar ();intf=1, x=0;Ten while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; Ch=GetChar ();} One while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); A returnf*x; - } - intA[maxn],b[maxn],ans,n,tot;BOOLc[maxn*2]; the intMain () { -N=read (); Inc (I,1, n) a[i]=read (), c[a[i]]=1; Inc (I,1,2*n)if(!c[i]) b[++tot]=i; Sort (A +1, a+n+1); - intp=1, q=1; - while(1){ + while(P<=n&&b[p]<a[q]) p++;if(p==n+1) Break; ans++; p++; q++; - } +printf"%d", ans);return 0; A}
20160908
bzoj4396[usaco2015 Dec]high Card wins*