Problem D: The mell hall
Time Limit: 2 Sec Memory Limit:128 MBDescription
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;
}