hoj2143 Songs 贪心
来源:互联网 发布:泰国国王科技大学知乎 编辑:程序博客网 时间:2024/06/05 19:43
Description
John Doe is a famous DJ and, therefore, has the problem of optimizing the placement of songs on his tapes. For a given tape and for each song on that tape John knows the length of the song and the frequency of playing that song. His problem is to record the songs on the tape in an order that minimizes the expected access time. If the songs are recorded in the order Ss(1), …, Ss(n) on the tape then the function that must be minimized is
where fs(i) is the frequency of playing the ith song and l is the length of the song. Can you help John?
The program input is from standard input. Each data set in the input stands for a particular set of songs that must be recorded on a tape. A data set starts with the number N (fits a 16 bit integer) of songs. Follow N the song specifications, and in the end, a number representing the position of a song S on the optimized tape. A song specification consists of the song identifier (fits an integer), the length of the song (fits a 16 bit integer), and the frequency of playing the song (a floating-point number). The program prints the identifier of the song S.
White spaces can occur freely in the input. The input data are correct and terminate with an end of file. For each set of data the program prints the result to the standard output from the beginning of a line. An input/output sample is given below. There is a single data set that contains 5 song specifications. The first song has the identifier 1, length 10 and playing frequency 45.5 etc. The result for the data set is the identifier of the 3rd song on the optimized tape. It is 2 for the given example.
Input
Output
Sample Input
5
1 10 45.5
2 5 20
30 20 10
400 50 35
15 17 89.9
3
Sample Output
2
题意:(考试时题意废,读了好久QAQ
给你一份歌单,每首歌都有各自的序号、时长(l)和被演奏的频率(f),要让歌单上面的所有歌都演奏完,且保证所需时间最少,问第k个演奏的歌曲序号是多少。
题解:考虑相邻的两首歌是否交换。
#include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <queue>#include <stack>#define N 100005using namespace std;struct A{ int id,len; double fre;}a[N];bool cmp(A i,A j){ return (double) (j.fre * i.len) < (double) (i.fre * j.len);}int T,n,m;int main(){ while(~scanf("%d", &n)){ for(int i = 1; i <= n; i++) scanf("%d%d%lf", &a[i].id, &a[i].len, &a[i].fre); sort(a + 1, a + 1 + n, cmp); scanf("%d", &m); printf("%d\n", a[m].id); } return 0;}
- hoj2143 Songs 贪心
- 1346 - Songs (贪心)
- UVA 1346 - Songs (贪心)
- UVA - 1346 Songs 贪心
- Songs (UVA-1346)贪心
- uva 1346 - Songs(贪心)
- POJ 2675 Songs (贪心)
- 【UVA】1346 - Songs(贪心)
- uva 1346 Songs(贪心)
- uva 1346 - Songs(贪心)
- songs
- songs
- Songs
- UVa 1346 Songs (贪心好题)
- english songs
- Christmas Songs
- some songs
- Spanish songs
- 开始学习 Python编程 从入门到实践。
- 深入理解 CSS 中的行高与基线
- 微农链的国内首创食品区块链产业前景如何
- SQL Alias(别名)
- oracle exp导出缺少表的处理
- hoj2143 Songs 贪心
- 深入理解javascript选择器API系列第一篇——4种元素选择器
- CSDN-markdown编辑器
- 工具类-日期工具类
- 网站建设需要的流程与注意细节
- MyBatis的Mapper接口以及Example的实例函数及详解
- iOS RAC学习笔记一
- 在eclipse 集成maven 用于新建或者导入maven项目
- 生成模型、判别模型、朴素贝叶斯