import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t > 0) {
int n = s.nextInt();
int[] arr = new int[n];
for (int i = 0; i <= n - 1; i++) {
arr[i] = s.nextInt();
}
if(t!=1) {
if (selectionSort(arr)) {
System.out.println("YES");
} else {
System.out.println("NO");
}
}else{
if(selectionSort(arr)){
System.out.print("YES");
}else {
System.out.print("NO");
}
}
t--;
}
}
public static int gcd(int m, int n) {
int i = 0, t, x;
while (m % 2 == 0 & n % 2 == 0) {
m /= 2;
n /= 2;
i++;
}
if (m < n) {
t = m;
m = n;
n = t;
}
while (n != (m - n)) {
x = m - n;
m = (n > x) ? n : x;
n = (n < x) ? n : x;
}
if (i == 0)
return n;
else
return (int) Math.pow(2, i) * n;
}
public static boolean selectionSort(int[] a) {
int N = a.length;
if (N==0){
return true;
}
int minNum = getMin(a);
for (int i = 0; i < N - 1; i++) {
//length = 5 i = 0 1 2 3 4 i= 0 j =1234
int min = i;
for (int j = i + 1; j < N; j++) {
//将a[i]和a[i+1...N-1]中的最小元素交换
if (a[j] < a[min]) {//升序排列
min = j;
}
}
if (min != i) {//一下是排序过程 a[min]跟a[i]进行交换
if (gcd(a[min], a[i]) != minNum) {
return false;
} else {//要不然就一直排序下去
int temp = a[i];
a[i] = a[min];
a[min] = temp;
}
}
}
return true;
}
public static int getMin (int[] arr){
int minNum = arr[0];
for (int i = 1; i < arr.length; i++) {
if (minNum > arr[i]) {
minNum = arr[i];
}
}
return minNum;
}
}
自测的时候都没什么问题 但是 已提交就是wrong answer 这是为什么呢? 关于#java#的问题,请各位专家解答 hdoj acm问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- CSDN专家-深度学习进阶 2021-09-20 08:41关注
说明只有测试样例对了,真正测评的时候他的数据可能是边界的测试
本回答被专家选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥17 pro*C预编译“闪回查询”报错SCN不能识别
- ¥15 微信会员卡接入微信支付商户号收款
- ¥15 如何获取烟草零售终端数据
- ¥15 数学建模招标中位数问题
- ¥15 phython路径名过长报错 不知道什么问题
- ¥15 深度学习中模型转换该怎么实现
- ¥15 HLs设计手写数字识别程序编译通不过
- ¥15 Stata外部命令安装问题求帮助!
- ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
- ¥15 TYPCE母转母,插入认方向