题意:
给出n首歌的频率和时长,求fs(i)ls(j)最小.即:b[i]=f[i]*(l[1]+...+l[i]),sum=b[1]+..+b[n],求使sum最小的歌曲排列方式.然后输入碟中位于s的歌,输出歌的id号
思路:
主要是排序,排序的技巧是a.l*b.f<a.f*b.l(个人的理解是上述的b[i]的值就是当前的f和前面的时长之和相乘,如果a.l*b.f<a.f<b.l,则令a在前面,b作为之后的当前值)//好乱
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 100010;
struct node {
int id;
long long l;
double f;
}arr[maxn];
int n;
bool cmp(node a, node b) {
return a.l*b.f < b.l*a.f;
}
int main() {
while(scanf("%d", &n) != EOF) {
for(int i=1; i<=n; i++) scanf("%d%lld%lf", &arr[i].id, &arr[i].l, &arr[i].f);
sort(arr+1, arr+n+1, cmp);
int t;
scanf("%d", &t);
printf("%d\n", arr[t].id);
}
return 0;
}