Codeforces 342B Xenia and Spies (water problem simulation, greed)

Source: Internet
Author: User

Test instructions: Given n spies, M-bands, an S, an F, and then from S to pass the note, and then to F, and then in each t time within the interval of the can not pass, ask you the least time passed.

Analysis: This problem, on the simulation of a good, greedy strategy, can pass on, find a good direction, always pass on the line, to the end of F.

The code is as follows:

#include <bits/stdc++.h>using namespace std;struct node{int L, R, T;    BOOL operator < (const node &p) const{return T < p.t;    }};node A[100005];int Main () {int S, T, M, N, F, L, R;        while (CIN >> n >> m >> s >> f) {bool OK = false; int x = f > S?        1:-1;        int pos = s;        for (int i = 0; i < m; ++i) {scanf ("%d%d%d", &a[i].t, &AMP;A[I].L, &AMP;A[I].R);        }//sort (A, a+m);        int cnt = 0; for (int i = 1;; ++i) {if (a[cnt].t = = i) {if (pos + x < A[CNT].L && Pos < A[CNT].L ) || (pos + x > A[CNT].R && pos > A[CNT].R)) {printf ("%c", x < 0?) ' L ': ' R '); pos + = x;                } else printf ("X");                if (pos = = f) break;            ++cnt;                }else{pos + = x; printf ("%c", x < 0?)                ' L ': ' R ');            if (pos = = f) break;        }        }printf ("\ n"); } return 0;}

Codeforces 342B Xenia and Spies (water problem simulation, greed)

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.