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]);
        }
    }

}
时间: 2024-11-13 06:52:23

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

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

Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一个整数,字符表示画笔,整数(>=5)表示高度. Output 画横线总是一个字符粗,竖线随着总高度每增长6而增加1个字符宽.当总高度从5增加到6时,其竖线宽度从1增长到2.下圈高度不小于上圈高度,但应尽量接近上圈高度,且下圈的内径呈正方形. 每画一个"8"应空一行,但最前和最后都无空

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

Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or the film of the same name by Stanley Kubrick. In it a spaceship is sent from Earth to Saturn. The crew is put into stasis for the long flight, only tw

HDOJ(HDU) 1555 How many days?(水题)

Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, k,(2 <= k <= M <= 1000).M = 0, k = 0代表输入结束. Output 对于每个测试实例输出一个整数,表示M元可以用的天数. Sample Input 2 2 4 3 0 0 Sample Output 3 5 水题.... import java.util.

HDOJ(HDU) 1859 最小长方形(水题、、)

Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内. Input 测试输入包含若干测试用例,每个测试用例由一系列坐标组成,每对坐标占一行,其中|x|和|y|小于 231:一对0 坐标标志着一个测试用例的结束.注意(0, 0)不作为任何一个测试用例里面的点.一个没有点的测试用例标志着整个输入的结束. Output 对每个测试用例,在1行内输出2对整数

HDOJ/HDU 2560 Buildings(嗯~水题)

Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, the green grids represent the buidings. Given the size of the HZNU Campus, and the color of each grid, you should count how many green grids in the N

字符-一道acm水题 all in all 一直找不出错误 求大神解答

问题描述 一道acm水题 all in all 一直找不出错误 求大神解答 描述字符串s和t均由字母组成,若在t中除去一些字母能够得到s,我们就说s是t的一个子串.比如abc就是acbefc的子串(acbefc去掉第二.第四.第五个字符后就得到abc)输入有若干组输入数据,每组一行,分别为字符串s和t,s与t之间用空格隔开输出对于一组s与t,若s是t的子串,则输出Yes,否则输出No 样例输入sequence subsequence abc acb VERDI vivaVittorioEmanu

HDU 1228 模拟水题

字符串的水题 用了两种方法做的 感觉做法都很山寨 题目很水 如果不限制小于100会很好   #include <iostream> #include<cstdio> #include<cstring> using namespace std; int pd(string s) { if(s=="zero") return 0; if(s=="one") return 1; if(s=="two") return

HDU1788 水题

本以为是道中国剩余定理的题 结果是一道水题啊 题意就是求最小公倍数然后减去a就可以了 #include <iostream> #include<cstdio> #include<cstring> using namespace std; long long gcd(long long a,long long b) { return b==0?a:gcd(b,a%b); } int main() { long long i,a,m,ans; while(cin>&g

acm水题 二叉树模拟 hdu5444,能想到的测试数据都测了还是WA,求大神

问题描述 acm水题 二叉树模拟 hdu5444,能想到的测试数据都测了还是WA,求大神 1)我的代码(题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=5444,也有复制内容在代码下面) #include <iostream> #include <string.h> using namespace std; const int maxn=1010; char record[maxn]; int sum=0; struct tree{ i