ZOJ 3890 Wumpus

时间:2022-02-21 00:47:24

Wumpus


Time Limit: 2 Seconds     
Memory Limit: 65536 KB

One day Leon finds a very classic game called Wumpus.The game is as follow.

Once an agent fell into a cave. The legend said that in this cave lived a kind of monster called Wumpus, and there were horrible pits which could lead to death everywhere. However, there were also a huge amount of gold in the cave. The agent must be careful
and sensitive so that he could grab all of the gold and climb out of the cave safely.



The cave can be regarded as a n*n board. In each square there could be a Wumpus, a pit, a brick of gold, or nothing. The agent would be at position (0,0) at first and headed right.(As the picture below)

ZOJ 3890 Wumpus

name=Wumpus1.png">

For each step, there are six possible movements including going forward, turning left, turning right, shooting, grabbing the gold, and climbing out of the cave. If the agent steps into a square containing a pit or Wumpus, he will die. When the agent shoots,
the Wumpus in front of him will die. The goal of the agent is to grab all of the gold and return to the starting position and climb out(it's OK if any Wumpus is still living).When a brick of gold is grabbed successfully, you will gain 1000 points. For each
step you take, you will lose 10 points.



Your job is to help him compute the highest point he can possibly get.



For the purpose of simplification, we suppose that there is only one brick of gold and the agent cannot shoot the Wumpus.

If there is a pit at (0, 0), the agent dies immediately. There will not be a Wumpus at (0, 0).

Input

There are multiple cases. The first line will contain one integer k that indicates the number of cases.



For each case:

The first line will contain one integer n (n <= 20).

The following lines will contain three integers, each line shows a position of an object. The first one indicates the type of the object. 1 for Wumpus, 2 for pit and 3 for gold. Then the next two integers show the x and y coordinates of the object.

The input end with -1 -1 -1. (It is guaranteed that no two things appear in one position.)

Output

The output contains one line with one integer, which is the highest point Leon could possibly get. If he cannot finish the game with a non-negative score, print "-1".

Sample Input

2
3
1 1 1
2 2 0
3 2 2
-1 -1 -1
3
1 1 1
3 2 2
-1 -1 -1

Sample Output

850
870

Hint

For the sample 1, the following steps are taken:

turn left, forward, forward, turn right, forward, forward, grab, turn left, turn left, forward, forward, turn left, forward, forward, climb.

There are in all 15 steps, so the final score is 840. For the sample 2 , the path is as follow:

ZOJ 3890 Wumpus

Author: JIANG, Kairong

Source: ZOJ Monthly, July 2022





转弯bfs。用四维标记

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <malloc.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
int n;
struct node
{
int x,y,gg,cost,fangxiang;
};
int vis[22][22][4][2];//一维,二维坐标。三维四个方向 四维金子拿了没有
int dir[4][2]= //zai 0 0
{
1,0, // 開始向右,1,0。
0,-1,
-1,0,
0,1,
};
char mp[22][22];
int judge(node &now)
{
if(now.x<0 ||now.y<0 ||now.x>=n ||now.y>=n)
return 0;
if(mp[now.x][now.y]==1)
return 0;
if(vis[now.x][now.y][now.fangxiang][now.gg])
return 0;
vis[now.x][now.y][now.fangxiang][now.gg]=1;
if(mp[now.x][now.y]==3 &&now.gg==0)
{
now.cost+=1000;
now.cost-=10;
now.gg=1;
}
return 1;
}
int bfs()
{
memset(vis,0,sizeof(vis));
queue<node>q;
node st,ed,now;
st.fangxiang=st.cost=st.gg=st.x=st.y=0;
q.push(st);
int ans=0;
while(!q.empty())
{
ed=q.front();
if(ed.x==0 &&ed.y==0)
ans=max(ans,ed.cost);
q.pop();
for(int i=-1; i<=1; i++)
{
now=ed;
now.cost-=10;
if(i==0)
{
now.x+=dir[now.fangxiang][0];
now.y+=dir[now.fangxiang][1];
}
else
now.fangxiang=(now.fangxiang+i+4)%4;
if(judge(now))
q.push(now);
}
}
return ans-10;
}
int main()
{
int t;
cin>>t;
while(t--)
{
int a,b,p;
int flag=0;
scanf("%d",&n);
memset(mp,0,sizeof(mp));
while(scanf("%d%d%d",&a,&b,&p)!=EOF&&a!=-1 &&b!=-1&&p!=-1)
{
if(a==1)
mp[b][p]=1;
else if(a==2)
{
mp[b][p]=1;
if(b==0 &&p==0)
flag=1;
}
else if(a==3)
mp[b][p]=3;
}
int ans1=bfs();
if(flag)
{
cout<<-1<<endl;
continue;
}
if(ans1<0)
cout<<-1<<endl;
else
cout<<ans1<<endl;
}
return 0;
}

ZOJ 3890 Wumpus的更多相关文章

  1. ZOJ - 3890 Wumpus(BFS基础题)

    Wumpus Time Limit: 2 Seconds      Memory Limit: 65536 KB One day Leon finds a very classic game call ...

  2. ZOJ People Counting

    第十三届浙江省大学生程序设计竞赛 I 题, 一道模拟题. ZOJ  3944http://www.icpc.moe/onlinejudge/showProblem.do?problemCode=394 ...

  3. ZOJ 3686 A Simple Tree Problem

    A Simple Tree Problem Time Limit: 3 Seconds      Memory Limit: 65536 KB Given a rooted tree, each no ...

  4. ZOJ Problem Set - 1394 Polar Explorer

    这道题目还是简单的,但是自己WA了好几次,总结下: 1.对输入的总结,加上上次ZOJ Problem Set - 1334 Basically Speaking ac代码及总结这道题目的总结 题目要求 ...

  5. ZOJ Problem Set - 1392 The Hardest Problem Ever

    放了一个长长的暑假,可能是这辈子最后一个这么长的暑假了吧,呵呵...今天来实验室了,先找了zoj上面简单的题目练练手直接贴代码了,不解释,就是一道简单的密文转换问题: #include <std ...

  6. ZOJ Problem Set - 1049 I Think I Need a Houseboat

    这道题目说白了是一道平面几何的数学问题,重在理解题目的意思: 题目说,弗雷德想买地盖房养老,但是土地每年会被密西西比河淹掉一部分,而且经调查是以半圆形的方式淹没的,每年淹没50平方英里,以初始水岸线为 ...

  7. ZOJ Problem Set - 1006 Do the Untwist

    今天在ZOJ上做了道很简单的题目是关于加密解密问题的,此题的关键点就在于求余的逆运算: 比如假设都是正整数 A=(B-C)%D 则 B - C = D*n + A 其中 A < D 移项 B = ...

  8. ZOJ Problem Set - 1001 A &plus; B Problem

    ZOJ ACM题集,编译环境VC6.0 #include <stdio.h> int main() { int a,b; while(scanf("%d%d",&amp ...

  9. zoj 1788 Quad Trees

    zoj 1788 先输入初始化MAP ,然后要根据MAP 建立一个四分树,自下而上建立,先建立完整的一棵树,然后根据四个相邻的格 值相同则进行合并,(这又是递归的伟大),逐次向上递归 四分树建立完后, ...

随机推荐

  1. 深入解析Windows操作系统笔记——CH2系统结构

    2.系统结构 本章主要介绍系统的总体结构,关键部件之间的交互,以及运行在什么环境. 2.系统结构 2.1 需求和设计目标 2.2 操作系统模型 2.3 总体结构 2.3.1 可移植性 2.3.2 对称 ...

  2. 查看Eclipse版本

    点击Help->About Eclipse,在弹出的对话框下部有很多logo. 鼠标在logo上停留,会有提示,找出提示为Eclipse.org的那个logo,即为Eclipse的logo,点击 ...

  3. Mysql-ERROR 1044 &lpar;42000&rpar;&colon; Access denied for user &&num;39&semi;&&num;39&semi;&commat;&&num;39&semi;localhost&&num;39&semi; to database &&num;39&semi;mysql&&num;39&semi;

    方法一:1.关闭mysql   # service mysqld stop2.屏蔽权限   # mysqld_safe --skip-grant-table   屏幕出现: Starting demo ...

  4. Hibernate(九)一对多双向关联映射

    上次的博文Hibernate从入门到精通(八)一对多单向关联映射中,我们讲解了一下一对多单向映射的相关 内容,这次我们讲解一下一对多双向映射的相关内容. 一对多双向关联映射 一对多双向关联映 射,即在 ...

  5. Android 使用 intent 实现简单登陆页面

    前言 第一个 Android 程序,应该有些纪念的意义吧~ 主页面布局 给 Button 添加响应函数:android:onClick="login" public void lo ...

  6. Mac OS使用技巧之十五&colon;快捷方便的Mini Dock

    Mini Dock是前面忘记了提,这里做一些补充.       Mini Dock是Mac OSX的一个值得大书特书的亮点.尽管windows下也有类似的东西,但Mac下却提供了更为全面的功能.通过M ...

  7. Scrapy框架--Requests对象

    Scrapy使用request对象来爬取web站点. request对象由spiders对象产生,经由Scheduler传送到Downloader,Downloader执行request并返回resp ...

  8. Visual Studio 2019 正式发布,重磅更新,支持live share

    如约而至,微软已于今天推出 Visual Studio 2019 正式版,一同发布的还有 Visual Studio 2019 for Mac. Visual Studio 2019 下载地址:htt ...

  9. 2017-10-5模拟赛T2 小Z爱排序&lpar;sorting&period;&ast;&rpar;

    Description Solution 比赛时找到了规律,但是没有证出来……(当然最后还是AC了……) 显然没有被操作的数在排好序的序列中一定是连续的一段. 所以,没有被操作的数一定从左到右连续地递 ...

  10. sql server 阻塞与锁

    SQL Server阻塞与锁 在讨论阻塞与加锁之前,需要先理解一些核心概念:并发性.事务.隔离级别.阻塞锁及死锁. 并发性是指多个进程在相同时间访问或者更改共享数据的能力.一般情况而言,一个系统在互不 ...