aoe:一个一维地图,上面有一些怪物,主角现在要打怪,每触发一次技能就会对范围内的怪物造成1点伤害,请问最少需要触发多少次技能才能消灭完怪物;
注:x为主角位置,伤害范围是 x-y 到 x+y ;
输入:第一行输入n表示怪物数量,y表示主角攻击范围;
接下来输入n组数据,每组包含两个值pos和ph,分别表示怪物的位置和血量;
输出:最少触发技能次数
eg:
输入:
3 3
3 4
1 10
10 5
输出:
15
#include<iostream>
#include<map>
using namespace std;int func(map<int, int> monster, int y)
{int pos1, pos2;int count = 0;int tmp;map<int, int>::iterator it = monster.begin();pos1 = it->first;tmp = it->second;it++;for (; it != d(); it++){pos2 = it->first;if (pos2 - pos1 <= 2 * y){tmp = it->second > tmp ? it->second : tmp;}else{count += tmp;pos1 = it->first;tmp = it->second;}}count += tmp;return count;
}int main()
{int n, y; //怪数量 人物伤害范围int pos, hp; //怪位置 怪hpmap<int, int> monster;while(cin >> n >> y){for (int i = 0; i < n; i++){cin >> pos >> hp;monster[pos] = hp;}cout << func(monster, y) << endl;}return 0;
}
本文发布于:2024-01-31 21:27:24,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170670764731467.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |