当时看了这题就感觉so easy。。。  本来不想写的,后来感觉是不是可以练一下搜索水平。。

比赛时有人过了就没写。       比赛完了写一下。

实现还不是那么顺利,  囧

本来自己以为这题能练下搜索,其实DFS、BFS都没用到,也许模拟中有点搜索吧。

还是类似方格的东西把外围也设置成未标记要好的多,做题多了也许就有这种感觉了吧。

还有自己忽略了驴 老虎前面是已经走过的路也可以转弯。   BS!!

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm> #define clr(x) memset(x, 0, sizeof(x)) using namespace std; const int maxn = 1200;
int dv[maxn][maxn], tv[maxn][maxn];
int n, temp; //碰到已经走过的点也会转向 不仅是撞墙时。 int main()
{
while(scanf("%d", &n) != EOF)
{
if(!n) break;
memset(dv, -1, sizeof(dv));
memset(tv, -1, sizeof(tv));
int a2, b2, c2, a1, b1, c1, ans;
scanf("%d%d%d",&a1, &b1, &c1);
a1++; b1++;
scanf("%d%d%d",&a2, &b2, &c2);
a2++; b2++;
ans = 0; for(int i = 1; i <= n; i++) //防止界外。 外围都要包一层
for(int j = 1; j <= n; j++)
{
dv[i][j] = 0;
tv[i][j] = 0;
} dv[a1][b1] = 1; tv[a2][b2] = 1; while(true)
{
int ok1 = 0, ok2 = 0, temp; if(a1 == a2 && b1 == b2) break; if(c1 == 0) // east
{
temp = b1 + 1;
if(!dv[a1][temp])
{
++b1;
ok1 = 1;
dv[a1][temp] = 1;
}
else if(!dv[a1+1][b1])
{
++a1;
ok1 = 1;
c1 = 1;
dv[a1][b1] = 1;
}
}
else if(c1 == 1) //south
{
temp = a1 + 1;
if(!dv[temp][b1])
{
++a1;
ok1 = 1;
dv[temp][b1] = 1;
}
else if(!dv[a1][b1-1])
{
--b1;
ok1 = 1;
c1 = 2;
dv[a1][b1] = 1;
}
}
else if(c1 == 2) //west
{
temp = b1 - 1;
if(!dv[a1][temp])
{
--b1;
ok1 = 1;
dv[a1][temp] = 1;
}
else if(!dv[a1-1][b1])
{
--a1;
ok1 = 1;
c1 = 3;
dv[a1][b1] = 1;
}
}
else if(c1 == 3) //north
{
temp = a1 - 1;
if(!dv[temp][b1])
{
--a1;
ok1 = 1;
dv[temp][b1] = 1;
}
else if(!dv[a1][b1+1])
{
++b1;
ok1 = 1;
c1 = 0;
dv[a1][b1] = 1;
}
} if(c2 == 0) // east
{
temp = b2 + 1;
if(!tv[a2][temp])
{
++b2;
ok2 = 1;
tv[a2][temp] = 1;
}
else if(!tv[a2-1][b2])
{
--a2;
ok2 = 1;
c2 = 3;
tv[a2][b2] = 1;
}
}
else if(c2 == 1) //south
{
temp = a2 + 1;
if(!tv[temp][b2])
{
++a2;
ok2 = 1;
tv[temp][b2] = 1;
}
else if(!tv[a2][b2+1])
{
++b2;
ok2 = 1;
c2 = 0;
tv[a2][b2] = 1;
}
}
else if(c2 == 2) //west
{
temp = b2 - 1;
if(!tv[a2][temp])
{
--b2;
ok2 = 1;
tv[a2][temp] = 1;
}
else if(!tv[a2+1][b2])
{
++a2;
ok2 = 1;
c2 = 1;
tv[a2][b2] = 1;
}
}
else if(c2 == 3) //north
{
temp = a2 - 1;
if(!tv[temp][b2])
{
--a2;
ok2 = 1;
tv[temp][b2] = 1;
}
else if(!tv[a2][b2-1])
{
--b2;
ok2 = 1;
c2 = 2;
tv[a2][b2] = 1;
}
} if(ok1 == 0 && ok2 == 0)
{
ans = -1; break;
}
} if(ans == -1) printf("-1\n");
else printf("%d %d\n", a1-1, b1-1);
}
return 0;
}

自己要是想缩短代码长度其实可以设个函数。

再看看THU的代码。。    有 1 -1 0 0 这种东西。。

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std; const int MAX_N = 1000 + 10;
int n; //E,S,W,N
int dx[4] = { 0, 1, 0, -1 }, dy[4] = { 1, 0, -1, 0 }; struct Walker {
int x, y, d, turn;
bool active; bool vis[MAX_N][MAX_N]; //where had he visited
void read(int turn) { this->turn = turn;
cin >> x >> y >> d; active = true;
memset(vis, 0, sizeof vis);
} bool check(int r, int c) {
return r >= 0 && r < n && c >= 0 && c < n && !vis[r][c];
} void walk() { //can walk?
//go stright
if (check(x + dx[d], y + dy[d])) {
x += dx[d], y += dy[d];
goto end;
}
d = (d + turn) % 4;
if (check(x + dx[d], y + dy[d])) {
x += dx[d], y += dy[d];
goto end;
}
active = false; //dead >_<
return;
end: {
}
vis[x][y] = true;
}
}; Walker A, B; int main() {
for (;;) {
cin >> n;
if (n == 0)
break;
A.read(1);
B.read(3); A.vis[A.x][A.y] = true;
B.vis[B.x][B.y] = true; for (;;) {
if (!A.active && !B.active)
break; //end!
if (A.x == B.x && A.y == B.y) {
cout << A.x << " " << A.y << endl;
goto end;
}
if (A.active) {
A.walk();
}
if (B.active) {
B.walk();
}
} cout << -1 << endl; end: {
}
}
}

