pid=4970">Killing Monsters

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

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.
 
题意:有n座塔,每座塔的攻击范围为[l,r],攻击力为d,有k个怪兽从这些塔前面经过。第i仅仅怪兽初始的生命力为hp,出现的位置为x。终点为第n个格子。问最后有多少仅仅怪兽还活着。
一開始用线段树写的,果断超时了。
事实上仅仅需开一个大小为n的数组attack。初值为0,对于每座塔的攻击(l,r,d),将attack[l]的值加上d,attack[r+1]的值减去d,然后对attack数组从前往后扫一遍。就可以求出经过每一个格子时受到的伤害;在从后往前扫一遍,便可求出从每一个格子到第n个格子受到的总伤害。最后对于每仅仅怪兽仅仅需推断attack[x]和hp的大小就可以。
#include<cstdio>
#include<cstring>
const int N = 100005;
typedef __int64 LL;
LL attack[N];
int main()
{
int n, l, r, m, k, pos;
LL d, hp;
while(~scanf("%d",&n) && n) {
memset(attack, 0, sizeof(attack));
scanf("%d",&m);
while(m--) {
scanf("%d%d%I64d", &l, &r, &d);
attack[l] += d;
attack[r+1] -= d;
}
for(int i = 2; i <= n; i++)
attack[i] += attack[i-1];
for(int i = n - 1; i > 0; i--)
attack[i] += attack[i+1];
int ans = 0;
scanf("%d",&k);
while(k--) {
scanf("%I64d%d",&hp, &pos);
if(attack[pos] < hp)
ans++;
}
printf("%d\n", ans);
}
return 0;
}


hdu 4970 Killing Monsters(数组的巧妙运用) 2014多校训练第9场的更多相关文章

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

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

  2. hdu 4970 Killing Monsters(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 Problem Description Kingdom Rush is a popular TD ...

  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. hdu 4911 Inversion(归并排序求逆序对数)2014多校训练第5场

    Inversion                                                                             Time Limit: 20 ...

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

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

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. HDU 5762 Teacher Bo (鸽笼原理) 2016杭电多校联合第三场

    题目:传送门. 题意:平面上有n个点,问是否存在四个点 (A,B,C,D)(A<B,C<D,A≠CorB≠D)使得AB的横纵坐标差的绝对值的和等于CD的横纵坐标差的绝对值的和,n<1 ...

  9. HDU 5752 Sqrt Bo (思维题) 2016杭电多校联合第三场

    题目:传送门. 题意:一个很大的数n,最多开5次根号,问开几次根号可以得到1,如果5次还不能得到1就输出TAT. 题解:打表题,x1=1,x2=(x1+1)*(x1+1)-1,以此类推.x5是不超过l ...

随机推荐

  1. luogu P1364 医院设置

    题目描述 设有一棵二叉树,如图: 其中,圈中的数字表示结点中居民的人口.圈边上数字表示结点编号,现在要求在某个结点上建立一个医院,使所有居民所走的路程之和为最小,同时约定,相邻接点之间的距离为1.如上 ...

  2. UVA12633 Super Rooks on Chessboard

    题目描述 题解: 第一眼满眼骚操作,然后全部否掉. 然后屈服于题解,才发现这题这么执掌. 首先,如果这个东西是普通的车,那我们可以记录一下$x,y$的覆盖情况,然后减一下; 但是这个可以斜着走. 所以 ...

  3. 深入Linux内核架构——进程虚拟内存

    逆向映射(reverse mapping)技术有助于从虚拟内存页跟踪到对应的物理内存页: 缺页处理(page fault handling)允许从块设备按需读取数据填充虚拟地址空间. 一.简介 用户虚 ...

  4. 嵩天老师的零基础Python笔记:https://www.bilibili.com/video/av13570243/?from=search&seid=15873837810484552531 中的1-14讲

    #coding=gbk#嵩天老师的零基础Python笔记:https://www.bilibili.com/video/av13570243/?from=search&seid=1587383 ...

  5. java多线程之ForkJoinPool

    转https://www.cnblogs.com/lixuwu/p/7979480.html 阅读目录 使用 背景:ForkJoinPool的优势在于,可以充分利用多cpu,多核cpu的优势,把一个任 ...

  6. pwnable.kr cmd2之write up

    来看一下源代码: #include <stdio.h> #include <string.h> int filter(char* cmd){ ; r += strstr(cmd ...

  7. LeetCode(16)3Sum Closest

    题目 Given an array S of n integers, find three integers in S such that the sum is closest to a given ...

  8. Android开发——Activity生命周期

    Android开发--Activity生命周期 Activity作为四大组件之首,也是使用最频繁的一种组件.本文将主要讲解Activity生命周期,包括正常情况下的Activity生命周期和异常情况下 ...

  9. 主题:学习Spring必学的Java基础知识(9)----HTTP报文

    转: 引述要学习Spring框架的技术内幕,必须事先掌握一些基本的Java知识,正所谓“登高必自卑,涉远必自迩”.以下几项Java知识和Spring框架息息相关,不可不学(我将通过一个系列分别介绍这些 ...

  10. HDU 4821 字符串hash

    题目大意: 希望找到连续的长为m*l的子串,使得m个l长的子串每一个都不一样,问能找到多少个这样的子串 简单的字符串hash,提前预处理出每一个长度为l的字符串的hash值 #include < ...