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的最短路 分析:一道最短路问题,加了传送门的功能, ...
随机推荐
- JSp获取到当前用户的全部session
<%@page import="java.util.Enumeration"%> <% for (Enumeration<?> e = session ...
- css所有属性(table,行列组)总结
概述: CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明: CSS声明总是以分号(;)结束,声明组以大括号({})括起来: 一.注释: CSS注释以 "/*" 开始, ...
- springboot项目封装为docker镜像
1.本次镜像的基础镜像是:https://www.cnblogs.com/JoeyWong/p/9173265.html 2.将打包好的项目文件放在与Dockerfile同级的目录下 3.Docker ...
- 【转】 C# ListView实例:文件图标显示
[转] C# ListView实例:文件图标显示 说明:本例将目录中的文件显示在窗体的ListView控件中,并定义了多种视图浏览.通过调用Win32库函数实现图标数据的提取. 主程序: 大图标: 列 ...
- 记一次在广播(BroadcastReceiver)或服务(Service)里弹窗的“完美”实践
事情是这样的,目前在做一个医疗项目,需要定时在某个时间段比如午休时间和晚上让我们的App休眠,那么这个时候在休眠时间段如果用户按了电源键点亮屏幕了,我们就需要弹出一个全屏的窗口去做一个人性化的提示,“ ...
- [AngularJS]Chapter 4 AngularJS程序案例分析
前边讲的都是基础.本章看看他们怎么合作的. 我们要建一个程序.一次一步.章末结束 [这个程序] GutHub是一个简单的菜谱管理程序.功能是存好吃的的菜谱并提供步骤.这个程序包含: 两列布局 左边是导 ...
- JavaSE入门学习24:Java面向对象补充
一Java中的Object类 Object类是全部Java类的父类.假设一个类没有使用extendskeyword明白标识继承另外一个类,那么这个类默认 继承Object类. public class ...
- 英语影视台词---八、the shawshank redemption
英语影视台词---八.the shawshank redemption 一.总结 一句话总结:肖申克的救赎 1.It's funny. On the outside, I was an honest ...
- vc应用CPictureEx类(重载CStatic类)加载gif动画
1.PictureEx.h文件: //////////////////////////////////////////////////////////////////////// PictureEx. ...
- SPSS学习小记
2013年1月8日 最近一直在SPSS中处理数据,涉及到函数部分,不是太懂,特记录于此,以便翻阅. SPSS判断字符变量中是否含有某字符串的表示方式: (INDEX(url,'ad')>0 ...