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的最短路 分析:一道最短路问题,加了传送门的功能, ...
随机推荐
- javaScript(其他引用类型对象)
javascript其他引用类型对象 Global对象(全局)这个对象不存在,无形的对象,无法new一个 其内部定义了一些方法和属性:如下 encodeURI str = www.baidu.com ...
- linux系统添加环境变量,node.js forever 守护进程添加环境变量
1.node.js 守护进程组件 forever 安装 npm install forever -g 安装完成后截图: 2.安装完成后在控制台输入 forever 出现 -bash: forever: ...
- 2019-03-18 OpenCV Tesseract-OCR 下载 安装 配置(cv2 报错)
OpenCV 下载 安装 配置 1.下载和Python版本对应的版本,此为下载地址 2.安装(在powershell管理员模式下安装) pip3 install .\opencv_python-3.4 ...
- 洛谷 P1147 连续自然数和 (滑动窗口)
维护一个滑动窗口即可 注意不能有m到m的区间,因为区间长度要大于1 #include<cstdio> #define _for(i, a, b) for(int i = (a); i &l ...
- 【codeforces 738E】Subordinates
[题目链接]:http://codeforces.com/problemset/problem/738/E [题意] 给你一个类似树形的关系; 然后告诉你某个人头顶上有多少个上司numi; 只有fat ...
- ASP.NET-Session cooike
Application .Cookie和 Session 两种会话有什么不同 答:Application是用来存取整个网站全局的信息,而Session是用来存取与具体某个访问者关联的信息, Sessi ...
- vue中export default 在console中是this.$vm
vue中export default 在console中是this.$vm 用vue-cli搭出框架,用webstorm进行开发,参考vue2的官网进行教程学习, 在vue-cli中是用es6的exp ...
- easyui datagrid 动态加入、移除editor
使用easyui 行编辑的时候完毕编辑的功能比較简单,可是假设要依据一个框的值动态改变别的值或者编辑的时候禁用某个框的时候就比較麻烦了. 比方像以下这样:加入行的时候每一个值都是手动输入,改动的时候第 ...
- 混合高斯模型的EM求解(Mixtures of Gaussians)及Python实现源代码
今天为大家带来混合高斯模型的EM推导求解过程. watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveHVhbnl1YW5zZW4=/font/5a6L5L2T/ ...
- node09---中间件
如果我的的get.post回调函数中,没有next参数,那么就匹配上第一个路由,就不会往下匹配了. 如果想往下匹配的话,那么需要写next() 1app.get("/",funct ...