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 ...
随机推荐
- gamma
图:显卡(驱动程序)上的Gamma设置 图:ACDSEE中的曝光调节 二. 什么是Gamma? 2.1. 显示器Gamma曲线 Gamma可能源于CRT(显示器/电视机)的响应曲线,即其亮度与输入电压 ...
- Python基础之列表
列表的内置方法 1.append() 描述:用于在列表末尾添加新的对象. 示例: msg_list=["aaaa","bbbbb","cccccc&q ...
- POJ 2104:K-th Number(整体二分)
http://poj.org/problem?id=2104 题意:给出n个数和m个询问求区间第K小. 思路:以前用主席树做过,这次学整体二分来做.整体二分在yr大佬的指点下,终于大概懂了点了.对于二 ...
- 来看看CBIS 2017中国(上海)大数据产业创新峰会有哪些大师出席
CBIS 2017中国(上海)大数据产业创新峰会,围绕"数据+产业.企业+数据.技术+人才.品牌+市场.应用+发展"相继展开话题讨论. CBIS 2017中国(上海)大数据产业创新 ...
- 【Python】协程实现生产者消费者模型
协程的实现为协作式而非抢占式的,这是和进程线程的最大区别.在Python中,利用yield和send可以很容易实现协程. 首先复习下生成器. 如果一个函数使用了yield语句,那么它就是一个生成器函数 ...
- 各种编码之间的关系以及getBytes的使用
编码基础知识参考http://my.oschina.net/chape/blog/201725 我对此作了简单的概括 iso8859-1 (通常叫做Latin-1) 属于单字节编码,最多能表示的字符范 ...
- js的兼容技巧
javascript原生代码中经常会遇到各式各样浏览器不兼容的问题,浏览器真是倔强,解决浏览器的兼容是前端猿们的一大难题 为了避免在工作中遇到这些简单的问题.节约开发时间,在这里总结一些常用的浏览器兼 ...
- [Centos] mod_wsgi 安装流程以及遇到问题解决办法。apxs: command not found 或 Sorry, Python developer package does not appear to be installed.
前提: Centos 系统, apache 已安装, python 已安装. 1. 首先下载mod_wsgi-3.5.tar.gz 下载地址:https://code.google.com/p/mod ...
- centos 安装cacti监控
CentOS 6下Cacti搭建文档 安装依赖关系 yum -y install mysql-devel httpd php php-pdo php-snmp php-mysql lm_sensors ...
- x264中的帧类型、条带类型、数据分区(data partition)
1 条带类型(slice type) x264的条带有三种基本类型分别为:I(主要用于帧内图像编码).P(用于帧间前向参考预测图像编码).B(用于帧间双向参考预测图像编码).SI与SP(切换码流时用) ...