View Code of Problem 5

#include<stdio.h>
int Find(int v[], int n)
{
	int max=0;
	for (int i = 0; i < n; i++)
	{
		if(v[i] > v[max])
			max = i;
	}
	return max;
}

int main()
{
	int s;//数据有S组
	int n, m;//篮子
	int a[100000][2],v[100000];
	while (scanf("%d",&s)!=EOF)
	{
		while (s--)
		{
			scanf("%d%d", &n, &m);
			for (int i = 0; i < n; i++)
			{
				scanf("%d%d", &a[i][0], &a[i][1]);//篮子中苹果和梨的数量
			}
			for (int i = 0; i < n; i++)
				v[i] = a[i][0] * 100000 + a[i][1]; //苹果的比重远大于梨
			for (int i = 0; i < m; i++)
			{
				if (i == m - 1) printf("%d", Find(v,n)+1);
				else
				{
					printf("%d ", Find(v, n) + 1);
				}
				v[Find(v, n)] = -1;
			}
			printf("\n");
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 5