Codeforces Round #258 (Div. 2) 小结

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)

考察是否能通过一次翻转,将数组变为升序。事实上就是考虑第一个下降的位置,和之后第一个上升的位置,推断边界值大小,细心的话非常easy发现。只是这道题坑点好多,尽管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;
}


转载于:https://www.cnblogs.com/lcchuguo/p/4510190.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值