POJ 1328(贪心)
2012-08-16 22:11
387 查看
贪心,区间排序
如果区间包含 略过,否则答案+1;
如果区间包含 略过,否则答案+1;
Program P1328; var n,d,i,j,k,ans:longint; x:double; tag:boolean; map:array[1..1000,1..2] of double; procedure qsort(l,r:longint); var i,j:longint; m,p:double; begin i:=l; j:=r; m:=map[(l+r) div 2,1]; repeat while map[i,1]<m do inc(i); while map[j,1]>m do dec(j); if i<=j then begin p:=map[i,1]; map[i,1]:=map[j,1]; map[j,1]:=p; p:=map[i,2]; map[i,2]:=map[j,2]; map[j,2]:=p; inc(i); dec(j); end; until i>j; if l<j then qsort(l,j); if i<r then qsort(i,r); end; begin i:=1; { assign(input,'P1328.in'); assign(output,'P1328.out'); reset(input); rewrite(output); } while not seekeof do begin tag:=true; read(n,d); if d<=0 then tag:=false; if (n=0) and (d=0) then break; j:=1; for k:=1 to n do begin read(map[j,1],map[j,2]); if map[j,2]<0 then continue; if d<map[j,2] then continue; x:=sqrt(d*d-map[j,2]*map[j,2]); map[j,2]:=map[j,1]+x; map[j,1]:=map[j,1]-x; inc(j); end; dec(j); if tag and (j=n) then begin qsort(1,j); ans:=1; x:=map[1,2]; for k:=2 to j do begin if (map[k,2]<x) then begin x:=map[k,2]; end else if (x<map[k,1]) then begin inc(ans); x:=map[k,2]; end; end; writeln('Case ',i,': ',ans); end else writeln('Case ',i,': -1'); inc(i); end; { close(input); close(output); } end.
相关文章推荐
- POJ 1328:Radar Installation 经典贪心
- poj 1328 贪心
- POJ 1328 Radar Installation(贪心)
- POJ 1328 - Radar Installation(贪心)
- poj 1328 Radar Installation (贪心选择性质,需要抽象出来才可以)
- POJ 1328 Radar Installation 贪心
- POJ 1328 Radar Installation(贪心)
- POJ_1328_Radar Installation_贪心
- POJ 1328 Radar Installation【贪心】
- POJ 1328 Radar Installation 雷达安装 贪心问题求解
- poj 1328 Radar Installation【贪心】【刷题计划】
- poj 1328 贪心 转化
- POJ1328 Radar Installation(贪心)
- poj 1328 Radar Installation (逆思维+贪心)
- poj 1328 Radar Installation_贪心
- POJ 1328 Radar Installation(贪心+区间覆盖)
- poj 1328 贪心 水题
- poj 1328 贪心
- POJ 1328 贪心
- POJ 1328 Radar Installation(贪心)