码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 5214 Movie

时间:2015-05-04 10:04:39      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:

赛码杯大赛的水题。。。

时限 7 秒,直接按照题意搞就好了。。

Movie

Time Limit: 14000/7000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 624    Accepted Submission(s): 168


Problem Description
Cloud and Miceren like watching movies. 

Today, they want to choose some wonderful scenes from a movie. A movie has N scenes can be chosen, and each scene is associate with an interval [LR]. L is the beginning time of the scene and R is the ending time. However, they can‘t choose two scenes which have overlapping intervals. (For example, scene with [1, 2] and scene with [2, 3], scene with [2, 5] and scene with[3, 4]). 

Now, can you tell them if they can choose such three scenes that any pair of them do not overlap? 

Since there are so many scenes that you can‘t get them in time, we will give you seven parameters N, L1, R1, a, b, c, d, and you can generate L1 ~ LNR1 ~ RNby these parameters.
 

Input
The first line contains a single integer T, indicating the number of test cases.

Each test case contains seven integers N, L1, R1, a, b, c, d, meaning that there are N scenes. The i-th scene‘s interval is [Li, Ri]. L1 and R1 have been stated in input, and Li = (Li?1 ? a + b) mod 4294967296, Ri = (Ri?1 ? c + d) mod 4294967296

After all the intervals are generated, swap the i-th interval‘s Li and Ri if Li > Ri.


T is about 100.

1  N  10000000.

1  L1,R1  2000000000.

1  a,b,c,d  1000000000.

The ratio of test cases with N > 100 is less than 5%.
 

Output
For each test, print one line.

If they can choose such three scenes, output "YES", otherwise output "NO".
 

Sample Input
2 3 1 4 1 1 1 1 3 1 4 4 1 4 1
 

Sample Output
NO YES
 

Source
 

#include <bits/stdc++.h>
using namespace std;
#define prt(k) cerr<<#k" = "<<k<<endl
#define pb push_back
#define MP make_pair
#define fi  first
#define se second
#define ALL(v) (v).begin(), (v).end()
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
#define SZ(X) ((int)(v).size())
#define For(i,l,r) for (int i = l; i <= r; ++i)
#define Cor(i,l,r) for (int i = l; i >= r; --i)
#define Fill(a,b) memset(a,b,sizeof(a))
#define READ freopen("a.in","r",stdin);freopen("a.out","w",stdout)
void read(string t)
{
    freopen((t+".in").c_str(),"r",stdin);
    freopen((t+".out").c_str(),"w",stdout);
}
const int inf = 0x3f3f3f3f;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair<int,int> pii;
template <class T>
void Max(T &a, T b) { a=max(a, b); }
typedef unsigned int uint;
const int N = 10000003;
struct P
{
    uint l, r;
    bool operator < (P b) const {
        return r < b.r;
    }
} p[N];
uint n, l1, r1, a, b, c, d;
int main()
{
    int re, ca=1; cin>>re;
    while (re--) {
        cin>>n>>l1>>r1>>a>>b>>c>>d;
        p[1].l = l1; p[1].r = r1;
        for (int i=2;i<=n;i++)
        {
            p[i].l = (p[i-1].l * a + b) ;
            p[i].r = (p[i-1].r * c + d);
        }
        for (int i=1;i<=n;i++) if (p[i].l > p[i].r) swap(p[i].l, p[i].r);
        sort(p+1, p+n+1);
        uint L, R;
        int cnt = 0;
        cnt = 1;
        int last = 1;
        while (cnt <3)  {
            bool ok = false;
            for (int i = last + 1 ; i<=n  ; i++)
            {
                if (p[last].r < p[i].l)
                {
                    ok = true;
                    last = i;
                    break;
                }
            }
            if (!ok) break;
            else cnt++;
        }
        if (cnt >= 3) puts("YES");
        else puts("NO");
    }
    return 0;
}



HDU 5214 Movie

标签:

原文地址:http://blog.csdn.net/oilover/article/details/45476473

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!