2143.cpp

来自「这是哈尔滨工业大学acmOJ的源代码」· C++ 代码 · 共 43 行

CPP
43
字号
/*  This Code is Submitted by wywcgs for Problem 2143 on 2005-11-11 at 19:43:59 */ 
#include <cstdio>
#include <cstdlib>

const int MAX = 1 << 16;
const double eps = 1e-10;

class Song {
public:
	int id;
	int l;
	double f;
};

int cmp(const void*, const void*);

int main()
{
	int n, o, i;
	Song song[MAX];
	
	while(scanf("%d", &n) == 1) {
		for(i = 0; i < n ; i++) {
			scanf("%d %d %lf", &song[i].id, &song[i].l, &song[i].f);
		}
		scanf("%d", &o);
		qsort(song, n, sizeof(Song), cmp);
		printf("%d\n", song[o-1].id);
	}
	
	return 0;
}

int cmp(const void *a, const void *b)
{
	Song *x = (Song*)a, *y = (Song*)b;
	if(x->f / x->l - y->f / y->l < eps) {
		return 1;
	} else {
		return -1;
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?