题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070

Milk

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 14286    Accepted Submission(s):
3525

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

Hint

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

 
 
题目大意:好久不做题目了,放松一段时间后,重整行囊,继续前行! 先做一水题找找感觉,没想到还找了好久0.0
这一题的要求:1、找到最便宜的牛奶 2、保质期只有五天(包含五天 ) 3、如果都是最便宜的话,要输出体积较大的
 
详见代码。
 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std; int main()
{
char name[],min_name[];
double Min,s;
int min_v;
int T,p,v,d,n;
scanf("%d",&T);
while (T--)
{
Min=;
min_v=;
scanf("%d",&n);
while(n--)
{
scanf("%s%d%d",name,&p,&v);
if (v<)
continue;
if (v/>=)
s=p/;
else
s=p*1.0/(v/);
if(Min>s)
{
min_v=v;
Min=s;
strcpy(min_name,name);
}
else if(Min==s)
{
if(min_v<v)
{
min_v=v;
strcpy(min_name,name);
}
}
}
printf("%s\n",min_name);
}
return ;
}

hdu 1070 Milk(贪心)的更多相关文章

  1. HDU 1070 Milk (模拟)

    题目链接 Problem Description Ignatius drinks milk everyday, now he is in the supermarket and he wants to ...

  2. HDU 1070 - Milk

    给每种牛奶价格和量 要求买最便宜的牛奶 #include <iostream> using namespace std; int t,n; ][]; ],v[]; int main() { ...

  3. Hdu 4864(Task 贪心)(Java实现)

    Hdu 4864(Task 贪心) 原题链接 题意:给定n台机器和m个任务,任务和机器都有工作时间值和工作等级值,一个机器只能执行一个任务,且执行任务的条件位机器的两个值都大于等于任务的值,每完成一个 ...

  4. D - 淡黄的长裙 HDU - 4221(贪心)

    D - 淡黄的长裙 HDU - 4221(贪心) James is almost mad! Currently, he was assigned a lot of works to do, so ma ...

  5. HDOJ.1070 Milk(贪心)

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

  6. hdu 2037简单贪心--活动安排问题

    活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...

  7. HDU 4864 Task (贪心+STL多集(二分)+邻接表存储)(杭电多校训练赛第一场1004)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4864 解题报告:有n台机器用来完成m个任务,每个任务有一个难度值和一个需要完成的时间,每台机器有一个可 ...

  8. HDU 4310 Hero (贪心算法)

    A - Hero Time Limit:3000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  9. hdu 4268 multiset+贪心

    Alice和Bob有n个长方形,有长度和宽度,一个矩形可以覆盖另一个矩形的条件的是,本身长度大于等于另一个矩形,且宽度大于等于另一个矩形,矩形不可旋转,问你Alice最多能覆盖Bob的几个矩形? /* ...

随机推荐

  1. Qt Creator子目录项目-类似VS解决方案

    版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:Qt Creator子目录项目-类似VS解决方案     本文地址:http://techie ...

  2. VUE01指令

    一.下载Vue2.0的两个版本: 官方网站:http://vuejs.org/ 开发版本:包含完整的警告和调试模式 生产版本:删除了警告,进行了压缩 二.项目结构搭建 这个部分要视频中有详细讲解. 三 ...

  3. my.conf 修改编码

    mysql汉字乱码的原因 mysql默认的编码是Latin1是I-8859-1的别名,但Latin1是不支持汉字的,所以要将其改为UTF-8或GBK 1.关闭mysql服务器,这个很重要. 2.通过m ...

  4. JSTL标签之核心标签

    JSTL(JSP Standard Tag Library ,JSP标准标签库)是一个实现 Web应用程序中常见的通用功能的定制标记库集,这些功能包括迭代和条件判断.数据管理格式化.XML 操作以及数 ...

  5. java 当读取的结果为-1时候说明已经读取结束了

    当读取的结果为-1时候说明已经读取结束了

  6. P4035 [JSOI2008]球形空间产生器

    题目描述 有一个球形空间产生器能够在 nn 维空间中产生一个坚硬的球体.现在,你被困在了这个 nn 维球体中,你只知道球面上 n+1n+1 个点的坐标,你需要以最快的速度确定这个 nn 维球体的球心坐 ...

  7. PowerDesigner 建表语句没出现字段描述

    填写了Name 还是没有 修改步骤如下:

  8. 【Codeforces Round #405 ( Div 2)】题解

    Bear and Big Brother 签到题,直接模拟就可以了. Bear and Friendship Condition 满足只能是每个朋友圈中每个人和其他人都是朋友,这样的边数的确定的. 然 ...

  9. BZOJ3670 & 洛谷2375 & UOJ5:[NOI2014]动物园——题解

    https://www.lydsy.com/JudgeOnline/problem.php?id=3670 https://www.luogu.org/problemnew/show/P2375#su ...

  10. 洛谷 P1291 [SHOI2002]百事世界杯之旅 解题报告

    P1291 [SHOI2002]百事世界杯之旅 题目描述 "--在2002年6月之前购买的百事任何饮料的瓶盖上都会有一个百事球星的名字.只要凑齐所有百事球星的名字,就可参加百事世界杯之旅的抽 ...