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的最短路 分析:一道最短路问题,加了传送门的功能, ...
随机推荐
- [置顶]
openHAB 部分代码结构 UML 图
openHAB 部分代码结构 UML 图 ModelRepository: ItemRegistry: ItemUIProvider: WebAppServlet:
- vue项目初始化步骤
项目初始化:() 1. 安装vue-cli : npm install -g vue-cli 2.初始化项目: vue init webpack my-project 3.进入项目: c ...
- Codeforces 679A Bear and Prime 100
链接:传送门 题意:给你一个隐藏数,这个隐藏数在[2,100]之间,现在最多可以询问20次,每次询问的是这个数是不是隐藏数的底数,是为yes,不是为no,每次询问后都需要flush一下输出缓冲区,最后 ...
- C++函数传递数组的两种方式
数组与指针. 传首地址过去,然后通过地址输出数组元素. 1.一维数组 #include<iostream> using namespace std; #include <cstrin ...
- jQuery 文档操作
一.插入操作 1. 父元素.append(子元素) 追加某元素,在父元素中添加新的子元素, 子元素可以为: stirng / element (js对象) / jquery 元素 var oli = ...
- Spring Boot 启动的时候遇到 java.lang.ClassNotFoundException: ch.qos.logback.classic.Level
在刚开始接触spring boot的时候,想创建一个Hello World 的project. 但是创建完之后,Run as 'Spring Boot APP'的时候遇到这个错误. Level类存在于 ...
- 使用InstelliJ IDEA创建Spring MVC应用程序
环境版本 Windows 8.1 IDE:InstelliJ IDEA 13 Spring:Spring 4.1.1 & Spring MVC 4.1.1 WebLogic 10. ...
- Git:Git的安装过程
Git:Git的安装过程 路径不要存在空格 默认即可,第一项为是否在页面显示 文本编辑器,默认VIM即可 设置环境变量: 1)最安全的选择,path环境变量不会改变,你只能在git bash里使用命令 ...
- COGS——T 438. 烦人的幻灯片
http://www.cogs.pro/cogs/problem/problem.php?pid=438 ★☆ 输入文件:slides.in 输出文件:slides.out 简单对比时间限 ...
- Java程序命令行打包Jar
最近要跑爬虫程序,需要打包成jar发在linux服务器中运行.主要是第三方的lib包与配置文件,不进行打包,方便修改. 1.eclipse中src中源码编译后生成的源码在bin文件中,把里面源码单独拿 ...