Codeforces round#297 Div2

Source: Internet
Author: User

B:

Test instructions: Given a string, and given m digits

For each of the digital AI meanings, flip the AI to the n-ai+1 string again.

A string that requires the output to be flipped after M-times.

The idea is to determine the position of the first character is reversed odd number of times, or even a few times on it, flipped an even number of times represents no flip

The idea is to store the m numbers down and then sort them. For each str[i], 1<=i<strlen (str),

Using Index=upper_bound (a,a+m,i), the return value of Upper_bound (A,a+m,i) is the first element iterator in the returned array that is larger than I, and if not, returns the iterator that points to the last element

So index-a represents the number of digits in array A that are smaller than I.

So if the index-a is odd, then the position I flips the odd number of times, the output STR[N-I+1]

If it is even, the code position I flips an even number of times, output STR[I]

1#include <stdio.h>2#include <string.h>3#include <algorithm>4 using namespacestd;5 Const intN =200000+Ten;6 CharStr[n];7 intA[n];8 BOOLVis[n];9 Ten intMain () One { A     intM,i,x,n; -scanf"%s", str+1); -scanf"%d",&m); then = strlen (str+1); -      for(i=1; i<=m; ++i) -scanf"%d",&a[i]); -Sort (A +1, a+m+1); +     intnn = n/2,*index; -      for(i=1; i<=nn; ++i) +     { A          atindex = Upper_bound (A +1, a+m+1, i); -         if((index-a-1)%2==1) -         { -printf"%c", str[n-i+1]); -vis[n-i+1] =true; -         } in         Else -printf"%c", Str[i]); to          +     } -      for(i=nn+1; i<=n; ++i) the     { *         if(Vis[i]) $printf"%c", str[n-i+1]);Panax Notoginseng         Else -printf"%c", Str[i]); the     } +Puts""); A}
View Code

But watching someone else.

Codeforces round#297 Div2

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.