zoukankan      html  css  js  c++  java
  • BestCoder8 1002 Revenge of Nim(hdu 4994) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4994

    题目意思:有 n 个 heap(假设从左至右编号为1~n),每个 heap 上有一些 objects。有两个player,轮流从左至右的 heap 上取走 object(1 <= 取走数 <= 当前heap上的最多objects数),规定当前的 heapi 如果还有object,那么不能取走heapi+1的object,直到把 heapi 的 object 全部取光。

        题解在这里

        http://bestcoder.hdu.edu.cn/

        其实好容易理解,如果 heap 上的object数一直为1,那么轮到的player1(or player2)只能不得不取走,直到遇到不为1的 heapx,那么此时轮到的player就取得主动权,取走 heapx(假设objects 数为 sum) 中sum-1的数,最后另一个player处于被动状态,也就是必败点。

         

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstdlib>
     4 #include <cstring>
     5 using namespace std;
     6 
     7 const int maxn = 1000 + 10;
     8 int a[maxn];
     9 
    10 int main()
    11 {
    12     int T, n, m;
    13     while (scanf("%d", &T) != EOF)
    14     {
    15         while (T--)
    16         {
    17             scanf("%d", &n);
    18             for (int i = 1; i <= n; i++)
    19                 scanf("%d", &a[i]);
    20             int i = 1;
    21             int ok = 1;
    22             while (a[i] == 1 && i+1 <= n)
    23             {
    24                 ok ^= 1;
    25                 i++;
    26             }
    27             printf("%s
    ", ok ? "Yes" : "No");
    28         }
    29     }
    30     return 0;
    31 }
    View Code
  • 相关阅读:
    Camera HAL3学习
    Android GPU呈现模式分析
    Android O版本自定义日志输出目录
    Android Configstore HAL
    Ubuntu下设置adb path的方法
    Ubuntu使用技巧
    PHP学习笔记
    mysql安装
    在ubuntu中安装Python
    OS X在使用<semaphore.h>时报错
  • 原文地址:https://www.cnblogs.com/windysai/p/3970824.html
Copyright © 2011-2022 走看看