NOI2002 荒岛野人

这题其实黑书上有,只是我脑残的没想起来……

其实就是拓展欧几里得算法

我参看的题解:http://www.cnblogs.com/Rinyo/archive/2012/11/25/2788373.html

还有一个讲解的很清楚的exgcd:http://www.cnblogs.com/Rinyo/archive/2012/11/25/2787419.html

代码:

 var c,p,l:array[..] of longint;
ans,now,n,i,j,d,x,y,pp,cc:longint;
flag:boolean;
function min(x,y:longint):longint;
begin
if x<y then exit(x) else exit(y);
end;
function max(x,y:longint):longint;
begin
if x>y then exit(x) else exit(y);
end;
function exgcd(a,b:longint;var x,y:longint):longint;
var t,d:longint;
begin
if b= then
begin
x:=;y:=;exit(a);
end;
d:=exgcd(b,a mod b,x,y);
t:=x;x:=y;y:=t-(a div b)*y;
exit(d);
end;
procedure main;
begin
readln(n);
for i:= to n do
begin
readln(c[i],p[i],l[i]);
ans:=max(ans,c[i]);
end;
while true do
begin
flag:=true;
for i:= to n- do
begin
for j:=i+ to n do
begin
pp:=p[i]-p[j];cc:=c[j]-c[i];
d:=exgcd(pp,ans,x,y);
if cc mod d<> then continue;
now:=x*cc div d;
now:=now mod (ans div d);
if now< then inc(now,abs(ans div d));
if now<=min(l[i],l[j]) then begin flag:=false;break;end;
end;
if not(flag) then break;
end;
if flag then break;
inc(ans);
end;
writeln(ans);
end;
begin
main;
end.

我要开始刷noi历年题了!我相信我一定能够坚持下来!

上一篇:在Linux(Centos7)上使用Docker运行.NetCore


下一篇:遍历input。select option 选中的值