题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970

Problem Description
Kingdom Rush is a popular TD game, in which you should build some towers to protect your kingdom from monsters. And now another wave of monsters is coming and you need again to know whether you can get through it.

The path of monsters is a straight line, and there are N blocks on it (numbered from 1 to N continuously). Before enemies come, you have M towers built. Each tower has an attack range [L, R], meaning that it can attack all enemies in every block i, where L<=i<=R. Once a monster steps into block i, every tower whose attack range include block i will attack the monster once and only once. For example, a tower with attack range [1, 3] will attack a monster three times if the monster is alive, one in block 1, another in block 2 and the last in block 3.

A witch helps your enemies and makes every monster has its own place of appearance (the ith monster appears at block Xi). All monsters go straightly to block N.

Now that you know each monster has HP Hi and each tower has a value of attack Di, one attack will cause Di damage (decrease HP by Di). If the HP of a monster is decreased to 0 or below 0, it will die and disappear.
Your task is to calculate the number of monsters surviving from your towers so as to make a plan B.

Input
The input contains multiple test cases.

The first line of each case is an integer N (0 < N <= 100000), the number of blocks in the path. The second line is an integer M (0 < M <= 100000), the number of towers you have. The next M lines each contain three numbers, Li, Ri, Di (1 <= Li <= Ri <= N, 0 < Di <= 1000), indicating the attack range [L, R] and the value of attack D of the ith tower. The next line is an integer K (0 < K <= 100000), the number of coming monsters. The following K lines each contain two integers Hi and Xi (0 < Hi <= 10^18, 1 <= Xi <= N) indicating the ith monster’s live point and the number of the block where the ith monster appears.

The input is terminated by N = 0.

Output
Output one line containing the number of surviving monsters.
Sample Input
5 2 1 3 1 5 5 2 5 1 3 3 1 5 2 7 3 9 1 0
Sample Output
3

Hint

In the sample, three monsters with origin HP 5, 7 and 9 will survive.

Source
2014 Multi-University Training Contest 9

官方题解:http://blog.sina.com.cn/s/blog_6bddecdc0102uzwm.html

代码例如以下:

//#pragma warning (disable:4786)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstdlib>
#include <climits>
#include <ctype.h>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <deque>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
const double eps = 1e-9;
//const double pi = atan(1.0)*4;
const double pi = 3.1415926535897932384626;
#define INF 1e18
//typedef long long LL;
typedef __int64 LL;
const int MAXN = 200017;
int num[MAXN];
LL sum[MAXN];
int main()
{int l,r,d;int tow,n,m,x;LL h;while(scanf("%d",&n) && n){scanf("%d",&tow);memset(num,0,sizeof(num));memset(sum,0,sizeof(sum));for(int i = 0; i < tow; i++){scanf("%d%d%d",&l,&r,&d);num[l] += d;num[r+1] -= d;}for(int i = 1; i <= n; i++){sum[i] = sum[i-1]+num[i];}for(int i = n; i >= 1; i--){sum[i] = sum[i+1]+sum[i];}int cont = 0;scanf("%d",&m);for(int i = 0; i < m; i++){scanf("%I64d%d",&h,&x);if(sum[x] < h){cont++;}}printf("%d\n",cont);}return 0;
}

转载于:https://www.cnblogs.com/zfyouxi/p/5114163.html

