选数问题
来源:互联网 发布:汽车报价大全软件下载 编辑:程序博客网 时间:2024/06/06 06:38
Problem DescriptionGiven a set of N numbers, we want to select R*C numbers from it, and filled the selected numbers into a R*C matrix(R rows with C numbers in each row).We define D(i) as the difference between the largest and the smallest number in the i-th row of the matrix(1<=i<=R). For the entire matrix, we define F as the largest D(i) of the R rows.The value F of the resulting matrix is expected to be as small as possible. Can you help us to tell what the smallest possible F is?InputThe first line of the input contains a positive integer T<=20 specifying the number of test cases to follow.The first line of each test case contains 3 positive integers N,R,C. The following line contains positive integers Pi.For all test cases: 1<=R,C<=10^4, R*C<=N<=5*10^5,0<Pi<=10^9OutputFor each test case you should output a single line containing "Case X: Y",where X is the number of the test case (starting at 1). Y is the smallest possible F.Sample Input17 2 3170 205 225 190 260 225 160Sample OutputCase 1: 30//题意:给你N个数,和一个R*C 的矩阵选取R*C个数放入矩阵中,每行有个最大值和一个最小值一个,一个矩阵有R个这样的值,组成了一个集合R,它们的元素分别为:R(i) = Max(i) - Min(i),从R集合中选取一个最大值,重新组成一个集合Z,我们要求的就是Z集合中的最小值.//标程:#include<iostream>#include<cstdio>#include<algorithm>using namespace std;const int inf = 1000000007;int a[500005];int main(){// freopen("a.txt","r",stdin); int t, n, r, c, i, k = 0; scanf("%d",&t); while(t --) { ++ k; int ans = 0; scanf("%d%d%d",&n,&r,&c); for(i = 0; i < n; ++ i) scanf("%d",a+i); sort(a,a+n); int low = 0, high = inf, mid; while(low <= high) { mid = (low + high) / 2; int cnt = 0; for(i = 0; i + c - 1 < n; ) { if(a[i+c-1] - a[i] <= mid) { i += c; cnt ++; } else i ++; } if(cnt >= r) { high = mid - 1; ans = mid; } else low = mid + 1; } printf("Case %d: %d\n",k,ans); } return 0;}
0 0
- 选数问题
- 选数问题
- 【jzoj4790】【选数问题】
- 【JZOJ4790】选数问题
- Jzoj4790 选数问题
- 【NOIP模拟】选数问题
- 喵哈哈的日常选数问题
- 喵哈哈的日常选数问题
- NOIP提高组【JZOJ4790】选数问题
- 【NOIP提高组】选数问题
- 分数变小数问题
- 数素数问题
- 和尚数佛珠问题
- 鬼谷子 猜数问题
- 方形问题(数方形)
- 删数问题
- 数塔问题
- "公平数"问题
- iOS UIGestureRecognizer的使用
- Ubuntu命令集
- linux 下安装postgesql
- C8051F410在线调试接口说明
- 多步 OLE DB 操作产生错误
- 选数问题
- UVA 10474 - Where is the Marble?
- cmakelists
- Java 二分法查找
- 栈的应用举例——迷宫求解
- 看雪论坛ios反编译网址记录
- 最长上升子序列
- 更新sdk
- ubunt & win7 双系统,如何互相访问对方硬盘分区?