zoukankan      html  css  js  c++  java
  • 博弈专题

    CodeForces - 549C

    剩下的人数之和为奇数时先手胜,否则后手胜。

    考虑最后一步

     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main(){
     5     //ios_base::sync_with_stdio(0);
     6     int n, k;
     7     while(cin>>n>>k){
     8         int cnt = 0;
     9         int x;
    10         long long sum = 0;
    11         for(int i = 0;  i < n; i++){
    12             scanf("%d", &x);
    13             sum = sum + x;
    14             if(x & 1) cnt++;
    15         }
    16         int ok = 1;
    17         if(n == k){
    18             if(sum & 1) ok = 1;
    19             else ok = 0;
    20         }else{
    21             int m = n - k, op = m / 2;
    22             if(m & 1) { // 先手最后拿
    23                 if(k & 1){
    24                     if(op >= cnt) ok = 0;
    25                     else ok = 1;
    26                 }else{
    27                     if(op >= cnt || op >= (n - cnt)) ok = 0;
    28                     else ok = 1;
    29                 }
    30             }else {
    31                 if(k & 1){
    32                     if(op >= (n - cnt)) ok = 1;
    33                     else  ok = 0;
    34                 }else{
    35                     ok = 0;
    36                 }
    37             }
    38         }
    39         if(ok) cout<<"Stannis
    ";
    40         else cout<<"Daenerys
    ";
    41     }
    42 }
    View Code

    取石子游戏

    链接:here

  • 相关阅读:
    UDP
    ICMP协议、DNS、ARP协议、ping、DHCP协议
    OSI七层模型和TCP/IP四层模型
    STL六大组件
    迭代器
    哈希表
    react wangeditor使用
    URL切割
    ES6对象合并
    nginx 访问本机文件
  • 原文地址:https://www.cnblogs.com/yijiull/p/8484474.html
Copyright © 2011-2022 走看看