hdu 4970 Killing Monsters(数学题)相关推荐

  1. HDU 4970 Killing Monsters 【搜索】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 题目大意:给你一些防御塔的位置和其攻击力,以及一些怪物的血量和位置,问走到终点还有几个怪物活着. ...

  2. hdu 4970 killing monster 代代相传刷qq 不用线段树啦~

    [题意]塔防游戏,一条n长的路上,有m个炮台,可以覆盖[li,ri]范围,威力ci,即每一秒,炮塔可以对范围 内的怪物可以造成ci点伤害.只有有q只怪物,每只怪物有hi点血,出现位置为xi:当怪物血量 ...

  3. 【HDOJ 4970】 Killing Monsters

    [HDOJ 4970] Killing Monsters 数据很大 立马想预处理 每只怪物会从点x出现移动到点n(终点) 问能剩几只怪物 预处理求出每个位置到终点所受伤害 出现一只怪物直接判断死活即可 ...

  4. HDU4970 Killing Monsters dp

    题意:给你n个操作,每一次对区间相加,询问区间和. 解题思路:这里没有动态更新, 所以我们用括号匹配那种方法就行 就是 a[l] + x  ,a[r+1] -x 这种做法. 解题代码: 1 #incl ...

  5. hdu 4970 树状数组 “改段求段”

    题意:塔防.给1--n,给出m个塔,每个塔有攻击力,给出k个怪兽的位子和血量,问有几只可以到达n点. 今天刚刚复习了树状数组,就碰到这个题,区间更新.区间求和类型.第三类树状数组可以斩. 注意一下大数 ...

  6. hdu 1174:爆头(计算几何,三维叉积求点到线的距离)

    爆头 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submiss ...

  7. 【SIGGRAPH 2015】【巫师3 狂猎 The Witcher 3: Wild Hunt 】顶级的开放世界游戏的实现技术。...

    [SIGGRAPH 2015][巫师3 狂猎 The Witcher 3: Wild Hunt ]顶级的开放世界游戏的实现技术 作者:西川善司 日文链接  http://www.4gamer.net/ ...

  8. 忽视警告_不要忽视下雨的风险2

    忽视警告 When I first saw Risk of Rain 2 a couple of months back in the Steam store, I didn't know what ...

  9. ios 打印 详细错误日志_iOS中打印系统详细日志

    Q:如何打印当前的函数和行号? A:我们可以在打印时使用一些预编译宏作为打印参数,来打印当前的函数和行号.如: 1 NSLog(@"%s:%d obj=%@", __func__, ...

最新文章

  1. js中bind、call、apply函数的用法
  2. 左外连接的sql语句_Django数据库连接和使用原生sql语句
  3. ActiveMQ的几种集群配置
  4. 绝对不忽悠、暑期择机功能该咋选?
  5. 20145326蔡馨熠《信息安全系统设计》第2周学习总结
  6. 解决安卓SDK无法下载Package的问题
  7. python利用pygame框架实现类似大鱼吃小鱼游戏 (松鼠吃松鼠) code from making games with python and pygame
  8. Rust: ,clone,Box,Arc 的address
  9. 易语言pc微信hook最新版本
  10. 网站制作教程:如何建设自己的网站?
  11. QT 使用 qcustomplot 编译出错
  12. matlab2016 wavread,matlab 7.10里面的wavread函数不能打开.wav文件。我的wav文件是电脑自带的录音机录的...
  13. 计算机启动后无法进入系统怎么办,电脑开机无法进入系统怎么办
  14. 第七十二章 Caché 函数大全 $WISWIDE 函数
  15. excel查找匹配项vlookup函数
  16. 名帖366 鲜于枢 草书《韩愈石鼓歌》
  17. html中auto是设置什么的,css中margin:auto什么意思?margin:auto属性的用法详解
  18. c语言字母从小到大,C语言编程:输入三个字符后,按各字符的ASCII码从小到大的顺序输出这三个字符。...
  19. 如何修改C盘用户目录下的用户名
  20. soul-网关实战(一)学习路线

热门文章

  1. ffmpeg 存流为hls文件
  2. web监听器监听mysql_JavaWEB开发15——ListenerListener
  3. 设置编译out_matlab2017a与 CCS 6.2联调设置
  4. centos7 最小gnome桌面_Linux 桌面进化史
  5. python实现解析oui.txt并抽取MAC前缀及组织名称
  6. r语言调用python_python3调用R语言干货
  7. apple color emoji_emoji的7个冷知识
  8. 【kafka】kafka KeeperErrorCode = ConnectionLoss for /config/topics
  9. 【ElasticSearch】 ElasticSearch 读取 流程
  10. 【ElasticSearch】ElasticSearch 中使用衰减函数来完美你的搜索结果