The Flying Bird
(Bird.cpp/c/pas)
"Problem description"
Flappy Bird is a rage casual mobile phone game. Players need to
To constantly control the frequency of tapping the phone screen to adjust the bird's flight altitude, let
The bird smoothly passes through the pipe gap on the right of the screen. If a bird accidentally hits
The water pipe or fell to the ground, then declared 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, where
There are k pipes (ignoring the width of the pipe). The bird always moves within the game's interface. The bird from the game interface to the left
At the far right of the game interface, starting at the position of any integer height,
The game is complete. 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. Such as
Fruit 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 on the horizontal axis, the
The height of the ascending X and the height of descent y may differ from each other. The bird height is equal to 0 or the bird hits the pipe and the game fails. When the bird height is m, it cannot
Up again.
Now, tell me if you can finish the game. If possible, output a minimum number of hits on the screen; otherwise, the output bird
The maximum number of pipe gaps that can be passed.
Input
The input file name is bird.in.
The 1th line has 3 integer n,m,k, each representing the length of the game interface, the height and the number of water pipes, every two whole
The number is separated by a space;
The next n rows, each row of 2 integers separated by a space of X and Y, in order to indicate in the horizontal 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 lines, 3 integers per line p,l,h, separated by a space between each of the two integers. Each row represents a
Pipe, where P represents the horizontal axis of the pipe, and L indicates that the bottom edge of this pipe gap is l,h on the pipe gap
The height of the edge (the input data guarantees that P varies, but is not guaranteed to be given in order of size).
Output
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 is 1, the output will require a minimum number of screen clicks to complete the game.
Otherwise, the output bird can pass the maximum number of pipe gaps.
"Input and output Example 1"
Bird.in
10 10 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 5
7 5 8
8 7 9
9 1 3
Bird.out
1
6
Input Output Sample 2
bird.in
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
Bird.out
0
3
"Input Output Sample description"
as shown in the following figure, the blue line indicates the bird's flight trajectory, red The color line represents the pipeline.
#include <cstdio> #include <algorithm> #include <cstring> using namespace std;
const INT maxn=10005,maxm=1005,inf=1<<30;
int X[MAXN],Y[MAXN];
int DP[MAXN][MAXM];
int UP[MAXN],DOWN[MAXN];
int n,m,k;
int main () {freopen ("bird.in", "R", stdin);
Freopen ("Bird.out", "w", stdout);
scanf ("%d%d%d", &n,&m,&k);
for (int i=0;i<n;i++) {scanf ("%d%d", &x[i],&y[i]);
} memset (Dp,0,sizeof (DP));
for (int i=0;i<=n;i++) down[i]=0,up[i]=m+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;
} int tubes=0;
for (int i=1;i<=n;i++) {for (int j=1;j<=m;j++) {dp[i][j]=inf; } for (int j=1;j<=m;j++) {if (j-x[i-1]>0) dp[i][j]=min (Dp[i][j],min (Dp[i-1][j-x[i-1]]
, Dp[i][j-x[i-1]]) +1); } for (int j=1;j<=m;j++) if (j+y[i-1]<=m) dp[i][j]=min (dp[i][j],dp[i-1][j+y[I-1]]);
for (int j=m-x[i-1];j<=m;j++) dp[i][m]=min (Dp[i][m],min (dp[i-1][j],dp[i][j]) +1);
for (int j=1;j<=down[i];j++) Dp[i][j]=inf;
for (int j=up[i];j<=m;j++) Dp[i][j]=inf;
int sign=0;
for (int j=1;j<=m;j++) if (dp[i][j]<inf) {sign=1;break;}
if (sign==0) {printf ("0\n%d", tubes);
return 0; } if (down[i]>0| |
up[i]<m+1) tubes++;
} int mn=inf;
for (int i=1;i<=m;i++) mn=min (Mn,dp[n][i]);
printf ("1\n%d", MN);
return 0; }