NOIP2014 Flying Birds

Source: Internet
Author: User

P1941 Flying Birds
      • 467 through
      • 2.5K Submit
    • Topic provider The user does not exist
    • Tags dynamic planning Noip raising group
    • Difficulty Increase +/province selection-

Submit a discussion of the problem record

Recent discussions
    • Konjac Konjac Help
    • 。。
Title Description

Flappy Bird is a rage casual mobile phone game. Players need to constantly control the frequency of clicking 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 a bird accidentally hits a water pipe or falls on the ground, it will fail.

To simplify the problem, we have simplified and adapted the rules of the game:

    1. The game interface is a two-dimensional plane with a length of N and a height of M, with a K-pipe (ignoring the width of the pipe).

    2. The bird always moves within the game's interface. The bird starts at the leftmost integer height of the game interface and reaches the far right of the game interface, completing the game.

    3. Birds each unit time along the horizontal axis to the right of the distance is 1, vertical movement of the distance is controlled by the player. If you click on the screen, the bird will rise a certain height x, each unit time can be clicked multiple times, effect overlay;

If you do not tap the screen, the bird will drop a certain height y. When the birds are in different positions in the horizontal axis, the ascending height x and the descending height y may differ from each other.

    1. The bird height is equal to 0 or the bird hits the pipe and the game fails. When the bird height is m, it can no longer rise.

Now, tell me if you can finish the game. If you can, output a minimum number of hits on the screen, otherwise, the output bird can pass the maximum number of pipe gaps.

Input output Format input format:

The input file name is bird.in.

The 1th line has 3 integers n, m, K, each representing the length of the game interface, the height and the number of water pipes, each two

Separated by a space between integers;

The next n rows, each row of 2 integers separated by a space of X and Y, in order to indicate at the horizontal axis position 0 ~n-1

When the player clicks on the screen, the bird rises in the next position x, and in this position the player does not click on the screen,

The bird drops the height in the next position y.

Next k line, 3 integers per line p, L, H, each two integers separated by a space. Each row represents a

A pipe, where p represents the horizontal axis of the pipe, l indicates that the bottom edge of the pipe gap is L, H represents the pipe gap

The height of the upper edge (the input data guarantees that p varies, but is not guaranteed to be given in order of size).

Output format:

The output file name is Bird.out.

A total of two lines.

The first line, which contains an integer, outputs 1 if the game can be completed successfully, otherwise outputs 0.

The second line, which contains an integer, if the first behavior 1, the output successfully completed the game requires a minimum number of clicks on the screen, otherwise, the output bird can pass the maximum number of pipe gaps.

Input and Output Sample input example # #:
Ten 6 3 9  9 9  1 2  1 3  1 2  1 1  2 1  2 1  1 6  2 2  
Sample # # of output:
16
Input Sample #:
Ten 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  
Output Example #:
03
Description

"Input and Output sample description"

As shown, the blue line represents the bird's flight trajectory, and the red line represents the pipeline.

"Data Range"

For 30% data: 5≤n≤10,5≤m≤10,k = 0, guaranteed to have a set of optimal solutions to make the same unit time up to click on the screen 3 times;

For 50% data: 5≤n≤2 0, 5≤m≤10, guaranteed that there is a set of optimal solutions to make the same unit time up to click on the screen 3 times;

For 70% data: 5≤n≤1000,5≤m≤1 0 0;

For 100% data: 5≤n≤100 0 0, 5≤m≤1 0 00,0≤k < N, 0<x < m, 0<y <m,0<p <n,0≤l < h≤m, L +1< ; H.

Analysis: Each time can jump XI, you can jump K times, each time can only jump up and down once, this is a backpack? And it's not a simple backpack, a full backpack +0-1 backpack? Yes. The first can be clear upward is a complete backpack, down is 0-1 backpack, but not at the same time up and down, must be separate processing, you can refer to the Watchman's escape, specifically why, because it will cause confusion, and then I can not say clearly. So first hand to the top, first f[i][j] from f[i-1][ J-x[i]], and then can be obtained by f[i][j-x[i]], then the recursive minimum value can be, but notice that jumping to M game will not end, so from M-x[i] to M to continue to enumerate J to update F[i][m], and then based on this to update the downward, The column is covered by the entire assignment of the INF, the final judgment on the answer can be.

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespacestd;Const intMAXN =10010;Const intINF =1000000000;intN, M, K, p, ans,up[maxn],down[maxn],x[maxn],y[maxn],f[maxn][1010];intMain () {scanf ("%d%d%d", &n, &m, &k); Up[n]= m +1; Down[n]=0;  for(inti =0; I < n; i++) {scanf ("%d%d", &x[i], &Y[i]); Up[i]= m +1; Down[i]=0; }     for(inti =1; I <= K; i++) {scanf ("%d", &p); scanf ("%d%d", &down[p], &up[p]); }     for(inti =1; I <= N; i++)         for(intj =0; J <= M; J + +) F[i][j]=inf; f[0][0] =inf;  for(inti =1; I <= N; i++)    {         for(intj = x[i-1];j <= m; J + +) {F[i][j]= Min (F[i][j], f[i-1][j-x[i-1]] +1); F[I][J]= Min (F[i][j], f[i][j-x[i-1]] +1); }         for(intj = m-x[i-1]; J <= M; J + +) {F[i][m]= Min (f[i][m], f[i-1][J] +1); F[I][M]= Min (F[i][m], f[i][j] +1); }         for(intj = Down[i] +1; J <= Up[i]-1; J + +)            if(j + Y[i-1] <=m) F[i][j]= Min (F[i][j], f[i-1][j + Y[i-1]]);  for(intj =1; J <= Down[i]; J + +) F[i][j]=inf;  for(intj = Up[i]; J <= M; J + +) F[i][j]=inf; } ans=inf; intCNT =K;  for(inti = n; I >=1; i--){         for(intj = Down[i] +1; J <= Up[i]-1; J + +) ans=min (ans, f[i][j]); if(ans! =inf) Break; if(Up[i]! = m +1) CNT--; }    if(CNT = =k) printf ("1\n%d\n", ans); Elseprintf ("0\n%d\n", CNT); return 0;}

NOIP2014 Flying Birds

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.