NOIP2014 The Flying Birds

Source: Internet
Author: User
Description

Flappy Bird is a rage casual mobile game. Players need to constantly control the number of clicks on the phone screen to adjust the bird's flight altitude, so that the bird smoothly through the screen to the right of the pipe gap. If the bird accidentally hit the water pipe or dropped on the ground, it will be declared a failure.

To simplify the problem, we have simplified and adapted the rules of the game: The game interface is a two-dimensional plane with a length of N and a height of M, with K pipes (ignoring the width of the pipe). The bird always moves within the game interface. Birds from the game interface to the left of the most arbitrary integer height position, to the game interface to the far right, the game completed. Birds each unit time in the direction of the horizontal shift to the right distance of 1, vertical movement of the distance by the player control. If you click on the screen, the bird will rise to a certain height X, each unit time can be clicked several times, the effect is superimposed; If you do not click on the screen, the bird will drop a certain height Y. When the birds are in different positions in the direction of the horizontal axis, the ascending height X and the descending height Y may not be the same. The bird height equals 0 or the bird touches the pipe and the game fails. When the bird height is m, can not rise again.

Now, please decide if you can finish the game. If you can, output at least click on the number of screens, otherwise, the maximum number of birds can pass through the pipe gap. format Input Format

Line 1th has 3 integer n,m,k, respectively, the length of the game interface, height and the number of water pipes, each of the two integers separated by a space;

The next n rows, 2 integers x and Y separated by a space in each row, indicate the height x of the bird in the next position, and the height of the bird in the next position when the player clicks on the screen in the 0~n-1 position.

Next line K, each row is 3 integers p,l,h, separated by a space between every two integers. Each line represents a pipe in which p represents the horizontal axis of the pipe, and L indicates the height of the bottom edge of the pipe gap as l,h indicates the altitude of the top edges of the pipe gap (the input data guarantee P varies, but is not guaranteed to be given in order of magnitude). output Format

A total of two lines.

The first line, containing an integer, if the game can be successfully completed, output 1, otherwise output 0. The second line, contains an integer, if the first behavior 1, then the output successfully completed the game need to click the minimum number of screens, otherwise, the output of birds can be up to how many pipe gaps. Sample 1 sample Input 1[replication]

6
3 9
9 9 1
2 1 3 1
2 1 1 2 1 2 1 1 6 2 2 1 2 7 5 1 5 6-3
7 5 8
8 7 9 9 1 3

sample Output 1[copy]
1
6
Sample 2 sample Input 2[replication]
A 4
1 2 3 1 2 2 1 8 1 8 3 2 2 1 2 1 2 2 1 2 1 0 2 6 7
9
  9 1 4
3 8 10
sample Output 2[copy]
0
3
Limit

For 30% of the data: 5≤n≤10,5≤m≤10,k=0, to ensure the existence of a set of optimal solution to the same unit time to click the screen 3 times;

For 50% of the data: 5≤n≤20,5≤m≤10, to ensure the existence of a set of optimal solution to the same unit time to click the screen 3 times;

For 70% of the data: 5≤n≤1000,5≤m≤100;

For 100% of the data: 5≤n≤10000,5≤m≤1000,0≤k<n,0<x<m,0<y<m,0<p<n,0≤lTips

As the following figure shows, the blue line indicates the bird's flight trajectory, and the red line represents the pipe.


"Please judge if you can finish the game." If you can, output at least click on the number of screens, otherwise, the maximum number of birds can pass through the pipe gap. ”

The solution structure is represented as ϕ= (b,h,t), B is 1 or 0 to indicate whether the game can be completed, and if so, h means the minimum number of clicks on the screen; t indicates how many pipe gaps can be passed. Defining ϕ1= (B1,H1,T1) <ϕ2= (B2,H2,T2) if and only if (b1=0,b2=1) or (B1=B2=0,T1<T2) or (B1=B2=1,H1>H2), we can create a full order relationship to the representation of the solution. The maximum value of the feasible solution is the optimal one, and we can optimize the memory representation with the symbolic number.

Define ϕ+t′={(b,h,t+t′) (b,h,t) b=0b=1,ϕ+h′={(b,h,t) (b,h+h′,t) b=0b=1

Φ (x,y) is the optimal solution for starting the game from (x,y) coordinates, α (x) and β (x) respectively indicate the height of the ascent and descent, and T (x) indicates whether there is a pipeline at the horizontal axis, then for the planar area where there is no pipeline Φ (x,y) =maxh=0,1,2,... {Φ (X+1,y+h∗α (x)) +h+t (x) Φ (x+1,y−β (x)) +t (x) h>0h=0
and the solution is

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.