bzoj4396[usaco2015 Dec]high Card wins*

Source: Internet
Author: User

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*

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.