Hangzhou Electric 1176 Free pie

Source: Internet
Author: User

DescriptionSaid 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)InputThere 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.OutputEach 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

A number of tower models, from the bottom up, to add a coordinate, to find d[0][6], the array d[i][j] represents the number of pies of the second coordinate J, because at the beginning of the coordinates 5 time is 0, record the pie number coordinates plus 1, so the final request d[0][6].

1#include <cstdio>2#include <string.h>3#include <algorithm>4 using namespacestd;5 intd[100000+ One][ the];6 intMaxintAintBintc)7 {8     intmax0;9     if(A >b)Tenmax0=A; One     Else Amax0=b; -     if(Max0 <c) -max0=C; the     returnmax0; - } - intMain () - { +     intN; -      while(SCANF ("%d", &n) &&N) +     { A         inta,b,max0=0; atmemset (D,0,sizeof(d)); -          for(inti =0; I < n; i++) -         { -scanf"%d%d",&a,&b); -d[b][a+1]++;//a pie that represents the second B's in the a+1 position. -             if(b > Max0)//record the maximum value of the time in             { -max0=b; to             } +                  -         } the          for(inti = max0-1; I >=0; i--) *         { $              for(intj =1; J <= One; J + +)Panax Notoginseng             { -D[i][j]=max (d[i+1][j],d[i+1][j+1],d[i+1][j-1]) +d[i][j];//to find out the results of D[0][i] the             } +         } Aprintf"%d\n", d[0][6]); the     } +}

Hangzhou Electric 1176 Free pie

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.