HDOJ 1070 Milk(水题,考英文的)
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(水题,考英文的)的更多相关文章
- HDOJ.1070 Milk(贪心)
Milk 点我挑战题目 题意分析 每组测试数据给出一系列牛奶商品,分别是牛奶的品牌,价格,以及体积.在读取数据的时候,体积在200以下的牛奶直接忽略掉.并且每天要喝200ML的牛奶.但是无论牛奶体积有 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- 水题 HDOJ 4727 The Number Off of FFF
题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...
- 水题 HDOJ 4716 A Computer Graphics Problem
题目传送门 /* 水题:看见x是十的倍数就简单了 */ #include <cstdio> #include <iostream> #include <algorithm ...
- [ZPG TEST 114] 阿狸的英文名【水题】
1. 阿狸的英文名 阿狸最近想起一个英文名,于是他在网上查了很多个名字.他发现一些名字可以由两个不同的名字各取一部分得来,例如John(约翰)的前缀 “John”和Robinson(鲁滨逊) ...
- HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)
Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...
- HDOJ/HDU 1256 画8(绞下思维~水题)
Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...
- HDOJ/HDU 2560 Buildings(嗯~水题)
Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...
- HDOJ(HDU) 2090 算菜价(简单水题、)
Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...
随机推荐
- 高效JQuery编码
缓存变量 DOM遍历是昂贵的,所以尽量将会重用的元素缓存. // 糟糕 h = $('#element').height(); $('#element').css('height',h-20); ...
- iOS 在 Xcode 中重命名项目名称
本教程使用的 Xcode 版本是Xcode 6.3.1,网上有好多的教程,都是在 Xcode 4 上做的讲解,现以本文章讲解一下如何在 Xcode 6.3.1 中重命名你的项目名称,包括你的应用名称. ...
- C#txt文件读写基本操作
string strFileName=@"C:\Users\Administrator\Desktop\记事2.txt"; //判断是否存在 if (File.Exists(str ...
- MVC4建立DBContext的EF6数据
MVC4建立DBContext的EF6数据时 1.需要using System.Data.Entity;命名空间 2.此命名空间需要安装EntityFromwork.dll,此dll可以在项目——&g ...
- java中保留几位小数
public class NumUtils { /** * 保留两位小数 * * @param d * @return */ public static String get2Wei(double d ...
- “The SQL Server license agreenment cannot be located for the selected edition.”MSSQL安装问题
今天老邹又来吐槽了.今天不和IE7较劲了.说点别的吧. 我呢什么软件都喜欢装最新版的,这部刚出来windows 8.1就赶紧装上了,随后就用上了vs2013.前天看到新闻说微软已经发布了sql ser ...
- CSS 解决<td>里面内容太多把表格弄变形的原因,设置 自动换行。
1 < style="word-break:break-all"> 例如div宽200px,它的内容就会到200px自动换行,如果该行末端有个英文单词很长(congra ...
- 跟踪对象属性值的修改, 设置断点(Break on property change)
代码 //Break on property change (function () { var localValue; Object.defineProperty(targetObject, 'pr ...
- 关于List、Set集合以及Map的使用
package tingjizifu; import java.util.*; public class TongJi { /* * 使用Scanner从控制台读取一个字符串,统计字符串中每个字符出现 ...
- noip201506 Message 信息传递
试题描述: 有 n 个同学(编号为 1 到 n )正在玩一个信息传递的游戏.在游戏里每人都有一个固定的信息传递对象,其中,编号为 i 的同学的信息传递对象是编号为 T_i 的同学.游戏开始时,每人都只 ...