HDU ACM 5214 Movie ->贪心+自然溢出取模->水题里的学问

分析:贪心,首先找到最右边的第一个左边界和最左边的第一个右边界。之后在判断是否有一个及一个以上的区间在这两个值之间,若有则能找到符合题意的三个区间,否则不能。

注意:这里利用的unsigned int的自然溢出决解了取模问题;第二个是一定生成完数据后在交换Li和Ri的值,这里被坑残了。

#include<iostream>
using namespace std;

//__int64 mod=4294967296;由于4294967296-1刚好是unsigned int类型的最大值,对它取模就相当于unsigned int溢出了
unsigned int L[10000005],R[10000005];       //因此这里不需要取模,利用溢出就相当于取摸了。

int main()
{
	unsigned int T,N,L1,R1,a,b,c,d,i;
	unsigned int max,min;
	bool ok;

	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d%d%d%d%d%d",&N,&L1,&R1,&a,&b,&c,&d);
		i=0;
		L[i]=L1;
		R[i++]=R1;
		for(;i<N;i++)
		{
			L[i]=L[i-1]*a+b;
			R[i]=R[i-1]*c+d;
		}

		for(i=0;i<N;i++)       //生成完数据后才能交换
			if(L[i]>R[i]) swap(L[i],R[i]);

		max=L[0];
		min=R[0];
		for(i=1;i<N;i++)
		{
			max=L[i]>max?L[i]:max;           //找到最右边的第一个左边界
			min=R[i]<min?R[i]:min;           //找到最左边的第一个右边界
		}
		ok=false;
		for(i=0;i<N;i++)
			if(L[i]>min && R[i]<max) //如果存在一个区间在上述求出的最大值和最小值之间,则可以找到,否则不能
			{
				ok=true;
				break;
			}
		if(ok)
			puts("YES");
		else
			puts("NO");
	}
	return 0;
}
时间: 2024-10-06 14:59:19

HDU ACM 5214 Movie ->贪心+自然溢出取模->水题里的学问的相关文章

HDU 4006 The kth great number (基本算法-水题)

The kth great number Problem Description Xiao Ming and Xiao Bao are playing a simple Numbers game. In a round Xiao Ming can choose to write down a number, or ask Xiao Bao what the kth great number is. Because the number written by Xiao Ming is too mu

HDU - 4788 Hard Disk Drive (成都邀请赛H 水题)

HDU - 4788 Hard Disk Drive Time Limit:1000MS   Memory Limit:32768KB   64bit IO Format:%I64d & %I64u [Submit]  [Go Back]  [Status] Description Yesterday your dear cousin Coach Pang gave you a new 100MB hard disk drive (HDD) as a gift because you will

HDU 5344(2015多校5)-MZL&#39;s xor(水题)

题目地址:HDU 5344 题意:求所有(Ai+Aj)的异或值. 思路:可以发现(Ai+Aj)和(Aj+Ai)的异或值为0,所以最后只剩下(Ai+Ai). #include <stdio.h> #include <math.h> #include <string.h> #include <stdlib.h> #include <iostream> #include <sstream> #include <algorithm>

HDU 5363 Key Set【快速幂取模】

Key Set Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1886    Accepted Submission(s): 990 Problem Description soda has a set S with n integers {1,2,-,n}. A set is called key set if the sum

HDU 5895 矩阵快速幂+高次幂取模

HDU 5895 Mathematician QSC 题意:已知f(n)=2*f(n-1)+f(n-2), g(n)=∑f(i)²(0<=i<=n), 给出n,x,y,s, 求x^(g(n*y))%(s+1); 思路:OEIS查到了g(n)=f(n)*f(n+1)/2, f(n)可以用矩阵快速幂求得, 有一个定理可以用于高次幂取模 x^n %k=x^(n%phi(k)+phi(k)) %k, 此处phi(x)为欧拉函数,但是在对幂次取模时存在一个除2, 又因为(a/b)%k=(a%bk)/b,

hdu 3037 Saving Beans 组合数取模模板题。。

Saving Beans Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2707    Accepted Submission(s): 1014 Problem Description Although winter is far away, squirrels have to work day and night to save b

HDU - 1061 - Rightmost Digit (快速幂取模!)

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 34329    Accepted Submission(s): 13091 Problem Description Given a positive integer N, you should output the most right digit of

hdu 4291 A Short problem(矩阵+取模循环节)

A Short problem                                                          Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1785    Accepted Submission(s): 651 Problem Description According to a r

HDU 5832 A water problem 【大数取模,Java 大数也不是万能的。。】

A water problem Description Two planets named Haha and Xixi in the universe and they were created with the universe beginning. There is 73 days in Xixi a year and 137 days in Haha a year. Now you know the days N after Big Bang, you need to answer whe