题目链接

题解:题意为给出一个N*M的矩阵,然后(i∗2,j∗2) (i,j=0,1,2...)的点处是数字,两个数字之间是符号,其他位置是‘#’号。
但不知道是理解的问题还是题目描述的问题,数据中还有类似1#1这种数据存在,因此WA了4次,加上了一句代码后,马上AC了,该行代码在下文以斜粗体标出。
此外,因为里面有除法,会有一定误差,所以用这句来判断:fabs(tar-nnum)<=1e-8,而不是tar==nnum。
 
#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)的更多相关文章

  1. hdu 5612 Baby Ming and Matrix games

    Baby Ming and Matrix games 题意: 给一个矩形,两个0~9的数字之间隔一个数学运算符(‘+’,’-‘,’*’,’/’),其中’/’表示分数除,再给一个目标的值,问是否存在从一 ...

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

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

  4. Baby Ming and Matrix games(dfs计算表达式)

    Baby Ming and Matrix games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Ja ...

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

  6. HDU 5614 Baby Ming and Matrix tree 树链剖分

    题意: 给出一棵树,每个顶点上有个\(2 \times 2\)的矩阵,矩阵有两种操作: 顺时针旋转90°,花费是2 将一种矩阵替换为另一种矩阵,花费是10 树上有一种操作,将一条路经上的所有矩阵都变为 ...

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

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

  9. HDU 5613 Baby Ming and Binary image

    因为第一行和最后一行都是0,我们只需枚举最左边或最右边一列的01情况,即可得到整张表 然后再检验表是否符合要求 #include<cstdio> #include<cstring&g ...

随机推荐

  1. 信息设计工具IDT创建从SAP Business Object到SAP HANA的连接

    1. 打开Information Design Tool, 并添加BO Server的连接 2. 在Connection上右击, 选择Insert Relational Connection 3. 输 ...

  2. hdu1035

    #include<stdio.h>#include<string.h>int step,n,m;int a[1010][1010];char map[11][11];void ...

  3. RSA算法记录----摘抄

    RSA算法原理(一)   "公钥加密算法". 因为它是计算机通信安全的基石,保证了加密数据不会被破解.你可以想象一下,信用卡交易被破解的后果. 进入正题之前,我先简单介绍一下,什么 ...

  4. StringMVC(拦截器)

    单个拦截器 使用jar包 创建FirstController.java @Controller public class FirstController { @RequestMapping(" ...

  5. 《C++反汇编与逆向分析技术揭秘》——函数的工作原理

    各种调用方式的考察 示例: cdecl方式是调用者清空堆栈: 如果执行的是fastcall: 借助两个寄存器传递参数: 参数1和2借助局部变量来存储: 返回值 如果返回值是结构体: 返回值存放在eax ...

  6. Windows端口转发

    1. PortTunnel 2. windows 自带的 netsh -----windows下也有一个小工具:portforward.exe,图形界面容易操作,个人平常使用可以,但是也没有办法实现与 ...

  7. Unity人工智能学习—确定性AI算法之追踪算法二

    转自:http://blog.csdn.net/zhangxiao13627093203/article/details/47658673 上一篇讲到了追踪算法的比较简单的形式,看上去比较假,因为AI ...

  8. 修复ubunut桌面

    title: 修复ubunut桌面 tags: 桌面, ubuntu grammar_cjkRuby: true --- ,按下Ctrl+Alt+F2.这会让你进入一个命令行界面而不是默认的用户桌面界 ...

  9. 一个简单sql注入的poc

    最近在提高自己编程能力,拿一些实用的小工具练下.该脚本为python语言,主要涉及模块urllib,re. 功能:验证CmsEasy5.5爆账号密码 实验用源码:http://pan.baidu.co ...

  10. Linux下服务器环境的搭建和配置之一——Apache篇

    最近一个多月(2016-06-20开始至今),一直在忙海外广告平台FAQ系统的开发,既要负责服务器环境的搭建,又要写前端,还要写后台和数据库,甚至还要考虑产品需求和设计.所以是一个很大的挑战,对自身也 ...