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. 微设计(www.weidesigner.com)介绍系列文章(二)

    微设计(www.weidesigner.com)是一个专门针对微信公众账号提供营销推广服务而打造的第三方平台. 2.1 怎样注冊微信公众号? 登录mp.weixin.qq.com,点击注冊填写相关信息 ...

  2. ICMP报文分析

    一.概述: 1.   ICMP同意主机或路由报告差错情况和提供有关异常情况.ICMP是因特网的标准协议,但ICMP不是高层协议,而是IP层的协议.通常ICMP报文被IP层或更高层协议(TCP或UDP) ...

  3. Com编程入门——什么是COM,如何使用COM

    本文的目的是为刚刚接触COM的程序员提供编程指南,并帮助他们理解COM的基本概念.内容包括COM规范简介,重要的COM术语以及如何重用现有的COM组件.本文不包括如何编写自己的COM对象和接口. CO ...

  4. Apache配置HTTPS协议搭载SSl配置全过程

    1.首先要开启相应的扩展和辅助的dll(ssleay32.dll,libeay32.dll)到system32下 2.生成服务器证书 安装好在bin目录下有一个openssl.exe文件,用来生成证书 ...

  5. [转] gdb中忽略信号处理

    信号(Signals) 信号是一种软中断,是一种处理异步事件的方法.一般来说,操作系统都支持许多信号.尤其是UNIX,比较重要应用程序一般都会处理信号.UNIX定义了许 多信号,比如SIGINT表示中 ...

  6. Chapter 7. Dependency Management Basics 依赖管理基础

    This chapter introduces some of the basics of dependency management in Gradle. 7.1. What is dependen ...

  7. sessionstorage,localstorage和cookie之间的区别

    sessionStorage 和 localStorage 是HTML5 Web Storage API 提供的,可以方便的在web请求之间保存数据.有了本地数据,就可以避免数据在浏览器和服务器间不必 ...

  8. ajax调用webservice(二) 跨域。

    所需工具与项目结构同(一). service.asmx中代码如下: using System; using System.Collections.Generic; using System.Web; ...

  9. 高放的c++学习笔记之类

    类的基本思想是数据抽象和封装1.this 成员函数通过一个名为this的额外隐式参数来访问调用它的对象,当我们调用一个函数的时候,用请求该函数的对象的初始化this. 如果某个类的名字为sale,某个 ...

  10. 转载:CURL常用命令

    转载网址:http://www.cnblogs.com/gbyukg/p/3326825.html 下载单个文件,默认将输出打印到标准输出中(STDOUT)中 curl http://www.cent ...