| ||||||||||
| 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 实数处理坑跌啊啊啊program poj1039;
type point=record
x,y:extended;
end;
const maxn=217;
eps=1e-9;
inf=1e9;
var pu,pl,s1,s2:array[0..maxn] of point;
n,cp,cs:longint;
t:extended;
function min(i,j:extended):extended; begin
if i<j then exit(i) else exit(j); end;
function max(i,j:extended):extended; begin
if i>j then exit(i) else exit(j); end;
function crs(a,b:point):extended;
begin
exit( a.x*b.y-b.x*a.y );
end;
function crs(a,b,c:point):extended;
begin
exit( (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y) );
end;
function intersect(p1,p2,p3,p4:point):point;
var l1:extended;
begin
p2.x:=p2.x-p1.x; p2.y:=p2.y-p1.y;
p4.x:=p4.x-p3.x; p4.y:=p4.y-p3.y;
l1:=( crs(p3,p4)-crs(p1,p4) )/( crs(p2,p4) );
with intersect do begin
x:=p1.x+p2.x*l1; y:=p1.y+p2.y*l1;
end;
end;
function check(p1,p2,p3,p4:point):boolean;
begin
exit( crs(p1,p2,p3)*crs(p1,p2,p4)<=0);
end;
function init:boolean;
var i,j:longint;
begin
readln(n); cp:=0; cs:=0;
if n=0 then exit(false);
for i:=1 to n do begin
readln(pu[i].x,pu[i].y);
pl[i].x:=pu[i].x; pl[i].y:=pu[i].y-1;
end;
end;
procedure work;
var i,j,k:longint;
flag:boolean;
ans,iy:extended;
begin
ans:=-inf;
for i:=1 to n do
for j:=1 to n do if i<>j then begin
flag:=true;
for k:=1 to n do begin
iy:=intersect(pu[i],pl[j],pu[k],pl[k]).y;
if not check(pu[i],pl[j],pu[k],pl[k]) then begin
flag:=false;
break;
end;
end;
if flag then begin
writeln('Through all the pipe.'); exit;
end;
if k>max(i,j) then begin
ans:=max(ans,intersect(pu[i],pl[j],pu[k],pu[k-1]).x);
ans:=max(ans,intersect(pu[i],pl[j],pl[k],pl[k-1]).x);
end;
end;
writeln(ans:0:200); // 输出ans 保留最大小数位数
writeln(extended(ans):0:2); // 输出ans 保留2位
end;
begin
//assign(input,'poj1039.in'); reset(input);
//assign(output,'poj1039.out'); rewrite(output);
while not seekeof do begin
if not init then break;
work;
end;
close(input); close(output);
end.
这样的程序对这个数据
3
0 -2
3 6
4 -5
0
输出
ans取最大小数位数 3.075000000000很多个0
ans取小数2位 3.07
坑跌啊啊啊 怎么搞?
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator