HDU 4753 Fishhead’s Little Game(DFS)
很繁琐的爆搜,最多要加2^12条边,暴力就可以,回溯那部分一直没有回溯好,写了一晚上。。。代码非常,非常难看。。对了,还不是普通的爆搜,双向搜索博弈,以前记得看过,这次好像第一次写。。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int p[][],flag[],o[][];
int que[];
int sp[];
int sf[];
int num,sz;
int t1,t2;
int dfs1(int x,int tc,int jc);
int dfs2(int x,int tc,int jc);
int fun(int a,int b,int c,int nu)
{
if(sz == )
{
if(sf[nu] == &&sp[a]&&sp[b]&&sp[c])
{
sf[nu] = ;
return ;
}
else
return ;
}
else
{
if(sf[nu] == &&sp[a]&&sp[b]&&sp[c])
{
sf[nu] = ;
return ;
}
else
return ;
}
}
int judge(int x)
{
if(x <= )
return fun(+x,+x,+x,x);
else if(x <= )
return fun(x-,x+,x+,x-) + fun(x+,x+,x+,x);
else if(x <= )
return fun(x-,x+,x+,x-) + fun(x+,x+,x+,x);
else if(x <= )
return fun(x-,x+,x+,x-);
else if(x == )
return fun(,,,);
else if(x == )
return fun(,,,);
else if(x == )
return fun(,,,);
else if(x == )
return fun(,,,);
else if(x == )
return fun(,,,);
else if(x == )
return fun(,,,);
else if(x == || x == )
return fun(x-,x-,x-,x-) + fun(x+,x-,x-,x-);
else if(x == ||x == )
return fun(x-,x-,x-,x-) + fun(x+,x-,x-,x-);
else if(x == ||x == )
return fun(x-,x-,x-,x-) + fun(x+,x-,x-,x-);
return ;
}
int dfs1(int x,int tc,int jc)
{
int i,z,s;
if(x == (<<num)-)
{
if(tc > jc)
return ;
else
return ;
}
s = ;
for(i = ; i < num; i ++)
{
if((x&(<<i)) == )
{
sz = ;
z = judge(que[i]);
sp[que[i]] = ;
if(dfs2(x+(<<i),tc+z,jc) == )
s = ;
sp[que[i]] = ;
sz = ;
judge(que[i]);
}
if(s) return s;//为了回溯,回溯完了,再返回。
}
return s;
}
int dfs2(int x,int tc,int jc)
{
int i,z,s;
if(x == (<<num)-)
{
if(tc > jc)
return ;
else
return ;
}
s = ;
for(i = ; i < num; i ++)
{
if((x&(<<i)) == )
{
sz = ;
sp[que[i]] = ;
z = judge(que[i]);
if(dfs1(x+(<<i),tc,jc+z) == )
s = ;
sz = ;
judge(que[i]);
sp[que[i]] = ;
}
if(s) return s;
}
return s;
}
int main()
{
int i,j,k,t,u,v,n,tc,jc,cas = ;
k = ;
for(i = ; i <= ; i ++)
{
for(j = ; j <= ; j ++)
p[i][j] = k ++;
}
k = ;
for(i = ; i <= ; i ++)
{
for(j = ; j <= ; j ++)
{
// printf("%d %d\n",p[i][j],p[i][j+1]);
o[p[i][j]][p[i][j+]] = k ++;
}
}
for(i = ; i <= ; i ++)
{
for(j = ; j <= ; j ++)
{
//printf("%d %d\n",p[i][j],p[i+1][j]);
o[p[i][j]][p[i+][j]] = k ++;
}
}
scanf("%d",&t);
while(t--)
{
memset(flag,,sizeof(flag));
memset(sp,,sizeof(sp));
memset(sf,,sizeof(sf));
scanf("%d",&n);
num = ;
tc = jc = ;
sz = ;
for(i = ; i < n; i ++)
{
scanf("%d%d",&u,&v);
int te;
if(u > v)
{
te = u;
u = v;
v = te;
}
if(i% == )
tc += judge(o[u][v]);
else
jc += judge(o[u][v]);
flag[o[u][v]] = ;
sp[o[u][v]] = ;
}
for(i = ; i < ; i ++)
{
if(!flag[i])
que[num++] = i;
}
printf("Case #%d: ",cas ++);
if(n% == )
{
if(dfs1(,tc,jc))
printf("Tom200\n");
else
printf("Jerry404\n");
}
else
{
if(dfs1(,jc,tc))
printf("Jerry404\n");
else
printf("Tom200\n");
}
}
return ;
}
HDU 4753 Fishhead’s Little Game(DFS)的更多相关文章
- hdu 4753 Fishhead’s Little Game 博弈论+记忆化搜索
思路:状态最多有2^12,采用记忆化搜索!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm& ...
- hdu 4753 Fishhead’s Little Game
状态压缩dp解博弈问题(记忆化搜索).比赛的时候最后才开始做这道题,而且当时不知道为什么一直犯一些很2B的问题,导致没能ac,晚上看了看原先的代码,改了一下就MLE了...我原先是开的dp[1 < ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- HDU 1078 FatMouse and Cheese ( DP, DFS)
HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...
- hdu 1258 Sum It Up(dfs+去重)
题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- HDU 1312 Red and Black (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1978 记忆化搜索(dfs+dp)
Y - How many ways Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u S ...
- HDU 3887:Counting Offspring(DFS序+树状数组)
http://acm.hdu.edu.cn/showproblem.php?pid=3887 题意:给出一个有根树,问对于每一个节点它的子树中有多少个节点的值是小于它的. 思路:这题和那道苹果树是一样 ...
随机推荐
- poj 3278:Catch That Cow(简单一维广搜)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 45648 Accepted: 14310 ...
- 攻城狮在路上(壹) Hibernate(十二)--- Hibernate的检索策略
本文依旧以Customer类和Order类进行说明.一.引言: Hibernate检索Customer对象时立即检索与之关联的Order对象,这种检索策略为立即检索策略.立即检索策略存在两大不足: A ...
- wp8 入门到精通 高仿微信发信息 键盘不消失
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> < ...
- OpenMesh 之向量操作
OpenMesh 提供了许多可供使用的向量操作函数,使用特别方便. 计算距离: 从官方文档可以看到OpenMesh提供了5个函数,分别为 Scalar length() const // ...
- 命令模式/command模式/行为型模式
举个栗子 指挥官向士兵下达命令,士兵执行 实现代码如下: class Soldier { public void exe() { System.out.println("执行命令" ...
- HDU 5919 Sequence II 主席树
Sequence II Problem Description Mr. Frog has an integer sequence of length n, which can be denoted ...
- canvas加载进度条
<!DOCTYPE html> <html><head><meta http-equiv="Content-Type" content=& ...
- phpstorm的安装、破解、和汉化
1.去官网下载最新版安装. 2.完成选择购买软件,下面选择中间那个账户方法License server,把这条链接复制下去:http://idea.qinxi1992.cn 3.下载汉化包resour ...
- ThinkPHP3.2 volist嵌套循环显示原理
php页面:$fatherList = $Document->where('pid=1')->select(); foreach($fatherList as $n=> ...
- 时间和地域三级联动选择器(Android-PickerView-master)
先附上下载和效果展示地址 https://github.com/saiwu-bigkoo/Android-PickerView 之后说一下程序依赖后会遇到的问题Error:(2, 0) Plugin ...