HDU 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.
分析:
简单的结构体排序,要找到最简单的牛奶,肯定就是单价最少的。
代码:
#include<iostream>
#include<stdio.h>
#include<cstdlib>
#include<string>
#include<string.h>
#include<algorithm>
using namespace std;
struct Niunai
{
char str[103];
double a;///价钱
double b;///体积
double c;///单价
} aa[104];
bool camp(Niunai x,Niunai y)
{
if(x.c!=y.c)///单价按照从小到大排序
return (x.c<y.c);
else
return (x.b>y.b);///单价相同,按照体积从大到小排序
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
memset(aa,0,sizeof(aa));///每次进行完,数组要刷新,
int m;
double n1;
scanf("%d",&m);
for(int i=0; i<m; i++)
{
scanf("%s%lf%lf",aa[i].str,&aa[i].a,&aa[i].b);
if(aa[i].b<200)
aa[i].c=0x3f3f3f;
else
{
n1=(int)(aa[i].b/200);
if(n1>=5)
n1=5;
aa[i].c=(double)(aa[i].a/n1);///得到每天的价钱
}
}
sort(aa,aa+m,camp);
printf("%s\n",aa[0].str);
}
return 0;
}
HDU 1070 Milk (模拟)的更多相关文章
- hdu 1070 Milk(贪心)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1070 Milk Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 1070 - Milk
给每种牛奶价格和量 要求买最便宜的牛奶 #include <iostream> using namespace std; int t,n; ][]; ],v[]; int main() { ...
- HDU 4121 Xiangqi 模拟题
Xiangqi Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4121 ...
- hdu 5071 Chat(模拟)
题目链接:hdu 5071 Chat 题目大意:模拟题. .. 注意最后说bye的时候仅仅要和讲过话的妹子说再见. 解题思路:用一个map记录每一个等级的妹子讲过多少话以及是否有这个等级的妹子.数组A ...
- hdu 4740【模拟+深搜】.cpp
题意: 给出老虎的起始点.方向和驴的起始点.方向.. 规定老虎和驴都不会走自己走过的方格,并且当没路走的时候,驴会右转,老虎会左转.. 当转了一次还没路走就会停下来.. 问他们有没有可能在某一格相遇. ...
- HDU 2568[前进]模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2568 关键思想:傻傻地模拟 代码如下: #include<iostream> using ...
- hdu 4964 恶心模拟
http://acm.hdu.edu.cn/showproblem.php?pid=4964 给定语句,按照语法翻译html并输出. 就是恶心的模拟,递归搞就行了 处理id和class时,在一个'&g ...
- HDOJ.1070 Milk(贪心)
Milk 点我挑战题目 题意分析 每组测试数据给出一系列牛奶商品,分别是牛奶的品牌,价格,以及体积.在读取数据的时候,体积在200以下的牛奶直接忽略掉.并且每天要喝200ML的牛奶.但是无论牛奶体积有 ...
- HDU 5965 枚举模拟 + dp(?)
ccpc合肥站的重现...一看就觉得是dp 然后强行搞出来一个转移方程 即 根据第i-1列的需求和i-1 i-2列的枚举摆放 可以得出i列摆放的种类..加了n多if语句...最后感觉怎么都能过了..然 ...
随机推荐
- ios::sync_with_stdio(false)提高C++读写速度
版权声明:若无来源注明,Techie亮博客文章均为原创. 转载请以链接形式标明本文标题和地址: 本文标题:ios::sync_with_stdio(false)提高C++读写速度 本文地址:h ...
- 老生常谈-从输入url到页面展示到底发生了什么
来自:咸鱼老弟 - 博客园 链接:http://www.cnblogs.com/xianyulaodi/p/6547807.html
- spring ioc经典总结
component-scan标签默认情况下自动扫描指定路径下的包(含所有子包),将带有 @Component @Repository @Service @Controller标签的类自动注册到spri ...
- checkBox1_CheckedChanged(object sender, EventArgs e)和checkBox1_CheckStateChanged(object sender, EventArgs e)不同
using System; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms ...
- Android Camera多屏幕适配解决预览照片拉伸
通常,拍照预览页面的照片拉伸主要与下面两个因素有关: 1. Surfaceview的大小 2. Camera中的Preview的大小 如下图: 图中preview显示的是手机支 ...
- Java中的缓冲流详解
缓冲流增强了读写文件的能力,比如Student.txt是一个学生的名单,每个姓名占一行.如果我们想要读取名字,那么每次必须读取一行,使用FileReader流很难完成这样的任务,因为我们不清楚一行有多 ...
- html的body内标签之超链接
一,先来个简单的练练手,target="_blank" 的作用是在新的tab中打开页面.href 是超链接的意思. <!DOCTYPE html> <html l ...
- BZOJ2809:[Apio2012]dispatching——题解
http://www.lydsy.com/JudgeOnline/problem.php?id=2809 题面复制于:https://www.luogu.org/problemnew/show/155 ...
- AOJ.176 两数组最短距离 (乱搞题)
两数组最短距离 点我挑战题目 题意分析 给出2个数组,让求出2个数组元素差的绝对值的最小值是多少. 我这里是o(m+n)的算法.首先对于第一个数组,让他的第一个元素和第二个元素比较,如果他的第一个元素 ...
- eclipse ide for java ee developers 开发环境搭建(J2EE) 【转载】
使用eclipse真的有年头了,相信java程序员没有不知道它的,最近在给团队中新来的应届生做指导,专门讲解了一下Eclipse开发环境的搭建过程, 一是帮助他们尽快的熟悉IDE的使用,二也是保证团队 ...