首页 技术 正文
技术 2022年11月18日
0 收藏 560 点赞 2,679 浏览 999 个字

SORT AGAIN

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3483    Accepted Submission(s): 1110

Problem Description给你N个整数,x1,x2…xn,任取两个整数组合得到|xi-xj|,(0<i,j<=N,i!=j)。 现在请你计算第K大的组合数是哪个(一个组合数为第K大是指有K-1个不同的组合数小于它)。 Input输入数据首先包含一个正整数C,表示包含C组测试用例. 每组测试数据的第一行包含两个整数N,K。(1<N<=1000,0<K<=2000) 接下去一行包含N个整数,代表x1,x2..xn。(0<=xi<=2000) Output对于每组测试数据,请输出第K大的组合数,每个输出实例占一行。 Sample Input33 24 0 74 21 2 3 42 12 9 Sample Output427 题意:给你N个数,运用组合数的原理,取第K个数, 思路  :  把和装起来,排序(从小到大),但是值得注意的是,当差相同时,只能算一个; ps:http://acm.hdu.edu.cn/showproblem.php?pid=2523 详见代码: 

#include<cstdio>//坑!重复的数字居然算一次,,,不解释。
#include<cmath>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;int cmp(int x,int y)
{
return x<y;
}
int main()
{
int num[],x[],a[];
int i,j,n,k,T,t;
scanf("%d",&T);
while(T--)
{
memset(num,,sizeof(num));
scanf("%d%d",&n,&k);
for(i=;i<n;i++)
scanf("%d",&x[i]);
t=;
for(i=;i<n-;i++)
for(j=i+;j<n;j++)
{
int temp=fabs(x[i]-x[j]);
num[temp]=;
}
for(i=;i<;i++)
if(num[i])
a[t++]=i;
printf("%d\n",a[k-]);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,401
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,813
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,896