NOIP Day1 The third problem flying birds

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, the bird smoothly through the screen to the right of the 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.   Birds always move within the game interface. Bird from the left side of the game interface any integer height position, arrive at the far right of the game interface, Tour play finished. &NBSP,
3.   Birds the distance from the horizontal axis to the right of each unit time is 1, and the distance of the vertical movement is controlled by the player. such as If you don't tap the screen, the bird will drop a certain height y. When the birds are in different positions on the horizontal axis, the upper

4. The bird height equals 0 or when the bird touches the pipe, 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.

The first thing: it should be easy to think of a 70 DP, set F[I][J] to indicate the minimum number of clicks required for the height of section I of Column J.

So we enumerate the number of times from the previous line by the screen, the 01 knapsack solution, and down similar.

However, this complexity will explode, so do a full backpack up.

In other words 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);//This line is complete backpack complexity O (nm);

Then notice that near the top of the lattice can not be exceeded, special transfer, details see code, and then the place of the pipe is assigned to the INF.

%%%__debug the Great God.

#include <cstdio> #include <cstdlib> #include <iostream> #include <algorithm> #define INF 0x7fffffff/10const int maxn=10001,maxm=1001;int N,m,k,x[maxn],y[maxn],up[maxn],down[maxn],f[maxn][maxm];int min ( int A,int b) {return a<b?a:b;}    int main () {freopen ("bird.in", "R", stdin);    Freopen ("Bird.out", "w", stdout);    scanf ("%d%d%d", &n,&m,&k);    for (int i=1;i<=n;i++) scanf ("%d%d", &x[i-1],&y[i-1]);        for (int i=1;i<=k;i++) {int a,b,c;        scanf ("%d%d%d", &a,&b,&c);    Down[a]=b;up[a]=c;    } for (int i=1;i<maxn;i++) for (int j=0;j<maxm;j++) F[i][j]=inf;    F[0][0]=inf; for (int i=1;i<=n;i++) {for (int j=0;j<=m;j++) if (J>x[i-1])//up {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 (int j=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);        } if (!down[i]) down[i]=0;        if (!up[i]) up[i]=m+1; for (int. j=down[i]+1;j<up[i];j++) if (j+y[i-1]<=m)//not 0 to M f[i][j]=min (f[i][j],f[i-1][j+        Y[I-1]]);        for (int j=0;j<=down[i];j++) F[i][j]=inf;        for (int j=m;j>=up[i];j--) F[i][j]=inf;    F[i][0]=inf;    } int ans=inf;    for (int j=0;j<=m;j++) ans=min (Ans,f[n][j]);    if (ans!=inf) printf ("1\n%d\n", ans);        else{int cnt=0;            for (int i=n-1;i>=0;i--) {for (int j=0;j<=m;j++) if (f[i][j]<inf) {ans=i;break;}        if (ans<inf) break;        } for (int i=0;i<=ans;i++) if (up[i]!=m+1&&up[i]!=0) cnt++;    printf ("0\n%d\n", CNT); }}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

NOIP Day1 The third problem 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.