Yet another end of the world
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 1106 Accepted Submission(s): 465
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.
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).
2 7 2 3 7 5 6 2 7 2 2 9 2 2
Can Take off Cannot Take off题目大意:给出n组x,y,z,问是否存在一个数ID,使得ID % xi = a , ID % xj = b, 并且有yi <= a <= yj, xj <= b <= zj。思路:设ID = k1*xi + a, ID = k2 * xj + b, 二式相减得一不定方程k2 * xj - k1 * xi = a - b。该方程有整数解的条件是(a - b) % gcd(xi, xj) == 0,a - b的范围是[yi-zj, zi-yj],则只要判断这个区间内是否存在能整除gcd(xi, xj)的数即可#include<cstdio> #include<cstring> #include<vector> #include<cmath> #include<iostream> #include<algorithm> #include<queue> using namespace std; typedef long long ll; const int INF = 1e9+10; const int maxn = 1000; ll x[maxn], y[maxn], z[maxn]; int n; ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); } bool attract(ll g, ll L, ll R) { if (L % g == 0 || R % g == 0) return true; if (L / g != R / g) return true; return false; } bool solve() { for (int i = 0; i < n; i++) { for (int j = i+1; j < n; j++) { ll g = gcd(x[i], x[j]); if (attract(g, y[i] - z[j], z[i] - y[j])) return false; } } return true; } int main() { while(scanf("%d",&n) == 1) { for (int i = 0; i < n; i++) scanf("%I64d %I64d %I64d", x+i, y+i, z+i); if (solve()) printf("Can Take off\n"); else printf("Cannot Take off\n"); } }
633



被折叠的 条评论
为什么被折叠?



