HZNUOJ 1472 The nearest taller cow

该博客介绍了HZNUOJ 1472题目的解决方案,即计算每头牛与其最近的比它高的牛之间的平均距离。当直接暴力解法会导致超时,作者提出了一种优化算法,通过双向扫描并记录答案的方法提高效率。博客提供了样例输入和输出,并给出了防止精度问题的提示以及AC代码。
摘要由CSDN通过智能技术生成

1472: The nearest taller cow

Time Limit: 3 Sec  Memory Limit: 64 MB
Submit: 151  Solved: 6  Scores: 94.48

Description

Farmer Zhao’s N cows (1 ≤ N ≤ 1,000,000) are lined up in a row. So each cow can see the nearest cow which is taller than it. You task is simple, given the height (0 < height ≤ 109) of each cow lined up in the row, to calculate the distance between each cow and its nearest taller cow (the nearest cow which is taller than him), if it is the tallest cow in the row, such distance is regarded as n. You should output the average distance.

Input

For each test case:

Line 1: One integers, N

Lines 2: N integers. The i-th integer is the height of the ith cow in the row.

Output

The average distance to their nearest taller cow, rounded up to 2 decimals.

Sample Input

7

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值