hdoj Airport 5046 () 好题
来源:互联网 发布:ghgvh软件 编辑:程序博客网 时间:2024/05/21 20:07
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 dij = |xi - xj| + |yi - yj|. 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 di(1 ≤ i ≤ N ) as the distance from city i to the nearest city with airport. Your aim is to minimize the value max{di|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 xi and yi (-109 ≤ xi, yi ≤ 109), denote the coordinates of city i.
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 xi and yi (-109 ≤ xi, yi ≤ 109), 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
23 20 04 05 14 20 31 03 08 9
Sample Output
Case #1: 2Case #2: 4唉,写了一早上,都没写出来。。先贴个错的代码,明天再看#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#define INF 0x3f3f3f3f#define ll long longusing 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;}
0 0
- hdoj Airport 5046 () 好题
- HDU 5046 Airport(DLX重复覆盖)
- HDOJ Robberies(好题背包)
- hdoj Consumer 3449 (背包)好题
- UVA 1450 Airport(二分+想法题)
- HDU 5046 Airport (2014年上海赛区网络赛E题)
- HDU 5046 Airport DLX
- HDU 5046 Airport
- hdu 5046 Airport
- HDU 5046 Airport
- HDU 5046 Airport
- Airport
- HDU 5046 ( Airport ) DLX模板题,手残again
- hdu 5046 Airport(Dancing Links重复覆盖)
- HDU 5046 Airport (DLX可重复覆盖+二分)
- HDU 5046 Airport(二分+DLX重复覆盖)
- hdoj 2531 Catch him(块状元素)(好题)
- hdoj Work 5326 (并查集+技巧) 好题
- leetcode|Single Number(136)
- Android MPAndroidChart:动态添加统计数据线【8】
- C语言关键字
- 生活中有用的小技巧
- python核心编程-filter重构2
- hdoj Airport 5046 () 好题
- 无线路灯项目——STM32L低功耗相关
- 滚动数组
- 机器学习算法及应用领域相关的中国大牛
- ZYB's Biology解题报告
- W3C代码标准规范
- PS替换图标颜色
- [LeetCode]Minimum Height Trees
- hdoj the Sum of Cube 5053 (简单数学)