Codeforces Round #258 (Div. 2) summary,

Source: Internet
Author: User

Codeforces Round #258 (Div. 2) summary,

A. Game With Sticks (451A)

In fact, no matter which intersection you choose, the result is that the number of rows and columns are reduced by one. Now, whoever first reduces the number of rows and the number of columns is 0, wins. Because Akshat is selected first, if the smallest of the columns is an odd number, Akshat wins. Otherwise, Malvika wins.

Code:

#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){    int a, b;    while(~scanf("%d%d", &a, &b))    {        int minn = a>b?b:a;        if(minn%2==0)            printf("Malvika\n");        else            printf("Akshat\n");    }    return 0;}

B. 451B-Sort the Array (451B)

Whether the array can be changed to ascending order by one flip. In fact, it is easy to find out the first drop position, the first rising position, and the boundary value. However, this question has many pitfalls. Although Pretest Pass is passed, WA is finished at last, because there is a condition in output that is not considered (start must not be greater than end ). As a result, it is difficult to write less judgment conditions.

Code:

By dzk_acmer, contest: Codeforces Round #258 (Div. 2), problem: (B) Sort the Array, Accepted, # #include <iostream>#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){    int n, a[100010];    while(~scanf("%d", &n))    {        for(int i = 1; i <= n; i++)            scanf("%d", &a[i]);        if(n == 1)        {            printf("yes\n1 1\n");            continue;        }        if(n == 2)        {            printf("yes\n");            if(a[1] < a[2])                printf("1 1\n");            else                printf("1 2\n");            continue;        }        int st = 1, ed = n, up = 0, down = 0;        for(int i = 2; i < n; i++)        {            if(a[i] > a[i-1] && a[i] > a[i+1])            {                up++;                st = i;            }            if(a[i] < a[i-1] && a[i] < a[i+1])            {                down++;                ed = i;            }        }        a[0] = -100;        a[n+1] = 1e9+2;        if(up >= 2 || down >= 2 || st >= ed || a[st] > a[ed+1] || a[ed] < a[st-1])        {            printf("no\n");            continue;        }        printf("yes\n");        if(a[st] > a[ed])            printf("%d %d\n", st, ed);        else            printf("1 1\n");    }    return 0;}





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.