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)

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:

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue> using namespace std;
#define INF 0x3f3f3f3f
#define maxn 25 int a[maxn][maxn], X, Y, n, flag;
int go[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; /// up right down left
int d[maxn][maxn][4]; struct Grid
{
int x, y, dire;
} g[2000]; bool judge(int x, int y)
{
if(x>=0 && y>=0 && x<n && y<n && a[x][y]!=1 && a[x][y]!=2)
return true;
return false;
} void bfs(int sx, int sy, int dire, int ex, int ey)
{
queue<Grid> Q;
Q.push(Grid {sx, sy, dire});
memset(d, 0x3f, sizeof(d));
d[sx][sy][dire] = 0;
while(!Q.empty())
{
Grid t = Q.front();
Q.pop(); if(t.x == ex && t.y == ey)
continue; for(int i=-1; i<3; i++)
{
int D = (t.dire + 4 + i) % 4;
int xx = t.x + go[D][0];
int yy = t.y + go[D][1];
if(judge(xx, yy) && d[xx][yy][D] > d[t.x][t.y][t.dire] + 10 + abs(i) * 10)
{
d[xx][yy][D] = d[t.x][t.y][t.dire] + 10 + abs(i) * 10;
Q.push(Grid {xx, yy, D});
}
}
}
} int main()
{
int T, t, x, y;
scanf("%d", &T);
while(T--)
{
X = Y = -1;
flag = 0;
memset(a, 0, sizeof(a));
scanf("%d", &n);
while(scanf("%d%d%d", &t, &x, &y) && t!=-1)
{
if(t == 3)
X = x, Y = y;
a[x][y] = t;
} int ans = INF;
if(a[0][0] != 2 && X != -1)
{
bfs(0, 0, 1, X, Y);
int Min1[4], Min2[4];
fill(Min1, Min1+4, INF);
fill(Min2, Min2+4, INF); for(int i=0; i<4; i++)
Min1[i] = d[X][Y][i]; for(int i=0; i<4; i++)
if(Min1[i] != INF)
{
flag = 1;
bfs(X, Y, i, 0, 0);
for(int j=0; j<4; j++)
Min2[i] = min(Min2[i], d[0][0][j]);
ans = min(ans, Min1[i] + Min2[i]);
}
} if(flag)
printf("%d\n", 980 - ans);
else
printf("-1\n");
}
return 0;
}

zoj 月赛的更多相关文章

  1. zoj 月赛B题(快速判断一个大数是否为素数)

    给出一个64位的大数,如何快速判断其是否为素数 #include<algorithm> #include<cstdio> #include<cstring> #in ...

  2. 有趣的数 zoj 月赛

    题目描述 让我们来考虑1到N的正整数集合.让我们把集合中的元素按照字典序排列,例如当N=11时,其顺序应该为:1,10,11,2,3,4,5,6,7,8,9. 定义K在N个数中的位置为Q(N,K),例 ...

  3. zoj 3725

    题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...

  4. ZOJ3802 Easy 2048 Again (状压DP)

    ZOJ Monthly, August 2014 E题 ZOJ月赛 2014年8月 E题 http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...

  5. zoj3802:easy 2048 again(状压dp)

    zoj月赛的题目,非常不错的一个状压dp.. 题目大意是一个一维的2048游戏 只要有相邻的相同就会合并,合并之后会有奖励分数,总共n个,每个都可以取或者不取 问最终得到的最大值 数据范围n<= ...

  6. 山东省第八届ACM省赛游记

    Day 1: 凌晨,来了几分兴致,和队友在VJudge上开了一把zoj月赛,WA一发闷一口拿铁,一瓶拿铁 不一会就被喝完了!好气啊!遂开始愉快地打游戏,打着打着,woc,居然3点半了,小睡片 刻,咬上 ...

  7. [置顶] 2013_CSUST暑假训练总结

    2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:h ...

  8. UVA 11922 伸展树Splay 第一题

    上次ZOJ月赛碰到一个题目要求对序列中的某个区间求gcd,并且还要随时对某位数字进行修改 插入 删除,当时马上联想到线段树,但是线段树不支持增删,明显还是不可以的,然后就敲了个链表想暴力一下,结果TL ...

  9. 浙大月赛ZOJ Monthly, August 2014

    Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...

随机推荐

  1. Redis远程连接

    一.打开CMD命令 二.打开Redis客户端安装地址

  2. FormsAuthentication权限管理

    通常我们在做访问权限管理的时候会把用户正确登录后的基本信息保存在Session中然后用户每次请求页面或接口数据的时候代上会话状态即能拿到Session中存储的基本信息Session的原理,也就是在服务 ...

  3. from scipy import spatial 出现 from .qhull import * ImportError: DLL load failed: The specified module could not be found. 错误

    错误描述: 本人机器window8.1 64位,python2.7. Traceback (most recent call last): File "C:/Users/Hamid/Docu ...

  4. CSS知识点整理(1):CSS语法,层叠次序,选择器,其他重要方面。

    1. css的全称 2. CSS的层叠次序:优先级由低到高 ·浏览器设置 ·外部样式表 或者 内部样式表 —— 就近原则 ·内联样式 3. CSS的3种形式,以及每种形式的语法格式 ——注意样式表的为 ...

  5. 3星|《哈佛商业评论》201708:IT项目风险之大远超你想象

    老牌管理学杂志.本期干货偏少,我评3星. 以下是本期一些信息的摘抄: 1:当我们调查被关闭餐馆周边的犯罪规律时,我们发现了与关闭药房同样的现象:被关闭餐馆周围财产犯罪和车内财物偷盗犯罪行为立即出现了上 ...

  6. mysql 性能优化索引、缓存、分表、分布式实现方式。

    系统针对5000台终端测试结果 索引 目标:优化查询速度3秒以内 需要优化.尽量避免使用select * 来查询对象.使用到哪些属性值就查询出哪些使用即可 首页页面: 设备-组织查询 优化 避免使用s ...

  7. POJ_3041_Asteroids

    参考自: http://user.qzone.qq.com/289065406/blog/1299322465 解题思路: 把方阵看做一个特殊的二分图(以行列分别作为两个顶点集V1.V2,其中| V1 ...

  8. GEO/SRA数据库

    GEO数据库 GEO数据库隶属于NCBI,是最大最全面的基因表达数据库,主要是芯片和转录组测序数据.除储存数据外,也提供一些数据挖掘工具,因此利用好这个数据库,没有实验,没有自己的数据也能发好文章! ...

  9. 梦想MxWeb3D,三维CAD协同设计平台 2019.04.09更新

    SDK开发包下载地址: http://www.mxdraw.com/ndetail_10140.html 在线演示网址: http://www.mxdraw.com:3000/ 1.  增加上传dwg ...

  10. Python自学-2-python解释器

    写python源文件,以.py为后缀名 用python解释器去执行.py文件 python解释器 CPython:官方版本,由C语言开发的,下载默认就是这个,使用最广的解释器.   用>> ...