鉴于时间紧张...虽然知道博弈是个大课题但是花一个上午时间已经极限了...

  希望省选过后再回过头来好好总结一遍吧。

  接下来为了看着顺眼一点...还是按照难度顺序吧


 

POJ1082

  一道最简单的博弈题,只需要DP就可以过。

  在这道题里我尽情展示了多函数多过程的代码风格。。

program poj1082;
const u:set of ..=[,,,,,,];
var n,i,x,y,z:longint;
f:array[..,..,..]of boolean; function leap(x:longint):boolean;
begin
if x mod = then
begin
if x mod = then exit(true);
end else
begin
if x mod = then exit(true);
end;
exit(false);
end; function exist(x,y,z:longint):boolean;
begin
if y in u then
begin
if z< then exit(true);
end else
begin
if y<> then
begin
if z> then exit(false) else exit(true);
end else
begin
if (z<)or(leap(x)and(z=)) then exit(true);
end;
end;
exit(false);
end; function next_day(x,y,z:longint):boolean;
begin
inc(z);
if not exist(x,y,z) then
begin
inc(y);z:=;
end;
if y> then
begin
inc(x);y:=;
end;
exit(f[x,y,z]);
end; function next_month(x,y,z:longint):boolean;
begin
inc(y);
if y> then
begin
inc(x);y:=;
end;
if not exist(x,y,z) then exit(false);
exit(f[x,y,z]);
end; procedure solve;
var i,j,k:longint;
flag:boolean;
begin
fillchar(f,sizeof(f),false);
for i:= downto do
for j:= downto do
for k:= downto do if exist(i,j,k) then
begin
flag:=true;
if next_day(i,j,k) then flag:=false;
if next_month(i,j,k) then flag:=false;
f[i,j,k]:=flag;
end;
end; begin
assign(input,'poj1082.in');reset(input);
readln(n);
solve;
for i:= to n do
begin
readln(x,y,z);
if f[x,y,z] then writeln('NO') else writeln('YES');
end;
end.

POJ2960

  简单的SG函数的运用。

program poj2960;
const maxn=;maxm=;
var sizes,i,n,m,x,ans,j:longint;
s:array[-..maxm]of longint;
w:array[-..maxn]of longint;
vis:array[-..*maxn,-..maxm]of boolean; procedure calc_SG;
var i,j:longint;
begin
fillchar(vis,sizeof(vis),false);
for i:= to maxn do
begin
for j:= to maxm do if not vis[i,j] then break;
w[i]:=j;
for j:= to sizes do vis[i+s[j],w[i]]:=true;
end;
end; begin
//assign(input,'poj2960.in');reset(input);
//assign(output,'poj2960.out');rewrite(output);
read(sizes);
while sizes<> do
begin
for i:= to sizes do read(s[i]);readln;
calc_SG;
readln(m);
for i:= to m do
begin
ans:=;
read(n);
for j:= to n do
begin
read(x);
ans:=ans xor w[x];
end;
if ans> then write('W') else write('L');
readln;
end;
writeln;
read(sizes);
end;
end.

POJ2505

  题面很亲切,就是不停乘上2~9之间的一个数,超过了某个数n即算赢。

  依稀记得去年暑假做过这道题,当时应该数据比较弱是直接DP过的...

  然后先还是无脑DP,然后输出发现了很神奇的规律...

  2~9 先手赢

  10~18 后手赢

  19~162 先手赢

  163~324 后手赢

  ...

  想来其实也并无道理,但是找规律无疑是最快捷的方法了。

program poj2505;
var x:int64; function solve(x:int64):boolean;
var k:int64;
begin
k:=;
while true do
begin
k:=k*;
if x<=k then exit(true);
k:=k*;
if x<=k then exit(false);
end;
end; begin
while not eof do
begin
readln(x);
if solve(x) then writeln('Stan wins.') else writeln('Ollie wins.');
end;
end.

POJ2348

  这道题我的思考出现了一点问题...

  刚开始认为,对于每一个(x,y)到(y,x mod y)的过程,都可以看做是一场Nim游戏

  然后石子的个数就是x div y的个数

  自己觉得非常有道理,然后就SG敲起来了...

  发现怎么都过不去,和标算对拍了之后发现是这样的...

  Nim游戏你可以任意选一堆石子开始,而这道题是从大减到小

  也就是强制必须先从第一堆石子里取完才能从第二堆取

  于是就不可以用SG函数了

  继续看,发现如果当x div y=1的时候,只有一种选择

  而当x div y>=2的时候,起码有两种选择而且显然是可以交换和对手的身份的

  这种情况下就是必胜的。

  然后辗转相除套一个特判就可以AC啦

program poj2348;
var tem,x,y:int64; function solve(x,y:int64):boolean;
begin
if y= then exit(false);
if x div y>= then exit(true);
exit(not solve(y,x mod y));
end; begin
assign(input,'poj2348.in');reset(input);
readln(x,y);
while (x<>)or(y<>) do
begin
if x<y then
begin
tem:=x;x:=y;y:=tem;
end;
if solve(x,y) then writeln('Stan wins')
else writeln('Ollie wins');
readln(x,y);
end;
end.

