0
点赞
收藏
分享

微信扫一扫

C. Mere Array(排序+思维) Codeforces Round #665 (Div. 2)

原题链接: ​​https://codeforces.com/contest/1401/problem/C​​

C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_i++
测试样例:

input
4
1
8
6
4 3 6 6 2 9
4
4 5 6 7
5
7 5 2 2 4
output
YES
YES
YES
NO

样例解释:

In the first and third sample, the array is already non-decreasing.
In the second sample, we can swap C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_02 and C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_03 first, and swap C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_02 and C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_i++_05 second to make the array non-decreasing.
In the forth sample, we cannot the array non-decreasing using the operation.

题意: 给你一个整数序列C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_06,其中你可以选择下标为C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_07C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_08,如果C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_ios_09的值为整数序列中数值最小的元素,那么就可以交换C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_10C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_思维_11。问你能否经过若干次这样的操作使得整数序列C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_06变为非递减序列。

解题思路: 我们的最终目的就是要将整数序列C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_#define_06变为非递减序列。那么我们拿这个最终序列和原序列进行对比,位置上数值不对的自然是需要靠交换来改变的。而交换的条件则是上述,那么我们如果每一个需要交换的数它们的因子都包含这个最小的数,那么我们就可以通过用这个最小的数来进行交换而不用考虑其他的。假设最小的数为C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_ios_14,即如果我们要交换的数C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_i++_15满足C. Mere Array(排序+思维)  Codeforces Round #665 (Div. 2)_i++_16,那么我们就是可以通过这个最小的数作为媒介来进行转移,如果不行,说明这个要交换的数不能被转移,则说明不行。OK,我们具体看代码。

AC代码:

/*

*
*/
#include<bits/stdc++.h> //POJ不支持

#define rep(i,a,n) for (int i=a;i<=n;i++)//i为循环变量,a为初始值,n为界限值,递增
#define per(i,a,n) for (int i=a;i>=n;i--)//i为循环变量, a为初始值,n为界限值,递减。
#define pb push_back
#define IOS ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
#define fi first
#define se second
#define mp make_pair

using namespace std;

const int inf = 0x3f3f3f3f;//无穷大
const int maxn = 1e5;//最大值。
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
//*******************************分割线,以上为自定义代码模板***************************************//

int t,n,a[maxn],b[maxn];
int main(){
//freopen("in.txt", "r", stdin);//提交的时候要注释掉
IOS;
while(cin>>t){
while(t--){
cin>>n;
rep(i,0,n-1){
cin>>a[i];
b[i]=a[i];
}
sort(b,b+n);//开始对比。
int minn=b[0];
int flag=false;
rep(i,0,n-1){
if(a[i]!=b[i]&&a[i]%minn!=0){
flag=true;
break;
}
}
if(flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
}
}
return 0;
}


举报

相关推荐

0 条评论