Little Xin Kills monsters Time limit:1000ms Memory limit:65536k have questions? Dot here ^_^ Title Description
Tower Defense Games It 's a very famous game. , in the game, you need to build some defense towers to attack the monsters to defend the King Xin. Now another wave of monsters, you need to know whether the king can withstand the monster attack.
The Beast's path is a straight line with n 1 n [l, r] to r all the enemies between. When a monster is in the i [1, 3] 1 " Span style= "" > lattice, section 2 lattice, 3 1
An evil witch will help all monsters to place the initial position ( I monsters appear in lattice Xi). All monsters move in a straight line (along the direction from 1 to N ).
Now you know the amount of blood for each monster, H . I and damage per tower D . I , (a single attack can cause a monster D I point damage, the monster's blood will drop D I ). If a monster's blood volume Hi drops below 0 or 0 , the beast will be killed and then gone.
Your task is to calculate the number of monsters that will be left behind by all defense tower attacks.
InputThe input contains multiple groups.
the first line of each group is an integerN (0 < n <= 100000), representing a total of N squares on the road . The second line is an integer m (0 < M <= 100000),represents the number of the defensive towers owned by Xiao Xin. next M line ,Each line consists of three integers Li, ri, di (1 <= li <= Ri <= N, 0 < Di <=) ,represents the attack range of the Tower of defense.[L, R] and the damage value of the tower. Next an integer K (0 < K <= 100000), representing the number of monsters. Next K -line with two integers per line hi and Xi (0 < Hi <= 10^18, 1 <= Xi <= N) ,represents the monster's blood volume and the starting position of the beast..
When N = 0 , the input ends.
OutputEnter an integer that represents the number of the last surviving monsters. Sample input
521 3 15 5 251 33 15 27 39 10
Sample output
3
TipsTips:
In the sample, three monsters with initial blood levels of 5,7 , and 9 are finally alive.
Sourceglsilence
Sample Program
#include <iostream> #include <cstring> #include <cstdio>using namespace std;long long int a[100010]; Long Long int hi,xi;int main () { int n,m,x,y,z,k; while (~SCANF ("%d", &n) } { if (n==0) break; scanf ("%d", &m); memset (A,0,sizeof (a)); for (int i=0;i<m;i++) { scanf ("%d%d%d", &x,&y,&z); Instead of every time from X run to Y assignment <span id= "Transmark" ></span> a[x]+=z; a[y+1]-=z; } for (int i=1;i<=n;i++) //scroll array anti-tle { a[i]=a[i-1]+a[i]; } for (int i=n-1;i>=1;i--) { a[i]+=a[i+1]; } scanf ("%d", &k); Long long int num=0; while (k--) { scanf ("%lld%lld", &hi,&xi); if (Hi>a[xi]) num++; } printf ("%lld\n", num);
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
SDUT3298 Little Xin kills Monsters scroll array anti-tle