题意:有n首歌,有各自的编号,长度,频率,给出一种排列方式要重新排列这些歌,问排列后第s首的编号是什么。
题解:排序方式是长度越短频率越高的排在前面。
#include <stdio.h>
#include <algorithm>
const int N = 70000;
using namespace std;
struct Song {
int id, l;
double fre;
}song[N];
int n, s;
int cmp(Song a, Song b) {
return (a.l / a.fre) < (b.l / b.fre);
}
int main() {
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; i++)
scanf("%d%d%lf", &song[i].id, &song[i].l, &song[i].fre);
sort(song, song + n, cmp);
scanf("%d", &s);
printf("%d\n", song[s - 1].id);
}
return 0;
}