A -Dragon Maze

Time Limit: 2000/1000MS (Java/Others)Memory Limit:
128000/64000KB (Java/Others)

题目连接:    
传送门

Problem Description

You are the prince of Dragon Kingdom and your kingdom is in danger of running out of power. You must find power to save your kingdom and its people. An old legend states that power comes from a place known as Dragon Maze. Dragon Maze appears randomly out
of nowhere without notice and suddenly disappears without warning. You know where Dragon Maze is now, so it is important you retrieve some power before it disappears.

Dragon Maze is a rectangular maze, an N×M grid of cells. The top left corner cell of the maze is(0, 0) and the bottom right corner is (N-1, M-1). Each cell making up the maze can be either a dangerous place which you never escape
after entering, or a safe place that contains a certain amount of power. The power in a safe cell is automatically gathered once you enter that cell, and can only be gathered once. Starting from a cell, you can walk up/down/left/right to adjacent cells with
a single step.

Now you know where the entrance and exit cells are, that they are different, and that they are both safe cells. In order to get out of Dragon Maze before it disappears,you must walk from the entrance cell to the exit cell taking as few steps as possible.

If there are multiple choices for the path you could take, you must choose the one on which you collect as much power as possible in order to save your kingdom.

Input

The first line of the input gives the number of test cases, T(1 ≤ T ≤ 30).T test cases follow.

Each test case starts with a line containing two integers N and M(1 ≤ N, M ≤ 100), which give the size of Dragon Maze as described above.

The second line of each test case contains four integers enx, eny, exx, exy(0 ≤ enx, exx < N, 0 ≤ eny, exy < M), describing the position of entrance cell(enx,
eny)
and exit cell (exx, exy).

Then N lines follow and each line has M numbers, separated by spaces, describing theN×M cells of Dragon Maze from top to bottom.

Each number for a cell is either -1, which indicates a cell is dangerous, or a positive integer, which indicates a safe cell containing a certain amount of power.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1).

If it's possible for you to walk from the entrance to the exit, y should be the maximum total amount of power you can collect by taking the fewest steps possible.

If you cannot walk from the entrance to the exit, y should be the string "Mission Impossible." (quotes for clarity).

Sample Input

2
2 3
0 2 1 0
2 -1 5
3 -1 6
4 4
0 2 3 2
-1 1 1 2
1 1 1 1
2 -1 -1 1
1 1 1 1

Sample Output

Case #1: Mission Impossible.
Case #2: 7 意解: 一个简单的BFS加优先队列,dfs也能够做,毕竟数据非常小. AC代码:
/*
* this code is made by eagle
* Problem: 1191
* Verdict: Accepted
* Submission Date: 2014-09-19 01:46:08
* Time: 72MS
* Memory: 1736KB
*/
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue> using namespace std;
int N,M,ux,uy,nx,ny;
int map[110][110];
int d[][2] = {-1,0,1,0,0,1,0,-1}; struct Node
{
int x,y,num,t;
//Node (int x, int y, int num) : x(x),y(y),num(num) {}
bool operator < (const Node &cnt) const
{
return cnt.t < t || (cnt.num > num && cnt.t == t);
}
}; bool query()
{
Node a;
priority_queue<Node>ms;
a.x = ux;
a.y = uy;
a.num = map[ux][uy];
a.t = 0;
ms.push(a);
while(!ms.empty())
{
a = ms.top();
ms.pop();
// cout<<a.x<<":"<<a.y<<endl;
if(a.x == nx && a.y == ny)
{
printf("%d\n",a.num);
return true;
}
for(int i = 0; i < 4; i++)
{
Node b;
b.x = a.x + d[i][0];
b.y = a.y + d[i][1];
if(b.x < 0 || b.y < 0 || b.x >= N || b.y >= M || map[b.x][b.y] == -1) continue;
b.num = a.num + map[b.x][b.y];
b.t = a.t + 1;
ms.push(b);
map[b.x][b.y] = -1;
}
}
return false;
} int main()
{
//freopen("in.txt","r",stdin);
int T,cnt = 0;
scanf("%d",&T);
while(T--)
{
printf("Case #%d: ",++cnt);
scanf("%d %d",&N,&M);
scanf("%d %d %d %d",&ux,&uy,&nx,&ny);
for(int i = 0; i < N; i++)
for(int j = 0; j < M; j++)
scanf("%d",&map[i][j]);
if(!query())
puts("Mission Impossible.");
}
return 0;
}

