A. Cubes Sorting(思维+排序/逆序对+贪心)

104 篇文章 0 订阅

https://codeforces.com/contest/1420/problem/A


贪心考虑极端情况,也就是完全从大到小的,手动模拟发现始终比题目的yes条件少一个,那么其他情况只要有一个地方和这个最劣解不同,就会至少有+1的优化,那么就是Yes

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e4+100;
typedef long long LL;
LL a[maxn]; 
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--)
  {
  	LL n;cin>>n;
  	for(LL i=1;i<=n;i++) cin>>a[i];
  	LL sum=0;
	for(LL i=1;i<n;i++)
  	{
  		if(a[i]>a[i+1]) sum++;	
	}
	if(sum==n-1) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
  }
return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值