POJ1067 

  一道裸的威佐夫博弈...

  两堆石子中可以在任意一堆中取若干个,也可以在两堆中取相同数量个。

  奇异状态(x,y)满足:

    x=a[i],y=a[i]+i

  而a[i]=i*(sqrt(5)-1)/2+i;

  非奇异状态为必胜状态,反之必败。

  我是用二分来实现x=a[i]这一步的查找的...

  (刚开始非常sx的用了1.618后来发现x<=10^9,乘到后面显然精度不够,然后copy来了一堆长的黄金分割数,但是忘记把小数点前改1了...然后一直WA。发现其实就是(sqrt(5)-1)/2...既简单不用背有精确度高...真是初三内容都还给李老师了...连黄金分割都忘掉了QAQ)

program poj1067;
const INF=;
num=(sqrt()-)/+;
var x,y,tem:int64; function find(x:int64):int64;
var L,R,mid,tem:int64;
begin
L:=;R:=INF;
while L<=R do
begin
mid:=(L+R) >> ;
tem:=trunc(num*mid);
if x=tem then exit(mid);
if x<tem then R:=mid- else L:=mid+;
end;
exit(-);
end; begin
while not eof do
begin
readln(x,y);
if x>y then
begin
tem:=x;x:=y;y:=tem;
end;
tem:=find(x);
if (tem=-)or(tem+x<>y) then writeln() else writeln();
end;
end.

[POJ1082&POJ2348&POJ1067&POJ2505&POJ1960]简单博弈题总结的更多相关文章

  1. ACM: NBUT 1107 盒子游戏 - 简单博弈

     NBUT 1107  盒子游戏 Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:  Practice  Appoint ...

  2. hdu4678 Mine 2013 Multi-University Training Contest 8 博弈题

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  3. 2019浙大校赛--A--Thanks, TuSimple!(简单模拟题)

    这题前三段都是一堆吹爆赞助商的屁话,正式题目在图片下边,一个简单模拟题. 题目大意: 有n个男生,m个女生在进行舞会,其中一部分男生祥和比自己矮的女生跳舞,一部分男生想和比自己高的女生跳舞,一部分女生 ...

  4. HDU 1564 简单博弈 水

    n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个 ...

  5. 简单数据结构题(from 钟子谦——IOI2018集训队自选题)

    简单数据结构题(from 钟子谦--IOI2018集训队自选题) 试题描述 给一棵 \(n\) 个点的树,点权开始为 \(0\) ,有 \(q\) 次操作,每次操作是选择一个点,把周围一圈点点权 \( ...

  6. java算法题每日一练01,java入门简单算法题小练

    1.给数组做反序 public class Ak01 { public static void main(String[] args) { int[] a = new int[]{22,48,41,2 ...

  7. ZOJ1913 Euclid's Game (第一道简单的博弈题)

    题目描述: Euclid's Game Time Limit: 2 Seconds      Memory Limit: 65536 KB Two players, Stan and Ollie, p ...

  8. HDU 1079 Calendar Game(简单博弈)

    Calendar Game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  9. acm之简单博弈 Nim Bash Wythoff

    前些日子我打算开了博弈基础,事后想进行总结下 一句话就是分析必胜或必败,异或为0. 以下内容来自转载: Nim游戏的概述: 还记得这个游戏吗?给出n列珍珠,两人轮流取珍珠,每次在某一列中取至少1颗珍珠 ...

随机推荐

  1. 了解url

    我对自己知道关于url的编码和解码的一些进行了一下整理. 我们的例子是百度翻译的地址: http://fanyi.baidu.com/translate#en/zh/The%20%22%3F%20ar ...

  2. 安装mathtype出问题卸载后 office2016打开mathtype弹错误窗口

    解决方法:找到 C:\Program Files (x86)\Microsoft Office\root\Office16\STARTUP目录下的MathType Commands 6 For Wor ...

  3. Viewer.js 图片预览插件使用

    一.简介 Viewer.js 是一款强大的图片查看器. Viewer.js 有以下特点: 支持移动设备触摸事件 支持响应式 支持放大/缩小 支持旋转(类似微博的图片旋转) 支持水平/垂直翻转 支持图片 ...

  4. Vue一些重要的知识点

    vue sync修饰(1)双向数据绑定,父子组件之间信息的交互 1⃣️在自组件中使用this.emmit('toFather'),子组件产生一个tofather事件,然后在父组件中通过@进行监听,那么 ...

  5. Selenium八大元素定位方式

    1.根据id来定位: import org.openqa.selenium.By;import org.openqa.selenium.WebDriver;import org.openqa.sele ...

  6. Java并发基础--Thread类

    一.Thread类的构成 Thread类实现Runnable接口.部分源码如下: 二.Thread类常用方法 1.currentThread()方法 currentThread()方法可以返回代码段正 ...

  7. spring boot 打包问题

    一.jar包 1.maven build package 2.linux 下执行 java -jar & 命令后台运行,也可加入服务运行 二.war包 1.将pom中的<packagin ...

  8. [OpenCV]DMatch类和KeyPoints类:特征点匹配

    DMatch struct CV_EXPORTS_W_SIMPLE DMatch { CV_WRAP DMatch() : queryIdx(-), trainIdx(-), imgIdx(-), d ...

  9. 九度OJ--Q1168

    import java.util.Scanner; public class q1168 { public static void main(String[] args) { Scanner scan ...

  10. Hyperledger04

    代码 'use strict'; var Fabric_Client = require('fabric-client'); var path = require('path'); var util ...