zoj3513 Human or Pig----P/N分析 博弈
2012-09-15 15:22
99 查看
HumanorPig
TimeLimit:2Seconds
MemoryLimit:65536KB
Amanislostinastrangeworld.Inthisworld,heisahumaninthedaytime,andhewillbecomeapigatnight.Thestrangeworldisrectanglewhichisseperatedintomany1*1grids,from(0,0)to(X,Y).Everygridhasacoordinate(
x,y).Ifheisinthegrid(x,y),hecanjumptogrid(
x-k*y,y)or(x,y-k*x).kisapositiveinteger.Forexample,ifheisinthegrid(4,9),hecanonlyjumptothegrid(4,1)or(4,5).Atnight,hejumpstoanothergridat1:00AMaspig.Inthedaytime,
hejumpstoanothergridat1:00PMasahuman.Sohewilljumpexactlytwiceeveryday.
Asthefigureshow,thegrids(x,0),(0,y)(0<=x<=X,0<=
y<=Y)aretheriver.WhenheJumpintotheriver,hewillchangefrompigtohumanorchangefromhumantopigimmediately.Andhispropertywillneverchangefromthenon.Itmeansthatifhejumpintotheriverinthedaytime,hewillbeapig
forever.Hewanttojumpintotheriveratnight,sothathechangefrompigtohumanimmediately,andcanbeahumanforever,neverbecomeapigagain.
Whenhebecomeapigatnight,hewilljumptoagridwhosecoordinatesatisfies(
x-k*y,y)or(x,y-k*x)arbitrarily.Hewillnotjumpoutofthestrangeworldeitherinthedaytimeoratnight.Atthebeginning,heisatthegrid(
x0,y0).Toensurethathecanjumpintotheriverasapigatlast,atthebeginning,hecanchoosetostartasapigatnightorasahumaninthedaytime.Youneedtodeterminewhattime(dayornight)tostartineverygridofthestrange
worldexcecpttheriver.Useamatrixtodisplayit.
EachcasecontaintwointegersXandY(1<=X*
Y<=40000)indicatingthesizeofthestrangeworld.
X*Ymatrix.Thejthcharateroftheithlineindicatingwhattime(dayornight)tostartinthegrid(
i,j).'H'meansthattoensurethathecanjumpintotheriverasahuman,heneedstostartasahumaninthedaytime.'P'meansthattoensurethathecanjumpintotheriverasahuman,heneedstostartasapigatnight.
[/code]
[/code]
TimeLimit:2Seconds
MemoryLimit:65536KB
Amanislostinastrangeworld.Inthisworld,heisahumaninthedaytime,andhewillbecomeapigatnight.Thestrangeworldisrectanglewhichisseperatedintomany1*1grids,from(0,0)to(X,Y).Everygridhasacoordinate(
x,y).Ifheisinthegrid(x,y),hecanjumptogrid(
x-k*y,y)or(x,y-k*x).kisapositiveinteger.Forexample,ifheisinthegrid(4,9),hecanonlyjumptothegrid(4,1)or(4,5).Atnight,hejumpstoanothergridat1:00AMaspig.Inthedaytime,
hejumpstoanothergridat1:00PMasahuman.Sohewilljumpexactlytwiceeveryday.
Asthefigureshow,thegrids(x,0),(0,y)(0<=x<=X,0<=
y<=Y)aretheriver.WhenheJumpintotheriver,hewillchangefrompigtohumanorchangefromhumantopigimmediately.Andhispropertywillneverchangefromthenon.Itmeansthatifhejumpintotheriverinthedaytime,hewillbeapig
forever.Hewanttojumpintotheriveratnight,sothathechangefrompigtohumanimmediately,andcanbeahumanforever,neverbecomeapigagain.
Whenhebecomeapigatnight,hewilljumptoagridwhosecoordinatesatisfies(
x-k*y,y)or(x,y-k*x)arbitrarily.Hewillnotjumpoutofthestrangeworldeitherinthedaytimeoratnight.Atthebeginning,heisatthegrid(
x0,y0).Toensurethathecanjumpintotheriverasapigatlast,atthebeginning,hecanchoosetostartasapigatnightorasahumaninthedaytime.Youneedtodeterminewhattime(dayornight)tostartineverygridofthestrange
worldexcecpttheriver.Useamatrixtodisplayit.
Input
Therearemultiplecases(nomorethan100).EachcasecontaintwointegersXandY(1<=X*
Y<=40000)indicatingthesizeofthestrangeworld.
Output
Foreachtestcasei,printcasenumberintheform"Case#i"inonesingleline.AndthereisaX*Ymatrix.Thejthcharateroftheithlineindicatingwhattime(dayornight)tostartinthegrid(
i,j).'H'meansthattoensurethathecanjumpintotheriverasahuman,heneedstostartasahumaninthedaytime.'P'meansthattoensurethathecanjumpintotheriverasahuman,heneedstostartasapigatnight.
SampleInput
12 23
SampleOutput
Case#1: PH Case#2: PHH HPP
[code]#include<fstream> #include<stdio.h> #include<iostream> #include<string.h> #include<string> #include<limits.h> #include<algorithm> #include<math.h> #include<numeric> #include<functional> #include<ctype.h> usingnamespacestd; constintkMAX=1<<16; chargrid_[kMAX]; intn,m; intgrid(intx,inty) { returnx*m+y; } charGet(intx,inty) { intret=grid(x,y); charc='P'; for(intk=1;x>k*y;++k) { intyy=grid(x-k*y,y); if(grid_[yy]=='P') { c='H'; break; } } for(intk=1;y>k*x;++k) { intyy=grid(x,y-k*x); if(grid_[yy]=='P') { c='H'; break; } } returngrid_[ret]=c; } intmain() { intcases=1; while(~scanf("%d%d",&n,&m)) { printf("Case#%d:\n",cases++); memset(grid_,'?',sizeof(grid_)); for(inti=1;i<=n;++i) { for(intj=1;j<=m;++j) putchar(Get(i,j)); puts(""); } } return0; }
[/code]
[code]#include<iostream>
#include<cstdlib>
#include<stdio.h>
#include<memory.h>
usingnamespacestd;
intn,m;
intmat[100000];
intget(intx,inty)
{
returnx*m+y;
}
voidsolve(intx,inty)
{
intid=get(x,y);
//if(mat[id]!=-1)return;
boolflag=true;
for(inti=1;;i++)
{
intpx=x-i*y;
if(px<=0)break;
intiid=get(px,y);
if(mat[iid]==0)
{
flag=false;
break;
}
}
if(flag)
{
for(inti=1;;i++)
{
intpy=y-i*x;
if(py<=0)break;//悲催,写成<0wrong了
intiid=get(x,py);
if(mat[iid]==0)
{
flag=false;
break;
}
}
}
if(flag)
mat[id]=0;
else
mat[id]=1;
return;
}
intmain()
{
intcount=1;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(mat,-1,sizeof(mat));
printf("Case#%d:\n",count++);
for(inti=1;i<=n;i++)
for(intj=1;j<=m;j++)
solve(i,j);
intid=1*m+1;
intc=0;
for(inti=id;i<=n*m+m;i++)
{
if(mat[i]==0)cout<<'P';
elsecout<<'H';
c++;
if(c==m)
{
c=0;
cout<<endl;
}
}
}
}
[/code]
相关文章推荐
- SRM 575 DIV2 博弈P/N分析 + 最大流
- 招聘应聘博弈之困境分析
- 逻辑分析推理(戴帽子问题)博弈
- Codeforces Canada Cup 2016 F. Family Photos 博弈 策略分析 好题
- POJ - 1704 Georgia and Bob 神TM NIM博弈,脑洞,神分析
- poj 2348 Euclid's Game (博弈局面分析)
- 关于巴什博弈的简单介绍分析
- 田忌赛马博弈矩阵分析
- 强盗分金算法及博弈分析
- 九城毒丸与恶意收购之博弈分析
- 博弈问题分析与数学归纳
- 很诡异的博弈问题分析方法
- 中美汇率博弈的分析和对策
- [置顶] acm--博弈入门2(P/N分析)--(HDU 1847 HDU 2188 HDU 3863)
- Webalizer日志分析
- MBA案例分析(人员培训三)
- [导入]SQL语句优化技术分析
- TCP/IP 协议简单分析
- [转旧闻]Sun收购MySQL事件之透视与分析
- KernelIoControl和OEMIoControl的分析和使用(作者:wogoyixikexie@gliet)