20130709 【南华大学 ACM】 新生赛第二场 【D: The mell hall】


Problem D: The mell hall

Time Limit: 2 Sec  Memory Limit:128 MB

Description

In HUST,there are always many students go to the mell hall at the same time as soon as the bell rings.
Students have to queue up for a meal ,and the queue is awalys long,So it takes much time.Suposse there
are N people in a queue,each person has two characteristic value A and B(both of them are integers,read
input for more details),the i-th person in the queue have to spend m(i) =
A1A2
:::Ai 1
Bi
minutes,Where Ai,Bi is the i-th person.s value A,B.Notice that if the order of the queue changes,the waiting time one spend(that is,the value of m(i))may changes too. Of course,every student want to reduce the time he spend.
Apparently,it is impossible to make everyone satis ed,in this problem,we only need to minimize the
waiting time of one who spend the longest time in the queue,that is,minimize Max m(1),m(2),,,m(n).You
can change the order of the queue in anyway in order to complete this problem.
You are asked to output the original location in the queue of the person who will cost the longest time
under optimal solution. Uniquity is insured by the given data.

Input

There are multiple test cases.
For each case, the rst line contains one integerN(1N1000).
The second line containsNintegers Ai
.(0 < Ai <100000)
The third line containsNintergers Bi
(0< Bi <10).
(Bi <10< Ai*bi)

Output

You are asked to output the original location in the queue of the person who will cost the longest time
under optimal solution. Uniquity is insured by the given data.

Sample Input

3
15 20 25
1 3 2

Sample Output

2



----------------------------------------------------------------------------------------------------------

解题报告:

其实呢,这题我看不懂。

不过我个人理解为:

有 n 个人排队买车票( Ai 为第 i 个人买一张车票的时间,Bi为该人要买的车票数),求花费时间最长的人排在第几个?

于是乎,该题很直接。


无非就是求出: Ai*Bi 最大时,i的值(i=0表示第一个人时,输出的为 i+1 )。  


----------------------------------------------------------------------------------------------------------

代码:


#include<stdio.h>

int main()
{
	long a[1005],b[1005],x,max,m;
	int n,i,j;
	while( EOF != scanf("%d",&n) )
	{
		for(i=0;i<n;i++)
			scanf("%ld",&a[i]);
		for(i=0;i<n;i++)
			scanf("%ld",&b[i]);
		max=a[0]*b[0];
		for(x=0,i=1;i<n;i++)
		{
			m=a[i]*b[i];
			if( max<m )
			{
				max=m;
				x=i;
			}
		}	
		printf("%ld\n",x+1);
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值