poj1328 区间贪心 <挑战程序设计竞赛>
2018-01-31 16:46
417 查看
2018-1-31
其实就是贪心,每次将所选的点尽可能的向右,那么我们所需的就会尽可能的少了。。。
其实就是贪心,每次将所选的点尽可能的向右,那么我们所需的就会尽可能的少了。。。
#include<iostream> #include<algorithm> #include<cmath> #define MIN 1e-5 using namespace std; const int N = 1000; struct zb{ double xz,xy; }s[N+1]; int n,r; //计算出可以覆盖该岛屿的发射器的坐标左右边界 void cal(int i,double p,double q){ double d=sqrt(r*r-q*q); s[i].xz=p-d; s[i].xy=p+d; } //按照右边界进行排序 bool cmp(struct zb a,struct zb b){ return a.xy<b.xy; } int main(){ int cnt=1; double p,q; while(cin>>n>>r){ if (n==0&&r==0) break; bool flag=false; for (int i=1;i<=n;i++){ cin>>p>>q; if (q>r||q<0){ flag=true; continue; } cal(i,p,q); } //所给数据不可能有解的情况,不能直接输出然后continue,而是要等待它输出完 if (flag){ cout<<"Case "<<cnt<<": -1"<<endl; cnt++; continue; } if (n==0||n==1){ cout<<"Case "<<cnt<<": "<<n<<endl; cnt++; continue; } sort(s+1,s+n+1,cmp);//排序 int res=0,i=1; double ee=s[1].xy; while (i<=n){ while (s[i].xz<=ee&&i<=n){ i++; } if (i<=n) ee=s[i].xy; res++; } cout<<"Case "<<cnt<<": "<<res<<endl; cnt++; } return 0; }
相关文章推荐
- poj2376 区间贪心 <挑战程序设计竞赛>
- poj2393 其它贪心 <挑战程序设计竞赛>
- poj3190 区间贪心 <挑战程序设计竞赛>
- poj2456 二分搜索 <挑战程序设计竞赛>
- 挑战程序设计竞赛里面的部分题目<用java写的>
- poj3320 尺取法 <挑战程序设计竞赛>
- poj1979 深度优先搜索 <挑战程式设计竞赛>
- 挑战程序设计竞赛 POJ 2431 贪心+优先队列
- poj2385 基础的动态规划算法 <挑战程序设计竞赛>
- poj3061 尺取法 <挑战程序设计竞赛>
- poj3279 反转 <挑战程序设计竞赛>
- [挑战程序设计竞赛] POJ 1328 - Radar Installation
- poj3050 穷竭搜索 <挑战程序设计竞赛>
- poj2229 基础的动态规划算法 <挑战程序设计竞赛>
- POJ - 1328 Radar Installation 安装雷达 贪心+区间选点 重庆一中高2018级竞赛班第八次测试 2016.8.7 Problem 3
- poj3176 基础的动态规划算法 <挑战程序设计竞赛>
- POJ 1328 区间覆盖 贪心
- (HDU 5929)Basic Data Structure 双端队列+模拟 <2016CCPC东北地区大学生程序设计竞赛 - 重现赛 >
- POJ1328-贪心-区间选点问题
- POJ1328 Radar Installation (区间选点问题,贪心)