2000. Toy Shopping
来源:互联网 发布:pymongo查询数据 ku 编辑:程序博客网 时间:2024/06/06 03:15
2000. Toy Shopping
Description
Bessie wants some toys. She's been saving her allowance for years, and has an incredibly huge stash. However, she is quite frugal and wants to get the best value for her cash. In fact, she has decided only to buy exactly three different toys of the N (3 <= N <= 25,000) offered at the Bovine Plaything Palace.
Toy i brings Bessie J_i (0 <= J_i <= 1,000,000) microbundles of joy and and has price P_i (0 < P_i <= 100,000,000). Bessie has enough money to buy any three toys that she chooses.
Bessie wants to maximize the sum of her happy-frugal metric (which is calculated as J_i/P_i -- joy divided by price) for the three toys she chooses. Help Bessie decide which toys she should buy. The answer is guaranteed to be unique.
Assume that the Bovine Plaything Palace offers 6 different toys for Bessie:
i Joy Price Happy-Frugal Metric - --- ----- ------------------- 1 0 521 0.00000 2 442 210 2.10476... 3 119 100 1.19000 4 120 108 1.11111... 5 619 744 0.83198... 6 48 10 4.80000
Bessie would choose toy 6 (HFM = 4.80), toy 2 (HFM = 2.10), and toy 3 (HFM = 1.19).
Input
* Line 1: A single integer: N
* Lines 2..N+1: Line i+1 contains two space-separated integers: J_i and P_i
Output
* Line 1: The total price that Bessie will have to pay
* Lines 2..4: In descending order sorted by the happy-frugal metric, the 1-based index of the toys that Bessie should buy, one per line
Sample Input
60 521442 210119 100120 108619 74448 10
Sample Output
320623
Problem Source
2010中山大学新手赛-网络预选赛
#include <iostream>#include <algorithm>using namespace std;struct toy{int index,joy,price;double hfm;};toy t[25007];bool cmp(const toy &t1,const toy &t2){if(t1.hfm>t2.hfm)return true;return false;}int main(){int n;cin>>n;for(int i=0;i<n;i++){cin>>t[i].joy>>t[i].price;t[i].index=i+1;t[i].hfm=double(t[i].joy)/t[i].price;}sort(t,t+n,cmp);int totalPrice=0;for(int i=0;i<3;i++)totalPrice+=t[i].price;cout<<totalPrice<<endl;for(int i=0;i<3;i++) cout<<t[i].index<<endl;return 0;}
- 2000. Toy Shopping
- Sicily 2000. Toy Shopping
- 2000. Toy Shopping
- 2000. Toy Shopping 继续是struct
- Sicily2000——Toy Shopping
- shopping
- shopping
- Shopping
- Shopping
- shopping
- Shopping
- New Toy
- POJ2318 TOY
- os toy
- linux toy
- petsc toy
- Toy Army
- hdu2481 Toy
- dede 相关文章
- VS2010 asp.net中在设计时控件可以拖动
- Windows API 大全
- myeclipse平台安装插件-如svn
- mtd-utils 及 ubi-utils 交叉编译
- 2000. Toy Shopping
- 设计模式C++学习笔记之一(Strategy策略模式)
- BW学习十五(删除dso的Change Log)
- 计模式C++学习笔记之二(Proxy代理模式)
- 在网看到了一个Silverlight导出DataGrid里的数据到Excel或xml文件里
- 玩转F#中的链表
- 去除左右空格
- 设计模式C++学习笔记之三(Singleton单例模式)
- 设计模式C++学习笔记之四(Multition多例模式)