题目链接

很繁琐的爆搜,最多要加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)的更多相关文章

  1. hdu 4753 Fishhead’s Little Game 博弈论+记忆化搜索

    思路:状态最多有2^12,采用记忆化搜索!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm& ...

  2. hdu 4753 Fishhead’s Little Game

    状态压缩dp解博弈问题(记忆化搜索).比赛的时候最后才开始做这道题,而且当时不知道为什么一直犯一些很2B的问题,导致没能ac,晚上看了看原先的代码,改了一下就MLE了...我原先是开的dp[1 < ...

  3. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  4. HDU 1078 FatMouse and Cheese ( DP, DFS)

    HDU 1078 FatMouse and Cheese ( DP, DFS) 题目大意 给定一个 n * n 的矩阵, 矩阵的每个格子里都有一个值. 每次水平或垂直可以走 [1, k] 步, 从 ( ...

  5. hdu 1258 Sum It Up(dfs+去重)

    题目大意: 给你一个总和(total)和一列(list)整数,共n个整数,要求用这些整数相加,使相加的结果等于total,找出所有不相同的拼凑方法. 例如,total = 4,n = 6,list = ...

  6. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...

  7. 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 ...

  8. HDU 1978 记忆化搜索(dfs+dp)

    Y - How many ways Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

  9. HDU 3887:Counting Offspring(DFS序+树状数组)

    http://acm.hdu.edu.cn/showproblem.php?pid=3887 题意:给出一个有根树,问对于每一个节点它的子树中有多少个节点的值是小于它的. 思路:这题和那道苹果树是一样 ...

随机推荐

  1. 【数据库】 防止sql注入,过滤敏感关键字

    private bool FilterIllegalChar(string sWord) { var result = false; var keyWord = @"select|inser ...

  2. select count(*)和select count(1)哪个性能高

    select count(*).count(数字).count(字段名)在相同的条件下是没有性能差别的,一般我们在统计行数的时候都会把NULL值统计在内的,所以这样的话,最好就是使用COUNT(*) ...

  3. 【翻译八】java-内存一致性错误

    Memory Consistency Errors Memory consistency errors occur when different threads have inconsistent v ...

  4. [LeetCode] Ugly Number II

    Write a program to find the n-th ugly number. Ugly numbers are positive numbers whose prime factors ...

  5. RTP/RTCP的时间同步机制

    转自:http://blog.csdn.net/leesphone/article/details/5571972 RTP支持传送不同codec的steaming,不同codec的clock rate ...

  6. 深入分析JavaWeb 技术内幕

    1,通过浏览器请求一个资源,会发生以下几种过程 1) http的解析过程,包括对于http请求头和响应头中指令(控制用户浏览器的渲染行为和 服务器的执行逻辑)的解析 2)DNS的解析过程(根据域名获取 ...

  7. How to use Ajax on Visualforce page on Salesforce platform

    Just use Ajax pattern to call object data from server on visualforce page. Following is the Asynchro ...

  8. UIPopoverController 的使用

    #import "ViewController.h" #import "RYColorSelectController.h" #import "RYM ...

  9. 对于c语言int类型和float,以及double类型表示范围的计算

    首先说一下我原来错误的认识 int是32个bit, 如果我们把第一位理解为符号位,那么很显然int的范围是-(2^31-1)~2^31-1 但是实际上我们都知道int的最小值是-2^31次.. 为什么 ...

  10. LoadRunner 一些快捷键

    F4   Runtime Setting F5   运行 Ctrl Alt C  注释 Ctrl Alt U  取消注释 Tab  缩进 Shift Tab  取消缩进 Ctrl L  打开参数管理对 ...