暑假培训题

本文探讨了一种算法,用于解决在餐厅排队时找到等待时间最长者的最优位置问题。通过输入人员的A、B值,算法能计算出每个人实际等待时间,并找出等待时间最长的人所在位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

这道题刚看的时候真的被那个求时间的公式坑了,其实这道题就是求排队人中的A*B最大人的编号

#include<stdio.h>
  int n;
  struct node{
      int x;//记录权值A
      int y;//记录权值B
      int  num;//记录编号
      int f;//记录A和B的乘积
  }s[1005]; 
 int main()
 {
     int i,max=0,j;
     while(scanf("%d",&n)!=EOF)
     {
        for(i=0;i<n;i++)
             scanf("%d",&s[i].x);
         for(i=0;i<n;i++)
         {
            scanf("%d",&s[i].y);
             s[i].f=s[i].x*s[i].y;
             s[i].num=i+1;
         }
        for(i=0;i<n;i++)
        {
        if(max<s[i].f)
        {max=s[i].f;
        j=i;}
        }
        printf("%d\n",s[j].num);
        max=0;
     }
     return 0;
     }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值