Codeforces round #265 (Div. 2)

Source: Internet
Author: User

A. inc ARG

I feel that the question is not very clear. I can understand it only when I look at the example. It is a string of binary numbers. The left side is a low position. I will scan it to record the changed bit numbers.

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 200;int n, cnt;char lis[maxn];int main(void){#ifdef LOCAL    freopen("465A.in", "r", stdin);#endif    scanf("%d", &n);    getchar();    for(int i = 0; i < n; i++)        scanf("%c", lis+i);    int tmp = 1;    for(int i = 0; i < n; i++) {        if(tmp) cnt++;          if(tmp && lis[i] == ‘1‘)    tmp = 1;        else    tmp = 0;    }    printf("%d\n", cnt);    return 0;}

 

B. inbox (100500)

When opening a letter, if the next letter is in the next position, you can directly jump to the next page. Otherwise, you can go back to the home page and jump to the next page. Pay attention to special cases, for example, you have read all of them.

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 1000+50;int n, ans;int st[maxn];int main(void){#ifdef LOCAL    freopen("465B.in", "r", stdin);#endif    scanf("%d", &n);    for(int i = 0; i < n; i++)        scanf("%d", st+i);    for(int i = 0; i < n; i++) {        if(st[i] == 0)  continue;        if(ans == 0 || i == 0)  ans++;        else    ans += (st[i-1] == 1? 1: 2);    }       printf("%d\n", ans);    return 0;}

 

C. No to palindromes!

It took me a long time to figure out the correct idea.

For a certain ABA or AA type in the middle of a text string (LEN> = 2), a simple method can be obtained to determine whether a string has a text string, there are two conditions where the character at a certain position meets

This question is to output the string with the smallest Lexicographic Order without the reply sub-string, so it is only possible that each of his locations does not meet the above conditions.

The method I constructed is: the original string has already met the above conditions and requires the minimum Lexicographic Order of the answer, so we will change the rightmost side and rightmost two .... to construct the answer: the left side is OK, and each character on the right needs to meet the conditions, from left to right, for each position, search for the first character that does not exceed the limit and does not form a return string with the first two characters (why not enumerate each character? Because the right part is arbitrary ???

... Groose, my mind is confused here = For details, see the code!

#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 1000+50;const int dx[] = {-2, -1, 1, 2};int n, p;char upper;char lis[maxn], ban[4];bool ok;bool checkLeft(int x){    for(int i = 1; i <= 2; i++)        if(x - i >= 0 && lis[x] == lis[x-i])    return false;    return true;}bool fillRight(int x){    for(int i = x; i < n; i++) {        bool canfill = false;        for(char c = ‘a‘; c <= upper; c++) {            lis[i] = c;            if(checkLeft(i)) {                canfill = true;                break;            }        }        if(!canfill)    return false;    }    return true;}int main(void){#ifdef LOCAL    freopen("465C.in", "r", stdin);#endif    scanf("%d%d", &n, &p);    scanf("%s", lis);    upper = ‘a‘+p-1;    for(int i = n-1; i >= 0; i--) {        for(char c = lis[i]+1; c <= upper; c++) {            lis[i] = c; //          if(i == 2 && c == ‘d‘)  cout << checkLeft(2) << endl;               if(!checkLeft(i))   continue;            if(fillRight(i+1)) {                ok = true;                printf("%s\n", lis);                break;            }        }        if(ok)  break;    }    if(!ok) printf("NO\n");    return 0;}

 

Codeforces round #265 (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.