zoukankan      html  css  js  c++  java
  • C

    C - Spider Man

    Peter Parker wants to play a game with Dr. Octopus. The game is about cycles. Cycle is a sequence of vertices, such that first one is connected with the second, second is connected with third and so on, while the last one is connected with the first one again. Cycle may consist of a single isolated vertex.

    Initially there are k cycles, i-th of them consisting of exactly vi vertices. Players play alternatively. Peter goes first. On each turn a player must choose a cycle with at least 2 vertices (for example, x vertices) among all available cycles and replace it by two cycles with p and x - p vertices where 1 ≤ p < x is chosen by the player. The player who cannot make a move loses the game (and his life!).

    Peter wants to test some configurations of initial cycle sets before he actually plays with Dr. Octopus. Initially he has an empty set. In the i-th test he adds a cycle with ai vertices to the set (this is actually a multiset because it can contain two or more identical cycles). After each test, Peter wants to know that if the players begin the game with the current set of cycles, who wins?

    Peter is pretty good at math, but now he asks you to help.

    Input
    The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of tests Peter is about to make.

    The second line contains n space separated integers a1, a2, …, an (1 ≤ ai ≤ 109), i-th of them stands for the number of vertices in the cycle added before the i-th test.

    Output
    Print the result of all tests in order they are performed. Print 1 if the player who moves first wins or 2 otherwise.

    在这里插入图片描述
    在这里插入图片描述
    题意:有n轮
    每轮加在上一轮的基础上再加一个数, 再次把所有的数进行拆分, 直到不可拆分。
    问:首先操作先手必胜还是必输。

    #include<stdio.h>
    int main ()
    {
        long n, i;
        long a[100006];
        int cou = 0;//统计每轮所有数可以拆分的次数总和
        scanf("%ld", &n);
        for(i = 0;i < n;i++)
        {
            scanf("%ld", a+i);
        }
    
        for(i = 0;i < n;i++)
        {
            cou += (a[i] - 1);//每一个数a[i]可以拆a[i]-1次;
            if(cou%2 == 0)//如果为偶数  先拆者 必输
            {
                printf("2
    ");
            }
            else printf("1
    ");//奇数次 先拆赢
        }
        return 0;
    }
    
  • 相关阅读:
    《GK101任意波发生器》升级固件发布(版本:1.0.2build306)
    《GK101任意波发生器》升级固件发布(版本:1.0.2build198)
    【液晶模块系列基础视频】3.2fatfs接口函数的使用2
    【液晶模块系列基础视频】3.1.fatfs文件系统的移植及接口函数的使用
    《GK101任意波形发生器》任意波文件格式说明
    【液晶模块系列基础视频】4.5.X-GUI图形界面库-进度条等函数简介
    己椒苈黄汤
    脱发与五苓散证
    女子咽部不适案
    凤翅医话——小青龙加石膏汤
  • 原文地址:https://www.cnblogs.com/TJack/p/10526952.html
Copyright © 2011-2022 走看看