题目传送
题意:
给你一个大小为n的数组,其他可能有俩种类型的元素,一种为0,一种为1,现在你可以操作任意次数 : 当俩个的种类不同时,我们可以交换他们,现在问:能否有办法,使得这个数组呈递增序列排序。
思路:
我们不妨画一画。
1.当只要有俩个种类的元素同时存在,我们可以把我们数组变成任意的排列类型(因为我们现在可以随时交换俩个不同类型的元素,这就有点类似选择排序一样当然只是类似,实质上还是很大不同的 ,只要你给我俩个可以交换的元素,我就可以造出他的全排列所有排列情况 ),那么这种情况输出yes
2.当只有一种元素存在时,我们交换不了元素,那么也就只能看看原序列是否就是递增的了
AC代码
#include <bits/stdc++.h>
inline long long read(){char c = getchar();long long x = 0,s = 1;
while(c < '0' || c > '9') {if(c == '-') s = -1;c = getchar();}
while(c >= '0' && c <= '9') {x = x*10 + c -'0';c = getchar();}
return x*s;}
using namespace std;
#define NewNode (TreeNode *)malloc(sizeof(TreeNode))
#define Mem(a,b) memset(a,b,sizeof(a))
#define lowbit(x) (x)&(-x)
const int N = 2e5 + 10;
const long long INFINF = 0x7f7f7f7f7f7f7f;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-7;
const unsigned long long mod = 998244353;
const double II = acos(-1);
const double PP = (II*1.0)/(180.00);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> piil;
int main()
{
std::ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
int arr[n+5] = {0},a = 0,b = 0,ans = 1;
for(int i = 1;i <= n;i++)
{
cin >> arr[i];
if(arr[i] < arr[i-1])//其实,数组都可以不用的,但是不敢乱压行了,上次压行压得太狠,出了bug了,哭唧唧
ans = 0;
}
for(int i = 1,num;i <= n;i++)
{
cin >> num;
num == 1 ? a++ : b++;
}
if((a && b) || ans) cout << "Yes" << endl;
else cout << "No" << endl;
}
}