The mell hell
Time Limit: 1 Sec Memory Limit: 128 MBSubmissions: 78 Solved: 33
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)=A[1]*A[2]*…A[i-1]/B[i] minutes,Where A[i],B[i] 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 satisfied,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 first line contains one integer N(1≤N≤1000).
The second line contains N integers A[i].(0<A[i]<100000)
The third line contains N intergers B[i](0<B[i]<10).
(B[i] < 10 < A[i]*b[i]) (Please pay attention to the range, it is useful on this problem)
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
HINT
Source
The 7th(2012) ACM Programming Contest of HUST
Problem Setter: Bingzhe Liu
http://acm.hust.edu.cn/problem.php?id=1611
/*E题 The mell hell
The mell hell
题意:一些人排队 每个人都有一个特定的 a,b 第i个人对应为a[i],b[i]。第i个人排队需要的时间是mi=
a[1]*a[2]*…a[i-1]/b[i]。你可以调动每个人的顺序即对任意一个排列都会有一个最大的m[i]=Max{ m(1),m(2),…,m(n)},问满足Max{ m(1),m(2),…,m(n)}最小的队列中最大的m[i]在初始序列中的位置 。
思路:
注意这句话 (B[i] < 10 < A[i]*b[i]) (Please pay attention to the range, it is useful on this problem)
m[i+1]/m[i]=b[i]*a[i]/b[i+1]>0 所以m[i+1]是递增的 所以对于没个序列 都是最后一个最大
现在只要求最后一个最小的是哪个 m(n)=a1*a2*a3*...*an/(an*bn);
只要求(an*bn)最大
代码:*/
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
using namespace std;
struct haha
{
double x;
double y;
int id;
}a[10000];
bool cmp(struct haha a,struct haha b)
{
return a.x*a.y<b.x*b.y;
}
int main()
{
int i,n;
while(scanf("%d",&n)!=EOF)
{
for(i=1;i<=n;i++)
{
scanf("%lf",&a[i].x);
a[i].id=i;
}
for(i=1;i<=n;i++)
{
scanf("%lf",&a[i].y);
}
sort(a+1,a+1+n,cmp);
printf("%d\n",a[n].id);
}
return 0;
}