hdu 1070(结构体排序)

Milk

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 13639    Accepted Submission(s): 3328

Problem Description

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.

Input

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.

Output

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.

Sample Input

2
2
Yili 10 500
Mengniu 20 1000
4
Yili 10 500
Mengniu 20 1000
Guangming 1 199
Yanpai 40 10000

Sample Output

Mengniu
Mengniu

Hint

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.

 

Author

Ignatius.L

难点:关于sort排序的不能得心应手

时间:8.8

做题人:洛可可

主要考查的是结构体的二级排序,并且是double 型的数据不能直接 等号表示,两者相等,因为牵扯到精度的问题。

二级排序的sort代码如下:

<span style="font-size:14px;">#include<stdio.h>
#include<algorithm>
using namespace std;
struct milk{
	char log[110];
	int p;
	int v;
	double xjb;
}a[110];
int cmp(milk x,milk y)
{
	if(x.xjb!=y.xjb)
	return x.xjb<y.xjb;
	return x.v>y.v;
}
int main()
{
	int n,i,m;
	scanf("%d",&n);
	while(n--)
	{
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%s%d%d",a[i].log,&a[i].p,&a[i].v);
			//getchar();
			if(a[i].v>1200)
			a[i].xjb=a[i].p*1.0/1200;
			else
			a[i].xjb=a[i].p*1.0/a[i].v;
		}
		sort(a,a+m,cmp);
		for(i=0;i<m;i++)
		{
			if(a[i].v<200)
			continue;
			else
			{
				printf("%s\n",a[i].log);
				break;
			}
		}
	}
	return 0;
}</span>

qsort代码如下:

<span style="font-size:14px;">#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct milk{
	char log[110];
	int p;
	int v;
	double xjb;
}a[110];
int cmp(const void *a,const void *b)
{
	if((*(milk *)a).xjb>(*(milk *)b).xjb)
	return  1;
	else if(((*(milk *)a).xjb<(*(milk *)b).xjb))
	return -1;
	else
	return (((milk *)a)->v)<(((milk *)b)->v);
}
int main()
{
	int t,i,n;
	scanf("%d",&t);
	while(t--)
	{
		scanf("%d",&n);
		getchar();
		for(i=0;i<n;i++)
		{
			scanf("%s %d %d",a[i].log,&a[i].p,&a[i].v);
			getchar();
			if(a[i].v>1200)
			a[i].xjb=a[i].p*1.0/1200;</span>
<span style="font-size:14px;">                           else
			a[i].xjb=a[i].p*1.0/a[i].v;
		}
		qsort(a,n,sizeof(a[0]),cmp);
		for(i=0;i<n;i++)
		{
			if(a[i].v<200)
			continue;
			else
			{
				printf("%s\n",a[i].log);
				break;
			}
		}
	}
	return 0;
}

</span>

hdu 1070(结构体排序)

时间: 2024-07-31 01:43:34

hdu 1070(结构体排序)的相关文章

HDOJ 2111. Saving HDU 贪心 结构体排序

Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 7194    Accepted Submission(s): 3345 Problem Description 话说上回讲到海东集团面临内外交困,公司的元老也只剩下XHD夫妇二人了.显然,作为多年拼搏的商人,XHD不会坐以待毙的.  一天,当他正在苦思冥想解困良策的

hdu 5182 结构体排序

BC # 32 : 打 BC 的时候没看全三个关键字,WA 了五发,花了近一小时,问了一下才发现少看一个条件,于是顺利给跪. 题意:给出若干城市的两次空气质量,首先按空气质量差排序,若相等则按第二次排序,再相等则按输入顺序排. 1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 using namespace std; 5 6 struct p{ 7 int a,l,t; 8 }a[200];

HDU 1084 [What Is Your Grade?] 结构体排序

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1084 题目大意:共5道题,N个学生.做出5道满分,0道50分.做出1-4道的同学,若在前50%(向下取整),则获得95.85.75.65,若在后50%则获得90.80.70.60. 关键思想:结构体排序 //结构体排序,考虑边界 #include <iostream> #include <algorithm> #include <cmath> #include <me

HDU 2409 Team Arrangement (结构体排序)

题目链接:HDU 2409 Team Arrangement 题意:给出22个人(编号,名字,踢的位置,在队里的时间),让我们选DD-MM-SS的阵型+一个守门员.在选出队长(时间在最久的就是队长,时间相同编号大为队长),选人的顺序是从编号小的开始. 结构体排序就好了,注意出输出是按队长,D,M,S的顺序,选队长记录队长的编号(而不是下标,我的代码之后还要排序). AC代码: #include<stdio.h> #include<string.h> #include<algo

hdu 5702 Solving Order(结构体排序 水题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5702 Solving Order Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 184    Accepted Submission(s): 135 Problem Description Welcome to HDU to take p

【结构体排序】hdu 2409 Team Arrangement

[结构体排序]hdu 2409 Team Arrangement 题目链接:hdu 2409 Team Arrangement 题目大意 给出22个球员的各种信息,要求按照给出的阵形选择球员和队长共11人: 选择球员的规则是:同角色的球员按照编号从小到大选择,直到选够此角色的人数: 选择队长的规则是:在所有已经被选择为某角色的球员中,选择服役时间最长的那个球员, 如果服役时间时间相同,就选择编号较大的那一个球员: 2006 Asia Regional Tehran(伊朗首都德黑兰)的第一题,题意

HDU 1862 EXCEL排序(结构体排序)

EXCEL排序 Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 16387    Accepted Submission(s): 6137 Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<=1

hdu 1069 Monkey and Banana (结构体排序,也属于简单的dp)

Monkey and Banana Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7770    Accepted Submission(s): 4003 Problem Description A group of researchers are designing an experiment to test the IQ of a

HDOJ 1009. Fat Mouse&#39; Trade 贪心 结构体排序

FatMouse' Trade Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 56784    Accepted Submission(s): 19009 Problem Description FatMouse prepared M pounds of cat food, ready to trade with the cats g