杭电acm2523

#include <stdio.h>
#include <string.h>
#include <math.h>

int main() {
	
	int book[4001], d[1001], b[4001];
	int c, n, k, i, j, temp, max, ids;
	scanf("%d", &c);
	while(c--) {
		scanf("%d%d", &n, &k);
		memset(book, 0, sizeof(book));
		memset(b, 0, sizeof(b));
		for(i=0; i<n; i++)
			scanf("%d", &d[i]);
		//使用桶排序记录组合数	
		max = -1;
		for(i=0; i<n; i++)
			for(j=i+1; j<n; j++) {
				temp = abs(d[j] - d[i]);
				book[temp] = 1;
				if(max<temp)
					max = temp;
			}
		//按顺序保存组合数 
		ids = 0;
		for(i=0; i<=max; i++)
			if(book[i] == 1) {
				b[ids++] = i;
			}
				
		
		printf("%d\n", b[k-1]);
	}
	
	return 0;
}

posted @ 2015-11-06 22:35  StevenLuke  阅读(124)  评论(0编辑  收藏  举报