HDU 5612 Baby Ming and Matrix games(DFS)
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define ms(a) memset(a,0,sizeof(a))
using namespace std;
#define LOCAL
char mp[][];
int n,m;
double tar;
bool flag;
int dir[][]= {{,},{,-},{,},{-,}};
double cal(double n,double m,char c)
{
if(c=='+')return n+m;
if(c=='-')return n-m;
if(c=='*')return n*m;
if(c=='/')return n/m;
return ;
}
void dfs(int x,int y,double num)
{
if(flag)return;
for(int i=; i<; i++)
{
int nx=x+dir[i][],ny=y+dir[i][];
if(mp[nx][ny]!='#'&&(nx>=&&nx<n&&ny>=&&ny<m))
{
char ch=mp[nx][ny];
mp[nx][ny]='#';
if(mp[x+dir[i][]/][y+dir[i][]/]=='#')return;
double nnum=cal(num,ch-'',mp[x+dir[i][]/][y+dir[i][]/]);
if(fabs(tar-nnum)<=1e-)
{
flag=true;
return;
}
dfs(nx,ny,nnum);
mp[nx][ny]=ch;
}
}
return;
}
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
//Start
int N;
cin>>N;
while(N--)
{
cin>>n>>m>>tar;
ms(mp);
flag=false;
for(int i=; i<n; i++)
{
cin>>mp[i];
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
if(isdigit(mp[i][j]))
{
char sav=mp[i][j];
if((sav-'')==tar)
{
flag=true;
break;
}
mp[i][j]='#';
dfs(i,j,sav-'');
mp[i][j]=sav;
}
if(flag)break;
}
if(flag)break;
}
if(flag)printf("Possible\n");
else printf("Impossible\n");
}
return ;
}
HDU 5612 Baby Ming and Matrix games(DFS)的更多相关文章
- hdu 5612 Baby Ming and Matrix games
Baby Ming and Matrix games 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一 ...
- hdu 5612 Baby Ming and Matrix games(dfs暴力)
Problem Description These few days, Baby Ming is addicted to playing a matrix game. Given a n∗m matr ...
- hdu5612 Baby Ming and Matrix games (dfs加暴力)
Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- Baby Ming and Matrix games(dfs计算表达式)
Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Ja ...
- hdoj--5612--Baby Ming and Matrix games(dfs)
Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K ...
- HDU 5614 Baby Ming and Matrix tree 树链剖分
题意: 给出一棵树,每个顶点上有个\(2 \times 2\)的矩阵,矩阵有两种操作: 顺时针旋转90°,花费是2 将一种矩阵替换为另一种矩阵,花费是10 树上有一种操作,将一条路经上的所有矩阵都变为 ...
- hdu 5611 Baby Ming and phone number(模拟)
Problem Description Baby Ming collected lots of cell phone numbers, and he wants to sell them for mo ...
- hdu 5610 Baby Ming and Weight lifting
Problem Description Baby Ming is fond of weight lifting. He has a barbell pole(the weight of which c ...
- HDU 5613 Baby Ming and Binary image
因为第一行和最后一行都是0,我们只需枚举最左边或最右边一列的01情况,即可得到整张表 然后再检验表是否符合要求 #include<cstdio> #include<cstring&g ...
随机推荐
- 微软sqlHelper
//微软的SQLHelper类(含完整中文注释) using System; using System.Data; using System.Xml; using System.Data.SqlCli ...
- ECMAScript6之let与const关键字
let关键字 let关键字和var关键字一样,都是用来声明变量的,但是和var不同的是,let关键字声明的变量仅在自己的块级作用域范围内发挥作用. 我们来比较下面两段代码 var arr = new ...
- Shell终端收听音乐--豆瓣FM命令行版
douban.fm Terminal-based douban.fm inspired by douban.fm.该版本版基于Python2.* 安装Python2.* pacman -S pytho ...
- 引用Excel.dll 时找不到类型怎么办
将引用(Microsoft.Office.Interop.Excel)的属性"嵌入互操作类型"由True修改为False即可
- bitcode 关于讯飞
在真机调试的时候一直报 ld: '/Users/Chenglijuan/Documents/语音识别/lib/iflyMSC.framework/iflyMSC(IFlyRecognizerView. ...
- 【IE6的疯狂之六】li在IE中底部3像素的BUG(增加浮动解决问题)
今天开发项目中碰到一个li在IE中的BUG,先来看设计原型(如图:) 两个红色中间是<li>1px的底边框: 我写的代码如下: ============================== ...
- web 服务器
作为一个跨专业转行的我来说,对后台一团浆糊,最近在看php,学的进度比较慢 (1)ApacheApache是世界使用排名第一的Web服务器软件.它可以运行在几乎所有广泛使用的计算机平台上.Apache ...
- onkeyup事件只能输入数字,字母,下划线
<input type="text" onkeyup="value=value.replace(/[\W]/g,'')"/>
- c#中命令copy已退出,返回值为1
c#中命令copy已退出,返回值为1 本正经的道:董姐刚才你说的修心养性其中的'修心'我 有孕在身刚好由戴梦瑶顶替了她的位置按照的指示 ╋旆呆 湎术葶页 邾箕砜笳 烦璜卿廑 奶奶个腿儿的等下次非让你 ...
- Hibernate配置详细解释
hibernate.cfg.xml <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> < ...