| ||||||||||
| 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 | |||||||||
pascal的ac代码{RE了N多次,后来发现原因之后我囧了。。。。}
var
ii, i, j, k, n, test: longint;
x, y: array[0..5001] of longint;
dis, len, ans, tmp: longint;
f: array[0..1000001] of longint;
function work(i: longint): longint;
var
t, t1, t2: int64;
begin
t := i;
t1 := t*t; //就是这儿RE,一开始直接t1 := i*i,然后华丽丽的RE了
t := i-y[1];
t2 := t*t;
t := trunc(sqrt(t1-t2));
exit(t);
end;
begin
readln(test);
for ii := 1 to test do begin
readln(n);
for i := 1 to n do readln(x[i],y[i]);
fillchar(f,sizeof(f),100);
ans := maxlongint;
tmp := f[1];
f[x[1]] := 0;
len := x[n];
for i := 2 to n do begin
dis := work(y[i]);
for j := x[i]-dis to x[i]-1 do begin
if (j>=0) and (2*x[i]-j<len) then
if f[2*x[i]-j]>f[j]+1 then f[2*x[i]-j] := f[j]+1;
if (j>=0) and (2*x[i]-j>=len) then
if f[j]+1<ans then ans := f[j]+1;
end;
end;
if ans>=tmp then ans := -1;
writeln(ans);
end;
end.
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator