题目描述
PVZ这款游戏中,有一种坚果保龄球。zombie从地图右侧不断出现,向左走,玩家需要从左侧滚动坚果来碾死他们。
我们可以认为地图是一个行数为6,列数为60的棋盘。zombie出现的那一秒站在这一行的第60列,之后每秒向左移动一步。玩家可以随时在屏幕最某一行第一列摆放坚果,这一行的zombie瞬间全被滚过去的坚果碾死。如果zombie走到第1列没有被消灭,如果再向左走,则你的大脑就会被zombie吃掉。
现在有n只zombie!告诉你每只zombie出现的时间以及在出现的行数(可能会同时出现同一位置的僵尸),请问至少需要多少坚果才能消灭所有的zombie。
输入格式
第一行一个正整数n,表示zombie数量。
之后n行中,每行两个正整数P和t,分别表示zombie所在行和zombie出现的时间。
输出格式
一个正整数,最少需要的坚果数。
输入输出样例
输入 #1
10
1 1
1 61
2 1
2 60
3 1
3 2
3 3
3 4
4 1
4 99999
输出 #1
6
说明/提示
【数据规模】
n<=2000,t<=100000,1<=P<=6
【题目来源】
kkksc03改编
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
#include<math.h>
using namespace std;
int n,m,k,s = 0;
int a[10][500000];
int maxn[10];
int main()
{
scanf("%d",&n);
for(int i = 1; i <= n; i++) {
scanf("%d %d",&m,&k);
maxn[m] = max(maxn[m],k ); // 记下每列最大的时间点
a[m][k]++;
}
for(int i = 1; i <= 6; i++) {
for (int j = 1; j <= maxn[i]; ) {
if(a[i][j] ) // 从第一个开始投坚果
s++;
j+=60; // 每次加60;
} else {
j++;
}
}
}
printf("%d\n",s);
return 0;
}