Codeforces Round #283 (Div. 2) D. Tennis Game

Source: Internet
Author: User

Test instructions: Give the match situation, output all the s,t that meet the condition, make this game have result.

Enumerate T, then two points to the lower bound of T, and update the boundaries of each inning, judging who wins the current innings. Finally, pay attention to whether the winner of the last inning is the winner of the whole game.

#include <cstdio>#include<cstring>#include<algorithm>#include<map>#include<Set>#include<bitset>#include<queue>#include<stack>#include<string>#include<iostream>#include<cmath>#include<climits>using namespacestd;Const intMAXN =111111;Const intINF =0xFFFFFFF;intSUM1[MAXN];intSUM2[MAXN];intN;intA[MAXN];intErfen1 (intLintRintkey) {    intAns =INF; intK =l;  while(l<=R) {        intMid= (l+r) >>1; if(sum1[mid]-sum1[k-1] = = key) ans=mid; if(sum1[mid]-sum1[k-1] >= key) R = mid-1; ElseL = mid+1; }    returnans;}intErfen2 (intLintRintkey) {    intAns =INF; intK =l;  while(l<=R) {        intMid= (l+r) >>1; if(Sum2[mid]-sum2[k-1]==key) ans =mid; if(Sum2[mid]-sum2[k-1]>=key) R = mid-1; ElseL = mid+1; }    returnans;}intJudgeintt) {    intANS1 =0;intAns2 =0; intL =1;  while(l<=N) {        intT1 =erfen1 (l,n,t); intt2 =Erfen2 (l,n,t); L= Min (t1,t2) +1; if(l>n+1)return 0; if(T1==t2&&t1==inf)Continue; if(T1&LT;T2) ans1++; Elseans2++; if(L-1==N) {            if(ANS1&GT;ANS2&AMP;&AMP;T1&GT;T2)return 0; if(ANS2&GT;ANS1&AMP;&AMP;T2&GT;T1)return 0; }    }    if(ANS1==ANS2)return 0; returnAns1>ans2?ans1:ans2;}structnode{intXinty;};intcmpConstNode &a,ConstNode &b) {    returna.x<b.x;} Vector<node >Q;intMain () {CIN>>N; memset (sum2,0,sizeof(sum2)); memset (SUM1,0,sizeof(SUM1));  for(inti =1; i<=n;i++) {scanf ("%d",&A[i]); if(a[i]==1) Sum1[i] =1; ElseSum2[i] =1; }     for(inti =1; i<=n;i++) Sum1[i]+=sum1[i-1],sum2[i]+=sum2[i-1];  for(intt =1; t<=n;t++){        intGG =judge (t); if(gg==0)Continue; Node K; k.x= GG; K.Y =T;    Q.push_back (k);    } sort (Q.begin (), Q.end (), CMP); printf ("%d\n", Q.size ());  for(inti =0; I<q.size (); i++) printf ("%d%d\n", Q[I].X,Q[I].Y); return 0;}

Codeforces Round #283 (Div. 2) D. Tennis Game

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.