HDOJ 1070 HDU 1070 Milk ACM 1070 IN HDU

MiYu原创, 转帖请注明 : 转载自 ______________白白の屋    

 

题目地址:

  http://acm.hdu.edu.cn/showproblem.php?pid=1070

题目描述:

Milk

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4483    Accepted Submission(s): 983


Problem Description
Ignatius drinks milk everyday, now he is in the supermarket and he wants to choose a bottle of milk. There are many kinds of milk in the supermarket, so Ignatius wants to know which kind of milk is the cheapest.

Here are some rules:
1. Ignatius will never drink the milk which is produced 6 days ago or earlier. That means if the milk is produced 2005-1-1, Ignatius will never drink this bottle after 2005-1-6(inclusive).
2. Ignatius drinks 200mL milk everyday.
3. If the milk left in the bottle is less than 200mL, Ignatius will throw it away.
4. All the milk in the supermarket is just produced today.

Note that Ignatius only wants to buy one bottle of milk, so if the volumn of a bottle is smaller than 200mL, you should ignore it.
Given some information of milk, your task is to tell Ignatius which milk is the cheapest.
 

Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case starts with a single integer N(1<=N<=100) which is the number of kinds of milk. Then N lines follow, each line contains a string S(the length will at most 100 characters) which indicate the brand of milk, then two integers for the brand: P(Yuan) which is the price of a bottle, V(mL) which is the volume of a bottle.
 

Output
For each test case, you should output the brand of the milk which is the cheapest. If there are more than one cheapest brand, you should output the one which has the largest volume.
 

Sample Input
      
        
2 2 Yili 10 500 Mengniu 20 1000 4 Yili 10 500 Mengniu 20 1000 Guangming 1 199 Yanpai 40 10000
 

Sample Output
      
        
Mengniu Mengniu
Hint
In the first case, milk Yili can be drunk for 2 days, it costs 10 Yuan. Milk Mengniu can be drunk for 5 days, it costs 20 Yuan. So Mengniu is the cheapest.In the second case, milk Guangming should be ignored. Milk Yanpai can be drunk for 5 days, but it costs 40 Yuan. So Mengniu is the cheapest.
 

 

题目分析 :

  SHIT!!!!

  很简单的一道水题!!   竟然 让我 WA 7 次.  日了 .    

  没仔细看清题目啊 ,  以为是水题就大意了..............    注意输出的 后面有一点  TIP :   

    If there are more than one cheapest brand, you should output the one which has the largest volume.

   其他的就是 算出 平均每天的 花费 排个序就OK了 .  但是这里又 让我 恶心了 :

    对DOUBLE 型排序 用  :

       if ( a.wei - b.wei > 1e-7 )

        return true;

      else if ( a.wei - b.wei < 1e-7 )

        return false;

      else return a.vol > b.vol;

    竟然是 WA  !!!!!!  硬是改用:

       if ( a.wei != b.wei )  //  double  这样比不会有精度问题 ???

              return a.wei < b.wei;

          else return a.vol > b.vol; 

    就AC 了 !!! ....做了这么久的题才发现 原来 DOUBLE  是这样比的?!?!??!?!?   

    求 解释.............. 

 

AC  代码如下 :

 /*

Coded By  : MiYu

Link      : Link      : http://www.cnblogs.com/MiYu  || http://www.cppblog.com/MiYu

Author By : MiYu

Test      : 1

Program   : 1070

*/

//#pragma warning( disable:4789 )

#include <iostream>

#include <algorithm>

#include <string>

#include <set>

#include <map>

#include <utility>

#include <queue>

#include <stack>

#include <list>

#include <vector>

#include <cstdio>

#include <cstdlib>

#include <cstring>

#include <cmath>

using namespace std;

typedef struct milk {

       char name[110];

       int pay;

       int vol; 

       double wei;    

}ML;

ML M;

bool cmp ( const ML &a, const ML &b ){

     if ( a.wei != b.wei )

        return a.wei < b.wei;

     else return a.vol > b.vol;  

int main ()

{

    int T;

    cin >> T; 

    while ( T -- ){

          int N;

          vector <ML> vec;

          cin >> N;

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

               cin >> M.name >> M.pay >> M.vol;

               int d = 0;

               int t = M.vol;

               while ( t >= 200 && d <= 4 ){

                     d ++;

                     t -= 200;  

               }

               if ( d ) {

                   M.wei = M.pay * 1.0 / d; 

                   vec.push_back ( M );

               }

          }       

          sort ( vec.begin(), vec.end(), cmp );

          cout << vec[0].name << endl;

    }

    return 0;

}


 

 

 

你可能感兴趣的:(ACM)