Fire -Control System hdoj 2469


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <algorithm>
#include <vector>
#include <cstring>
#include <stack>
#include <cctype>
#include <utility>   
#include <map>
#include <string>  
#include <climits> 
#include <set>
#include <string> 
#include <sstream>
#include <utility>
#include <ctime>
 
using std::priority_queue;
using std::vector;
using std::swap;
using std::stack;
using std::sort;
using std::max;
using std::min;
using std::pair;
using std::map;
using std::string;
using std::cin;
using std::cout;
using std::set;
using std::queue;
using std::string;
using std::istringstream;
using std::make_pair;
using std::greater;

const int MAXN(5010);
const double INFI(1e30);
double PI;
double PI_2;

struct NODE
{
	double rad;
	int dis;
	friend bool operator < (const NODE &op1, const NODE &op2) 
	{
		return op1.rad < op2.rad;
	}
};

NODE node[MAXN*2];

int dis[MAXN];
int que[MAXN*2];



int main()
{
	PI = asin(1.0)*2;
	PI_2 = PI*2;
	int n, k, tx, ty, n_case(0);
	while(scanf("%d%d", &n, &k), n || k)
	{
		for(int i = 1; i <= n; ++i)
		{
			scanf("%d%d", &tx, &ty);
			if(tx >= 0)
			{
				if(ty >= 0)
					node[i].rad = atan(double(ty)/tx);
				else
					node[i].rad = PI_2-atan(double(-ty)/tx);
			}
			else
			{
				if(ty >= 0)
					node[i].rad = PI-atan(double(ty)/-tx);
				else
					node[i].rad = PI+atan(double(-ty)/-tx);
			}
			dis[i] = tx*tx+ty*ty;
			node[i].dis = dis[i];
		}
		if(n == 0 || k == 0)
		{
			printf("Case #%d: 0.00\n", ++n_case);
			continue;
		}
		sort(node+1, node+1+n);
		sort(dis+1, dis+1+n);
		int ind = 0;
		dis[0] = -1;
		for(int i = 1; i <= n; ++i)
			if(dis[i] != dis[ind])
				dis[++ind] = dis[i];
		int tn = n*2;
		memcpy(node+1+n, node+1, sizeof(node[0])*n);


		for(int i = n+1; i <= tn; ++i)
			node[i].rad += PI_2; 
		double ans = INFI;
		for(int i = 1; i <= ind; ++i)
		{
			int td = dis[i];
			double tans = INFI;
			int front = 1, rear = 0;
			for(int j = 1; j <= n; ++j)
				if(node[j].dis <= td)
				{
					que[++rear] = j;
					if(rear == k)
						break;
				}
			if(rear == k)
			{
				tans = node[que[rear]].rad-node[que[front]].rad;
				for(int j = que[rear]+1; j <= tn && que[front] <= n; ++j)
					if(node[j].dis <= td)
					{
						que[++rear] = j;
						++front;
						double temp = node[que[rear]].rad-node[que[front]].rad;
						if(temp < tans)
							tans = temp;
					}
				tans *= td;
				if(tans < ans)
					ans = tans;
			}
		}
		printf("Case #%d: %.2f\n", ++n_case, ans/2);
	}
	return 0;
}


你可能感兴趣的:(Fire -Control System hdoj 2469)