poj1328
来源:互联网 发布:手机单怎么预防淘宝客 编辑:程序博客网 时间:2024/06/05 19:04
做这道题目的时候参考了如下博客:http://blog.csdn.net/zhengnanlee/article/details/9613161
发现一个反例。先按照左交点排序,以三个区间为例,则有l1<l2<l3。反例为: l1<l2<r1<l3<r2<r3的情况。
不过可能是实现有问题,思路没有问题。
代码如下:
#include<iostream>
#include<algorithm>
using namespace std;
struct island
{
double a;
double b;
double left;
double right;
}A[100];
flag[100];
bool cmp(island A, island B)
{
return A.a<B.a;
}
int main()
{
memset(flag,sizeof(bool),100);
int n,r;//n为岛的数目,r为雷达的覆盖半径
int num=0;//num为需要的最小雷达数目
int i=0;
int case;
while(cin>>n&&cin>>r&&(n||r))
{
for(int i=0;i<n;i++)
cin>>A[i].a>>A[i].b;
cout<<"Case "<<case<<": "
for(int i=0;i<n;i++)
if(abs(A[i].b)>r)
{
cout<<"-1"<<endl;
return;
}
for(int i=0;i<n;i++)
{
A[i].left=A[i].a-sqrt(pow((double)r,2)-pow((double)A[i].b,2)));
A[i].right=-A[i].left+2*A[i].a;
}
sort(A,A+n,cmp);
for(int i=0;i<n;i++)
{
if(A[i+1].left<=A[i].right)
{
A[i+1].right=min(A[i+1].right,A[i].right);
continue;
}
else
num++;
}
cout<<"Case "<<case<<": "<<num<<endl;
case++;
}
return 0;
}
- POJ1328
- poj1328
- POJ1328
- poj1328
- POJ1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- poj1328
- POJ1328
- POJ1328
- POJ1328
- poj1328
- POJ1328
- 【开源】scrapy爬取亚马逊商品评论
- ExtJs基础
- maven进阶:基础知识
- hog 图像特征提取
- linux ubuntu引导 win7
- poj1328
- 关于EPCS 分配管脚的问题
- (hdu step 1.3.6)Wooden Sticks(求长度和重量都严格递增的数列的个数)
- DeepLearning tutorial(5)CNN卷积神经网络应用于人脸识别(详细流程+代码实现)
- 完整的可按年份和月份查询数据并显示
- Spring MVC 表单控制器实现验证用户登录验证
- POJ 2458 Highways
- UVA 11695 Flight Planning 修改一条边使得树的直径最短
- python第四天