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 S(s1),..., Ss(n)<tex2html_verbatim_mark> on the tape then the function that must be minimized is

fs(i)ls(j)

<tex2html_verbatim_mark>

where fs(i)<tex2html_verbatim_mark> is the frequency of playing the i<tex2html_verbatim_mark> -th song and l<tex2html_verbatim_mark> is the length of the song. Can you help John?

Input

The program input is from a text file. Each data set in the file stands for a particular set of songs that must be recorded on a tape. A data set starts with the number N<tex2html_verbatim_mark> (fits a 16 bit integer) of songs. Follow N<tex2html_verbatim_mark> the song specifications, and in the end, a number representing the position of a song S<tex2html_verbatim_mark> 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<tex2html_verbatim_mark> .

White spaces can occur freely in the input. The input data are correct and terminate with an end of file.

Output

For each set of data the program prints the result to the standard output from the beginning of a line.

Note: An input/output sample is in the table 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.

Sample Input

5
1 10 45.5
2 5 20
30 20 10
400 50 35
15 17 89.9
3

Sample Output

2
题意:给你一份歌单,其中包括歌曲号,歌曲时长还有歌曲被点播的频率,要求你刻录这些歌到一张光碟里,不同的刻录顺序,光碟也就不同,要求的顺序是让上面给出的公式的值尽可能地小
思路:其实看懂了,就知道这不就是背包贪心问题么。。。。。。
#include"iostream"
#include"algorithm"
using namespace std;
const int maxn=100000; struct node
{
int x;
double y;
}a[maxn]; bool cmp(struct node a1,struct node a2)
{
return a1.y>a2.y;
} int main()
{
int n;
while(cin>>n)
{
int t,id;double f;
for(int i=0;i<n;i++)
{
cin>>id>>t>>f;
a[i].x=id;
a[i].y=f/t;
}
sort(a,a+n,cmp);
int temp;
cin>>temp;
cout<<a[temp-1].x<<endl;
}
return 0;
}

集训第四周(高效算法设计)L题 (背包贪心)的更多相关文章

  1. 集训第四周(高效算法设计)N题 (二分查找优化题)

    原题:poj3061 题意:给你一个数s,再给出一个数组,要求你从中选出m个连续的数,m越小越好,且这m个数之和不小于s 这是一个二分查找优化题,那么区间是什么呢?当然是从1到数组长度了.比如数组长度 ...

  2. 集训第四周(高效算法设计)E题 (区间覆盖问题)

    UVA10382 :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21419 只能说这道题和D题是一模一样的,不过要进行转化, ...

  3. 集训第四周(高效算法设计)D题 (区间覆盖问题)

    原题 UVA10020  :http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=19688 经典的贪心问题,区间上贪心当然是右区间越 ...

  4. 集训第四周(高效算法设计)A题 Ultra-QuickSort

    原题poj 2299:http://poj.org/problem?id=2299 题意,给你一个数组,去统计它们的逆序数,由于题目中说道数组最长可达五十万,那么O(n^2)的排序算法就不要再想了,归 ...

  5. 集训第四周(高效算法设计)P题 (构造题)

    Description   There are N<tex2html_verbatim_mark> marbles, which are labeled 1, 2,..., N<te ...

  6. 集训第四周(高效算法设计)O题 (构造题)

    A permutation on the integers from 1 to n is, simply put, a particular rearrangement of these intege ...

  7. 集训第四周(高效算法设计)M题 (扫描法)

    原题:UVA11078 题意:给你一个数组,设a[],求一个m=a[i]-a[j],m越大越好,而且i必须小于j 怎么求?排序?要求i小于j呢.枚举?只能说超时无上限.所以遍历一遍数组,设第一个被减数 ...

  8. 集训第四周(高效算法设计)K题 (滑窗问题)

    UVA 11572 唯一的雪花 题意:给你从1到n的数组,要求求得其中的最长连续不重复子序列,经典的滑窗问题,方法是维护一个窗口,设置左框和右框,然后不断的进行维护和更新 方法一: #include& ...

  9. 集训第四周(高效算法设计)I题 (贪心)

    Description Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshe ...

随机推荐

  1. Luogu P1970 花匠 【线性Dp】 By cellur925

    题目描述 Description 花匠栋栋种了一排花,每株花都有自己的高度.花儿越长越大,也越来越挤.栋栋决定把这排中的一部分花移走,将剩下的留在原地,使得剩下的花能有空间长大,同时,栋栋希望剩下的花 ...

  2. c语言类型修饰符及内存

    今天来学习一下c语言类型修饰符及内存分布 1.auto int a; 默认在内存 2.register int a; 限制变量定义在寄存器上的修饰符 编译器会尽量安排CPU的寄存器去存放这个a,如果寄 ...

  3. python爬虫爬取腾讯招聘信息 (静态爬虫)

    环境: windows7,python3.4 代码:(亲测可正常执行) import requests from bs4 import BeautifulSoup from math import c ...

  4. ElasticSearch | centos7 上安装ES

    0 参考博客文章(感谢!!!) [1]  https://www.jianshu.com/p/10949f44ce9c 在linux服务器上安装jdk [2]  https://www.elastic ...

  5. Ubuntu Server 上安装pip后pip命令报错的解决办法

    Installation Do I need to install pip? pip is already installed if you are using Python 2 >=2.7.9 ...

  6. Hanlder + 弱引用防内存漏泄示例*

    Hanlder + 弱引用防内存漏泄示例: public class MainActivity extends AppCompatActivity { public final MyHandler h ...

  7. RegisterClientScriptBlock和RegisterStartupScript的区别

    RegisterClientScriptBlock在 Page 对象的 元素的开始标记后立即发出客户端脚本,RegisterStartupScript则是在Page 对象的 元素的结束标记之前发出该脚 ...

  8. 1、QQ装机部落---腾讯软件

    亲,赚钱快人一步,我给你推荐QQ装机部落!大品牌,口碑好,知名软件,绿色无毒,每天结算,回报高!到这里注册:http://zjbl.qq.com/#/?invid=476058088 返利网邀请码立即 ...

  9. xamarin 学习笔记01-环境配置

    1.安装AndroidSDK 参考 2.安装NDK NDK下载地址:http://dl.google.com/android/ndk/android-ndk-r10e-windows-x86_64.e ...

  10. 计算机网络、OSI模型、TCP/IP族

    一.计算机网络分类 1.按通信距离分类: 局域网:LAN,10m-1000m,房间.校园: 城域网:MAN,10km,城市: 广域网:WAN,100km以上,国家.全球. 二.OSI(Open Sys ...