Codeforces Round #310 (Div. 2)

Source: Internet
Author: User
Tags cmath

A. Case of the zeros and Ones

Main topic:

Give a string containing only 0 and 1, when it is 0 and 1 adjacent, the two characters can be deleted, ask the last character can not be deleted how many?

Problem Solving Ideas:

Only the number of 0 and 1 is counted separately, then the absolute value after subtracting is the answer.

1#include <algorithm>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <cmath>7 using namespacestd;8 9 Const intMAXN =200010;Ten Const intINF =0x3f3f3f3f; One intFabs (intAintb) A { -     if(A >b) -         returnAb; the     returnB-A; - } - intMain () - { +     CharSTR[MAXN]; -     intN, a, B; +      while(SCANF ("%d", &n)! =EOF) A     { atA = b =0; -scanf ("%s", str); -          for(intI=0; i<n; i++) -         { -             if(Str[i] = ='0') -A + +; in             Else -b++; to         } +printf ("%d\n", Fabs (A, b)); -     } the     return 0; *}

B. Case of Fake Numbers

Main topic:

A sequence has n number, starting from 1 numbering, each time the operation of the sequence is the odd tree to add one, even minus one, ask after a limited number of operations can not constitute 0,1,2,3,4 The sequence of the n-1.

Problem Solving Ideas:

Because the number in this sequence is a number in the [0,n-1] interval, the sequence is bound to loop after an n-number of operations,

1#include <algorithm>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <cmath>7 using namespacestd;8 9 Const intMAXN = -;Ten Const intINF =0x3f3f3f3f; One  A intMain () - { -     intN, A[maxn], I; the      while(SCANF ("%d", &n)! =EOF) -     { -          for(i=0; i<n; i++) -scanf ("%d", &a[i]); +          for(i=0; i<n; i++) -         { +             intFlag =0; A              for(intj=0; j<n; J + +) at             { -                 if(j%2) -A[J] = (A[j] +1) %N; -                 Else -A[J] = (A[j]-1+ N)%N; -                 if(A[j]! =j) inFlag + +; -             } to             if(flag==0) +                  Break; -         } the         if(I <N) *printf ("yes\n"); $         ElsePanax Notoginsengprintf ("no\n"); -     } the     return 0; +}

C. Case of Matryoshkas

Main topic:

There are n lovely beautiful drops of Russian dolls, numbering starting from 1, the number of large can be set on the number of small on the top, because they love cute, so now to put them all together to marry home.

There are only two things to do when a doll is set:

1: Put a single big Doll out of a string or a doll.

2: Take a single doll off the outermost layer of a doll.

How many times do I have to ask the youngest to marry the doll home?

Problem Solving Ideas:

Is the simulation, is the Mini.

1#include <algorithm>2#include <iostream>3#include <cstdio>4#include <cstring>5#include <cstdlib>6#include <cmath>7 using namespacestd;8 9 Const intMAXN =100010;Ten Const intINF =0x3f3f3f3f; One  A intMain () - { -     intN, M; the      while(SCANF ("%d%d", &n, &m)! =EOF) -     { -         intsum = M-1, ans =0, a1, B; -          while(M--) +         { -             intnum, F =0; +scanf ("%d", &num); Ascanf ("%d", &A1); atNum--; -             intc =num; -             intA =A1; -              while(Num--) -             { -scanf ("%d", &b); in                 if(b > A +1&& F = =0) -f = num +1; toA =b; +             } -             if(A1! =1)//only big can be to the small upper one a set, remember Oh, is one, here WA's heart is really rubber cork stoppling thef =C; *Ans + =F; $Sum + =F;Panax Notoginseng         } -Ans + =sum; theprintf ("%d\n", ans); +     } A     return 0; the}

After the topic of the baby really do not ah, after all, the hands of the party, tomorrow must be the first time for everyone to fill up, ~~~~~~~~

Codeforces Round #310 (Div. 2)

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.