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 ...
随机推荐
- SKViedoNode类
继承自 SKNode:UIResponder:NSObject 符合 NSCoding(SKNode)NSCopying(SKNode)NSObject(NSObject) 框架 /System/L ...
- test_wifi
#!/system/bin/sh #Load driver echo "ASD WIFI TESTING..." AP_NAME="default" num=0 ...
- Php面向对象 – 单例模式
Php面向对象 – 单例模式 保证类仅仅有一个实例 1. 怎样能够解决一个类能够被无限地实例化? New,就能实例化一次,怎么去限制,用户不能无限次地new? 将构造方法私有化.全部外部的new ...
- 杭电 2047 阿牛的EOF牛肉串 (递推)
阿牛的EOF牛肉串 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- Linux Mysql如何移动MySQL数据库目录位置
假如要把目录移到/home/data下需要进行下面几步: 1.home目录下建立data目录 cd /home mkdir data 2.把MySQL服务进程停掉: mysqladmin -u r ...
- Java基础知识强化之IO流笔记01:异常的概述和分类
IO流操作的时候会出现很多问题,java中叫作异常,所以我们先介绍一下异常: 1. 程序的异常:Throwable(Throwable类是java中所有异常或错误的超类) (1)严重问题:Error ...
- i利用图片按钮 和 input type="image" 为背景提交表单
<img src="img/cancel.jpg" onclick="javascript:document.getElementByIdx_x('loginFor ...
- Myeclipse笔记
1. 自动提示:窗口->首选项->Java->编辑器->内容辅助->自动激活,在下面的“Java的自动激活触发器里面填上“.abcdefghijklmnopqrstuv ...
- 数据库、C#、Java生成唯一GUID 方法
GUID(Global unique identifier)全局唯一标识符,它是由网卡上的标识数字(每个网卡都有唯一的标识号)以及 CPU 时钟的唯一数字生成的的一个 16 字节的二进制值.GUID ...
- TFS统计编码行数语句
****** Script for SelectTopNRows command from SSMS ******/ SELECT TeamProjectProjectNodeName 项目名称 ,c ...