zoj 月赛
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 月赛的更多相关文章
- zoj 月赛B题(快速判断一个大数是否为素数)
给出一个64位的大数,如何快速判断其是否为素数 #include<algorithm> #include<cstdio> #include<cstring> #in ...
- 有趣的数 zoj 月赛
题目描述 让我们来考虑1到N的正整数集合.让我们把集合中的元素按照字典序排列,例如当N=11时,其顺序应该为:1,10,11,2,3,4,5,6,7,8,9. 定义K在N个数中的位置为Q(N,K),例 ...
- zoj 3725
题意: n个格子排成一条直线,可以选择涂成红色或蓝色,问最少 m 个连续为红色的方案数. 解题思路: 应该是这次 ZOJ 月赛最水的一题,可惜还是没想到... dp[i] 表示前 i 个最少 m 个连 ...
- ZOJ3802 Easy 2048 Again (状压DP)
ZOJ Monthly, August 2014 E题 ZOJ月赛 2014年8月 E题 http://acm.zju.edu.cn/onlinejudge/showProblem.do?proble ...
- zoj3802:easy 2048 again(状压dp)
zoj月赛的题目,非常不错的一个状压dp.. 题目大意是一个一维的2048游戏 只要有相邻的相同就会合并,合并之后会有奖励分数,总共n个,每个都可以取或者不取 问最终得到的最大值 数据范围n<= ...
- 山东省第八届ACM省赛游记
Day 1: 凌晨,来了几分兴致,和队友在VJudge上开了一把zoj月赛,WA一发闷一口拿铁,一瓶拿铁 不一会就被喝完了!好气啊!遂开始愉快地打游戏,打着打着,woc,居然3点半了,小睡片 刻,咬上 ...
- [置顶] 2013_CSUST暑假训练总结
2013-7-19 shu 新生训练赛:母函数[转换成了背包做的] shuacm 题目:http://acm.hdu.edu.cn/diy/contest_show.php?cid=20083总结:h ...
- UVA 11922 伸展树Splay 第一题
上次ZOJ月赛碰到一个题目要求对序列中的某个区间求gcd,并且还要随时对某位数字进行修改 插入 删除,当时马上联想到线段树,但是线段树不支持增删,明显还是不可以的,然后就敲了个链表想暴力一下,结果TL ...
- 浙大月赛ZOJ Monthly, August 2014
Abs Problem Time Limit: 2 Seconds Memory Limit: 65536 KB Special Judge Alice and Bob is playing a ga ...
随机推荐
- poj2502 Subway
思路: 需要注意的地方:一条地铁线路并不一定和样例描述的那样是直的:同一条线路上的两个站点步行可能更快. 实现: #include <iostream> #include <cstd ...
- android cmd adb命令安装和删除apk应用
copy自http://blog.csdn.net/xpsharp/article/details/7289910 1. 安装Android应用程序 1) 启动Android模拟器 2) adb in ...
- QT开发之旅-Udp聊天室编程
一.概要设计 登录对话框(继承自QDialog类)进行用户登录查询数据库用户是否存在,注册插入数据到用户表.用户表字段: (chatid int primary key, passwd varchar ...
- U盘安装完美的WIN7操作系统教程
准备工作 首先备份或者在官网下载好您机器的驱动,否则完成后可能无法正常使用 ①一个有win7或者XP系统的电脑(制作启动盘用) ②一个4G以上的U盘 ③win7&win8系统包(请到官网下载或 ...
- EF 迁移操作
一. 模型设计 1. 遵循EF标准,注意表关系配对 2. 数据模型里尽量把必须的属性和说明都写全 3. EF默认id字段为主键,如果没有,需指定主键 二. 数据迁移 1. 命令运行环境:vis ...
- Shell printf命令
Shell 的另一个输出命令 printf.默认 printf 不会像 echo 自动添加换行符,我们可以手动添加 \n. #!/bin/bash printf "%-10s %-8s %- ...
- 413 Request Entity Too Large报错处理
修改nginx配置 这是最简单的一个做法,着报错原因是nginx不允许上传配置过大的文件,那么件把nginx的上传大小配置调高就好. 1.打开nginx主配置文件nginx.conf,一般在 ...
- CAD得到ImageMark数据(com接口VB语言)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3 ...
- jenkins部署遇到离线问题如何解决
部署jenkins页面时遇到离线问题如何解决 部署jenkins遇到一个问题,然后告诉我你的jenkins已经离线,什么鬼,后来找了很多博客 后来自己终于验证成功了,也分享给大家,只需把https改为 ...
- Python orm基础
ORM 对象映射关系程序. 通过orm将编程语言的对象模型和数据库的关系模型建立映射关系,这样我们在使用编程语言对数据库进行操作的时候可以直接使用编程语言的对象模型进行操作就可以了,而不用直接使用sq ...