2015-05-07 11:32:38

总结:hdu 主办的 “bc” 杯的网络赛~

  12.30开始,历时5h...

  比赛中搞掉了5题... room rank3 抢到一件 t 恤 0.0...

  赛后补了下题... 最终8题... 本来想补一下 07,但进度不允许啦QAQ。

 

1001题 hdu 5214:贪心算法

  题意就是根据一定规律生成 N 个区间,问能否找出三个两两相离的区间。 4294967296

  观察生成规律发现,模数就是unsigned int的最大值,所以就直接用unsigned int来保存各个变量使之自然溢出即可(取模会 TLE)

  接着考虑贪心法,只要找到一个最左区间和一个最右区间,再检查是否有一个区间在其中即可。而最左区间我们只考虑右端点最小值,最右区间只考虑左端点最大值。

#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;

#define getmid(l,r) ((l) + ((r) - (l)) / 2)
#define MP(a,b) make_pair(a,b)
#define PB(a) push_back(a)

typedef long long ll;
typedef pair<int,int> pii;
const double eps = 1e-8;
const int INF = (1 << 30) - 1;
const ll mod = 4294967296LL;

int T;
unsigned int N,L,R,a,b,c,d;

unsigned int Max(unsigned int a,unsigned int b){ return a > b ? a : b; }
unsigned int Min(unsigned int a, unsigned int b){ return a < b ? a : b; }

int main(){
    scanf("%d",&T);
    while(T--){
        int tn,tl,tr,ta,tb,tc,td;
        scanf("%d%d%d%d%d%d%d",&tn,&tl,&tr,&ta,&tb,&tc,&td);
        N = tn; L = tl; R = tr; a = ta; b = tb; c = tc; d = td;
        unsigned int tL = L,tR = R;
        unsigned int tmin = Max(L,R);
        unsigned int tmax = Min(L,R);
        for(int i = 2; i <= N; ++i){
            tL = tL * a + b;
            tR = tR * c + d;
            tmin = Min(tmin,Max(tL,tR));
            tmax = Max(tmax,Min(tL,tR));
        }
        bool flag = false;
        tL = L;
        tR = R;
        if(Min(tL,tR) > tmin && Max(tL,tR) < tmax){
             printf("YES\n");
             continue;
        }
        for(int i = 2; i <= N; ++i){
            tL = tL * a + b;
            tR = tR * c + d;
            if(Min(tL,tR) > tmin && Max(tL,tR) < tmax){
                flag = true;
                break;
            }
        }
        if(flag) printf("YES\n");
        else printf("NO\n");
    }
    return 0;
}
View Code

相关文章: