UVALive - 4356 Fire-Control System 三角函数+暴力+剪枝
来源:互联网 发布:阿里云招聘 网络 编辑:程序博客网 时间:2024/06/11 20:49
题目大意:平面上有n个点,你的任务是以(0,0)为圆心画一个扇形,至少覆盖其中的k个点,使得该扇形的面积最小
解题思路:先把每个点和圆心的距离计算出来,然后再一次排序,统计出以此距离为半径的圆里面有多少个点(第一次剪枝)
如果该半径已经被计算过了就不用再计算了(第二次剪枝)
#include<cstdio>#include<algorithm>#include<cmath>#include<set>using namespace std;#define maxn 5010#define INF 0x3f3f3f3fconst double pi = acos(-1.0);int n, k;struct Point{int x, y, cnt;double r, c;void count() {r = sqrt(x * x * 1.0 + y * y * 1.0);c = atan2(y,x);cnt = 1;}}p[maxn], que[maxn];int cmpR(const Point a, const Point b) {return a.r < b.r;}int cmpC(const Point a, const Point b) {return a.c < b.c;}double solve() {if(k == 0)return 0;double ans = INF;set<double> s;sort(p,p+n,cmpC);for(int i = 0; i < n; i++) {if(p[i].cnt < k)continue;double R = p[i].r, C = 2 * pi;if(s.find(R) != s.end())continue;s.insert(R);int tmp = 0;for(int j = 0; j < n; j++)if(p[j].r < R || fabs(p[j].r - R) < 1e-9) {que[tmp++] = p[j];if(tmp >= k)C = min(C,que[tmp-1].c-que[tmp-k].c);}if(tmp < k)continue;for(int j = 0; j < k - 1; j++)C = min(C,que[j].c - que[tmp+j-k+1].c + 2 * pi);ans = min(ans,R * R * C / 2);}return ans;}int main(){int mark = 1;while(scanf("%d%d",&n, &k) == 2 && n + k) {for(int i = 0; i < n; i++) {scanf("%d%d",&p[i].x, &p[i].y);p[i].count();}sort(p,p+n,cmpR);for(int i = 1; i < n; i++)p[i].cnt += p[i-1].cnt;printf("Case #%d: %.2lf\n",mark++, solve());}return 0;}
0 0
- UVALive - 4356 Fire-Control System 三角函数+暴力+剪枝
- UVALive - 4356 Fire-Control System
- UVaLive LA 4356 - Fire-Control System (扫描法 思维)
- LA 4356 Fire-Control System -
- uva 1432 - Fire-Control System(枚举+剪枝)
- LA 4356 Fire-Control System (扫描法)
- LA4356 Fire-Control System
- Fire -Control System hdoj 2469
- 【暴力预处理+剪枝/bitset】Golf Bot UVALive
- HDU 2469 Fire-control System解题报告
- UVa 1432 - Fire-Control System (思维)
- UVaLive4356 Fire-Control System (扫描法)
- UVA 1432 Fire-Control System(枚举)
- UVALive 6843Volume Control(暴力压位)
- UVALive 6843 Volume Control(暴力压位)
- UVA 1432 - Fire-Control System(技巧枚举+线性扫描)
- UVALive 5066 Fire Drill
- UVa 1432 Fire-Control System 解题报告(离散化 + 扫描)
- 数据库插入数据时间比较
- 革工程团队应对移动转型
- Java并发编程】之四:守护线程与线程阻塞的四种情况
- 00-自测3. 数组元素循环右移问题 (20)
- Linux程序设计(Linux shell编程五)
- UVALive - 4356 Fire-Control System 三角函数+暴力+剪枝
- Java虚拟机之运行时数据区域
- Android应用程序的打包与发布
- Thrift 多线程阻塞式IO服务模型-TThreadPoolServer
- 【学习笔记】信息系统项目监理“四控三管一协调”以及监理工作的分类和监理单位的作用
- 微信关注公众账号的QR_LIMIT_STR_SCENE问题
- 基础算法之贪心算法
- LayoutInflater的使用
- “三位一体”新颖教学方式,助你学得更快更好 2014年是传智播客上海校区飞速发展的一年,更是上海传智历史里程碑的一年。在过去的一年里,上海传智广招实力师资,组建了上海校区的教学团队,学生规模实现100