• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
dwtfukgv
博客园    首页    新随笔    联系   管理    订阅  订阅
HDU 4596 Yet another end of the world (数学,扩展欧几里德)

题意:给出n组x,y,z。判断是否存在一个id使得id%x1∈(y1,z1),id%x2∈(y2,z2)。

析:

设 id/x1=a , id/x2=b ,则

id-a*x1=u;   (1)

id-b*x2=v;   (2)

(1)-(2)得  一阶不定方程:  bx2-ax1=u-v .

方程可解性为是否存在 (u-v) 是gcd(x1,x2)的整数倍。

那么也就是判断y[x1]-z[x2], z[x1]-y[x2],这就是范围,然后在判断是的时候,如果两个端点能够整除,就返回真,如果两个端点除以g,

不相等,那么一定有一个数能整除g。

代码如下:

 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1000 + 5;
int x[maxn], y[maxn], z[maxn];
int n;

bool judge(int g, int l, int r){
    if(l % g == 0 || r % g == 0)  return true;
    return l / g != r / g;
}

bool solve(){
    for(int i = 0; i < n; ++i){
        for(int j = i+1; j < n; ++j){
            int  g = __gcd(x[i], x[j]);
            if(judge(g, y[i]-z[j], z[i]-y[j]))  return true;
        }
    }
    return false;
}

int main(){
    while(scanf("%d", &n) == 1){
        for(int i = 0; i < n; ++i)
            scanf("%d %d %d", &x[i], &y[i], &z[i]);
        if(solve())  puts("Cannot Take off");
        else  puts("Can Take off");
    }
    return 0;
}

 

 

 

posted on 2016-07-28 23:27  dwtfukgv  阅读(168)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3