hdu 4596 (数论)

题目大意:给定若干组x,y,z,问是否能找到一个整数d,使得至少两组x,y,z满足y≤d%x≤z。


解题思路:首先枚举出两组x,y,z。

然后判断这两组是否能找到一个d,使得满足题目条件。

现在假设a、b,有a*x1+y1≤d≤a*x1+z1和b*x2+y2≤d≤b*x2+z2;

若两段区间有交集,必有a*x1+y1≤b*x2+z2且b*x2+y2a*x1+z1

化简得a*x1-b*x2≤z2-y1 且a*x1-b*x2≥y2-z1;

若a,b有整数解,根据拓展欧几里得定理ax1+bx2=u有整数解的情况为u/gcd(x1,x2)==0;

所以若存在y2-z1≤u≤z2-y1,使得u/gcd(x1,x2)==0即可。

//  Created by Chenhongwei on 2016-05-01 Sunday 12:24
//  Copyright (c) 2016 Chenhongwei. All rights reserved.

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#define root 1,n,1
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+100;
typedef long long ll;
typedef unsigned long long ull;
ll n;
ll a[1100],b[1100],c[1100];
ll gcd(ll x,ll y)
{
	if(y==0)
		return x;
	else
		return gcd(y,x%y);
}
bool check(int x,int y)
{
	ll tt=gcd(a[x],a[y]);
	ll left=b[y]-c[x];
	ll right=c[y]-b[x];
	if(left%tt==0||right%tt==0)
		return true;
	if(left<=0&&right>=0)
		return true;
	if(right/tt-left/tt>=1)
		return true;
	return false;
}
int main()
{
	//ios::sync_with_stdio(false);
    // freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	while(scanf("%lld",&n)!=EOF)
	{
		for(int i=1;i<=n;i++)
			scanf("%lld%lld%lld",&a[i],&b[i],&c[i]);
		bool flag=0;
		for(int i=1;i<=n;i++)
		{
			for(int j=i+1;j<=n;j++)
				if(check(i,j))
				{
					flag=1;
					break;
				}
			if(flag)
				break;
		}
		if(!flag)
			puts("Can Take off");
		else
			puts("Cannot Take off");
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值