poj1328Radar Installation
来源:互联网 发布:anywhereanything源码 编辑:程序博客网 时间:2024/06/11 21:10
http://poj.org/problem?id=1328
按右端点升序排序。
贪心,每次贪心选取“右端点”,实在取不到交集,雷达个数才加一。
然后再贪心的选取“右端点”,重复上述过程。
<span style="font-size:18px;">#include <stdio.h>#include <stdlib.h>#include <math.h>//gcc -o xxx xxx.c -lmtypedef struct node{ double x,y;}Node;int compare(const void*elem1,const void* elem2){ Node*p1,*p2; p1=(Node*)elem1; p2=(Node*)elem2; if((p1->y==p2->y))//主序相等 { if((p1->x-p2->x)>0) return 1; else if((p1->x-p2->x)==0) return 0; else return -1; } else if((p1->y-p2->y)<0) return -1;//主序按区间右端点升序排序 else return 1;}int main(){ int n,d,t1,t2,i,tag,count=1,num; double t,temp; Node section[1005];//雷达区间 while(scanf("%d %d",&n,&d)!=EOF) { if(n==0||d==0) break; tag=0; if(d<0)//雷达辐射半径小于0 tag=1; for(i=0;i<n;i++) { scanf("%d %d",&t1,&t2);//岛屿坐标 t=sqrt(d*d-t2*t2); section[i].x=t1-t; section[i].y=t1+t; if(t2>d||t2<0)//岛屿纵坐标超过辐射半径,岛屿纵坐标小于0 tag=1; } if(tag) { printf("Case %d: -1\n",count++); continue; } qsort(section,n,sizeof(Node),compare); temp=section[0].y; num=1; for(i=1;i<n;i++) { if(section[i].x>temp) { num++; temp=section[i].y; } } printf("Case %d: %d\n",count++,num); } return 0;}</span>
0 0
- poj1328Radar Installation
- poj1328Radar Installation
- poj1328Radar Installation
- POJ1328Radar Installation
- POJ1328Radar Installation
- poj1328Radar Installation(贪心)
- poj1328Radar Installation解题报告
- poj1328radar installation 【贪心】
- poj1328Radar Installation 贪心
- poj1328Radar Installation--贪心
- POJ1328Radar Installation(贪心)
- poj1328Radar Installation (贪心)
- poj1328Radar Installation(贪心+区间选择)
- POJ1328Radar Installation(贪心,区间)
- poj1328Radar Installation(贪心—区间选点)
- .NET Installation
- apache installation
- SAProuter Installation
- 06-图1 列出连通集 (25分)
- ubuntu上ssh免登陆
- 删除一个无头单链表的非尾节点
- CodeForces 321A Ciel and Robot
- Android中获取系统通讯录联系人并显示在EditText
- poj1328Radar Installation
- 安卓初识基本控件_AutoCompleteTextView
- WIN10中运行ASP项目出错
- 【白帽子讲web安全】关于XSS,CSRF,SQL注入
- Android_ListView_BaseAdapter
- Linux系统设置静态IP地址
- 使用Agera,gson,okhttp获取豆瓣读书数据
- C++中父类成员变量和子类成员变量重复定义及访问方法的深入探究
- php函数ob_start()、ob_end_clean()、ob_get_contents()