HDU1070:Milk
Milk
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 25253 Accepted Submission(s): 6841
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.
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.
2
Yili 10 500
Mengniu 20 1000
4
Yili 10 500
Mengniu 20 1000
Guangming 1 199
Yanpai 40 10000
Mengniu
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.
题意:每瓶奶最多喝5天,当剩余少于200ml时就全部扔掉(资本主义的丑恶嘴脸),刚买回来少于200ml自动忽略,求哪种奶的性价比最高,当性价比相同时选择容量最多的。
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<limits.h>
using namespace std;
struct wzy{
char s[20];
int p,v;
}B[1010];
int yuan(int x,int y)
{
if(x<200) return INT_MAX;
else if(x/200>5) return y/5;
else return y/(x/200);
}
int cmp(wzy u,wzy v)
{
if(yuan(u.v,u.p)==yuan(v.v,v.p)) return u.v>v.v;//性价比一样的时候,把容量大的放前面
else return yuan(u.v,u.p)<yuan(v.v,v.p);
}
int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++) scanf("%s %d%d",B[i].s,&B[i].p,&B[i].v);
sort(B,B+n,cmp);
printf("%s\n",B[0].s);
}
return 0;
}
HDU1070:Milk的更多相关文章
- POJ3261:Milk Patterns——题解
http://poj.org/problem?id=3261 给一个序列,求至少出现 k 次的最长重复子串,这 k 个子串可以重叠. 论文题+傻逼题. 上一道题(POJ1743)会做即可. 还是二分长 ...
- POJ3261:Milk Patterns
题面 vjudge Sol 二分答案+分组,判断有没有一个组的后缀个数不小于 k 做法 # include <bits/stdc++.h> # define IL inline # def ...
- head first-----decorate design pattern
浅谈设计模式之------装饰者模式 首先给出装饰者模式的定义吧: 动态的将责任附加到对象上,若是要扩展功能,装饰者提供了比继承更加具有弹性的替代方案. 其中 ...
- 设计模式之装饰者模式(Decorator Pattern)
一.什么是装饰者模式? 装饰者模式能够完美实现“对修改关闭,对扩展开放”的原则,也就是说我们可以在不修改被装饰者的前提下,扩展被装饰者的功能. 再来看看我们的文件操作代码: 1 InputStream ...
- ExtJs的事件机制Event(学员总结)
一.事件的三种绑定方式 1.HTML/DHTML 在标签中直接增加属性触发事件 [javascript] view plaincopy <script type="text/javas ...
- 后缀数组--可重叠的K次最长重复子串(POJ3261)
题目:Milk Patterns #include <stdio.h> #include <string.h> #define N 1000010 int wa[N],wb[N ...
- Java设计模式(三)-修饰模式
我们都知道.能够使用两种方式给一个类或者对象加入行为. 一是使用继承.继承是给一个类加入行为的比較有效的途径.通过使用继承,能够使得子类在拥有自身方法的同一时候,还能够拥有父类的方法.可是使用继承是静 ...
- 3.Decorator Pattern(装饰者模式)
装饰者模式: 动态地将责任附加到对象上.想要扩展功能,装饰者提供有别于继承的另一种选择. 举例: 不知道大家学校的食堂是什么点餐制度(或者大家就直接想成吃火锅,我们要火锅料 + 配菜),我们学校的点餐 ...
- English trip -- VC(情景课) 7 A Shopping 购物
Words The clothes place a dress 长裙 short skirt 短裙 pants 裤子 / trousers 长裤 / shorts 短裤 a shir ...
随机推荐
- 怎么运行cocos2dx 3.x simulator?
1.simulator的好处是: 快速切换分辨率:F5快速重新启动项目: 这对于脚本语言来说都是很方便快捷的. 2.涉及到显示参数的文件有两个: ①lang,这个是菜单的语言文件,如果没有这个文件的话 ...
- Codeforces 837D - Round Subset(dp)
837D - Round Subset 思路:dp.0是由2*5产生的. ①dp[i][j]表示选i个数,因子2的个数为j时因子5的个数. 状态转移方程:dp[i][j]=max(dp[i][j],d ...
- python导包显示No module named XXX问题
最近用sublime text写python脚本,在导包是一直显示No module named XXX. 问题描述: 首先文件夹的目录结构如下: count.py文件,代码如下: #coding=u ...
- 真核生物基因结构 & mRNA结构
参考: 分子生物学教材 再一次,翻看真核生物基因结构! mRNA基本结构特点 Structure and function of Messenger RNA (mRNA ) 基因结构 其实这个结构不完 ...
- WPF 的 数据源属性 和 数据源
(一)数据源(数据对象)属性 :path 或 path的值(path=VM.Property或M.Property),通常具有通知功能(特例除外). (二)path不能孤立而存在,它一定具有所归属的 ...
- CAS操作原理分析
一.CAS简单介绍 CAS:Compare and Swap, 翻译成比较并交换. java.util.concurrent包中借助CAS实现了区别于synchronouse同步锁 ...
- 『TensorFlow』通过代码理解gan网络_中
『cs231n』通过代码理解gan网络&tensorflow共享变量机制_上 上篇是一个尝试生成minist手写体数据的简单GAN网络,之前有介绍过,图片维度是28*28*1,生成器的上采样使 ...
- 10046 event 知多少
10046 event 知多少 2017年5月10日 10:08 1.在当前session级打开trace 适用于SQL语句可以在新的session创建后再运行. 在session级收集10046 t ...
- 数据库操作——SQL
()修改数据表内容 UPDATE t_com_staffinfo set upnative = '河南省郑州市金水区' WHERE id = 1082
- (转)使用UTL_SMTP包发送邮件
使用UTL_SMTP包发送邮件 参考文档 Email From Oracle PL/SQL (UTL_SMTP) UTL_SMTP Oracle 存储过程中发送邮件,并支持用户验证.中文标题和内容