AcWing 1843. 圆形牛棚(java)
原题链接
简单
作者:
yoiy-sk
,
2022-01-26 15:54:49
,
所有人可见
,
阅读 210
import java.util.Scanner;
public class Main{
static int N = 1010;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] q = new int[N];
int[] s = new int[N];//存储从每一个门进入需要的总步数
for (int i = 1; i <= n; i++) {
q[i] = sc.nextInt();
}
int res = 0x3f3f3f3f;
// s[i] = q[j + 1] * l + q[j + 2] * l + q[ j + 3 ] * l ………………
// l 为一圈每一个点的步数,因为顺时针走,所以 l 小于等于 n - 1, 每次走完便 ++
// j 统计走到的点
for (int i = 1; i <= n; i++) {
int j = i + 1 , l = 1;
while ( l <= n - 1) {
if( j > n ){
j = 1;
}
s[i] += q[j % (n + 1)] * l;
j++;
l++;
}
res = Math.min(res,s[i]);
}
System.out.println(res);
}
}