题解:T480718 eating

eating

题目背景

从前有个荣光的王国,小 A 是里面的国王,今天他要赐予他的子民以仓廪。

题目描述

在一条街上有 nnn 个饭店。小 A 站在这条街的最左端。

iii 个饭店离这条街最左端的距离是 aia_iai,它所售卖的菜品的美味值是 bib_ibi

小 A 不想走太多路,但是又想吃到好吃的东西。因此他定义一个饭店的吸引力是 wi=biaiw_i = \frac{b_i}{a_i}wi=aibi

小 A 想知道吸引力最大的饭店的编号是多少。如果有多个吸引力最大的饭店,你要告诉他距离街道左端距离最近的那个饭店的编号。

输入格式

第一行是一个整数 nn

c++题解,代码无注释 T-2 Rabbits and Grass 分数 35 作者 陈越 单位 浙江大学 There is a proverb(谚语)saying that “rabbits don’t eat grass around their nests”(兔子不吃窝边草). Now given several blocks of grass that are trimmed in a line. Assume that a rabbit starts eating from any block, and will never eat the neighboring blocks next. Your job is to tell the maximum amount of grass this rabbit can eat. Input Specification: Each input file contains one test case. For each case, two positive integers are given in the first line, namely N (≤10 5 ), the number of blocks, and i (1≤i≤N), the block index that the rabbit starts eating. Then N positive integers (≤10 3 ) are given in the next line, separated by spaces. The integers are the amount of grass in the corresponding blocks. Output Specification: Print in a line the maximum amount of grass this rabbit can eat. Then in the next line, print in order the indices of the blocks that rabbit eats. All the numbers in a line must be separated by 1 space, and there must be no extra space at the beginning or the end of the line. Note: we have to assume that the rabbit only jumps in one direction. Otherwise if it jumps back and forth, it can eat up all the grass. If both directions are okay for the rabbit, it always prefer jumping toward left. And more, if there are more than one block to choose from, the rabbit always prefer the nearest block it can jump to. Sample Input 1: 10 4 2 1 4 3 1 1 5 2 3 1 Sample Output 1: 11 4 7 9 Sample Input 2: 10 8 2 1 4 3 1 1 5 2 3 1 Sample Output 2: 9 8 6 3 1 代码长度限制 16 KB Java (javac) 时间限制 800 ms 内存限制 512 MB 其他编译器 时间限制 150 ms 内存限制 64 MB 栈限制 8192 KB
最新发布
08-22
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值