Hoj 2143 Songs
来源:互联网 发布:淘宝精品女装 编辑:程序博客网 时间:2024/05/17 01:07
题目链接:http://acm.hit.edu.cn/hoj/problem/view?id=2143
若有两相邻的song,准备先听的那个时间为L1,听的频率为F1,后听的那个分别为L2和F2
设他们前面的所有歌的长度和为S。
他们两个产生的代价为 S * F1 + ( S + L1 ) * F2 = S * ( F1 + F2 ) + L1 * F2
若交换,那么新代价为 S * F2 + ( S + L2 ) * F1 = S * ( F1 + F2 ) + L2 * F1
那么显然,L1 * F2 <= L2 * F1 ( 因为我们假设这个排列已经最优 )
两边都除以 F1 * F2 ,那么有 L1 / F1 <= L2 / F2
对任意的相邻的song都有这个性质,那么对整个排列方案而言,那么整个排列都是按 Li / Fi 升序排列的。
#include <iostream>#include <math.h>#include <stdio.h>#include <string.h>#include <queue>#include <algorithm>using namespace std;struct Song{ int num; double len; double f;};Song so[100000];bool cmp(Song a,Song b){ return a.len * b.f <b.len * a.f;}int main(){#ifndef ONLINE_JUDGE freopen("in.txt","r",stdin);#endif int n; int r; while(scanf("%d",&n)!=EOF) { for(int i=0;i<n;i++) { scanf(" %d %lf %lf",&so[i].num,&so[i].len,&so[i].f); } scanf(" %d",&r); sort(so,so+n,cmp); printf("%d\n",so[r-1].num); } return 0;}
- Hoj 2143 Songs
- songs
- songs
- Songs
- HOJ 2143
- english songs
- Christmas Songs
- some songs
- Spanish songs
- Songs test
- HOJ
- nice flash songs
- The Best Songs!!
- 圣诞颂歌(Christmas Songs)
- UVA 1346 - Songs
- poj 2675 songs
- 1346 - Songs (贪心)
- UVALive - 3303 Songs
- GOF设计模式
- oracle函数
- CRC原理篇
- 三层架构与MVC的区别
- Flex中ViewStack 中NavigatorContent监听报错 解决办法
- Hoj 2143 Songs
- Oracle 闪回语句
- LAMP碰到问题与解决
- 播放优酷视频相关
- BLOG搬家了,新家地址http://changeself.com,改变网!
- POJ 1988 Cube Stacking
- Keil的lib库函数的封装
- WINCE6 多应用同时请求GPS数据解决方法
- 物料分类BAPI