“美登杯”上海市高校大学生程序设计邀请赛 (华东理工大学)——D. 小花梨的取石子游戏

题目:
在这里插入图片描述
这题我wa到想死了,,,崩溃的心都有了。。。。。。。

思路:

遇到 1 必胜态就会跳转,所以,你的任务其实就是统计从i开始后开头有多少个1,但是你不能用两循环(会T),,,所以,, ,你可以用一个bool型函数从数组的后面对 值为 1 的数进行跳转,然后输出就可以了(全是1的情况和全部不是 1 的情况要分开。。。。)
我被卡的几组样例是:

5
1 1 1 1 2
5
2 1 1 1 1
5
1 1 2 1 1
5
1 2 1 1 1
5
1 1 1 1 1
每一组样例我都wa了一次,最后绿了的时候我,,,,,快~~~·枯了

#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<math.h>
using namespace std;
typedef long long ll;
#define MAXN 100005
#define INF 0x3f3f3f3f//将近int类型最大数的一半,而且乘2不会爆int

int a[MAXN*2];
bool s[MAXN*2];
int main()
{
    int n, sum=0;
    cin >> n;
    memset(s, true, sizeof(s));
    bool ans = true, tem = true;
    for(int i=1; i<=n; ++i)
    {
        scanf("%d", &a[i]);
        a[n+i] = a[i];
        if(a[i] == 1)
        {
            ans = false;
            sum++;
        }
    }
    if(ans)
        for(int i=0; i<n; ++i)
            cout << "First\n";
    else
    {
        if(sum == n)
        {
            if(sum%2)
                for(int i=0; i<n; ++i)
                    cout << "First\n";
            else
                for(int i=0; i<n; ++i)
                    cout << "Second\n";
        }
        else
        {
            for(int i=2*n; i>0; --i)
            {
                if(a[i] == 1)
                    s[i] = !s[i+1];
            }
            for(int i=1; i<=n; ++i)
                if(s[i] == true)
                    cout << "First\n";
                else
                    cout << "Second\n";
        }
    }

    return 0;
}

题解是这样的:
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值