题目链接:

Fire-Control System

Time Limit: 12000/5000 MS (Java/Others)   

 Memory Limit: 32768/32768 K (Java/Others)

Problem Description
A new mighty weapon has just been developed, which is so powerful that it can attack a sector of indefinite size, as long as the center of the circle containing the sector is the location of the weapon. We are interested in developing a fire-control system that calculates firing-solutions automatically.
The following example gives an example of a firing solution:
Figure 1

Here the firing region is the sector "ABC" that covers six points: A, B, C, D, E, H. You may further assume that the weapon is always located at point (0, 0), no targets will be on the point (0, 0) and the coordinates of the targets will be distinct.
A firing solution is called effective if and only if it covers a minimum of K points
out of N given points (targets) on the two-dimensional Cartesian plane. Furthermore,since the cost of a particular fire solution is in direct proportion to the size of the area it covers, a firing could be quite costly; thus we are only interested in the optimal firing solution with the minimum cost.
 
Input
There are multiple test cases in the input file.
Each test case starts with two non-negative integers, N and K
(1 ≤ N ≤ 5000 , K ≤ N ), followed by N lines each containing two integers, X, and Y, describing the distinct location of one target. It is guaranteed that the absolute value of any integer does not exceed 1000.
Two successive test cases are separated by a blank line. A case with N = 0 and K = 0 indicates the end of the input file, and should not be processed by your program.
 
Output
For each test case, please print the required size (to two decimal places), in the
format as indicated in the sample output.
 
Sample Input
 
3 1
0 1
1 0
-5 -6
3 2
0 2
2 0
-5 -6
0 0
 
Sample Output
 
Case #1: 0.00
Case #2: 3.14

题意:

给n个点,找出一个圆心在(0,0)的扇形,至少覆盖k个点,使得扇形的面积最小;

思路:

枚举半径r,找到与原点距离小于等于r的点,这些点极角排序后看覆盖k个点的面积,更新最小值就可以,在k==0的地方wa了几发;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map> using namespace std; #define For(i,j,n) for(int i=j;i<=n;i++)
#define mst(ss,b) memset(ss,b,sizeof(ss)); typedef long long LL; template<class T> void read(T&num) {
char CH; bool F=false;
for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
F && (num=-num);
}
int stk[70], tp;
template<class T> inline void print(T p) {
if(!p) { puts("0"); return; }
while(p) stk[++ tp] = p%10, p/=10;
while(tp) putchar(stk[tp--] + '0');
putchar('\n');
} const LL mod=998244353;
const double PI=acos(-1.0);
const LL inf=1e18;
const int N=1e4+10;
const int maxn=1e3+10;
const double eps=1e-4; struct node
{
int x,y;
double dis,ang;
}po[N];
int temp[N];
int cmp(node a,node b)
{
if(a.ang<b.ang)return 1;
return 0;
}
int main()
{
int Case=0;
while(1)
{
int n,k;
read(n);read(k);
if(!n&&!k)break;
printf("Case #%d: ",++Case);
For(i,1,n)
{
read(po[i].x),read(po[i].y);
po[i].ang=atan2(po[i].y,po[i].x);
po[i].dis=sqrt(po[i].x*po[i].x+po[i].y*po[i].y);
}
sort(po+1,po+n+1,cmp);
For(i,1,n)
{
po[i+n]=po[i];
po[i+n].ang+=2*PI;
}
double ans=1e18;
if(k==0)ans=0;
For(i,1,n)
{
double r=po[i].dis;
int cnt=0;
For(j,1,2*n)if(po[j].dis<=po[i].dis+eps)temp[++cnt]=j;
For(j,1,cnt)
{
if(temp[j]>n||j+k-1>cnt||temp[j+k-1]-temp[j]>=n)continue;
double angle=po[temp[j+k-1]].ang-po[temp[j]].ang;
ans=min(ans,angle*r*r/2);
}
}
printf("%.2lf\n",ans);
}
return 0;
}

  

