hdoj Airport 5046 () 好题

211 篇文章 1 订阅

Airport

Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1534    Accepted Submission(s): 486


Problem Description
The country of jiuye composed by N cites. Each city can be viewed as a point in a two- dimensional plane with integer coordinates (x,y). The distance between city i and city j is defined by d ij = |x i - x j| + |y i - y j|. jiuye want to setup airport in K cities among N cities. So he need your help to choose these K cities, to minimize the maximum distance to the nearest airport of each city. That is , if we define d i(1 ≤ i ≤ N ) as the distance from city i to the nearest city with airport. Your aim is to minimize the value max{d i|1 ≤ i ≤ N }. You just output the minimum.

Input
The first line of the input is T (1 ≤ T ≤ 100), which stands for the number of test cases you need to solve.

The first line of each case contains two integers N ,K (1 ≤ N ≤ 60,1 ≤ K ≤ N ),as mentioned above.

The next N lines, each lines contains two integer x i and y i (-10 9 ≤ x i, y i ≤ 10 9), denote the coordinates of city i.

Output
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning. Then a single integer means the minimum.

Sample Input
  
  
2 3 2 0 0 4 0 5 1 4 2 0 3 1 0 3 0 8 9

Sample Output
  
  
Case #1: 2 Case #2: 4
 
唉,写了一早上,都没写出来。。
先贴个错的代码,明天再看
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#define INF 0x3f3f3f3f
#define ll long long
using namespace std;
ll sum[110];
ll a[110][110];
struct zz
{
	ll x;
	ll y;
}q[1010];
int main()
{
	int t,T=1;
	int n,m,i,j,k,kk;
	scanf("%d",&t);
	while(t--)
	{		
		scanf("%d%d",&n,&k);
		for(i=0;i<n;i++)
			scanf("%lld%lld",&q[i].x,&q[i].y);
		//sort(q,q+n,cmp);
		memset(a,0,sizeof(a));
		memset(sum,0,sizeof(sum));
		for(i=0;i<n;i++)
		{
			kk=0;
			for(j=0;j<n;j++)
			{
				a[i][kk++]=abs(q[i].x-q[j].x)+abs(q[i].y-q[j].y);
			}
		}
		for(i=0;i<n;i++)
			sort(a[i],a[i]+kk);
		for(i=0;i<n;i++)
		{
			for(j=0;j<kk;j++)
			{
				printf("%d ",a[i][j]);
			}
			printf("\n");
		}
		
		int m=0;
		for(i=0;i<n;i++)
			sum[m++]=a[i][kk-k];
		sort(sum,sum+m);
			printf("Case #%d: %lld\n",T++,sum[0]);
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值