Description
Said the sky will not drop pies, but one day Gameboy is walking home on the path, suddenly fell into the sky a lot of pie. Gameboy's character was so good that the pie was not lost elsewhere, and fell within 10 metres of his side. If the pie fell on the ground, of course, it could not eat, so Gameboy immediately remove the backpack to pick up. But because the trails could not stand on either side, he could only pick it up on the path. As Gameboy usually stay in the room to play games, although in the game is a skill Agile master, but in the reality of the motor is particularly dull, every second species only in the move not more than a meter in the range to catch falling pies. Now mark the path with the coordinates:
To make the problem easier, let's say that over the next period of time, the pie drops in 0-10 of these 11 positions. At the beginning Gameboy stood at 5, so in the first second he could only receive a 4,5,6 in one of these three positions. Q. How many pies can Gameboy receive? (assuming his backpack can hold an infinite number of pies)
Input
There are multiple sets of input data. The first behavior of each group of data is a positive integer n (0<n<100000), which indicates that there are n pies falling on the path. In the row of n rows, each row has two integers x,t (0<t<100000), indicating that there is a pie drop at x point in T-second. The same second may drop multiple pies at the same point. N=0 when the input ends.
Output
Each set of input data corresponds to one row of output. Output an integer m, indicating that Gameboy may receive a maximum of M pies.
Tip: The amount of input data in the subject is relatively large, it is recommended to read in scanf, with CIN may time out.
Sample Input
65 14 16 17 27 28 30
Sample Output
4
#include <iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespacestd;ints[ -][100010]; intMain () {intN; inta,b,i,j; while(~SCANF ("%d",&N), N) {intmax=0; memset (s),0,sizeof(s)); for(i=0; i<n;i++) {scanf ("%d%d",&a,&b); S[a+1][b]++; Max=max (MAX,B);//Find the maximum time, as a cyclic condition } for(i=max-1; i>=0; i--)//push forward from the last time { for(j=1; j<= One; j + +)//Current number of pies = number of pies before + maximum value of current positionS[j][i]+=max (s[j][i+1],max (s[j+1][i+1],s[j-1][i+1])); } printf ("%d\n", s[6][0]); } return 0;}
View Code
HDU 1176 Free Pies