南华大学ACM个人练习 第二场 D: The mell hall

Problem D: The mell hall

Time Limit: 2 Sec   Memory Limit: 128 MB
Submit: 22   Solved: 6
[ Submit][ Status][ Web Board]

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
 
 
题目意思是要你求出谁所消耗的时间最长,其实理解起来挺麻烦的,后来我就想,如果把这个排序一下,最大的那个就相当于排在最后,所消耗的时间自然也就最大了。在后来和同学讨论一下,其实不用排序也能做出来,只要保存那个最大的数的下标,并将其输出就好了。
代码如下:
 

#include<iostream>
#include<cstdlib>
#include<algorithm>

using namespace std;

const int MAXN=100000+5;

struct S{
    int x;
    int y;
    int id;
}str[MAXN];

bool cmp(struct S a,struct S b)
{
    return a.x*a.y<b.x*b.y;
}

int main(void)
{
    int i;
    int n;
    while(cin>>n)
    {
        for(i=1; i<=n; i++)
        {
            cin>>str[i].x;
            str[i].id=i;
        }
        for(i=1; i<=n; i++)
        {
            cin>>str[i].y;
        }
        sort(str+1,str+n+1,cmp);
        cout<<str[n].id<<endl;
    }
    return 0;
}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值