先看一些推导:
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
int c[20], p[20], l[20];
void exgcd(int a, int b, int &x, int &y, int &d)
{
if (b == 0)
{
d = a, x = 1, y = 0;
return;
}
else
{
exgcd(b, a%b, y, x, d);
y -= a / b*x;
}
}
bool getans(int a, int b, int m,int x1,int x2)
{
int x, y, gcd;
exgcd(a, m, x, y, gcd);
if (b%gcd != 0)return true;
int mm = m / gcd;
if (mm<0)mm = -mm;
x = x*(b / gcd);
x = ((x%mm) + mm) % mm;
return x>min(x1, x2);
}
bool istrue(int m)
{
for (int i = 0; i < n; i++)
{
for (int j = i + 1; j < n; j++)
{
if (!getans(p[i] - p[j], c[j] - c[i], m, l[i], l[j]))
return false;
}
}
return true;
}
int main()
{
scanf("%d", &n);
int j=-1;
for (int i = 0; i < n; i++)
{
scanf("%d%d%d", &c[i], &p[i], &l[i]);
j = max(j, c[i]);
}
for (;j<=1000000; j++)
if (istrue(j))
break;
printf("%d\n", j);
return 0;
}