Songs

题意:

给出n首歌的频率和时长,求$\displaystyle \sum^{​{n}}_{​{i=1}}$fs(i)$\displaystyle \sum^{​{s(i)}}_{​{j=1}}$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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值