Codeforces Round #258 (Div. 2) 小結

來源:互聯網
上載者:User

A. Game With Sticks (451A)

水題一道,其實不管你選取哪一個交叉點,結果都是行數列數都減一,那現在就是誰先減到行、列有一個為0,那麼誰就贏了。由於Akshat先選,因此如果行列中最小的一個為奇數,那麼Akshat贏,否則Malvika贏。

代碼:

#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)

考察能否通過一次翻轉,將數組變為升序。其實就是考慮第一個下降的位置,和之後第一個上升的位置,判斷邊界值大小,細心的話很容易發現。不過這道題坑點好多,雖然Pretest Pass了,但是,最後WA了,因為在output裡面有一個條件沒有考慮,就是(start must not be greater than end) 。導致少寫一個判斷條件,好坑啊。

代碼:

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;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.