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. C# 写的正整数四则运算计算器

    实际上没能做出来负数.括号.小数的功能,才写这么个标题 大神直接略过,也欢迎指指点点-.- 输入一个四则运算表达式,计算出结果,想想不难,实现起来也不是很容易的. 流程:1.for循环输入的四则运算字 ...

  2. Jax

    The scope of this project is to automate the current Credit Correction process of opening, editing, ...

  3. php-5.3源码编译autoconf版本不符合解法

    1. 网上下载符合版本的autoconf 2. 卸载本地原本的autoconf 3. 解压autoconf 后进入目录 ./configure && make && s ...

  4. spark web ui

    spark UI 界面:http://www.cnblogs.com/xing901022/p/6445254.html 几个概念的解释:http://blog.csdn.net/jiangwlee/ ...

  5. python对象以及pickle腌制

    #python对象 1.什么是python的对象 2.详解pickle腌制 1.什么是python的对象 Python的内置的对象类型主要有数字.字符串.列表.元组.字典.集合等等.其实,在pytho ...

  6. Android Studio 1.5启动出现“SDK Manager: failed to install”问题的解决

    问题描述 Android Studio 1.5是当前最新Android手机应用开发平台,下载bundle版安装后,启动Studio后出现“SDK Manager: failed to install” ...

  7. mongo 3.4分片集群系列之二:搭建分片集群--哈希分片

    这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...

  8. Windows提高_2.2第二部分:用户区同步

    第二部分:用户区同步 同步和互斥 同步:就是按照一定的顺序执行不同的线程 互斥:当一个线程访问某一资源的时候,其它线程不能同时访问 多线程产生的问题 #include <stdio.h> ...

  9. CAD梦想看图6.0安卓版详情介绍

    下载安装 MxCAD6.0(看图版).2018.10.22更新,扫描下面二维码,安装CAD梦想看图:   下载地址: http://www.mxdraw.com/help_8_20097.html 软 ...

  10. 动态生成java、动态编译、动态加载

    我曾经见过一个“规则引擎”,是在应用系统web界面直接编写java代码,然后保存后,规则即生效,我一直很是奇怪,这是如何实现的呢?实际这就好像jsp,被中间件动态的编译成java文件,有被动态的编译成 ...