Problem - A - Codeforces (Unofficial mirror by Menci)
You are given a permutation a1,a2,…,ana1,a2,…,an of size nn, where each integer from 11 to nn appears exactly once.
You can do the following operation any number of times (possibly, zero):
Determine whether you can make the array aa sorted in non-descending order.
Input
Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤50001≤t≤5000) — the number of test cases. The description of test cases follows.
The first line of each test case contains a single integer nn (3≤n≤103≤n≤10) — the length of the array aa.
The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤n1≤ai≤n, ai≠ajai≠aj if i≠ji≠j) — the elements of the array aa.
Output
For each test case, output "Yes" (without quotes) if the array can be sorted in non-descending order, and "No" (without quotes) otherwise.
You can output "Yes" and "No" in any case (for example, strings "YES", "yEs" and "yes" will be recognized as a positive response).
要使用题目要求的方式进行排序的话,数组第一位必须是1,否则无解。
只要数组第一位是1,总能用这个1把整个数组都排好。
- #include
- using namespace std;
- #define endl '\n'
- typedef long long ll;
- typedef unsigned long long ull;
- const int maxn = 1e3 + 10;
- const int INF = 0x3fffffff;
-
- /*
- 要使用题目要求的方式进行排序的话,数组第一位必须是1,否则无解。
- 只要数组第一位是1,总能用这个1把整个数组都排好。
- */
-
- int main()
- {
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cout << fixed;
- cout.precision(18);
-
- int t;
- cin >> t;
- while(t--)
- {
- int n;
- cin >> n;
- int first;
- cin >> first;
- for (int i = 2, x; i <= n; i++)
- {
- cin >> x;
- }
- if(first == 1)
- cout << "YES\n";
- else
- cout << "NO\n";
- }
- return 0;
- }