LA-4356&&hdu-2469 (极角排序+扫描线)的更多相关文章

  1. POJ 2280 Amphiphilic Carbon Molecules 极角排序 + 扫描线

    从TLE的暴力枚举 到 13313MS的扫描线  再到 1297MS的简化后的扫描线,简直感觉要爽翻啦.然后满怀欣喜的去HDU交了一下,直接又回到了TLE.....泪流满面 虽说HDU的时限是2000 ...

  2. 【极角排序、扫描线】UVa 1606 - Amphiphilic Carbon Molecules(两亲性分子)

    Shanghai Hypercomputers, the world's largest computer chip manufacturer, has invented a new class of ...

  3. HDU 5738 Eureka(极角排序)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5738 [题目大意] 给出平面中一些点,在同一直线的点可以划分为一个集合,问可以组成多少包含元素不少 ...

  4. 【极角排序+双指针线性扫】2017多校训练七 HDU 6127 Hard challenge

    acm.hdu.edu.cn/showproblem.php?pid=6127 [题意] 给定平面直角坐标系中的n个点,这n个点每个点都有一个点权 这n个点两两可以连乘一条线段,定义每条线段的权值为线 ...

  5. HDU Always Cook Mushroom (极角排序+树状数组)

    Problem Description Matt has a company, Always Cook Mushroom (ACM), which produces high-quality mush ...

  6. 2017ACM暑期多校联合训练 - Team 7 1008 HDU 6127 Hard challenge (极角排序)

    题目链接 Problem Description There are n points on the plane, and the ith points has a value vali, and i ...

  7. 【极角排序】【扫描线】hdu6127 Hard challenge

    平面上n个点,每个点带权,任意两点间都有连线,连线的权值为两端点权值之积.没有两点连线过原点.让你画一条过原点直线,把平面分成两部分,使得直线穿过的连线的权值和最大. 就把点极角排序后,扫过去,一侧的 ...

  8. LA 4064 (计数 极角排序) Magnetic Train Tracks

    这个题和UVa11529很相似. 枚举一个中心点,然后按极角排序,统计以这个点为钝角的三角形的个数,然后用C(n, 3)减去就是答案. 另外遇到直角三角形的情况很是蛋疼,可以用一个eps,不嫌麻烦的话 ...

  9. poj2280--Amphiphilic Carbon Molecules(扫描线+极角排序+转换坐标)

    题目链接:id=2280">点击打开链接 题目大意:给出n个点的坐标.每一个点有一个值0或者1,如今有一个隔板(无限长)去分开着n个点,一側统计0的个数,一側统计1的个数,假设点在板上 ...

随机推荐

  1. Python入门--7--处理数据时学习到的东西

    一.数据导入(这里使用的是pands包) import pands as pd wenjian = pd.read_csv('路径') 二.数据变换 print wenjian.head()    # ...

  2. cmd指令

    d:  进入D盘: cd job 进入d盘名为job的文件夹:cd显示当前路径: md test创建名为test的文件夹: rd test删除名为test的文件夹: cd.>test.json创 ...

  3. Day 8 Linux之Day8

    Linux 之 Day 8 一.Linux网络原理及基础设置 1. 使用ifconfig命令来维护网络 1) ifconfig命令的功能:显示所有正在启动的网卡的详细信息或设定系统中网卡的IP地址. ...

  4. MySQL的LOOP, LEAVE 和ITERATE语句(类似Continue、Break的写法)

    和REPEAT和while语句不同,LOOP.LEAVE.ITERATE更像其他编程语言中的goto语句. LOOP要设定一个label指定循环的开始位置,而LEAVE则像其他语言中的Break会离开 ...

  5. 数据库设计三范式(3NF)

    问:当时你数据库是如何设计的? 答:当时是按照三范式规范设计的: 第一范式: 1:数据库的原子性,即保证数据库表的每一列都不可分割的 第二范式: 1:原子性,即保证数据库表的每一列都不可分割 2:表中 ...

  6. Java下接口interface前面要不要加I

    说明:加I和不加I都可以,看需要,没有强制要求. 在Java中更多是提倡不加I的,可以看下JDK的源码,都是不加I的. 微软C#是规定要加I,这也是影响从而导致有这个话题的原因. Java中特定不直接 ...

  7. 多个Nginx如何实现集群(没具体方案,只是初步探究)

    场景: Nginx+Web服务器可以实现负载均衡,但是一台Nginx也是有限的,如果并非量高的话,在他的上层如何实现负载均衡. 如果是DNS或者CDN的话,建多个机房,势必有多个机房数据同步的问题. ...

  8. BS版代码生成器 简介

    自用的代码生成器 核心:JdbcTemplate+freemarker 目前支持sqlserver和mysql 演示: 1.首界面 2.读数据库中的所有表 3.打开某数据库下的所有表.视图.存储过程 ...

  9. 【面试 AOP】【第八篇】AOP的问题

    1.AOP的原理以及应用场景 面向切面编程,不修改原有代码逻辑的情况下进行逻辑增强. 使用场景:短信业务,restful返回统一响应体等等. ============================= ...

  10. 使用java连接AD域,验证账号密码是否正确

    eb项目中有时候客户要求我们使用ad域进行身份确认,不再另外做一套用户管理系统.其实客户就是只要一套账号可以访问所有的OA,CRM等办公系统.这就是第三方验证.一般有AD域,Ldap,Radius,邮 ...