Milk HDU - 1070

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

写这篇博客的就是为了吐槽一下题目描述的坑。题目原文是这样描述的
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). 
就是说这个人不喝已经生产六天及以上的牛奶。因为不注意想当然的按照题目给的6来计算。其实1号到6号只有五天的时间。

解题思路:类比在一个数组中找最大值的方法,不一样的是需要计算性价比和注意性价比相同时选取量多的那个。假设第一个是最大值然后往后不停的比较变换,一遍过后就得到结果。

code:

#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream> 

using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	int t;
	cin >> t;
	while(t--)
	{
		int n; cin >> n;
		string name;
		int money, volume;
		int days;
		double perm;	// 性价比 
		
		string ans;		// 输出结果 
		int m, v;
		int ds;
		double pm;
		
		int cnt = 0;	// 记录读了多少次 
		do{
			cin >> name >> money >> volume;
			ans = name;
			m = money;
			v = volume;
			cnt ++;
		}while(v < 200);	// 一直读入到第一个volume大于200的数据 
		
		ds = v / 200;
		if(ds > 5)	// 计算性价比 
			pm = 1.0 * money / 5;
		else
			pm = 1.0 * money / ds;
		for(int i=cnt; i<n; i++)	// 从上次读入的地方继续读入 
		{
			cin >> name >> money >> volume;
			if(volume < 200)
				continue;
			days = volume / 200;
			if(days > 5)
			{
				perm = 1.0 * money / 5;
				if(perm < pm)
				{
					ans = name;
					m = money;
					v = volume;
					pm = perm;
				}
				else if(perm == pm)
				{
					if(volume > v)	// 性价比相同时选量多的那一个 
					{
						ans = name;
						m = money;
						v = volume;
						pm = perm;
					}
				}
			}
			else
			{
				perm = 1.0 * money / days;
				if(perm < pm)
				{
					ans = name;
					m = money;
					v = volume;
					pm = perm;
				}
				else if(perm == pm)
				{
					if(volume > v)
					{
						ans = name;
						m = money;
						v = volume;
						pm = perm;
					}
				}
			}
		}
		cout << ans << endl;
		
		
	}
	
	
	return 0;
 } 

 

全部评论

相关推荐

专业嗎喽:个人信息名字太大,合到电话邮箱那一栏就行,有党员写过党,剩下其他全删,站空太大了 把实习经历丰富,放最前面,然后是个人评价,技能之类的,然后是学校信息。项目经历最后面,可以就选一个自己擅长的。 现在是学校不是92就扣分的,没必要放前面。 然后现在看重实习经历>竞赛经历(校园经历)>课程项目经历
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务