zoukankan      html  css  js  c++  java
  • 博弈 HDOJ 4371 Alice and Bob

    题目传送门

    题意:Alice和 Bob轮流写数字,假设第 i 次的数字是S[i] ,那么第 i+1 次的数字 S[i+1] = S[i] + d[k] 或 S[i] - d[k],条件是 S[i+1] <= n && S[i-1]<S[i+1]

    分析:设d[]最小的数字为mn,除此之外设为d,第一次A写了0,第二次B如果写了d,那么A可以写d - mn,确保自己有数直到胜利;如果B第一次写了mn,那么以后的数都只能加mn直到>n,这个很好判断谁胜利。

    收获:博弈题想到了就简单了

    代码:

    #include <cstdio>
    #include <algorithm>
    using namespace std;
    
    const int M = 1e2 + 10;
    int a[M];
    
    int main(void)	{
    	int T, cas = 0;
    	int n, m;
    	scanf ("%d", &T);
    	while (T--)	{
    		scanf ("%d%d", &n, &m);
    		for (int i=1; i<=m; ++i)	scanf ("%d", &a[i]);
    		printf ("Case #%d: ", ++cas);
    		sort (a+1, a+1+m);
    	    if ((n / a[1]) & 1) puts ("Bob");
            else    puts ("Alice");
        }
    
    	return 0;
    }
    

      

    编译人生,运行世界!
  • 相关阅读:
    异或运算
    GitHub使用简介
    归并排序
    快速排序
    字符串匹配
    Runner站立会议06
    Runner站立会议05
    Runner站立会议04
    记计账需求分析
    Runner站立会议03
  • 原文地址:https://www.cnblogs.com/Running-Time/p/4773303.html
Copyright © 2011-2022 走看看