题目链接: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

官方题解: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;
}

hdu 4970 Killing Monsters(数学题)的更多相关文章

  1. hdu 4970 Killing Monsters(数组的巧妙运用) 2014多校训练第9场

    pid=4970">Killing Monsters                                                                   ...

  2. HDU 4970 Killing Monsters(树状数组)

    Killing Monsters Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  3. hdu 4970 Killing Monsters (思维 暴力)

    题目链接 题意: 有n座塔,每座塔的攻击范围为[l,r],攻击力为d,有k个怪兽从这些塔前面经过,第i只怪兽初始的生命力为hp,出现的位置为x,终点为第n个格子.问最后有多少只怪兽还活着. 分析: 这 ...

  4. HDU 4970 Killing Monsters

    开始以为是线段树,算了一下复杂度也觉得能过...但是这题貌似卡了线段树... 具体做法: 对每一个塔,记录attack[l]+=d,attack[r+1]-=d;这样对于每个block,受到的伤害就是 ...

  5. hdu4970 Killing Monsters (差分数列)

    2014多校9 1011 http://acm.hdu.edu.cn/showproblem.php?pid=4970 Killing Monsters Time Limit: 2000/1000 M ...

  6. HDU 4970(杭电多校#9 1011题)Killing Monsters(瞎搞)

    题目地址:HDU 4970 先进行预处理.在每一个炮塔的火力范围边界标记一个点. 然后对每一个点的伤害值扫一遍就能算出来. 然后在算出每一个点到终点的总伤害值,并保存下来,也是扫一遍就可以. 最后在询 ...

  7. 周赛-Killing Monsters 分类: 比赛 2015-08-02 09:45 3人阅读 评论(0) 收藏

    Killing Monsters Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...

  8. Killing Monsters(hdu4970)

    Killing Monsters Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...

  9. hdu 4970 trick

    http://acm.hdu.edu.cn/showproblem.php?pid=4970 有n个格子在一条线标号1-n上,可以给范围在l到r内的格子架上攻击力为d的攻击塔,有m个怪物,每个怪物有个 ...

随机推荐

  1. 在Android中显示GIF动画

    gif图动画在android中还是比较常用的,比如像新浪微博中,有很多gif图片,而且展示非常好,所以我也想弄一个.经过我多方的搜索资料和整理,终于弄出来了,其实github上有很多开源的gif的展示 ...

  2. NodeJs 实时压缩 项目js文件

    + 1. 下载nodejs : "http://nodejs.org/". + 2. 以administrator权限打开cmd.+ 3. cmd路径定位到要压缩的目录: &quo ...

  3. spark集群安装配置

    spark集群安装配置 一. Spark简介 Spark是一个通用的并行计算框架,由UCBerkeley的AMP实验室开发.Spark基于map reduce 算法模式实现的分布式计算,拥有Hadoo ...

  4. 什么是透明(和Windows主题有关系),研究TLable和TPanel是两个好例子

    在controls.pas单元里只有判断,没有赋值,所以一直不是很明白.于是在stdCtrls.pas里找了几个例子,直观加深一下印象: constructor TCustomLabel.Create ...

  5. rowid结构浅析

    select rowid from dual AAAAB0AABAAAAOhAAA rowid结构如下: 对象号    文件号   块号   行号 XXXXXX    XXX     XXXXXX X ...

  6. 《火球——UML大战需求分析》(第1章 大话UML)——1.5 小结和练习

    说明: <火球——UML大战需求分析>是我撰写的一本关于需求分析及UML方面的书,我将会在CSDN上为大家分享前面几章的内容,总字数在几万以上,图片有数十张.欢迎你按文章的序号顺序阅读,谢 ...

  7. 基于visual Studio2013解决面试题之1102合并字符串

     题目

  8. sql: DUAL

    FROM <<Oracle.Database.11g.SQL>> dual is a table that contains a single row. The followi ...

  9. linux命令:rm

    删文件要一个个回答y,谁有好办法自动删除? rm -rf 用rm递归删除目录下面的所有.o文件: find . -name "*.o"  | xargs rm -f :

  10. shadow dom

    初识shadow dom 我们先看个input="range"的表现: what amazing ! 一个dom能表现出这么多样式嘛? 无论是初学者和老鸟都是不肯相信的,于是在好奇 ...