Hoj 2245 planktonic Triangular cell (mathematics AH)

Source: Internet
Author: User

Title Link: http://acm.hrbust.edu.cn/index.php?m=ProblemSet&a=showProblem&problem_id=2245


Time limit:500 MS Memory limit:50000 K
Total submit:129(users) Total accepted:66(users) Rating: Special Judge: No
Description

, Zoidtrip is a casual to small game ...
The player needs to manipulate a triangular cell that keeps moving forward at a speed of 45 degrees downward, constantly avoiding horizontal obstructions, and can change direction each time the screen is clicked. [Oblique left (right) 45° can be transformed to oblique right (left) 45°]
Now, there are N-layer obstacles, layer I obstacles can be worn from the range of the horizontal axis l[i]~r[i] (including l[i] and R[i]), and the distance between the layer I obstacle and the i-1 barrier is d[i].
May I ask, assuming that you can move up to the first layer of the field if you can change direction infinitely?
We stipulate that the player is born on the No. 0 floor, where the horizontal axis is 0.
You can change direction at any real number moment.

Input
Multiple sets of test data.
The first behavior of each set of test data is two positive integers n and v.
Next n lines, 3 integers per line l[i], R[i], d[i].
(N <= 2000000,0 <= all data < 2^31)
Output
For each set of data, the output line contains an integer that represents the maximum number of layers to advance to.
Sample Input
3 7
1 3 1
4 10 5
8 10 1
4 1
1 1 1
2 5 10
1 1 1
3 5 2
Sample Output
2
4
Hint

"The distance between the layer I obstacle and the barrier of the i-1 layer is d[i]"
So d[1] is the distance between the first and 0th floors.

Sample 1 is explained as follows:

We can move from the birth position to the right down to the first layer with coordinates 1.
Next, you can continue to move right down to the second-level coordinate of 6.

But in any case it cannot be moved to the third level between the 8~10.


Example 2 illustrates the following:
(0,0), (2,2), (3,1), (4,3)
So it reaches the fourth floor.

Source
The fifth annual ACM Program Design Contest of Harbin Polytechnic University


Ps:

Find the triangular cell at the left and right distance from each layer that can be reached and meet the obstacles.

The code is as follows:

#include <cstdio> #include <iostream> #include <algorithm>using namespace std; #define LL Long long# Define MAXN 2000047LL L[MAXN], R[MAXN], D[maxn];int main () {    LL n, v;    while (scanf ("%lld%lld", &n,&v)!=eof)    {        LL L = 0,r = 0;        int ans = 0;        for (int i=0; i<n; i++)        {            scanf ("%lld%lld%lld", &l[i],&r[i],&d[i]);        }        for (int i = 0; i < n; i++)        {            if (L[i] > R[i])            {                LL t = r[i];                R[i] = L[i];                L[i] = t;            }            L-=d[i];            R+=d[i];            L = max (l[i],l);            R = min (r[i],r);            if (L > R)            {break                ;            }            ans++;        }        if (v = = 0)            ans = 0;        printf ("%d\n", ans);    }    return 0;}


Hoj 2245 planktonic Triangular cell (mathematics AH)

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.