AcWing 944. 荒岛野人
原题链接
中等
作者:
Bzdhxs
,
2021-04-29 21:33:41
,
所有人可见
,
阅读 421
算法
(暴力枚举)
/*@author:ntttttt
to->myself->add oil!*/
#include<bits/stdc++.h>
using namespace std;
#define gcd __gcd
#define _ ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pll;
typedef pair<ll,ll> pLL;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9+7;
const int N = 20;
ll qpow(ll a, ll b){ll res = 0; while(b){if(b&1)res = a*res%mod;b >>= 1;a=a*a%mod;}return res;}
struct node{
int c,p,l;
}pe[N];
int n;
int exgcd(int a,int b,int &x,int &y)
{
if(!b)
{
x = 1,y = 0;
return a;
}
int d = exgcd(b,a%b,y,x);
y -= a/b*x;
return d;
}
int judge(int m)
{
int a,b,c;
for(int i = 1; i<= n;i++)
for(int j = i+1; j <= n;j++)
{
a = pe[j].p - pe[i].p;
b = m,c = pe[i].c - pe[j].c;
int x,y;
int d = exgcd(a,b,x,y);
if(!(c%d))
{
int r = abs(b/d);
int res = ((c/d*x)%r+r)%r;
if(res<=min(pe[i].l,pe[j].l)) return 0;
}
}
return 1;
}
int main()
{
cin >> n;
int _max = -1;
for(int i = 1; i <= n ;i++)
{
cin >> pe[i].c >> pe[i].p >> pe[i].l;
_max = max(_max,pe[i].c);
}
for(int i = _max;i;i++)
{
if(judge(i))
{
cout << i << endl;
break;
}
}
return 0;
}