题解 | 元素方碑
元素方碑
https://www.nowcoder.com/practice/5c6e7ed4726e41f4ac99a4dedf1e5bb2
import java.util.Scanner;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0;i<t;i++){
int n=in.nextInt();
int[] nums = new int[n];
int count = 0;
for(int j = 0;j<n;j++){
nums[j]=in.nextInt();
count+=nums[j];
}
// 1.判断总能量是否为n的倍数
if(count%n!=0){
System.out.println("NO");
}else{
for(int j=0;j<n;j++){
nums[j]-=(count/n);
}
for(int j=1;j<n-1;j++){
nums[j+1]+=nums[j-1];
nums[j-1]=0;
}
boolean mark = true;
for(int j=0;j<n;j++){
if(nums[j]!=0){
mark=false;
break;
}
}
System.out.println(mark?"YES":"NO");
}
}
}
}
