P1907 Flying Birds

Source: Internet
Author: User

P1907 Flying BirdsDescribe

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.
    4. 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.

Format input Format

The 1th line has 3 integer n,m,k, which indicates the length of the game interface, the height and the number of water pipes, separated by a space between each two 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 position 0~n-1 on the player click on the screen, the bird in the next position of the height of the X, and in this position when the player does not click the screen, the bird in the next position down the height of Y.

Next k lines, 3 integers per line p,l,h, separated by a space between each of the two integers. Each line represents a pipe, where p represents the horizontal axis of the pipe, and L indicates that the bottom-edge height of the pipe gap is l,h, which indicates the height of the edge on the pipe gap (the input data guarantees that P varies, but is not guaranteed in order of size).

Output format

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.

Example 1 sample input 1[copy]
10 10 63 99 91 21 31 21 12 12 11 62 21 2 75 1 56 3 57 5 88 7 99 1 3
Sample output 1[Copy]
16
Example 2 sample input 2[copy]
10 10 41 23 12 21 81 83 22 12 12 21 21 0 26 7 99 1 43 8 10
Sample output 2[Copy]
03
Limit

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

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

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

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

Tips

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

Source

NOIP2014 Raising Group Day1

The subject is dynamic planning, the gall is not found at the beginning, and later only to understand that can optimize the space to 2N without MN from the forward state of the back to the time to set an array to save the status of the search to arrive, and finally take no pipe on the line because the process is similar to the full backpack, so to push from the bottom of the click
#include <cstdio>#include<iostream>#include<cstring>#defineMAX 10002using namespacestd;intX[max],y[max];intUp[max],down[max];intF[max],d[max];intn,m,k;intans,cnt;BOOLFlag;Const intinf=0xFFFFFFF;int_min (intAintb) {    returnA<b?a:b;}voidinit () {cin>>n>>m>>K;  for(intI=0; i<=n;i++) Up[i]=m+1;  for(intI=0; i<n;i++) scanf ("%d%d",&x[i],&Y[i]);  for(intI=1; i<=k;i++)    {intNo; scanf ("%d",&no); scanf ("%d%d",&down[no],&Up[no]); } ans=INF;}intdp () { for(intI=1; i<=m;i++) F[i]=0;  for(intI=1; i<=n;i++) {flag=0; Fill (d,d+Max,inf); //Click         for(intj=1; j<=m;j++)        {            if(j-x[i-1]<up[i-1]&&j-x[i-1]>down[i-1]&&d[j]>f[j-x[i-1]]+1) D[j]=f[j-x[i-1]]+1; if(j-x[i-1]>0&&d[j]>d[j-x[i-1]]+1) D[j]=d[j-x[i-1]]+1; }        //if you fly up and hit the top ,         for(intj=m-x[i-1]+1; j<=m;j++)        {            if(j>down[i-1]&&j<up[i-1]) D[m]=_min (f[j]+1, D[m]); D[M]=_min (d[j]+1, D[m]); }         //do not click         for(intj=1; j<=m;j++)            if(j+y[i-1]>down[i-1]&&j+y[i-1]<up[i-1]&&d[j]>f[j+y[i-1] ]) d[j]=f[j+y[i-1]];  for(intj=down[i]+1; j<up[i];j++)            if(D[j]<inf) flag=1; if(!flag) {printf ("0\n%d", CNT); return 0; }        if(up[i]<=m) cnt++; memcpy (F,d,sizeof(f)); }         for(intI=1; i<m;i++) ans=_min (Ans,f[i]); return 1;}intMain () {Freopen ("bird.in","R", stdin); Freopen ("Bird.out","W", stdout);    Init (); if(DP ()) printf ("1\n%d", ans); return 0;}

P1907 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.