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

【题意】塔防游戏,一条n长的路上,有m个炮台,可以覆盖[li,ri]范围,威力ci,即每一秒,炮塔可以对范围 内的怪物可以造成ci点伤害。只有有q只怪物,每只怪物有hi点血,出现位置为xi;当怪物血量减少到0或以下时消失,怪物一直朝n位置前进。问有几只怪物可以离开这条路。

【题解】用线段树可以做,不过还好我们有代代相传的刷qq 算法 ,让解法变得简单的多~    ^_^

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #include <cmath>
 5 #include <algorithm>
 6
 7 using namespace std;
 8 __int64 num[100005];
 9
10 struct node{__int64 hp,x;}m[100005];
11
12 int cmp(node a,node b)
13 {
14     return a.x<b.x;
15 }
16
17 int main()
18 {
19     int n,k,a,b,d;
20     while(~scanf("%d",&n),n)
21     {
22         scanf("%d",&k);
23         memset(num,0,sizeof(num));
24         while(k--)
25         {
26             scanf("%d%d%d",&a,&b,&d);
27             num[a]+=d;
28             num[b+1]-=d;
29         }
30         __int64 sum=0;
31         for(int i=0;i<=n;i++)
32         {
33             sum+=num[i];
34             num[i]=sum;
35         }
36         //num[i]:每个点i的攻击力度
37         scanf("%d",&k);
38         for(int i=0;i<k;i++)
39             scanf("%I64d%I64d",&m[i].hp,&m[i].x);
40         sort(m,m+k,cmp);
41         sum=0;
42         int ans=0,j=k-1;
43         for(int i=n;i>=0;i--)
44         {
45             sum+=num[i];          // sum:从点n到点i 怪物会受到的总攻击力度
46             while(i==m[j].x)       // 可能有好几个怪物从点i冒出来
47             {
48                 if(m[j].hp>sum)
49                    ans++;
50                 j--;
51                 if(j<0)
52                     break;
53             }
54             if(j<0)
55                 break;
56         }
57         printf("%d\n",ans);
58     }
59     return 0;
60 }

hdu 4970 killing monster 代代相传刷qq 不用线段树啦~,布布扣,bubuko.com

时间: 2024-10-12 21:17:34

hdu 4970 killing monster 代代相传刷qq 不用线段树啦~的相关文章

HDU - 4970 Killing Monsters

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 mons

hdu 4970 Killing Monsters(数学题)

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

hdu 4970 Killing Monsters(简单题) 2014多校训练第9场

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 b

HDU 4970 Killing Monsters 多校第九场1011

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 mons

HDU 4970 Killing Monsters 【搜索】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4970 题目大意:给你一些防御塔的位置和其攻击力,以及一些怪物的血量和位置,问走到终点还有几个怪物活着. 题目思路:最开始看题目的时候就是区间更新的过程觉得会花很多时间,然后用的树状数组,后来发现用的一个机智方法可以过,简单了很多. 区间更新的主要时间是花在塔的伤害,(L,R)D伤害上面,我们用一个sttack数组记录伤害,在attack[L]+=D,在attack[R]-=D,然后从前往后扫一遍,可

hdu 4893 (多校1007)Wow! Such Sequence!(线段树&amp;二分&amp;思维)

Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 352    Accepted Submission(s): 104 Problem Description Recently, Doge got a funny birthday present from his new friend, Prot

HDU 4027 Can you answer these queries?(线段树的单点更新+区间查询)

题目链接 题意 : 给你N个数,进行M次操作,0操作是将区间内的每一个数变成自己的平方根(整数),1操作是求区间和. 思路 :单点更新,区间查询,就是要注意在更新的时候要优化,要不然会超时,因为所有的数开几次方之后都会变成1,所以到了1不用没完没了的更新. 1 //HDU 4027 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <iostream> 6 #defi

怒刷30道线段树、树状数组

HDU 1754 单点更新,区间查询最大值,水题-- #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<map> #include<queue> #include<set> #include<cmath> #include<bitset> #define mem(a,b) memset

HDU 5023 A Corrupt Mayor&#39;s Performance Art 线段树区间更新+状态压缩

Link:  http://acm.hdu.edu.cn/showproblem.php?pid=5023 1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #include <algorithm> 5 #include <vector> 6 #include <string> 7 #include <cmath> 8 using namesp