Saving Princess

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on ZJU. Original ID: 3369
64-bit integer IO format: %lld      Java class name: Main

Special Judge
 

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 nhsp and m (1 ≤ n ≤ 50, 1 ≤ h ≤ 50, 0 ≤ spm ≤ 50). The following n lines contain three integer numbers each --- sipi, and mi (1 ≤ sipimi≤ 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

Andrew Stankevich
 
解题:好强的BFS。。。记录状态,保留最优的健康值,在各项一样的情况下,选择活得最久的,啊哈。。。。
 #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的更多相关文章

  1. 2012 #1 Saving Princess claire_

    Saving Princess claire_ Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  2. hdu----(4308)Saving Princess claire_(搜索)

    Saving Princess claire_ Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/ ...

  3. hdu 4308 Saving Princess claire_

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Description Princess cla ...

  4. HDU 4308 BFS Saving Princess claire_

    原题直通车:HDU 4308 Saving Princess claire_ 分析: 两次BFS分别找出‘Y’.‘C’到达最近的‘P’的最小消耗.再算出‘Y’到‘C’的最小消耗,比较出最小值 代码: ...

  5. Saving Princess claire_(hdu 4308 bfs模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4308 Saving Princess claire_ Time Limit: 2000/1000 MS (Jav ...

  6. UESTC 1811 Hero Saving Princess

    九野的博客,转载请注明出处 http://blog.csdn.net/acmmmm/article/details/11104265 题目链接 :http://222.197.181.5/proble ...

  7. hdu 4308 Saving Princess claire_ BFS

    为了准备算法考试刷的,想明确一点即可,全部的传送门相当于一个点,当遇到一个传送门的时候,把全部的传送门都压入队列进行搜索 贴代码: #include <iostream> #include ...

  8. HDU 4308 Saving Princess claire_(简单BFS)

    求出不使用P点时起点到终点的最短距离,求出起点到所有P点的最短距离,求出终点到所有P点的最短距离. 答案=min( 不使用P点时起点到终点的最短距离, 起点到P的最短距离+终点到P的最短距离 ) #i ...

  9. BFS(最短路) HDOJ 4308 Saving Princess claire_

    题目传送门 题意:一个(r*c<=5000)的迷宫,起点'Y‘,终点'C',陷阱‘#’,可行路‘*’(每走一个,*cost),传送门P,问Y到C的最短路 分析:一道最短路问题,加了传送门的功能, ...

随机推荐

  1. laravel save() 返回 null

    原因:引用其他方法时,没有 return save()的操作结果. 在使用save()方法时,发现返回值是:null:

  2. vi 编辑器的日常使用

    命令行模式: 光标管理 text  屏幕 行 单词 gg 跳转到文档头部 H 跳转到屏幕首行 ^  或 数字0 跳转到行首 w 向前 G 跳转到文档尾部 M 跳转到屏幕中行 $ 跳转到行尾 b 向后 ...

  3. WPF原生环形图表

    原文:WPF原生环形图表 版权声明:欢迎转载.转载请注明出处,谢谢 https://blog.csdn.net/wzcool273509239/article/details/56480963 主要利 ...

  4. Win10和子系统Ubuntu简单共享

    Win10和子系统Ubuntu简单共享 C:\Users\用户名\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp ...

  5. 对苹果“五仁”编程语言Swift的简单分析

    对苹果"五仁"编程语言Swift的简单分析 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvUHJvdGVhcw==/font/5a6L5 ...

  6. linux 命令 xxd

    xxd,能够查看linux下文件的二进制表示.man一下xxd.能够得到下面信息 NAME        xxd - make a hexdump or do the reverse. SYNOPSI ...

  7. Asp.net button防止点击多次数据提交

     <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat= ...

  8. Javascript防冒泡事件与Event对象

    防冒泡 防冒泡用到的就是event的属性和方法 function add2shop(e) { if (!e) var e = window.event; e.cancelBubble = true; ...

  9. Oracle RAC集群体系结构

    一. Oracle集群体系结构 Oracle RAC,全称是Oracle Real Application Cluster,即真正的应用集群,是oracle提供的一个并行集群系统,整个集群系统由Ora ...

  10. java 后台实现ajax post跨域请求传递json格式数据获取json数据问题

    参考大神:http://blog.csdn.net/chunqiuwei/article/details/19924821 java后台: public String ajaxProxy(Intege ...