[codevs3729] Flying Birds

Source: Internet
Author: User

[codevs3729] Flying Birds

Question Description

Input

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 Output sample

Data size and conventions

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

Exercises

Set F[I][J] Indicates the horizontal axis in I, the minimum number of clicks of the ordinate in J (if not reached this point is positive infinity). Consider each transfer, from i-1 to I, click k times, ordinate increase x[i-1] * k (Increase cannot exceed m), or do not click, ordinate decrease y[i-1].

However, such a transfer is O (N/x[i]), when the x[i] compared to the hour will not be able to, so we can F[i][j] j, and ordinate the model X[i-1] classification, and then maintain the minimum value of the prefix can be.

#include <iostream> #include <cstdio> #include <algorithm> #include <cmath> #include <stack > #include <vector> #include <queue> #include <cstring> #include <string> #include <map > #include <set>using namespace std;const int buffersize = 1 << 16;char buffer[buffersize], *head, *TAIL;INL        ine Char Getchar () {if (Head = = Tail) {int L = fread (buffer, 1, buffersize, stdin);    Tail = (Head = buffer) + L; } return *head++;}    int read () {int x = 0, f = 1; char c = Getchar ();    while (!isdigit (c)) {if (c = = '-') f =-1; c = Getchar ();}    while (IsDigit (c)) {x = x * + C-' 0 '; c = Getchar ();} return x * f;} #define MAXN 1010#define Maxl 10010#define oo 2147483647int N, M, K, F[2][MAXN], MINF[MAXN], X[maxl], y[maxl];struct Tun { int up, low, x; Tun () {}tun (int _1, int _2, int _3): Up (_1), Low (_2), X (_3) {}bool operator < (const tun& t) const {return x < T.x; }} Ts[maxl];int Main () {n = read (); m = READ (); K = read (); for (int i = 0; i < n; i++) X[i] = Read (), y[i] = Read (), for (int i = 1; I <= K; i++) {int p = read (), L = Read (), h = Read (); Ts[i] = Tun (H, L, p);} Sort (ts + 1, ts + k + 1); F[0][0] = oo;for (int i = 1; I <= m; i++) f[0][i] = 0;int cur = 1, kt = 1, at;for (int i = 1; i <= N; i++, cur ^= 1) {for (int j = 0; J <= M; j + +) Minf[j] = f[cur][j] = oo;for (int j = 1; j <= M; j + +) if (J >= X[i-1]) { int lf = f[cur^1][j-x[i-1]], MF = minf[j%x[i-1]];minf[j%x[i-1]] = min (MF = = oo OO:MF + 1, lf = = oo Oo:lf + 1); F[cu R][j] = min (F[cur][j], minf[j%x[i-1]]);} for (int j = m + 1; J <= m + x[i-1]; j + +) {int lf = f[cur^1][j-x[i-1]], MF = minf[j%x[i-1]];minf[j%x[i-1]] = min (MF = = O O? OO:MF + 1, lf = = oo? OO:LF + 1); F[cur][m] = min (F[cur][m], minf[j%x[i-1]]);}  for (int j = 1; J <= M-y[i-1], j + +) F[cur][j] = min (F[cur][j], f[cur^1][j+y[i-1]]); if (kt <= k && ts[kt].x = = i) {//puts ("here"), for (int j = 1; J <= Ts[kt].low; j + +) F[cur][j] = oo;for (int j = Ts[kt].up; J <= M; J + +) f[cur][j] = oo;kt++;} for (int j = 1; j <= M; j + +) printf ("%d", f[cur][j] < oo? F[CUR][J]:-1); Putchar (' \ n '); for (int j = 1; j <= M; j + +) if (F[cur][j] < oo) {at = kt-1; int ans = oo;for (int i = 1; I <= m; i++) ans = min (ans, f[cur^1][i]), if (ans < oo) printf ("1\n%d\n", ans); else printf ("0\n%d\n", at); return 0;}

[codevs3729] 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.