zoukankan      html  css  js  c++  java
  • HDU 3420 Bus Fair [补]

    今天玩魔灵玩多了,耽误了时间,回去宿舍又没电。

    /*********************************************/

    Bus Fair

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 900    Accepted Submission(s): 444


    Problem Description
    You are now in Foolish Land. Once moving in Foolish Land you found that there is a strange Bus fair system. The fair of moving one kilometer by bus in that country is one coin. If you want to go to X km and your friend wants to go to Y km then you can buy a ticket of X+Y coins (you are also allowed to buy two or more tickets for you two).
      
    Now as a programmer, you want to show your creativity in buying tickets! Suppose, your friend wants to go 1 km and you want to go 2 km. Then it’s enough for you to buy a 2coin ticket! Because both of you are valid passengers before crossing the first km. and when your bus cross the first km your friend gets down from the bus. So you have the ticket of 2km! And you can safely reach to your destination, 2km using that ticket.
      
    Now, you have a large group of friends and they want to reach to different distance. You think that you are smart enough that you can buy tickets that should manage all to reach their destination spending the minimum amount of coins. Then tell us how much we should at least pay to reach our destination.
     
    Input
    There are multiple test cases. Each case start with a integer n, the total number of people in that group. 0<=n<=1000. Then comes n integers, each of them stands for a distance one of the men of the group wants to go to. You can assume that the distance a man wants to go is always less than 10000.
     
    Output
    Your program should print a single integer for a single case, the minimum amount of coins the group should spend to reach to the destination of all the members of that group.
     
    Sample Input
    2 1 2 2 2 3
     
    Sample Output
    2 4
     
    Author
    Muhammed Hedayet
     
    Source
     
    Recommend
    lcy   |   We have carefully selected several similar problems for you:  3422 3421 3423 3418 3419
     1 #include<math.h>
     2 #include<stdio.h>
     3 #include<string.h>
     4 #include<iostream>
     5 #include<algorithm>
     6 using namespace std;
     7 #define N 1234567
     8 
     9 int n;
    10 int a[N];
    11 int b[N];
    12 
    13 int main()
    14 {
    15     while(~scanf("%d",&n))
    16     {
    17         int ma=0;
    18         for(int i=0;i<n;i++)
    19         {
    20             scanf("%d",&a[i]);
    21         }
    22         sort(a,a+n);
    23         for(int i=0;i<n;i++)
    24         {
    25             b[i]=a[i]*(n-i);
    26             ma=max(ma,b[i]);
    27         }
    28         cout<<ma<<endl;
    29     }
    30     return 0;
    31 }
  • 相关阅读:
    【转载】CentOS 6.3(x86_64)下安装Oracle 10g R2 天高地厚
    Oracle查看表空间和删除表空间 天高地厚
    获取android手机的定位信息(转)
    android里pull解析xml文件
    google map 开发去掉图片阴影
    ubuntu12.04配置android开发环境遇到的问题
    google code中下载你的项目源码
    android无法自动生成R文件
    android中ocr解决方案(tesseract)
    自定义Android标题栏TitleBar布局(转)
  • 原文地址:https://www.cnblogs.com/wmxl/p/4690786.html
Copyright © 2011-2022 走看看