hdu4740【杭州网赛、模拟、有点搜索?】的更多相关文章

  1. 杭州网赛 two rabbits (hdu 4745)

    算法很简单,问题是,怎么证明,答案是回文序列. 设a,b走的序列按顺时针是: a1 , a2 , a3 , ... , ak b1 , b2 , b3 , ... , bk 考虑端点的2种情况: 1. ...

  2. HDU4738【杭州网赛、判桥】

    刚拿到这道题时挺有思路,无奈平日里只敲过找割顶的代码,判桥的代码当时自己也没仔细敲. 当时一把泪啊,忽然感觉自己的图论才只是刚搞了个起步啊.. 题目有神坑.    就是先判是否连通,不连通直接输出0; ...

  3. 2013杭州网赛 1001 hdu 4738 Caocao's Bridges(双连通分量割边/桥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4738 题意:有n座岛和m条桥,每条桥上有w个兵守着,现在要派不少于守桥的士兵数的人去炸桥,只能炸一条桥 ...

  4. hdu 4771 Stealing Harry Potter's Precious (2013亚洲区杭州现场赛)(搜索 bfs + dfs) 带权值的路径

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4771 题目意思:'@'  表示的是起点,'#' 表示的是障碍物不能通过,'.'  表示的是路能通过的: ...

  5. ZOJ Bizarre Routine 2013杭州网赛B题

    题目意思: 给定n, expect, a, b 要求你构造一组array[],存放一个1..n的排列,使的下面的程序能输出YES 题目所示代码: bool less_than(x, y) { T++; ...

  6. HDU 4746 HDOJ Mophues 2013杭州网赛I题

    比赛的时候就预感到这题能出,但是会耗时比较多.结果最后是出了,但是有更简单的题没出. 是不是错误的决策呢?谁知道呢 题目意思: 定义f(x) = x分解质因数出来的因子个数 如 x = p0 * p0 ...

  7. python--selenium简单模拟百度搜索点击器

    python--selenium简单模拟百度搜索点击器 发布时间:2018-02-28 来源:网络 上传者:用户 关键字: selenium 模拟 简单 点击 搜索 百度 发表文章摘要:用途:简单模拟 ...

  8. HDU 4738 Caocao's Bridges (2013杭州网络赛1001题,连通图,求桥)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  9. Splinter学习--初探1,模拟百度搜索

    Splinter是以Selenium, PhantomJS 和 zope.testbrowser为基础构建的web自动化测试工具,基本原理同selenium 支持的浏览器包括:Chrome, Fire ...

随机推荐

  1. (五)boost库之随机数random

    (五)boost库之随机数random boost库为我们提供了许多的日常随机数生成器: 1.uniform_smallint:在小整数域内的均匀分布 2.uniform_int:在整数域上的均匀分布 ...

  2. Unity doesn't load, no Launcher, no Dash appears

    1. 重新安装 ubuntu-desktop不起作用. Enter the following commands:- Ctrl+Alt+F1 login there by user name and ...

  3. ngrok首页、文档和下载 - Web服务安全通道 - 开源中国社区

    ngrok首页.文档和下载 - Web服务安全通道 - 开源中国社区      Web服务安全通道 ngrok 编辑/纠错    分享到     新浪微博腾讯微博    已用    +0    收藏 ...

  4. CURL 宏定义列表

    摘自http://blog.csdn.net/msda/article/details/38047809/ CURL 宏定义列表 列表CURL库一共有17个函数 curl_close:关闭CURL会话 ...

  5. POJ 3311 Hie with the Pie(状压DP + Floyd)

    题目链接:http://poj.org/problem?id=3311 Description The Pizazz Pizzeria prides itself in delivering pizz ...

  6. ORACLE AUTOMATIC STORAGE MANAGEMENT翻译-第二章 ASM instance(1)

    第二章  ASM INSTANCE ASM的类型,例如可以: 10g后ORACLE instance 类型增加了一个ASM种类.参数INSTANCE_TYPE=ASM进行设置. ASM实例启动命令: ...

  7. 数据结构:最小生成树--Prim算法

    最小生成树:Prim算法 最小生成树 给定一无向带权图.顶点数是n,要使图连通仅仅需n-1条边.若这n-1条边的权值和最小,则称有这n个顶点和n-1条边构成了图的最小生成树(minimum-cost ...

  8. GetBuffer与ReleaseBuffer的用法,CString剖析

    转载: http://blog.pfan.cn/xman/43212.html GetBuffer()主要作用是将字符串的缓冲区长度锁定,releaseBuffer则是解除锁定,使得CString对象 ...

  9. 安装rvm命令行工具

    rvm是一个命令行工具,可以提供一个便捷的多版本ruby环境的管理和切换. https://rvm.io/ 如果你打算学习ruby/rails, rvm是必不可少的工具之一. 这里所有的命令都是再用户 ...

  10. C# 2 闰年平年 老狼几点了

    作业 第一题 老狼几点了.凌晨,上午,下午,晚上. static void Main (string[] args) { //输入 Console.Write("老狼老狼几点了?" ...