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. json常识

    转载网址:http://developer.51cto.com/art/201704/536386.htm   我们先来看一个JS中常见的JS对象序列化成JSON字符串的问题. 请问:以下JS对象通过 ...

  2. mysql之命令行导入导出

    命令介绍 mysqldump:导出命令,在系统”命令提示符“窗口直接使用,如果提示没有此命令(前提是已经安装成功mysql),在环境变量中的path添加mysql,即path=D:\xxx\mysql ...

  3. jsp学习笔记 - 内置对象 pageContext

    1.pageContext几乎可以操作所有的页面内置对象 pageContext.getRequest();    得到的对象只是属于ServletRequest类,httpServletReques ...

  4. java如何区分同时继承的父类和实现的接口中相同的方法

    基类代码: public class Father { public Father() { System.out.println("基类构造函数{"); show(); Syste ...

  5. Win10 “此环境变量太大。此对话框允许将值设置为最长2047个字符。" 解决方法。

    打开注册表 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment 双击右边的 Path (RE ...

  6. Alpha项目测试

    这个作业属于哪个课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/homework/3338 这个作业要求在哪里 htt ...

  7. 01Hypertext Preprocessor

    Hypertext Preprocessor PHP即Hypertext Preprocessor是一种被广泛使用的开放源代码多用途动态交互性站点的强有力的服务器端脚本语言尤其适用于 Web开发人员可 ...

  8. 基础:VS快捷键

    VS.net中快捷键收缩和展开代码段 i. Ctrl-M-O   折叠所有方法 ii. Ctrl-M-P   展开所有方法并停止大纲显示(不可以再折叠了) iii. Ctrl-M-M   折叠或展开当 ...

  9. 荷兰国旗问题、快排以及BFPRT算法

    荷兰国旗问题 给定一个数组arr,和一个数num,请把小于num的数放数组的左边,等于num的数放在数组的中间,大于num的数放在数组的右边.要求额外空间复杂度O(1),时间复杂度O(N). 这个问题 ...

  10. [bzoj1966][Ahoi2005][VIRUS 病毒检测] (字符串dp)

    Description 科学家们在Samuel星球上的探险仍在继续.非常幸运的,在Samuel星球的南极附近,探险机器人发现了一个巨大的冰湖!机器人在这个冰湖中搜集到了许多RNA片段运回了实验基地.科 ...