zoukankan      html  css  js  c++  java
  • hdu 4596 Yet another end of the world 线性同余方程组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4596

    日本人白书P293面最上的公式

    #include <iostream>
    #include <cstdlib>
    #include <cstdio>
    #include <algorithm>
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    typedef long long ll;
    
    const int maxn = 1010;
    
    int x[maxn], y[maxn], z[maxn];
    
    int gcd(int a, int b)
    {
        if(b == 0)
            return a;
        return gcd(b, a % b);
    }
    
    int main()
    {
        //freopen("in.txt", "r", stdin);
    
        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 ans = true;
            for(int i = 0; i < n-1 && ans; i++)
                for(int j = i + 1; j < n && ans; j++)
                {
                    int e = gcd(x[i], x[j]);
                    int maxnum = max(abs(z[j] - y[i]), abs(z[i] - y[j]));
    
                    int minnum;
                    if(z[j] > z[i])
                    {
                        minnum = max(y[j] - z[i], 0);
                    }
                    else
                    {
                        minnum = max(y[i] - z[j], 0);
                    }
    
                    int k = minnum / e;
                    if(k * e == minnum)
                    {
                        ans = false;
                        break;
                    }
                    else if((k+1) * e <= maxnum)
                    {
                        ans = false;
                        break;
                    }
                }
    
            if(ans)
                printf("Can Take off
    ");
            else
                printf("Cannot Take off
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    内存相关函数
    Redis入门
    libevent(九)evhttp
    Python基础00 教程
    Python之re模块
    Makefile入门
    cmake安装jsoncpp
    awk调用date命令
    SQLite使用(二)
    SQLite使用(一)
  • 原文地址:https://www.cnblogs.com/dishu/p/4529669.html
Copyright © 2011-2022 走看看