标签:style http color os io for ar 代码
题意:塔防游戏,长为n的一条路上建造m个箭塔,每个箭塔攻击范围为[l, r],每格造成伤害为d,再给出k只怪兽的血量h,出现位置x,怪兽向前走,问最后还有几只怪兽存活。
思路:先求出每个格子造成的伤害,开一个stack数组,stack[l] += d,stack[r + 1] -= d,然后从前往后扫描一次,这样就可以得到每个格子造成的伤害;然后求出第1格到第i格造成的伤害,做法同上,之后就可以判断哪些怪兽是活着的了。
代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef __int64 ll; const int MAXN = 100005; ll sum[MAXN], stack[MAXN], hurt[MAXN]; int L[MAXN], R[MAXN], d[MAXN]; int n; int main() { while (scanf("%d", &n) && n) { memset(stack, 0, sizeof(stack)); memset(sum, 0, sizeof(sum)); memset(hurt, 0, sizeof(hurt)); int a; scanf("%d", &a); for (int i = 1; i <= a; i++) { scanf("%d%d%d", &L[i], &R[i], &d[i]); stack[L[i]] += d[i]; stack[R[i] + 1] -= d[i]; } for (int i = 1; i <= n; i++) { sum[i] = sum[i - 1] + stack[i]; }//每格的伤害 for (int i = 1; i <= n; i++) { hurt[i] = hurt[i - 1] + sum[i]; }//从第1格到第i格的伤害 ll h; int ans = 0, x, b; scanf("%d", &b); for (int i = 0; i < b; i++) { scanf("%I64d%d", &h, &x); if (hurt[n] - hurt[x - 1] < h) ans++; } printf("%d\n", ans); } return 0; }
HDU4970-Killing Monsters,布布扣,bubuko.com
标签:style http color os io for ar 代码
原文地址:http://blog.csdn.net/u011345461/article/details/38687149