zoukankan      html  css  js  c++  java
  • K Yet another end of the world(2013南京邀请赛K题)

    K - Yet another end of the world

    时间限制: 5000 Ms
    内存限制: 65535 Kb

    问题描述

    In the year 3013, it has been 1000 years since the previous predicted rapture. However, the Maya will not play a joke any more and the Rapture finally comes in. Fortunately people have already found out habitable planets, and made enough airships to convey all the human beings in the world. A large amount of airships are flying away the earth. People all bear to watch as this planet on which they have lived for millions of years. Nonetheless, scientists are worrying about anther problem…

    As we know that long distance space travels are realized through the wormholes, which are given birth by the distortion of the energy fields in space. Airships will be driven into the wormholes to reach the other side of the universe by the suction devices placed in advance. Each wormhole has its configured attract parameters, X, Y or Z. When the value of ID%X is in [Y,Z], this spaceship will be sucked into the wormhole by the huge attraction. However, the spaceship would be tear into piece if its ID meets the attract parameters of two wormholes or more at the same time.

    All the parameters are carefully adjusted initially, but some conservative, who treat the Rapture as a grain of truth and who are reluctant to abandon the treasure, combine with some evil scientists and disrupt the parameters. As a consequence, before the spaceships fly into gravity range, we should know whether the great tragedy would happen or not. Now the mission is on you.

    输入说明

    Multiple test cases, ends with EOF.
    In each case, the first line contains an integer N(N<=1000), which means the number of the wormholes. 
    Then comes N lines, each line contains three integers X,Y,Z(0<=Y<=Z<X<2*10^9).

    输出说明

    If there exists danger, output “Cannot Take off”, else output “Can Take off”.

    输入样例

    2
    7 2 3
    7 5 6
    2
    7 2 2
    9 2 2

    输出样例

    Can Take off
    Cannot Take off
    

    题目链接:http://icpc.njust.edu.cn/Contest/194/Problem/K


    题目意思挺难理解的。
    其实就是给了n组X[i],Y[i],Z[i].0<=Y[i]<=Z[i]<X[i]<2*10^9

    其实就是确定有没有两个不同的i,j.(i!=j)

    使得存在一个ID (0<=ID<inf) 满足

    Y[i]<=ID%X[i]<=Z[i]
    Y[j]<=ID%X[j]<=Z[j]


    就是ID对X取模,落在[Y,Z]区间上

    设ID%X[i]=a, ID%X[j]=b
    那么
    存在x,y
    ID+X[i] *x =a
    ID+X[j] *y =b
    相减得到
    X[i] *x - X[j] *y =a-b;
    这个方程有解的条件就是a-b整除gcd(X[i],X[j])

    所以只要判断gcd(X[i],X[j])的倍数在一个区间上即可。

    #include <stdio.h>
    #include <algorithm>
    #include <iostream>
    #include <string.h>
    using namespace std;
    
    int gcd(int a,int b)
    {
        if(b==0)return a;
        else return gcd(b,a%b);
    }
    const int MAXN=1010;
    int X[MAXN],Y[MAXN],Z[MAXN];
    
    bool check2(int d,int l,int r)//判断d的倍数能不能在[l,r]区间上
    {
        if(l%d==0 || r%d==0)return true;
        if(r-l+1>=d)return true;
        int t1=l/d,t2=r/d;
        if(t1!=t2)return true;
        else return false;
    }
    
    bool check(int i,int j)
    {
        if(Y[i]>Z[j]||Y[j]>Z[i])
        {
            if(Z[i]<Y[j])swap(i,j);
            int d=gcd(X[i],X[j]);
            if(check2(d,Y[i]-Z[j],Z[i]-Y[j]))return true;
            else return false;
        }
        return true;
    }
    int main()
    {
        int n;
        while(scanf("%d",&n)==1)
        {
            for(int i=0;i<n;i++)
              scanf("%d%d%d",&X[i],&Y[i],&Z[i]);
            bool flag=true;
            for(int i=0;i<n;i++)
              for(int j=i+1;j<n;j++)
                if(check(i,j))
                {
                    flag=false;
                    break;
                }
            if(flag)printf("Can Take off\n");
            else printf("Cannot Take off\n");
        }
        return 0;
    }









    人一我百!人十我万!永不放弃~~~怀着自信的心,去追逐梦想
  • 相关阅读:
    laravel tinker的使用
    清空表中数据
    不要为过多思考浪费你的精力
    #tomcat#启动过程分析(上)
    #hashMap冲突原理#详细
    #数组集合知识#HashMap的实现原理
    #数据库#连接数据库的几个步骤
    #数据库#JDBC基础知识
    #数据库#查询语句 1=1的使用条件
    #tomcat#虚拟主机配置及访问(三)
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3082810.html
Copyright © 2011-2022 走看看