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. MySQL的两种存储引擎storage engine特点和对比

    MyISAM 优点:快速读取数据, 占用空间小 缺点:不支持事务,外键 (表级别锁) InnoDB 优点:支持事务,外键; 高性能(CPU效率高) 缺点: 慢,占空间 (行级别锁)

  2. 【转】Java实现将文件或者文件夹压缩成zip

    转自:https://www.cnblogs.com/zeng1994/p/7862288.html package com.guo.utils; import java.io.*; import j ...

  3. Linux 学习(四)

    搭建jdk 安装jdk操作: 1.光驱挂载:mount /dev/cdrom /mnt 2.拷贝安装包至其他文件夹(如home目录下) 3.执行安装包(bin包:./包名) 4.配置环境变量:打开文件 ...

  4. Typora——自定义设置

    Typora提供自定义设置,在偏好设置里面,有一个主题文件夹,如果对界面的样式进行设定,可以添加一个css文件,命名规范是 github.user.css,下面代码会对h1~h4进行自动序列化 bod ...

  5. Python-Day07-图形用户界面和游戏开发

    Python-100Day-学习打卡Author: Seven_0507Date: 2019-05-22123 文章目录Python图形用户界面和游戏开发1. tkinter模块2. Pygame进行 ...

  6. python json格式和csv文件转换

    python json格式和csv文件转换 上代码 import csv import json ''' json格式示例 [{ "firstName":"Bill&qu ...

  7. Python isdigit() 方法检测字符串是否只由数字组成

    Python isdigit() 方法检测字符串是否只由数字组成

  8. TWaver 3D作品Viewer查看器

    为了让开发者更方便的对各类3D模型.设备.物体进行浏览和查看,我们直接封装了mono.Viewer组件.它可以直接根据给定的数据源(json.obj.url等)进行数据加载和浏览展示.对于一般的3D设 ...

  9. C#读取文件-古文观止(总结一下)

    1,读取单个文件 //读取一个文本文件 private void buttonRead_Click(object sender, EventArgs e) { String path = Enviro ...

  10. ZOJ - 3983 - Crusaders Quest(思维 + 暴力)

    题意: 给出一个字符串,长度为9,包含三种各三个字母"a","g","o",如果一次消除连续三个一样的分数+1,消完自动向左补齐 其中可以消 ...