NOIP2014 Flying Bird (Flappy Bird)

Source: Internet
Author: User

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.

This problem is really leather, nothing to our kind Flappy Brid changed into a disgusting topic.

At first glance, there is no clue to this question, but to think carefully, in fact, in each column corresponds to a number of heights, for each height, you can get the best number of jumps to this height.

The so-called pipe is the scope of the specified jump, jumping can not exceed the range.

It's not hard to know that. Status: $f [i][j]$ indicates the minimum number of times required for column I to fly to the height of J.

And for each column, you can know the height of the rising height, each column has the corresponding maximum height.

Then this question can be converted into knapsack problem.

I have a list of I items, put in the capacity of $m$ (refer to the meaning of the title) in the backpack

For every upward jump, you can point countless times, that is, there are unlimited items can be put into the backpack.

And when it's down, it's a 01-pack, and the number doesn't increase, it only has to do with the previous state.

But the time complexity of doing this is about $o (n*m^{2}) $,$100$% data, so we need to do a little bit of optimization.

Because we each point once, the height will rise, so the point $i$ times is related to the point $i-1$ times.

The space can also be optimized to open the scrolling array, because the state of each column is only related to the state of the previous column.

You can also not scroll, directly to the previous state with the $memcpy$ function assigned to another array, and then all $memset$ the DP array is all assigned to $0x7f7f7f7f$.

At the top, you need a special sentence, because you can't jump any more.

The code is as follows (refer to Luogu):

1#include <algorithm>2#include <cctype>3#include <cstdio>4#include <cstring>5  6 using namespacestd;7  8 #defineINF 0x7f7f7f7f9  Ten Const intMAXN =10010; One Const intMAXM =1010; A   -InlineintReadin () - { theintx =0; -Charc =GetChar (); - while(!isdigit (c)) C =GetChar (); - while(IsDigit (c)) { +x = x *Ten+ C-'0'; -c =GetChar (); +     } Areturnx; at } -   - intN, M, k, ans =INF, num; - intBUP[MAXN], BDOWN[MAXN]; - intF[MAXM], G[MAXM]; - BOOLjudge, check; in   - structNode { tointL; +intH; -intLoc; theBOOL operator< (Constnode& x)Const{returnLoc <X.loc;} * } GUAN[MAXN]; $  Panax Notoginseng intMain () - { then =Readin (); +m =Readin (); AK =Readin (); the  for(inti =1; I <= N; i++) { +Bup[i] =Readin (); -Bdown[i] =Readin (); $     } $ for(inti =1; I <= K; i++) { -Guan[i].loc =Readin (); -Guan[i]. L =Readin (); theGuan[i]. H =Readin (); -     }WuyiSort (Guan +1, Guan + k +1); thenum =1; - for(inti =1; I <= N; i++) { Wumemcpy (g, F,sizeofg); -Memset (f, INF,sizeoff); AboutJudge = Check =false; $if((I-1) = = Guan[num].loc && num! = (k +1)) Judge =true;//Because the data is from 0~n-1, and my array subscript is starting from 1, so subtract 1.  - for(intj =1; J <= M; J + +) { -if(J-bup[i] >=0) { -if((Judge && j-bup[i] > Guan[num]. L && J-bup[i] < Guan[num]. H) | | !judge) AF[j] = min (F[j], G[j-bup[i]] +1); +F[j] = min (F[j], F[j-bup[i]] +1); theif(F[j]! = INF) Check =true; -             } $if(M-j <=Bup[i]) {//Special award theif((Judge && J > Guan[num]. L && J < Guan[num]. H) | | !judge) F[m] = min (F[m], g[j] +1); theF[m] = min (F[m], f[j] +1); theif(f[m]! = INF) Check =true; the             } -         } in for(intj = M-bdown[i]; J >=1; j--) theif((Judge && J + Bdown[i] > Guan[num]. L && J + Bdown[i] < Guan[num]. H) | | !judge) theF[j] = min (F[j], g[j +Bdown[i]]); Aboutif(Judge = =true) { theif(!check) { theprintf"0\n%d", Num-1);//The current pipe can not fly, just the number of pipelines previously flown out of the line.  thereturn 0; +             } -num++; the if(num > k) num = k +1;Bayi         } the     } the for(inti =1; I <= m; i++) ans =min (ans, f[i]); -printf"1\n%d", ans); -return 0; the}

NOIP2014 Flying Bird (Flappy Bird)

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.