题意:略
思路:从小到大枚举天数,两个人在同一处只有可能如下情况:
某个同余方程(懒得写)有解且两个解都在寿命范围之内,然后如果任意两个人出现这种情况,就是会重合
代码:
#include <bits/stdc++.h>
#define gc getchar()
#define N 20
using namespace std;
int n,c[N],p[N],t[N];
int Max=0;
int read()
{
int x=1;
char ch;
while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
int s=ch-48;
while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-48;
return s*x;
}
int exgcd(int x,int y,int &a,int &b)
{
if (y==0)
{
a=1,b=0;
return x;
}
int r=exgcd(y,x%y,a,b);
int tmp=a;
a=b,b=tmp-x/y*b;
return r;
}
bool check(int m)
{
int x,y,temp;
for (int i=1;i<n;i++)
for (int j=i+1;j<=n;j++)
{
int A=((p[i]-p[j])%m+m)%m,C=((c[j]-c[i])%m+m)%m;
temp=exgcd(A,m,x,y);
if (C%temp!=0) continue;
int M=m/temp;
x=(x*(C/temp)%M+M)%M;
if (x<=t[i]&&x<=t[j]) return 0;
}
return 1;
}
int main()
{
n=read();
for (int i=1;i<=n;i++)
c[i]=read()-1,p[i]=read(),t[i]=read(),Max=max(Max,c[i]+1);
for (int i=Max;;i++)
if (check(i))
{
printf("%d\n",i);
return 0;
}
return 0;
}