Free pie
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 13077 accepted submission (s): 4328
Problem description all said there would be no pie in the sky, but one day Gameboy was walking on the path home, And suddenly there were a lot of pies in the sky. It is really good to say that Gameboy's character is good. This Pie won't fall anywhere, and it will fall within 10 meters of his side. If the pie falls to the ground, it cannot be eaten, so Gameboy immediately unmounts his backpack to pick it up. But because neither side of the trail can stand, he can only pick up on the trail. Since Gameboy is always playing games in the room, although he is an agile player in the game, he is very slow in reality, A falling pie can only be reached within one meter of movement per second. Now mark the path with coordinates:
In order to simplify the problem, it is assumed that the pie falls to the 11 positions 0-10 in the next period of time. At the beginning, Gameboy stood at the position 5, so in the first second, he could only receive pies from one of the three positions, namely, 4, 5, and 6. How many pies can Gameboy receive at most? (Assuming his backpack can accommodate an infinite number of pies)
There are multiple groups of input data. The first behavior of each group of data is a positive integer N (0 <n <100000), indicating that there are n pies falling onto this path. In the final N rows, each row has two integers x, t (0 <t <100000), indicating that there is a pie on the second t at the X point. Multiple pies may be dropped at the same point in a second. When n = 0, the input ends.
Each group of input data corresponds to a row of output. Output an integer m, indicating that GameBoy can be connected to a maximum of M pies.
Tip: the input data volume in this question is relatively large. It is recommended to use scanf to read data. Using CIN may time out.
Sample input6 5 1 4 1 6 1 7 2 7 2 8 3 0
Sample output4
Use other people's code for reference:
#include<stdio.h>
#include<string.h>
#define M 100001
int
n;
int
x;
// Location
int
T;
// Time
int
time
;
int
number[M][13];
int
max2(
int
a,
int
b)
{
if
(a>b)
return
a;
return
b;
}
int
max3(
int
a,
int
b,
int
c)
{
if
(max2(a,b)>max2(b,c))
return
max2(a,b);
return
max2(b,c);
}
int
main()
{
while
(
scanf
(
"%d"
, &n)==1 && n)
{
memset
(number, 0,
sizeof
(number));
// Initialize the Array
time
= 0;
while
(n--){
scanf
(
"%d %d"
, &x, &T);
// Read data
number[T][x + 1]++;
// The time is used for the vertical axis of the number tower, and the position is + 1 for the horizontal axis of the number tower. The problem is converted to the classic number tower problem.
if
(T >
time
)
// Determine the maximum time
time
= T;
}
for
(
int
i =
time
- 1; i >= 0; i--){
for
(
int
j = 11; j >=1; j--) {
number[i][j] += max3(number[i+1][j],number[i+1][j-1],number[i+1][j+1]);
// Perform operations on familiar data tower problems. Note that the operations can be performed at any of the following three locations:
}
}
printf
(
"%d\n"
, number[0][6]);
// Output result
}
return
0;
}