C题
2015-08-10 10:16
218 查看
C - C
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescriptionAssume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d<tex2html_verbatim_mark> distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d<tex2html_verbatim_mark> .We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark> -axis. The sea side is above x<tex2html_verbatim_mark> -axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x<tex2html_verbatim_mark> - y<tex2html_verbatim_mark>coordinates.
Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %lluDescriptionAssume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d<tex2html_verbatim_mark> distance, so an island in the sea can be covered by a radius installation, if the distance between them is at most d<tex2html_verbatim_mark> .We use Cartesian coordinate system, defining the coasting is the x<tex2html_verbatim_mark> -axis. The sea side is above x<tex2html_verbatim_mark> -axis, and the land side below. Given the position of each island in the sea, and given the distance of the coverage of the radar installation, your task is to write a program to find the minimal number of radar installations to cover all the islands. Note that the position of an island is represented by its x<tex2html_verbatim_mark> - y<tex2html_verbatim_mark>coordinates.
#include<stdio.h> #include<iostream> #include<math.h> #include<algorithm> using namespace std; struct node { double l,r; }; node a[1010]; int cmp(node a,node b) { return a.l<b.l; } int main() { int n,d; int x,y,f,t; int s=0; while(cin>>n>>d&&n&&d) { f=1; t=1; s++; for(int i=0; i<n; i++) { cin>>x>>y; if(y>d)f=0; else { a[i].l=(double)x-sqrt((double)d*d-y*y); a[i].r=(double)x+sqrt((double)d*d-y*y); } } if(f==0) { cout<<"Case "<<s<<": -1"<<endl; continue; } sort(a,a+n,cmp); double p=a[0].r; for(int i=1; i<n; i++) { if(a[i].r<p) p=a[i].r; else if(p<a[i].l) { p=a[i].r; t++; } } cout<<"Case "<<s<<": "<<t<<endl; } return 0; }View Code
相关文章推荐
- openwrt下载编译
- 查看 SELinux状态及关闭SELinux
- Common Subsequence
- 一个简单的springMVC的定时任务实例
- Avoid passing null as the view root (needed to resolve layout parameters on the inflated layout's ro
- 使用JDeveloper 11g 发布EJB3.0
- facebook的Android调试工具Stetho介绍
- C++_inline内联函数
- 利用css样式画各种图形--初步、进阶、高级(一)
- 最长公共子序列(Longest common subsequence)
- UIScrollView - 点击跳转
- [转载]【电子书下载神器】太给力了!你还找不到想要的电子书吗?
- 声卡常见故障处理
- 【Android UI】TabHos之基础实现
- BorderLayout的布局
- Windows编译64位QT并使用VS2010开发
- 使用JDeveloper 11g 发布Web应用(基于ADF、EJB、JPA、JSF)
- 计蒜客 难题题库 217 阶乘
- 早找癌准吗?慈铭体检“Hsp90α(早找癌)”肿瘤筛查的准确度高吗
- Android利用Intent与其他应用交互