hdu 4741 2013杭州赛区网络赛 dfs ***
起点忘记录了,一直wa
代码写的很整齐,看着很爽
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<map>
using namespace std;
#define MOD 1000000007
const int INF=0x3f3f3f3f;
const double eps=1e-;
typedef long long ll;
#define cl(a) memset(a,0,sizeof(a))
#define ts printf("*****\n");
const int MAXN=;
int n,m,tt;
int dir[][]={,,,,,-,-,};
bool vis1[MAXN][MAXN];
bool vis2[MAXN][MAXN];
void dfs(int dx,int dy,int dd,int tx,int ty,int td)
{
if(dx==tx&&dy==ty)
{
printf("%d %d\n",dx,dy);
return;
}
bool f1=,f2=;
int ndd=dd;
int ndx=dx+dir[dd][];
int ndy=dy+dir[dd][];
if(ndx<||ndx>=n||ndy<||ndy>=n||vis1[ndx][ndy]) ndd=(dd+)%;
ndx=dx+dir[ndd][];
ndy=dy+dir[ndd][];
if(ndx<||ndx>=n||ndy<||ndy>=n||vis1[ndx][ndy])
{
f1=;
ndx=dx,ndy=dy,ndd=dd;
} int ntd=td;
int ntx=tx+dir[td][];
int nty=ty+dir[td][];
if(ntx<||ntx>=n||nty<||nty>=n||vis2[ntx][nty]) ntd=(td-+)%;
ntx=tx+dir[ntd][];
nty=ty+dir[ntd][];
if(ntx<||ntx>=n||nty<||nty>=n||vis2[ntx][nty])
{
f2=;
ntx=tx,nty=ty,ntd=td;
}
if(f1&&f2)
{
printf("-1\n");
return;
}
vis1[ndx][ndy]=;
vis2[ntx][nty]=; dfs(ndx,ndy,ndd,ntx,nty,ntd);
}
int main()
{
int i,j,k,ca=;
#ifndef ONLINE_JUDGE
freopen("1.in","r",stdin);
#endif
int dx,dy,dd,tx,ty,td;
int tot=;
while(scanf("%d",&n)!=EOF&&n)
{
cl(vis1);
cl(vis2);
scanf("%d%d%d",&dx,&dy,&dd);
scanf("%d%d%d",&tx,&ty,&td);
vis1[dx][dy]=;
vis2[tx][ty]=;
dfs(dx,dy,dd,tx,ty,td);
}
}
hdu 4741 2013杭州赛区网络赛 dfs ***的更多相关文章
- hdu 4738 2013杭州赛区网络赛 桥+重边+连通判断 ***
题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥,使得这n座岛不连通,求最少要派多少人去. 处理重边 边在遍历的时候,第一个返回的一定是之前去的边,所以 ...
- hdu 4739 2013杭州赛区网络赛 寻找平行坐标轴的四边形 **
是平行坐标轴的,排个序搞一下就行了,卧槽,水的不行 如果不是平行的,则需要按照边长来判断
- hdu 4751 2013南京赛区网络赛 二分图判断 **
和以前做过的一个二分图颇为相似,以前的是互相不认识的放在一组,这个是互相认识的,本质上是相同的 是 hdu 2444 #include<cstdio> #include<iostre ...
- hdu 4277 2012长春赛区网络赛 dfs+hashmap ***
hashmap判重大法好 #include<cstdio> #include<iostream> #include<algorithm> #include<c ...
- hdu 4272 2012长春赛区网络赛 dfs暴力 ***
总是T,以为要剪枝,后来发现加个map就行了 #include<cstdio> #include<iostream> #include<algorithm> #in ...
- hdu 4753 2013南京赛区网络赛 记忆化搜索 ****
看到范围基本可以想到dp了,处理起来有点麻烦 #include<iostream> #include<cstdio> #include<cstring> #incl ...
- hdu 4731 2013成都赛区网络赛 找规律
题意:找字串中最长回文串的最小值的串 m=2的时候暴力打表找规律,打表可以用二进制枚举
- hdu 4412 2012杭州赛区网络赛 期望
虽然dp方程很好写,就是这个期望不知道怎么求,昨晚的BC也是 题目问题抽象之后为:在一个x坐标轴上有N个点,每个点上有一个概率值,可以修M个工作站, 求怎样安排这M个工作站的位置,使得这N个点都走到工 ...
- hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***
题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙, 每个逮捕队伍在每个城市可以选 ...
随机推荐
- Hibernate 多对多关联查询条件使用
from Brand as b inner join fetch b.styles as s where s.styleId=?
- IntelliJ IDEA 常用快捷键列表及技巧大全
IntelliJ Idea 常用快捷键列表 Alt+回车 导入包,自动修正Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+L 格式化代码Ctrl+Alt+O 优化导入的类和 ...
- POJ 1088
http://poj.org/problem?id=1088 一道中文题,这道题如果不限时的话,是个简单的搜索,但限时的话,就要用记忆化搜索 所谓记忆化搜索就是对每一次搜索的结果进行记录,然后之后的如 ...
- ansible操作远程服务器报Error: ansible requires the stdlib json or simplejson module, neither was found!
通过ansible执行远程命令时报如下异常: Error: ansible requires the stdlib json or simplejson module, neither was fou ...
- 一步步搭建docker私有仓库并从私有仓库中下载镜像
一步步搭建docker私有仓库 #下载镜像 docker pull registry#查看镜像 docker images #运行私有仓库,指定端口和数据卷 docker run -d -p : -v ...
- uml 推荐文章
http://blog.csdn.net/zfrong/article/details/4086424 http://www.cnblogs.com/ywqu/archive/2009/12/14/1 ...
- 和我一起学python,控制语句 (life is short ,we need python)
控制语句 if/elif/else if语句和一般编程语言一样,条件为true 执行 如: if true : print 'true' <----if.else下对齐,要使用相 ...
- ABAP 销售范围
*&---------------------------------------------------------------------* *& Report ZSDR008 ...
- 【leetcode】 Unique Path ||(easy)
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 【linux】vim的一些快捷键
ctrl+y :重复上一行内容 v+移动光标 :选择内容 y :复制选中的内容 p :在光标处粘贴复制的内容 ctrl+v :进入列模式,可以选择多列数据 dd :剪切一行,也可做删除一行使用