59: loj #10215

Posted shandongs1

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了59: loj #10215相关的知识,希望对你有一定的参考价值。

$des$

https://loj.ac/problem/10215

$sol$

技术分享图片

exgcd检查

$code$

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

using namespace std;

#define gc getchar()
inline int read() {
    int x = 0; char c = gc;
    while(c < 0 || c > 9) c = gc;
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, c = gc;
    return x;
}

#define LL long long

const int N = 20;

LL C[N], P[N], L[N];
int n;
int M = 1e6;

LL Exgcd(LL a, LL b, LL &x, LL &y) {
    if(b == 0) {
        x = 1, y = 0; return a;
    }
    LL gg = Exgcd(b, a % b, x, y);
    LL tmp = x;
    x = y, y = tmp - a / b * y;
    return gg;
}

bool Solve(LL k) {
    for(int i = 1; i <= n; i ++) {
        for(int j = i + 1; j <= n; j ++) {
            LL c1 = C[i], c2 = C[j], p1 = P[i], p2 = P[j], x, y;
            LL b = p1 - p2, d = c2 - c1;
            if(b < 0) b = -b, d = -d;
            LL g = Exgcd(b, k, x, y);
            if(d % g) continue;
            x *= (d / g);
            LL r = k / g;
            while(x < 0) x += r;
            x %= r;
            if(x <= min(L[i], L[j])) return 0;
        }
    }
    return 1;
}

int main() {
    n = read();
    LL Max = 0;
    for(int i = 1; i <= n; i ++)
        C[i] = read(), P[i] = read(), L[i] = read(), Max = max(Max, C[i]);
    int a;
    for(a = Max; a <= M; a ++) {
        if(Solve(1ll * a)) {
            cout << a; return 0;
        }
    }
    
    return 0;
}

 

以上是关于59: loj #10215的主要内容,如果未能解决你的问题,请参考以下文章

Xcode 4.6 的备份代码片段

在代码片段中包含类型转换

如何通过单击片段内的线性布局从片段类开始新活动?下面是我的代码,但这不起作用

在 Python 多处理进程中运行较慢的 OpenCV 代码片段

Loj 6285. 数列分块入门 9

ASP.net MVC 代码片段问题中的 Jqgrid 实现