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

HintIn 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.

首先要确认的是,每盒奶只喝五天啊。

倘若两种奶的日花销相同,那么就只挑量大的那盒买。

有2种方法,一种是对每天的开销来求的:如下:

import java.util.Scanner;
//按照每天的开销来算
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
sc.nextLine();
String[] strs = new String[n];
for(int i=0;i<n;i++){
strs[i]=sc.nextLine();
}
// for(int i=0;i<n;i++){
// System.out.println(strs[i]);
// }
String[][] milk = new String[n][3];
int num[][] = new int[n][2];
for(int i=0;i<n;i++){
milk[i]=strs[i].split(" ");
num[i][0]=Integer.parseInt(milk[i][1]);
num[i][1]=Integer.parseInt(milk[i][2]);
if(num[i][1]>1000){
num[i][1]=1000;
}
}
int k=0;
int day=0;
day=0;
double vp = 100000000;
for(int i=0;i<n;i++){
if(num[i][1]<200){
continue;
}
day=num[i][1]/200;
if((num[i][0]*1.0/day*1.0)<vp){
k=i;
vp=num[i][0]*1.0/day*1.0;
}
if((num[i][0]*1.0/day*1.0)==vp){
if(Integer.parseInt(milk[i][2])>Integer.parseInt(milk[k][2])){
k=i;
vp=num[i][0]*1.0/day*1.0;
}
}
}
System.out.println(milk[k][0]);
}
} }

还有一种是按照实际的没ml的价格来算的:

import java.util.Scanner;

public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-->0){
int n = sc.nextInt();
sc.nextLine();
String[] strs = new String[n];
for(int i=0;i<n;i++){
strs[i]=sc.nextLine();
}
// for(int i=0;i<n;i++){
// System.out.println(strs[i]);
// }
String[][] milk = new String[n][3];
int num[][] = new int[n][2];
for(int i=0;i<n;i++){
milk[i]=strs[i].split(" ");
num[i][0]=Integer.parseInt(milk[i][1]);
num[i][1]=Integer.parseInt(milk[i][2]);
if(num[i][1]>1000){
num[i][1]=1000;
}
}
int k=0;
double vp = -100;
for(int i=0;i<n;i++){
if(num[i][1]<200){
continue;
}
while(num[i][1]%200!=0){
num[i][1]--;
}
double p =num[i][1]*1.0/num[i][0]*1.0;
if(p>vp){
k=i;
vp=p;
}
if(p==vp){
if(Integer.parseInt(milk[i][2])>Integer.parseInt(milk[k][2])){
k=i;
vp=p;
}
}
}
System.out.println(milk[k][0]);
}
} }

HDOJ 1070 Milk(水题,考英文的)的更多相关文章

  1. HDOJ.1070 Milk(贪心)

    Milk 点我挑战题目 题意分析 每组测试数据给出一系列牛奶商品,分别是牛奶的品牌,价格,以及体积.在读取数据的时候,体积在200以下的牛奶直接忽略掉.并且每天要喝200ML的牛奶.但是无论牛奶体积有 ...

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. 水题 HDOJ 4727 The Number Off of FFF

    题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...

  4. 水题 HDOJ 4716 A Computer Graphics Problem

    题目传送门 /* 水题:看见x是十的倍数就简单了 */ #include <cstdio> #include <iostream> #include <algorithm ...

  5. [ZPG TEST 114] 阿狸的英文名【水题】

    1.      阿狸的英文名 阿狸最近想起一个英文名,于是他在网上查了很多个名字.他发现一些名字可以由两个不同的名字各取一部分得来,例如John(约翰)的前缀 “John”和Robinson(鲁滨逊) ...

  6. HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

    Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...

  7. HDOJ/HDU 1256 画8(绞下思维~水题)

    Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...

  8. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  9. HDOJ(HDU) 2090 算菜价(简单水题、)

    Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...

随机推荐

  1. AIX Study之--AIX网卡配置管理(ent0、en0、et0)

    AIX Study之--AIX网卡配置管理(ent0.en0.et0) 1.查看AIX系统网卡信息: [root@aix211 /]#lsdev |grep et  en0 Available 1L- ...

  2. SQL语句查询结果额外加入一列序号自己主动添加

    sqlserver 能够用row_number函数实现 例如以下: SELECT *,row_number() OVER(ORDER BY score(列名) DESC) AS rank FROM s ...

  3. [Falcor] Intro to JSON Graph

    JSON is a very commonly used data interchange format. Unfortunately while most application domain mo ...

  4. Android TagFlowLayout完全解析 一款针对Tag的布局(转)

    一.概述 本文之前,先提一下关于上篇博文的100多万访问量请无视,博文被刷,我也很郁闷,本来想把那个文章放到草稿箱,结果放不进去,还把日期弄更新了,实属无奈. ok,开始今天的博文,今天要说的是Tag ...

  5. Java基础知识强化83:System类之gc()方法(垃圾回收)以及和finalize()区别

    1. System概述: System类包含一些有用的类字段和方法.它不能被实例化. 2. gc()方法:垃圾回收器 public static void gc()       调用gc方法暗示着Ja ...

  6. [AngularJS 2 实践 一]My First Angular App

    最近一直在看关于AngularJS 2的资料,查看了网上和官网很多资料,接下来就根据官网教程步骤一步步搭建我的第一个Angular App AngularJS 2说明请参考:http://cnodej ...

  7. OD: Vulnerability Detection

    终于看完第二篇漏洞利用原理高级篇,内容虽然看懂了,但深入理解不够,这部分内容以后还要不断强化. 第三篇是漏洞挖掘技术,篇首的话中,提到程序的不可计算性(图灵机的停机问题).希伯尔数学纲领的失败,结尾说 ...

  8. php的mq客户端获取队列方法改造

    获取mq中消息然后处理失败重试机制: 下面的代码是php连接mq客户端的获取queue队列中的消息代码: public function createDurableSubscriber($queue, ...

  9. Examples_07_06 无法下载android的sdk

    在hosts里面配置. 74.125.237.1 dl-ssl.google.com 在AndroidManifest.xml中添加 <uses-feature android:name=&qu ...

  10. Ps 美白磨皮【1】

      方法一:去色加图层模式法 打开需要编辑的图片,按Ctrl+J复制新的图层1. 点击菜单栏“图像”-“调整”-“去色”,如下图所示. 将图层面板的混合模式更改为“滤色”,如下图4所示. 最后的显示效 ...