LA4356

la上不去了,给杭电的链接:

http://acm.hdu.edu.cn/showproblem.php?pid=2469

要去上课了,题解先不写了- -

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

#define pi acos(-1.0)

typedef struct point
{
    int x, y;
    int r;
    double theta;
} p;

bool operator <(p a,p b)
{
    return a.theta < b.theta;
}

int main()
{
    ios::sync_with_stdio(false);

    int N,K;
    int count_of_case = 0;

    while(cin>>N>>K && (N || K))
    {
        int t = N;
        vector<p> a;
        p temp;
        while(t--)
        {
            cin>>temp.x>>temp.y;
            temp.r = temp.x*temp.x + temp.y*temp.y;
            temp.theta = atan2((double)temp.y,(double)temp.x);
            a.push_back(temp);
        }
        if(!K)
        {
            printf("Case #%d: 0.00\n",++count_of_case);
            continue;
        }

        sort(a.begin(),a.end());
        
        double ans = 1 << 30;
        double angle;

        double b[5000];

        printf("Case #%d: ",++count_of_case);

        for(int i=0; i<N; i++)
        {
            int n=0;
            for(int j=0; j<N; j++)
            {
                if(a[j].r<=a[i].r)
                {
                    b[n++]=a[j].theta;
                }
            }
            if(n<K)
            {
                continue;
            }
            for(int j=0, k = K - 1; j<n; j++,k++)
            {
                if(k<n)
                {
                    angle=b[k]-b[j];
                }
                else
                {
                    angle=b[k-n]-b[j]+pi*2;
                }
                ans=min(ans,.5*angle*a[i].r);
            }
        }
        printf("%.2f\n",ans);
    }
}


你可能感兴趣的:(uva,ACM题解报告)