hdu 4970 Killing Monsters(数学题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970
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.
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.
5
2
1 3 1
5 5 2
5
1 3
3 1
5 2
7 3
9 1
0
3HintIn the sample, three monsters with origin HP 5, 7 and 9 will survive.
官方题解: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(数学题)的更多相关文章
- hdu 4970 Killing Monsters(数组的巧妙运用) 2014多校训练第9场
pid=4970">Killing Monsters ...
- HDU 4970 Killing Monsters(树状数组)
Killing Monsters Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Other ...
- hdu 4970 Killing Monsters (思维 暴力)
题目链接 题意: 有n座塔,每座塔的攻击范围为[l,r],攻击力为d,有k个怪兽从这些塔前面经过,第i只怪兽初始的生命力为hp,出现的位置为x,终点为第n个格子.问最后有多少只怪兽还活着. 分析: 这 ...
- HDU 4970 Killing Monsters
开始以为是线段树,算了一下复杂度也觉得能过...但是这题貌似卡了线段树... 具体做法: 对每一个塔,记录attack[l]+=d,attack[r+1]-=d;这样对于每个block,受到的伤害就是 ...
- hdu4970 Killing Monsters (差分数列)
2014多校9 1011 http://acm.hdu.edu.cn/showproblem.php?pid=4970 Killing Monsters Time Limit: 2000/1000 M ...
- HDU 4970(杭电多校#9 1011题)Killing Monsters(瞎搞)
题目地址:HDU 4970 先进行预处理.在每一个炮塔的火力范围边界标记一个点. 然后对每一个点的伤害值扫一遍就能算出来. 然后在算出每一个点到终点的总伤害值,并保存下来,也是扫一遍就可以. 最后在询 ...
- 周赛-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) ...
- Killing Monsters(hdu4970)
Killing Monsters Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)T ...
- hdu 4970 trick
http://acm.hdu.edu.cn/showproblem.php?pid=4970 有n个格子在一条线标号1-n上,可以给范围在l到r内的格子架上攻击力为d的攻击塔,有m个怪物,每个怪物有个 ...
随机推荐
- 《C++ Primer Plus》学习笔记1
C++ Primer Plus>学习笔记1 第二章.開始学习C++ 1.控制符endl 假设显示字符串时,在字符串中包括换行符,而不是在末尾加上endl,这样能够大大降低输入量:假设是要生成一个 ...
- RedHat Linux 5.5安装JDK+Tomcat并部署Java项目
与大家分享下RedHat Linux 5.5安装JDK+Tomcat并部署Java项目的步骤,希望对大家有用. 1.下载并安装jdk 虚拟机中安装RedHat Linux 5.5 64位企业版, 这里 ...
- 基于visual Studio2013解决C语言竞赛题之1037数组求列和
题目 解决代码及点评 /* 功能:已知有三个数组A,B,C,A为5行5列的二维数组,B.C为只有5个元素的一维数组,键盘输入数据的顺序如下: 23,45,6,1,- ...
- Lisp学习:这是本质与应用?
The Common Lisp Programming Language "The programming language of choice for those who set out ...
- 3.跟我学solr---使用solrj加入索引
上一章讲了怎么使用solr admin向solrserver加入索引,Solr 是一个独立的企业级搜索应用server.它对外提供类似于 Web-service 的 API 接口. 用户能够通过 ht ...
- spring中bean的一些知识点
知识点1: 实例化bean的3种方法. 1. 使用类构造器 (90%用这个方法) 2. 使用静态工厂方法 3. 使用实例化工厂 知识点2: 看这段代码 Applicati ...
- linux c: core dump
1. core dump文件系统设置 http://www.cnblogs.com/no7dw/archive/2013/02/18/2915819.html 编译时需要输入-g才会生成coredum ...
- CSDN头版头条 《近匠》 Wijmo 5 CTO:从Web到移动,我的25年编程生涯
现年52岁的Bernardo Castilho先生是GrapeCity(中文名为葡萄城)ComponentOne公司的CTO,在与他的对话过程中.充满风趣严谨和厚重的历史感. 当作为年轻人的我们崇拜着 ...
- cookie的path和domain參数实例解析
一句话概括两个參数含义各为: path表示cookie所在的文件夹 domain表示的是cookie所在的域,默觉得请求的地址 首先改动我们的 hosts 文件 我本机内网ip 192.168.1.1 ...
- 【HTML】让<pre>标签文本自动换行
利用<pre></pre>这个标签可以将其包起来的文字排版.格式,原封不动的呈现出来. 也就是说你输入的东西被原封不动的输出,包括你输入的空格之类的,不用 和<BR> ...