View Code of Problem 5

/*
jlh很喜欢吃水果,苹果是他最喜欢的,其次是梨。他天天想着吃水果,竟然感动了女娲大神,女娲大神给了他n个篮子,让他选择其中的m个(m<=n)个篮子。
每个篮子里有a个苹果和b个梨。请你们帮jlh选择篮子吧。

Input:
输入一个t(t<=10),表示有t组测试数据,再输入n和m(0=<m<=n<=100000),接下来的n行,输入a和b表示苹果和梨的数量。

Output:

按jlh选择的顺序(先选苹果多的,苹果数量相同选梨多的,两者相同选序号小的)篮子的序号(1-n),m个数用空格隔开。

Sample Input:
2
2 1
2 0
1 4

3 2
3 4
2 6
3 5

Sample Output:
1
3 1

*/

#include<stdio.h>
int main()
{
	int t, n[10], m[10], a[10][10000], b[10][100000], i, j, k, c;
	scanf("%d", &t);
	for(k = 0; k < t; k++)
	{
		scanf("%d%d", &n[k], &m[k]);
		for(i = 0; i < n[k]; i++)
		{
			scanf("%d%d", &a[k][i], &b[k][i]);
		}
	}
	for(k = 0; k < t; k++)
	{
		for(j = 0; j < m[k]; j++)
		{
			for(i = 1, c = 0; i < n[k] ; i++)
			{
				if(a[k][c] < a[k][i])
					c = i;
				else if(a[k][c] == a[k][i])
				{
					if(b[k][c] < b[k][i])
						c = i;
				}
			}
			if(k < t)
				printf("%d ", c + 1);
			else
				printf("%d", c + 1);
			a[k][c] = 0;
		}
		printf("\n");
	}
}
//Runtime Error
//http://acm.zjgsu.edu.cn/status

Double click to view unformatted code.


Back to problem 5