AOE打怪

阅读: 评论:0

AOE打怪

AOE打怪

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小时内删除。

下一篇:AOE
标签:打怪   AOE
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23