Bzoj 4723: [Poi2017]flappy Bird

Source: Internet
Author: User

4723: [Poi2017]flappy Bird time limit:10 Sec Memory limit:128 MB
Submit:34 solved:16
[Submit] [Status] [Discuss] Description "Flying Bird" is a popular little game. In the game, the bird is initially located at (0,0), its goal is to fly to a position of x in the horizontal axis. Every second, you can choose to click on the screen, then the bird will fly from (x, y) to (x+1,y+1), or not click, then the bird will fly to (X+1,Y-1). In the game there are n obstacles, with ternary (X[i],a[i],b[i]) description, said in the line X=x[i], y<=a[i] or y>=b[i] parts are obstacles, hit or grazing are counted game failure. Ask for a minimum number of clicks from a bird (0,0) to its destination.

The first line of input contains two integers n (0<=n<=500000), X (1<=n<=10^9). Next n lines, three integers per line x[i],a[i],b[i] (0<x[i]<x,-10^9<=a[i]<b[i]<=10^9). Data Assurance x[i]<x[i+1].

Output If you cannot fly to the destination at any rate, export the NIE, or the minimum number of times the output hits the screen.

Sample Input4 11
4 1 4
7-1 2
8-1 3
9 0 2Sample Output5HINT


Source

Acknowledgement Claris Upload

[Submit] [Status] [Discuss]

Analysis

Note that the bird can "punch holes", that is, the height of the negative is also legal!

So, as long as we pass the last obstacle, we can definitely not fly to the destination without any clicks.

The difference between the horizontal axis of the adjacent two obstacles is the largest rise (or fall) of this distance, you can calculate the range of the flight to the next obstacle can reach, and then with the requirements of the obstacle card can be.

Code
1#include <bits/stdc++.h>2 Const intMAXN =500005;3 intN, X[maxn], A[MAXN], B[MAXN], a, b;4 intMain () {5scanf"%d%*d", &n);6      for(inti =1; I <= N; ++i)7scanf"%d%d%d", x + i, a + I, B +i);8      for(inti =1; I <= N; ++i) {9         intTMP = X[i]-x[i-1];TenA = Std::max (a-tmp, A[i] +1); Oneb = std::min (b + tmp, B[i]-1); A         if(A &1)! = (X[i] &1)) A = a +1; -         if(B &1)! = (X[i] &1)) B = B-1; -         if(A > B)returnPuts"NIE"),0; the     } -printf"%d\n", (A + x[n]) >>1); -}
Bzoj_4723.cpp

@Author: Yousiki

Bzoj 4723: [Poi2017]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.