2000. Toy Shopping

2000. Toy Shopping

Constraints

Time Limit: 1 secs, Memory Limit: 64 MB

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

6

0 521

442 210

119 100

120 108

619 744

48 10

Sample Output

320

6

2

3

Problem Source

注意算法,不要超时了。

2010中山大学新手赛-网络预选赛

// Problem#: 2000

// Submission#: 1980197

// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License

// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/

// All Copyright reserved by Informatic Lab of Sun Yat-sen University

#include<stdio.h>

int main(){

    int N,i;

    scanf("%d",&N);

    double J[N],P[N];

    double JP[N];

    double tempJP[3]={0};

    for(i=0;i<N;i++){

        scanf("%lf %lf",&J[i],&P[i]);

        JP[i]=J[i]/P[i];

        if(i==0){

            tempJP[0]=JP[0];

        }

        if(i==1){

            if(JP[1]<JP[0]){

                tempJP[1]=JP[1];

            }

            else{

                tempJP[0]=JP[1];

                tempJP[1]=JP[0];

            }

        }

        if(i>=2){

            if(JP[i]>tempJP[0]){

                tempJP[2]=tempJP[1];

                tempJP[1]=tempJP[0];

                tempJP[0]=JP[i];

            }

            else if(JP[i]<tempJP[0]&&JP[i]>tempJP[1]){

                tempJP[2]=tempJP[1];

                tempJP[1]=JP[i];

            }

            else if(JP[i]>tempJP[2]){

                tempJP[2]=JP[i];

            }

        }

    }

    double sum=0;

    int three[3];

    for(i=0;i<N;i++){

        if(tempJP[0]==JP[i]){

            three[0]=i;

        }

        if(tempJP[1]==JP[i]){

            three[1]=i;

        }

        if(tempJP[2]==JP[i]){

            three[2]=i;

        }

    }

    sum=P[three[0]]+P[three[1]]+P[three[2]];

    printf("%.0lf\n",sum);

    printf("%d\n",three[0]+1);

    printf("%d\n",three[1]+1);

    printf("%d\n",three[2]+1);

    return 0;

}    

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值