题目链接: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;
 }