D - qj的招待会

Time Limit: 100/50MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others)

Problem Description

最终,qj不负众望的拿到了爱情。
可是其它村子的人都不相信这个注定孤独一生的孩子竟然会拥有爱情。于是都决定到qj所在的村子里去看看是否真的如此。
这时,qj为了(xiu)招(en)待(ai),他就必须得知道他们最早什么时候到。而且是哪个村子的。
qj所在的村子会用'Z'来代表,其它人的村子被标记为'a'..'z'和'A'..'Y',在用大写字母表示的村子中有人,小写字母中则没有。
为了使问题简单化,设定这些人每分钟走1km(喂喂,这可能吗。!!)
他如今非常忙,正在和爱情约会中,所以请各位帮帮qj算算吧。

Input

第一行 N表示道路数量(1<= N<=10000),

第2-N+1行 用空格隔开的两个字母和整数代表道路连接的村子与道路的长度(km)(1<=长度<=1000)

Output

输出:最先到达qj村子的村民所在的村子的标记,和这村民须要的时间(min)。

Sample Input

5
A d 6
B d 3
C e 9
d Z 8
e Z 3

Sample Output

B 11

意解: 这是一个简单的floyd最短路算法,仅仅须要给每一个村庄表上号,以A-z标为1到64,然后就是一个模板题了.

AC代码:
/*
* this code is made by eagle
* Problem: 1209
* Verdict: Accepted
* Submission Date: 2014-09-20 10:58:32
* Time: 12MS
* Memory: 1716KB
*/
#include <iostream>
#include <cstring>
#include <cstdio> using namespace std;
const int INF = 1e8;
int map[100][100]; void unit()
{
for(int i = 1; i <= 100; i++)
for(int j = 1; j <= 100; j++)
if(i != j) map[i][j] = INF;
else map[i][j] = 0;
} int main()
{
//freopen("in","r",stdin);
int T;
cin>>T;
getchar();
unit();
while(T--)
{
char c1,c2;
int x,a,b;
scanf("%c %c %d",&c1,&c2,&x);
getchar(); if(c1 > c2) swap(c1,c2); if(c1 > 'Z') a = c1 - 'a' + 27;
else a = c1 - 'A' + 1; if(c2 > 'Z') b = c2 - 'a' + 27;
else b = c2 - 'A' + 1; if(x < map[a][b]) map[a][b] = map[b][a] = x;
}
for(int k = 1; k <= 70; k++)
for(int j = 1; j <= 70; j++)
for(int i = 1; i <= 70; i++)
if(map[j][k] == INF || map[k][i] == INF) continue;
else map[j][i] = min(map[j][i] , map[j][k] + map[k][i]);
int ans = INF;
char t;
for(int i = 1; i < 26; i++)
if(map[i][26] < ans)
{
t = (char)(i + 'A' - 1);
ans = map[i][26];
}
printf("%c %d\n",t,ans);
return 0;
}

