hdu1070Milk
2016-08-16 12:57
190 查看
Milk
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19525 Accepted Submission(s): 5081
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
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.
[align=left]Output[/align]
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.
[align=left]Sample Input[/align]
2
2
Yili 10 500
Mengniu 20 1000
4
Yili 10 500
Mengniu 20 1000
Guangming 1 199
Yanpai 40 10000
[align=left]Sample Output[/align]
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 <cstdio>
#include <cstring>
using namespace std;
struct node
{
string s;
int p,l;
double e;
int day;
} s[1010];
int main()
{
int min,t,n,k;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
min=999999;
k=0;
for(int i=0; i<n; i++)
{
cin>>s[i].s>>s[i].p>>s[i].l;
if(s[i].l<200)
continue;
s[i].day=s[i].l/200;
if(s[i].day>=6)s[i].day=5;
s[i].e=s[i].p/s[i].day*1.0;
if(min>s[i].e)
{
min=s[i].e;
k=i;
}
if(min==s[i].e)
{
if(s[i].l>s[k].l)
{
min=s[i].e;
k=i;
}
}
}
cout<<s[k].s<<endl;
}
return 0;
}
/*
#include<iostream>
#include<string>
using namespace std;
struct milk
{
string s;
int p;
int v;
double e;
int day;
}d[1000];
int main()
{
int t,n,i,j;
double min;
while(cin>>t)
{
while(t--&&cin>>n)
{
min=999999;
j=0;
for(i=0;i<n;i++)
{
cin>>d[i].s>>d[i].p>>d[i].v;
if(d[i].v<200)continue;
d[i].day=d[i].v/200;
if(d[i].day>=6)d[i].day=5;
d[i].e=d[i].p/d[i].day*1.0;
if(min>d[i].e){min=d[i].e;j=i;}
if(min==d[i].e)
{
if(d[i].v>d[j].v)
{
min=d[i].e;
j=i;
}
}
}
cout<<d[j].s<<endl;
}
}
return 0;
}
*/
[align=left]Author[/align]
相关文章推荐
- 内存链表union类型节省内存
- python爬取花瓣网图片
- 随便写的随机数生成器,目前并没有实现设置精度和去重功能
- JS判断输入是否为整数的正则表达式
- 《编码的法则--C++实用经验》
- Android 开发绕不过的坑:你的 Bitmap 究竟占多大内存?
- HDU 2196 Computer(树状DP)
- 【搜索】 noi openjudge 2.5 拯救行动
- python3.3 lxml+beautifulsoup 爬虫说明
- SGU 149 Computer Network 树状DP求单点到树的最大距离
- bjfu1012 素数
- 漫步微积分二十一——不定积分和换元法
- IT相关证书
- .Net扩展类的研究-提高编程效率
- Laravel笔记之Call to undefined method DebugBar\DebugBar::warning()
- NSString 字符串的截取和替换
- SpringMVC(二)
- 灵活运用 SQL SERVER FOR XML PATH
- bjfu1011 Convert decimal to fraction
- hadoop2.2.0安装spark1.1.0(maven编译)