zoukankan      html  css  js  c++  java
  • ACM南京邀请赛Yet another end of the world数学题

    Yet another end of the world

    Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 0    Accepted Submission(s): 0

    Problem Description
    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.
     
    Input
    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*109).
     
    Output
    If there exists danger, output “Cannot Take off”, else output “Can Take off”.
     
    Sample Input
    2
    7 2 3
    7 5 6
    2
    7 2 2
    9 2 2
     
    Sample Output
    Can Take off
    Cannot Take off
     
     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <cmath>
     5 #include <cstdlib>
     6 #include <algorithm>
     7 #include <vector>
     8 #include <stack>
     9 #include <queue>
    10 #include <cassert>
    11 #include <set>
    12 #include <sstream>
    13 #include <map>
    14 #include <bitset>
    15 using namespace std ;
    16 #define zero {0}
    17 #define INF 2000000000
    18 #define eps 1e-6
    19 #define maxn 1005
    20 int x[maxn];
    21 int y[maxn];
    22 int z[maxn];
    23 
    24 bool is(int i,int j)
    25 {
    26     int r,l;
    27     if(y[i]>z[j]||y[j]>z[i])
    28     {
    29         if(y[j]>z[i])
    30         swap(i,j);
    31         r=z[i]-y[j];
    32         l=y[i]-z[j];
    33         int xx=__gcd(x[i],x[j]);
    34         int k=1;
    35         if((l/xx)*xx<=r&&(l/xx)*xx>=l)
    36         return true;
    37         if((l/xx+1)*xx>=l&&(l/xx+1)*xx<=r)
    38         return true;
    39         return false;
    40     }
    41     else
    42     return true;
    43 }
    44 int main()
    45 {
    46     #ifdef DeBUG
    47         freopen("C:\Users\Sky\Desktop\1.in","r",stdin);
    48     #endif
    49     int n;
    50     while(scanf("%d",&n)+1)
    51     {
    52         int i,j,k;
    53         int _flag=1;
    54         for(i=0;i<n;i++)
    55         scanf("%d %d %d",&x[i],&y[i],&z[i]);
    56         for(i=0;i<n;i++)
    57         {
    58             for(j=i+1;j<n;j++)
    59             {
    60                 if(is(i,j))
    61                 {
    62                     _flag=0;
    63                     break;
    64                 }
    65             }
    66         }
    67         if(_flag)
    68         printf("Can Take off
    ");
    69         else
    70         printf("Cannot Take off
    ");
    71     }
    72     return 0;
    73 }
    View Code

    此题印证了数学思路的重要性,数学题只要方向对了代码没几行的,判断gcd(x1,x2)的倍数在区间里可以O(1)的,结果SB的TLE三次

     
  • 相关阅读:
    FileSystemWatcher用法详解【转】
    关于TransactionScope事务的TransactionScopeOption的实例
    TransactionScope IsolationLevel 事务隔离级别
    C#中TransactionScope的使用方法和原理
    关于Qt 静态成员函数调用信号
    【Qt编程】基于QWT的曲线绘制及图例显示操作——有样点的实现功能
    使用qwt作曲线图——有网格线背景的画法
    Qt程序app添加图标复制到其它电脑后不显示的解决方法
    QUrl的使用,特别是对含特殊字符的字符串进行 URL 格式化编码
    QDateTime 本地时间和UTC时间转换问题
  • 原文地址:https://www.cnblogs.com/Skyxj/p/3264998.html
Copyright © 2011-2022 走看看