hdu 2177(威佐夫博奕+打表)
取(2堆)石子游戏
Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2622 Accepted Submission(s): 1594
1
1
const int N=;
int a[N][N];
int main(){
int i,j,k;
a[][]=;
for(i=;i<N;i++){
a[][i]=a[i][]=;
}
for(i=;i<N;i++){
for(j=;j<N;j++){
a[i][j]=;
for(k=;k<i;k++)
if(a[k][j]==)a[i][j]=;
for(k=;k<j;k++)
if(a[i][k]==)a[i][j]=;
for(k=;k<=min(i,j);k++)
if(a[i-k][j-k]==)a[i][j]=;
}
}
for(i=;i<;i++){
for(j=;j<;j++)
printf("%d ",a[i][j]);
printf("\n");
}
}
输出前20组数据
我们可以发现这几种情况是输的
1 2
3 5
4 7
6 10 可以发现规律为 a=(int)(b-a)(aqrt(5)+1)/2 我也不知道规律怎么得到这个公式的
输出为1的情况 我们只需要让状态转为必败的状态就可以了
int t=(b-a)*(sqrt(5)+1)/2;
if(t<a) 假设 bb=b-(a-t) 及证明 t 和bb满足必败的条件、、
(bb+t-a-t)*(sqrt(5)+1)/2=(b-a)*(sqrt(5)+1)/2=t;
并且这种情况属于[x-k,y-k]这种 所以我们可以先判断
其他的两种自己看代码想 不想解释了
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
#include<set>
#include<vector>
#include<algorithm>
#include<string.h>
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int INF=0x3f3f3f3f;
const double eps=0.0000000001;
const int N=+;
const int MAX=+;
int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
if(n==&&m==)break;
double b=(sqrt(5.0)+)/;
if(n==(int)(b*(m-n))){
cout<<<<endl;
continue;
}
cout<<<<endl;
int t=(int)(m-n)*b;
if(t<n)cout<<t<<" "<<t+m-n<<endl;
for(int i=;i<=m;i++){
int x=m-i;
if(x>n&&(int)(b*(x-n))==x)cout<<x<<" "<<n<<endl;
else if(x<n&&(int)(b*(n-x))==x){
cout<<x<<" "<<n<<endl;
}
}
}
}
hdu 2177(威佐夫博奕+打表)的更多相关文章
- hdu 2177(威佐夫博奕)
题意:容易理解,在威佐夫博奕的基础上新增加了一条要求:就是如果在赢得条件下,输出第一步怎么走. 分析:使用暴力判断,详细见代码. 代码: #include<stdio.h> #includ ...
- hdu 2897(威佐夫博奕变形)
题意:容易理解. 分析:当n%(p+q)==0时,先取者必胜,必胜方案:先取q,然后对方去x个,先取者就取(p+q-x)个,最后对方就必须取玩p个, 当n%(p+q)==r(r<=p),先取者必 ...
- hdu 2177 取(2堆)石子游戏(威佐夫博奕)
题目链接:hdu 2177 这题不是普通的 Nim 博弈,我想它应该是另一种博弈吧,于是便推 sg 函数打了个 20*20 的表来看,为了方便看一些,我用颜色作了标记,打表代码如下: #include ...
- HDU 5973 Aninteresting game 威佐夫博奕(Wythoff Game)
HDU 5973:http://acm.hdu.edu.cn/showproblem.php?pid=5975 题意: 有两堆石子,每次可以从一堆石子中取任意个,或者从两堆石子中取相同个数的石子.两个 ...
- hdu 1527(威佐夫博奕)
题意:容易理解. 分析:威佐夫博奕的模板题. 代码实现: #include<stdio.h> #include<string.h> #include<math.h> ...
- 【威佐夫博奕】 betty定理 poj 1067
Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...
- poj1067威佐夫博奕
取石子游戏 Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 31490 Accepted: 10374 Descripti ...
- 博弈论基础知识: 巴什博奕+斐波那契博弈+威佐夫博奕+尼姆博弈(及Staircase)(转)
(一)巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个.最后取光者得胜.若(m+1) | n,则先手必败,否则先手必胜.显然,如果n=m+1 ...
- 博弈---威佐夫博奕(Wythoff Game)
这个写的不错 威佐夫博奕(Wythoff Game):有两堆各若干个物品,两个人轮流从某一堆或同 时从两堆中取同样多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 这种情况下是颇为复杂 ...
随机推荐
- win32之bitmap篇
先讲一下LoadBitmap的用法,代码如下: PAINTSTRUCT ps; HDC hdc = BeginPaint(hwnd,&ps); HDC hMemDC = CreateCompa ...
- Storm 入门一:基本知识+网上资源链接
Strom首页:http://storm.apache.org/ 下载地址:http://www.apache.org/dyn/closer.lua/storm/apache-storm-1.1.0/ ...
- querySelector
this.el.nativeElement.querySelector import {Component, ElementRef, OnInit} from '@angular/core';
- select 多选 和单选,分组
<select name="group"> <option value="1">北京</option> <option ...
- 7-9 旅游规划 (25 分)(Dijkstra算法)
题意: 思路:单源最短路问题,Dijkstra算法搞定就可以了,因为要找出最便宜的最短路,所以需要在更新最短距离的时候加一个条件(即当最短距离相等的时候,如果该路径的花费更小,就更新最小花费)就可 ...
- vue 瀑布流实现
<div class="myWrite" v-if="list.length==0"> - 这个福宝有点懒哦 - </div> < ...
- ActiveMQ学习总结(10)——ActiveMQ采用Spring注解方式发送和监听
对于ActiveMQ消息的发送,原声的api操作繁琐,而且如果不进行二次封装,打开关闭会话以及各种创建操作也是够够的了.那么,Spring提供了一个很方便的去收发消息的框架,spring jms.整合 ...
- Pycharm 的基本操作
下载:https://www.jetbrains.com/pycharm/ 安装:随意安装在那个目录都可以 注册:可以采用 激活码 或者激活服务器,并对应在选项下面填入激活码或者激活服务器URL即可. ...
- nyoj_513_A+B Problem IV_20130131532
A+B Problem IV 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 acmj最近发现在使用计算器计算高精度的大数加法时很不方便,于是他想着 ...
- 【ACM】hdu_1089_A+BI_201307261121
A+B for Input-Output Practice (I)Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...