Survival
来源:互联网 发布:manjaro linux 编辑:程序博客网 时间:2024/04/20 17:21
The King of Fighter 97 (KOF97) is an electronic game of wrestling type. Once it was fashionable among youths. The game is amused. However, playing by oneself is not as excited as with friends. Getting bored? Maybe you can alter to the survival mode.
In the but under quite unfair conditions: you must use your only character to beat all the other characters and Orichi as well (who is the BOSS)!!! How can you do that? We know that usually we will consume some HP of the character to beat one opponent. Although the character will recover some HP after beating one opponent, the amount of HP recovered is affected by the time you used, so it��s possible that the character lose some HP after one round. What��s worse, if the HP of your character is not enough for you to beat your opponent, you lose!
Given the HP of your character you need to consume and the HP your character will recover if you win for every opponent, you are to determine whether you can clear the game.
NOTE:
1. The initial HP of your character is 100.
2. You can challenge your opponents in any order except that Orichi is always the last one.
3. If your HP falls BELOW zero after any fights (before recovery), you will get your mission failed. 4. Your HP should never exceed 100.
There are multiple test cases, which are separated by a blank line. The first line of each test case is a single integer N (1 <= N <= 20), gives the number of opponents you need to beat. The following N �C 1 lines each contain two integers C and R (0 <= C, R <= 100), where C for the HP you need to consume to beat the opponent and R for the HP recovered after you beat the opponent. The last line contains only one integer P (0 <= P <= 100), describing the HP you need to consume to beat Orichi.
<b< dd="">
For each test case, generate one line of output: if you can clear the game, print "clear!!!" otherwise print "try again" (both without quotations).
<b< dd="">
3
50 50
40 40
70
<b< dd="">
clear!!!
本题思路:
题意:游戏者必须打败给定数量的怪,才能获得胜利。而除了boss只能放在最后一个打之外,其余打怪的顺序随意,每打一个怪,需要一定的血量,打败后可以获得一定的血量,开始的血量为100,打怪过程中,血量如果少于0,则失败,游戏者血量最多为100。当打某一个怪物时,必须首先达到打败该怪物需要的血量,否则不能打该怪物。求是否能够把所有的怪物干掉。
思路:设置一个数组dp ,dp[1<<i]表示打完第i个怪物后,所剩余的血量,根据题目意思,那么就是求dp[1<<n]是否大于p(p代表打败boss所需要的血量)。二进制的0表示不打这个怪物,1表示打怪
代码:
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int dp[1<<21];int c[21],r[21];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n-1;i++) scanf("%d%d",&c[i],&r[i]); int p; scanf("%d",&p); memset(dp,-1,sizeof(dp)); dp[0]=100; int j; for(j=0;j<(1<<n-1);j++) { for(int i=0;i<n-1;i++) { if(j&(1<<i)||dp[j]<c[i])//这个怪物已经打过了,或者上次剩余的血量不够 continue; int end=dp[j]-c[i]+r[i]; if(end>100)//保证血量不超过100 end=100; if(dp[j|(1<<i)]<end)//如果存在与现有状态相同,但是血量小于新的血量,更新 dp[j|(1<<i)]=end; } } if(dp[j-1]>=p)//注意是j-1,因为最后一个没有打 cout<<"clear!!!"<<endl; else cout<<"try again"<<endl; } return 0;}
- Survival
- Survival
- Survival analysis
- Software Project Survival Guide
- RuneScape Terrain Survival Guide
- Oracle Locking Survival Guide
- Oracle Locking Survival Guide
- Bee Run: Survival Challenge
- LightOJ1265 - Island of Survival
- unity survival shooter ZSpace
- 【hdu4903】The only survival
- CRM Middleware Survival Guide
- titanic survival 1
- titanic survival 2
- LightOJ1265-Island of Survival
- Island of Survival LightOJ
- LightOJ1265---Island of Survival
- Island of Survival LightOJ
- 20171205_工作记录
- 数据结构
- 如何说服你的同事使用TDD
- MongoDB使用实践:妈妈帮平台技术架构
- Java的io流学习记录(1)--IO流的概述
- Survival
- 用蛮力法解决冒泡排序
- Python3与OpenCV3.3 图像处理(十二)--图像直方图应用
- 集群RPC通信该怎么做
- 在CentOS中编译c源文件,遇到(.text+0x20): undefined reference to `main'
- 解决Django网页端口显示被占用问题
- oracle--months_between函数
- hibernate框架中数据库的关系维护简析
- docker 跨主机通信(virtualbox)