Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:为什么没人写pascalIn Reply To:为什么没人写pascal Posted by:jinzhihan at 2013-10-19 16:06:57 有啊。。。。 var a,b,c,x,y,k,x1,y1,t1,t2:longint; function gcd(a,b:longint):longint; var t,d:int64; begin if b=0 then begin x:=1; y:=0; exit(a); end; d:=gcd(b,a mod b); t:=x; x:=y; y:=t-(a div b)*y; exit(d); end; begin readln(a,b,c); while (a<>0)or(b<>0)or(c<>0) do begin k:=gcd(a,b); x1:=x*(c div k); y1:=y*(c div k); t1:=b div k; t2:=a div k; while abs(x1+t1)+abs(y1-t2)<abs(x1)+abs(y1) do begin x1:=x1+t1; y1:=y1-t2; end; while abs(x1-t1)+abs(y1+t2)<abs(x1)+abs(y1) do begin x1:=x1-t1; y1:=y1+t2; end; while (abs(x1+t1)+abs(y1-t2)=abs(x1)+abs(y1))and (abs(a*(x1+t1))+abs(b*(y1-t2))<abs(a*x1)+abs(b*y1)) do begin x1:=x1+t1; y1:=y1-t2; end; while (abs(x1-t1)+abs(y1+t2)=abs(x1)+abs(y1))and (abs(a*(x1-t1))+abs(b*(y1+t2))<abs(a*x1)+abs(b*y1)) do begin x1:=x1-t1; y1:=y1+t2; end; writeln(abs(x1),' ',abs(y1)); readln(a,b,c); end; end. 暴力~~~~~~~~ Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator