zoukankan      html  css  js  c++  java
  • Bzoj 1982: [Spoj 2021]Moving Pebbles 博弈论

    1982: [Spoj 2021]Moving Pebbles

    Time Limit: 10 Sec  Memory Limit: 64 MB
    Submit: 130  Solved: 88
    [Submit][Status][Discuss]

    Description

    2021. Moving Pebbles Two players play the following game. At the beginning of the game they start with n (1<=n<=100000) piles of stones. At each step of the game, the player chooses a pile and remove at least one stone from this pile and move zero or more stones from this pile to any other pile that still has stones. A player loses if he has no more possible moves. Given the initial piles, determine who wins: the first player, or the second player, if both play perfectly. 给你N堆Stone,两个人玩游戏. 每次任选一堆,首先拿掉至少一个石头,然后移动任意个石子到任意堆中. 谁不能移动了,谁就输了...

    Input

    Each line of input has integers 0 < n <= 100000, followed by n positive integers denoting the initial piles. 

    Output

    For each line of input, output "first player" if first player can force a win, or "second player", if the second player can force a win. 

    Sample Input

    3 2 1 3



    Sample Output

    first player

    HINT

    鸣谢lqp18_31..

    Source

     题解:
    在纸上画画就可以得出必败态为:n为偶数且可以分成n/2组两两相同的石子堆。
    例如:
    n=8 
    石子为:1 1 6 6 8 8 8 8
    博弈的题都不太好想,要从小到大一个一个去尝试。
    但。。。
    代码。。。
     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 int a[100010];
     4 int main()
     5 {
     6     int n,i;
     7     while(scanf("%d",&n)!=EOF)
     8     {
     9         for(i=1;i<=n;i++)scanf("%d",&a[i]);
    10         sort(a+1,a+n+1);
    11         if(n%2==0)
    12         {
    13             for(i=1;i<=n;i+=2)if(a[i]!=a[i+1])break;
    14             if(i>n){printf("second player
    ");continue;}
    15         }
    16         printf("first player
    ");
    17     }
    18     return 0;
    19 }
    View Code
  • 相关阅读:
    vue + ajax + php 接口的使用小接
    网页调用qq聊天
    基于touch.js 左滑删除功能
    touch.js——常见应用操作
    常用链接
    如何判断滚动条已到达底部
    前端如何优雅的选择字体
    纯css3打造瀑布流布局
    移动端软键盘监听(弹出,收起),及影响定位布局的问题
    jq获取图片的原始尺寸,自适应布局
  • 原文地址:https://www.cnblogs.com/Var123/p/5297887.html
Copyright © 2011-2022 走看看