UVA 1432 Fire-Control System(枚举)

枚举半径,然后控制角度。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<set>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ss(x) scanf("%d",&x)
const double pi=acos(-1.0);
const int maxn=5000+10;
const int inf=0x3f3f3f3f;
struct node{
    int x,y;
    double r,c;
    int cnt;
    void get(){
        ss(x);ss(y);
        r=sqrt(x*x*1.0+y*y*1.0);
        c=atan2(y,x);
        cnt=1;
    }
}p[maxn],rec[maxn];
int n,k;
bool cmp1(const node &a,const node &b) {return a.r<b.r;}
bool cmp2(const node &a,const node &b) {return a.c<b.c;}
double solve()
{
    if(k==0) return 0;
    sort(p,p+n,cmp2);
    double ans=inf;
    set<double> v;
    rep(i,0,n){
        if(p[i].cnt<k) continue;
        double R=p[i].r,C=2*pi;
        if(v.find(R)!=v.end()) continue;
        v.insert(R);
        int tmp=0;
        rep(j,0,n){
            if(p[j].r<R||fabs(p[j].r-R)<1e-9){//精度问题,所以在半径周围1e-9的圆周内的点也算进扇形包括的点中
                rec[tmp++]=p[j];
                if(tmp>=k) C=min(C,rec[tmp-1].c-rec[tmp-k].c);
            }
        }
        if(tmp<k) continue;
        rep(j,0,k-1) C=min(C,rec[j].c-rec[tmp+j-k+1].c+2*pi);
        ans=min(ans,R*R*C/2);
    }
    return ans;
}
int main()
{
    int cas=0;
    while (true)
    {
        ss(n);ss(k);if(n+k==0) break;
        rep(i,0,n) p[i].get();
        sort(p,p+n,cmp1);
        rep(i,1,n) p[i].cnt+=p[i-1].cnt;
        printf("Case #%d: %.2lf\n", ++cas, solve());
    }
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值