http://acm.hdu.edu.cn/showproblem.php?pid=2523

学习哈希和注意i++,后要--i;

SORT AGAIN

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

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 Input
3
3 2
4 0 7
4 2
1 2 3 4
2 1
2 9
 
 
Sample Output
4
2
7
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main()
{
int t,n,k,i,a[2000],j,b[2000];
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&k);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
memset(b,0,sizeof(b));
sort(a,a+n);
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
b[a[j]-a[i]]=1;
i=0;
while(k!=0)
k-=b[i++];
printf("%d\n",--i);//注意i++,后要--i;
}
return 0;
}

HDU-2523 SORT AGAIN的更多相关文章

  1. HDOJ(HDU) 2523 SORT AGAIN(推导排序、、)

    Problem Description 给你N个整数,x1,x2-xn,任取两个整数组合得到|xi-xj|,(0 < i,j<=N,i!=j). 现在请你计算第K大的组合数是哪个(一个组合 ...

  2. HDU 2523 sort (hash)

    #include<iostream> #include<cstring> #include<cmath> #include<cstdio> using ...

  3. HDU 2689 Sort it (树状数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2689 Sort it Problem Description You want to processe ...

  4. hdu 1425 sort 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 常规的方法是对输入的数从大到小进行排序(可以用sort或qsort),然后输出前m大的数. 不过 ...

  5. HDU 5884 Sort (二分)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5884 nn个有序序列的归并排序.每次可以选择不超过kk个序列进行合并,合并代价为这些序列的长度和.总的 ...

  6. hdu 2689 Sort it

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2689 题目分析:求至少交换多少次可排好序,可转换为逆序对问题. 用冒泡排序较为简单,复杂度较大~~ 也 ...

  7. HDU 2689 Sort it【树状数组】

    Sort it Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. HDU 5884 Sort(二分+优先队列)

    http://acm.hdu.edu.cn/showproblem.php?pid=5884 题意:有个屌丝设计了一个程序,每次可以将k个数组进行合并,代价为这k个数组总的长度之和.现在另外一个屌丝要 ...

  9. E题hdu 1425 sort

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1425 sort Time Limit: 6000/1000 MS (Java/Others)    M ...

  10. HDU 5884 Sort(二分答案+计算WPL的技巧)

    Sort Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submi ...

随机推荐

  1. O-C-11-利用类方法做一个简单的计算器

    #import <Foundation/Foundation.h> @interface calculator : NSObject //@property  double    numb ...

  2. leetcode344——Reverse String(C++)

    Write a function that takes a string as input and returns the string reversed. Example:Given s = &qu ...

  3. GitHub Windows客户端部署

    下载网址:https://windows.github.com 点击下载按钮即可下载一个小程序,这个小程序会去服务器端下载完整的Windows版客户端,然后自动安装. 如果安装出错的话,那就打开IE浏 ...

  4. #添加屏蔽IP LINUX

    netfilter/iptables 的最大优点是它可以配置有状态的防火墙,这是 ipfwadm 和 ipchains 等以前的工具都无法提供的一种重要功能.有状态的防火墙能够指定并记住为发送或接收信 ...

  5. wamp5 忘记mysql root密码 重置方法

    wamp5比较恶心,忘记mysql root密码了,重新安装都没用,网上找了个文章可以修改root的密码. http://www.kuqin.com/database/20080306/4249.ht ...

  6. std::string stringf(const char* format, ...)

    std::string stringf(const char* format, ...){ va_list arg_list; va_start(arg_list, format); // SUSv2 ...

  7. AMAZON PRICE TRACKER, AMAZON PRICE HISTORY, AMAZON PRICE DROP ALERT | DROPGG.COM

    DropGG.com is the destination for savvy shoppers looking to save money by buying smart. DropGG.com a ...

  8. php练习5——简单的学生管理系统(隐藏控件的使用)

    要求:    程序:gradeManage.html和gradeManage.php          结果       注意:   1.使用隐藏控件时,得在不同表单下,不能在同一个表单下:   2. ...

  9. PHP、JSP、.NET各自的真正优势是什么

    PHP的优势在于, 跨平台, 极易部署, 易维护, 为Web而生, 开源社区强大, 文档丰富.至于说3足鼎立, 谈不上, 全球前100万的sites中, 70%是PHP. JSP和Asp..net 也 ...

  10. POJ 2442 Sequence 优先队列

    题目: http://poj.org/problem?id=2442 #include <stdio.h> #include <string.h> #include <q ...