ACdream区域赛指导赛之手速赛系列(7)的更多相关文章

  1. ACdream区域赛指导赛之手速赛系列(2)

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/DaiHaoC83E15/article/details/26187183        回到作案现场 ...

  2. ACdream区域赛指导赛之手速赛系列(5) 题解

    A - Problem A Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submi ...

  3. ACDream手速赛2

    地址:http://acdream.info/onecontest/1014   都是来自Codeforce上简单题.   A. Boy or Girl 简单字符串处理   B. Walking in ...

  4. 快速切题 acdream手速赛(6)A-C

    Sudoku Checker Time Limit: 2000/1000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Submi ...

  5. Acdream手速赛7

    蛋疼啊,本次只做出了一道题目...渣爆了... 妈蛋,,卡题之夜..比赛结果是1道题,比赛完哗啦哗啦出4道题.. A acdream1191 Dragon Maze 题意: 给一个迷宫,给出入口坐标和 ...

  6. ACdream区域赛指导赛之专题赛系列(1)の数学专场

    Contest : ACdream区域赛指导赛之专题赛系列(1)の数学专场 A:EOF女神的相反数 题意:n(<=10^18)的数转化成2进制.翻转后(去掉前导零)输出十进制 思路:water ...

  7. Contest - 2014 SWJTU ACM 手速测试赛(2014.10.31)

    题目列表: 2146 Problem A [手速]阔绰的Dim 2147 Problem B [手速]颓废的Dim 2148 Problem C [手速]我的滑板鞋 2149 Problem D [手 ...

  8. 手速太慢QAQ

    显然D是个细节题,但是还剩1h时看眼榜还没人过EF,只好冷静写D,大概思路是任何时候如果min(n,m)<=2,max(n,m)<=4暴搜,否则直接贪心是很对的,即第一步让S.T长度平均化 ...

  9. tensorflow笔记(四)之MNIST手写识别系列一

    tensorflow笔记(四)之MNIST手写识别系列一 版权声明:本文为博主原创文章,转载请指明转载地址 http://www.cnblogs.com/fydeblog/p/7436310.html ...

随机推荐

  1. 总结esp8266刷Python的完整的步骤(终极总结)

    2018-04-0319:12:02 从玩microPython 到现在,一路荆棘一路坎坷. 不知道只有我遇到这样的问题还是microPython太不稳定,还是我买的板子太糙.总之遇到了太多问题了. ...

  2. 【OptiX】第5个示例 递归反射、抗锯齿

    运行结果如下: [抗锯齿] 可以看到中间那个竖线的右侧从地面上看有款明显的锯齿,而左边就没有.包括球的反射出来的三角形和地面也有明显的锯齿.那么抗锯齿究竟本例中是怎么做的呢? 首先在采样时,当场景需要 ...

  3. vba txt读写的几种方式

    四种方式写txt 1.这种写出来的是ANSI格式的txt Dim TextExportFile As String TextExportFile = ThisWorkbook.Path & & ...

  4. mysql数据转sql server

    创建一个mysql的ODBC数据源,在sql server中“任务”-“导入数据” -“选择创建的ODBC数据源” 然后填写服务器 登录名.密码,需要导入的数据库表什么的

  5. [JSOI2012]玄武密码 题解(AC自动机)

    显然是AC自动机对吧 插入单词之后把文章在自动机上跑一遍,到达过的节点打上花火标记 之后检查一下每个单词有几个标记即可 可以把题目中的4个字母映射成abcd方便遍历 一定要记得把文章也映射啊! #in ...

  6. C# HttpWebRequest Post Get 请求数据

    Post请求 1 //data 2 string cookieStr = "Cookie信息"; 3 string postData = string.Format("u ...

  7. phpExcel导出excel打不开问题

    用wps和office都打不开,使用旧版的office打开了 出现了一些 warming警告,虽然warming不影响函数的执行,但是php导出excel文件,是header出来的.这个warning ...

  8. vscode调试单个PHP脚本文件

    1.安装完vscode里的debug插件后, 在WorkSpace setting:添加上php的可执行文件路径: 2.下载适合自己PHP版本的Xdebug 3.在PHP目录下的php.ini配置文件 ...

  9. zip相关知识梳理(一)

    zip相关知识梳理(一) 经过对zip文件的长时间研究,对zip文件进行相关知识进行梳理,虽然网上很多牛人对其做了相关基础解析,但是对于特殊情况没有进行说明,比如超过4G的zip文件该以什么格式进行编 ...

  10. TestNG套件测试(二)

    在xml中指定要运行的整个包来执行套件测试 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE ...