NYOJ-12 喷水装置2(贪心 区间覆盖)
来源:互联网 发布:融资租赁软件市场 编辑:程序博客网 时间:2024/05/20 10:56
#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#define MAX 10000+1using namespace std;struct node{double left,right;};bool cmp_left(struct node a, struct node b){return a.left<b.left;}int main(){int T;int n,w,h;int count,flag;double circle_x,circle_r,half,now_len,Max;struct node a[MAX]; cin>>T;while(T--){count=0;//所需装置的个数flag=1;now_len=0;//已覆盖的长度cin>>n>>w>>h;half=h/2.000000;for(int i=0;i<n;i++){double temp;cin>>circle_x>>circle_r;temp=sqrt(circle_r*circle_r-half*half);if(temp>0){a[i].left=circle_x-temp;//左端点a[i].right=circle_x+temp;//右端点}}sort(a,a+n,cmp_left);//左端点从小到大排序while(now_len<w){Max=0;for(int i=0;i<n&&a[i].left<=now_len;i++){if((a[i].right-now_len)>Max) Max=a[i].right-now_len;//用来选出左端点满足条件的线段中,右端点最大的线段}if(Max==0){flag=0;//没有左端点符合的break;}else{count++;now_len+=Max;//更新覆盖到的区间}}if(flag==1) cout<<count<<endl;else cout<<"0"<<endl;}return 0;}
0 0
- NYOJ-12 喷水装置2(贪心 区间覆盖)
- nyoj 12 喷水装置(二) 贪心 区间覆盖
- NYOJ 12 喷水装置(二)【贪心+区间覆盖】
- NYOJ 12 喷水装置(2)贪心之区间覆盖问题
- nyoj 12 喷水装置(二)【贪心】+【区间完全覆盖覆盖】
- nyoj--12--喷水装置(二)(区间覆盖问题+贪心)
- 【喷水装置(二) 区间覆盖 贪心。】
- NYOJ 6 喷水装置(一) 贪心算法 之 区间覆盖问题
- NYOJ-----12---喷水装置(二)贪心
- NYOJ 喷水装置2 (贪心)
- NYOJ 喷水装置(二)(区间覆盖)
- 喷水装置(二) +区间覆盖-基础问题-贪心
- NYOJ——12 喷水装置(二)(区间覆盖)
- NYOJ 题目12 喷水装置(二) 最小区间覆盖问题
- 南阳 12 喷水装置(二)区间覆盖问题
- 区间全覆盖-喷水装置(2)
- 喷水装置(二)--区间覆盖问题
- NYOJ 12 喷水装置(二)(贪心算法)
- 【taotao】VMware虚拟机下安装CentOS
- css颜色属性
- c中预处理简谈
- Strom学习00---ISpout
- Hadoop入门(Hadoop2.7.2源码编译与伪分布安装)
- NYOJ-12 喷水装置2(贪心 区间覆盖)
- LeetCode 454 4Sum II 题解
- C提高(4)/const
- PHP-memcahce概念
- 272. Closest Binary Search Tree Value II
- python实现简单的图片隐写术
- redis数据对象底层结构图
- Git——Day2(git初始化及仓库创建)
- Java 读书笔记 21.1并发