当前位置:网站首页>1007 Climb Stairs (greedy | C thinking)
1007 Climb Stairs (greedy | C thinking)
2022-08-05 03:59:00 【Codiplay】
Intention
Xiao Ming wants to climb a building with n floors, and each floor has a monster with a life value of hi.This monster can only be destroyed when Xiao Ming's attack power a>= health h.If Xiao Ming destroys this monster, he will absorb his HP and convert it into his own attack power.Initially, Xiao Ming is on the 0th floor and has an attack power of a0.
Xiao Ming has two ways of acting
One is to move up i cells, i<=k; the other is to go down 1 cell.A floor cannot be climbed twice
Now Xiaoming wants to climb to the top of the building and destroy all the monsters, ask Xiaoming if he can do it.
Thoughts
Segmented processing.Since the title requires that all monsters must be beaten, the skipped monsters have to go back to defeat them.We need to find a right endpoint r from the current position x, so that the monsters in this section can be defeated in the order of r, r-1, r-2, x.It is not difficult to see that it is not worse when r is smaller.
greedy.Greed from back to front.The farthest can be from i + k - 1 (equivalent to Xiaoming jumping to i + k - 1 and then going down, and when you reach i, you can still jump to the i + k layer) Start greedy, and reset the value if you are not greedy.(Skip this hard bone for a while, and process the current a[i] hard bone first), reduce the scope of greed, the purpose is to make value >= a[i], if it is not reached, output NO
#includetypedef long long ll;using namespace std;int n,w,k;void solve(){cin >> n >> w >> k;std::vector a(n + 1);for (int i = 1; i <= n; i++ ) cin >> a[i];for (int i = 1; i <= n; i++ ) {if(a[i] <= w) {w += a[i];} else {bool ok = false;int j = min(n, i + k - 1);int value = w;for (int z = j; z >= i; z -- ) {if(a[z] <= value) {value += a[z];if(z == i) {ok = true;}} else {value = w;j = z;// i = j;;}}if(ok) {i = j;w = value;} else {cout << "NO\n";return;}}}cout << "YES\n";}int main(){std::ios::sync_with_stdio(false);std::cin.tie(nullptr);int t;cin >> t;while(t--) {solve();}return 0;}
边栏推荐
- Package zip is not available, but is referred to by another package.
- Dameng 8 database export and import
- 日志导致线程Block的这些坑,你不得不防
- UE4 第一人称角色模板 添加生命值和调试伤害
- 多御安全浏览器新版下载 | 功能优秀性能出众
- Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
- 开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..
- cross domain solution
- UE4 opens door via interaction (keyboard key)
- [Paper Notes] MapReduce: Simplified Data Processing on Large Clusters
猜你喜欢
工业级远距离无线传输装置的功能有哪些?
How to solve the three major problems of bank data collection, data supplementary recording and index management?
public static <T> List<T> asList(T... a) 原型是怎么回事?
Acid (ACID) Base (BASE) Principles for Database Design
从企业的视角来看,数据中台到底意味着什么?
测试薪资这么高?刚毕业就20K
Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals
[GYCTF2020]EasyThinking
iMedicalLIS listener (2)
Detailed and comprehensive postman interface testing practical tutorial
随机推荐
Initial solution of the structure
DNS被劫持如何处理?
UE4 opens door via interaction (keyboard key)
How to find all fields with empty data in sql
This year's Qixi Festival, "love vegetables" are more loving than gifts
阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿
达梦8数据库导出导入
YYGH-13-客服中心
[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction
事件解析树Drain3使用方法和解释
ffmpeg enumeration decoders, encoders analysis
BI业务分析思维:现金流量风控分析(二)信用、流动和投资风险
UE4 第一人称角色模板 添加蹲伏功能
DEJA_VU3D - Cesium功能集 之 058-高德地图纠偏
pyqt5 + socket 实现客户端A经socket服务器中转后主动向客户端B发送文件
Shell script: for loop and the while loop
Acid (ACID) Base (BASE) Principles for Database Design
public static
List asList(T... a) What is the prototype? [BSidesCF 2019]Kookie
Queue Topic: Recent Requests