ZOJ 3369 Saving Princess
Saving Princess
This problem will be judged on ZJU. Original ID: 3369
64-bit integer IO format: %lld Java class name: Main
Saving princesses is always a hard work. Ivan D'Ourack is planning to save the princess locked in the tower. However, n dangerous monsters are guarding the road from the city where Ivan lives to the tower where the princess is locked.
Fortunately Ivan is a warrior and a magician. Thus he can defeat monsters in a fight, and enchant them to pass unnoticed.
Initially Ivan has h health points, strength s, spell power p and m mana points. To defeat i-th monster in a fight, he must have strength at least si, and he loses max(2si - s, 0) health points in a fight. If the number of health points becomes 0 or less, Ivan dies. After defeating a monster Ivan's strength increases by 1.
To enchant i-th monster Ivan must have spell power at least pi and he spends mi mana points to do it. If Ivan does not have mi mana points, he cannot enchant the monster. After enchanting the monster Ivan's spell power increases by 1.
Find out, whether Ivan can save princess, and if he can how to do it.
Input
The first line of the input file contains n, h, s, p and m (1 ≤ n ≤ 50, 1 ≤ h ≤ 50, 0 ≤ s, p, m ≤ 50). The following n lines contain three integer numbers each --- si, pi, and mi (1 ≤ si, pi, mi≤ 50).
There are multiple cases. Process to the end of file.
Output
If Ivan cannot save princess, output "UNLUCKY". In the other case output n characters, the i-th character must be 'D' if Ivan must defeat the i-the monster, or 'E' if he must enchant it.
Sample Input
3 12 5 5 6
5 5 2
6 5 2
6 7 3
3 11 5 5 6
5 5 2
6 5 2
6 7 3
Sample Output
DED
UNLUCKY
Source
Author
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
const int maxn = ;
struct node{
int h,s,p,m,step;
node(int ax = ,int ab = ,int ac = ,int ad = ,int ae = ){
h = ax;
s = ab;
p = ac;
m = ad;
step = ae;
}
char way[maxn];
};
queue<node>q;
int n,h,s,p,m;
int ms[maxn],mp[maxn],mm[maxn],opti[maxn][maxn][maxn];
bool bfs(){
while(!q.empty()) q.pop();
q.push(node(h,s,p,m,));
while(!q.empty()){
node now = q.front();
q.pop();
if(now.step == n){
for(int i = ; i <= n; ++i)
putchar(now.way[i]);
putchar('\n');
return true;
}
if(now.h < opti[now.s][now.p][now.m]) continue;
if(now.s >= ms[now.step+]){
node tmp = now;
tmp.step++;
tmp.s++;
tmp.h -= max(*ms[tmp.step] - now.s,);
tmp.way[tmp.step] = 'D';
if(tmp.h > opti[tmp.s][tmp.p][tmp.m]){
opti[tmp.s][tmp.p][tmp.m] = tmp.h;
q.push(tmp);
}
}
if(now.p >= mp[now.step+] && now.m >= mm[now.step+]){
node tmp = now;
tmp.step++;
tmp.p++;
tmp.m -= mm[now.step+];
tmp.way[tmp.step] = 'E';
if(tmp.h > opti[tmp.s][tmp.p][tmp.m]){
opti[tmp.s][tmp.p][tmp.m] = tmp.h;
q.push(tmp);
}
}
}
return false;
}
int main() {
while(~scanf("%d %d %d %d %d",&n,&h,&s,&p,&m)){
for(int i = ; i <= n; ++i)
scanf("%d %d %d",ms+i,mp+i,mm+i);
memset(opti,,sizeof(opti));
if(!bfs()) puts("UNLUCKY");
}
return ;
}
ZOJ 3369 Saving Princess的更多相关文章
- 2012 #1 Saving Princess claire_
Saving Princess claire_ Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- hdu----(4308)Saving Princess claire_(搜索)
Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/ ...
- hdu 4308 Saving Princess claire_
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...
- HDU 4308 BFS Saving Princess claire_
原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...
- Saving Princess claire_(hdu 4308 bfs模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...
- UESTC 1811 Hero Saving Princess
九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/11104265 题目链接 :http://222.197.181.5/proble ...
- hdu 4308 Saving Princess claire_ BFS
为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...
- HDU 4308 Saving Princess claire_(简单BFS)
求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...
- BFS(最短路) HDOJ 4308 Saving Princess claire_
题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...
随机推荐
- webstorm狂吃内存的解决方法
今天使用webstorm,电脑居然卡死了,我的电脑配置: 运行内存16g,1.5T内存的台式, 后来发现,可以通过设置 内存值大小来解决. 具体办法: 找到WebStorm.exe.vmoptions ...
- Python基本类型操作
# str = "2017.1.1.wmv" # #print(str[str.rfind('.'):]) # #print(str.count(".")) # ...
- VUE:内置指令与自定义指令
VUE:内置指令与自定义指令 常用的内置指令 1)v:text 更新元素的 textContent 2)v-html 更新元素的 innerHTML 3)v-if 如果为true,当前标签才会输出到页 ...
- java几种读写文件的方式
java.io的几种读写文件的方式 一.java把这些不同来源和目标的数据都统一抽象为数据流. Java语言的输入输出功能是十分强大而灵活的. 在Java类库中,IO部分的内容是很庞大的,因为它涉及的 ...
- 简单谈谈MySQL优化利器-慢查询
慢查询 首先,无论进行何种优化,开启慢查询都算是前置条件.慢查询机制,将记录过慢的查询语句(事件),从而为DB维护人员提供优化目标. 检查慢查询是否开启 通过show variables like ' ...
- HDOJ 1874 畅通project续
畅通project续 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- 解读HDFS(转载)
是蛮久木有写过关于hadoop的博客了额,虽然最近也看了一些关于linux的基础知识,但似乎把这个东西忘记了,其实时不时回顾一下以前的知识还是蛮有意思的,且行且忆! 我们Hadoop 主要由HDFS和 ...
- angular4中日期格式的用法
dateTime: Date; this.dataTime = new Date(); // 获取当前日期 // Wed Apr 18 2018 10:54:47 GMT+0800 (中国标准时间) ...
- etxjs
序言 编辑 功能丰富,无人能出其右. 无论是界面之美,还是功能之强,ext的表格控件都高居榜首. 单选行,多选行,高亮显示选中的行,拖拽改变列宽度,按列排序,这些基本功能ExtJS轻量级实现. 自动生 ...
- H.264标准(一)mp4封装格式详解
在网络层,互联网提供所有应用程序都要使用的两种类型的服务,尽管目前理解这些服务的细节并不重要,但在所有TCP/IP概述中,都不能忽略他们: 无连接分组交付服务(Connectionless Packe ...