hd 1070 Milk(sort+结构体)
2016-07-19 16:50
246 查看
Milk
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19038 Accepted Submission(s): 4930
[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<cstdio> #include<cstring> #include<algorithm> using namespace std; struct note{ char name[105]; int p; int v; float ap; }q[110]; bool cmp1(note a,note b) { return a.v>b.v; } bool cmp2(note a,note b) { return a.ap<b.ap; } int main() { int t,i,n; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%s%d%d",&q[i].name,&q[i].p,&q[i].v); sort(q,q+n,cmp1); for(i=0;i<n;i++) { if(q[i].v<200) break; else { int t=q[i].v/200; if(t>5) t=5; q[i].ap=q[i].p*1.0/t; } } int k=i; sort(q,q+k,cmp2); printf("%s\n",q[0].name); } return 0; }
相关文章推荐
- 实时查看及监控PHP-FPM的运行状态
- Kubernetes1.3新特性
- css3中的前缀
- 一个都不能少观后感
- Mongodb副本集+分片集群环境部署记录
- mysql 线程级别的缓冲区
- SQLServer复合查询条件(AND,OR,NOT)对NULL值的处理方法
- 如何打开WCF测试客户端
- C#生成PDF总结
- Linux下which、whereis、locate、find 命令的区别
- POJ3301
- Spring和MyBatis环境整合
- Java调用Tuxedo方案浅析
- 常用加密算法的Java实现(一)
- 导入js出错
- 微信网页授权接口代码示例
- 朴素贝叶斯分类算法
- 处理大数据对象:处理CLOB数据
- TCP/IP学习(一) -- 网络分层(OSI分层和TCP/IP分层)
- 打包好的javaweb项目(.war格式)在tomcat上运行时提示404notfond