其他分享
首页 > 其他分享> > A. Prof. Slim_水

A. Prof. Slim_水

作者:互联网

A. Prof. Slim

题目大意:

是否可能通过交换任意两个数的正负号,使得整个序列非降序。

思路和代码:

把所有负号放到前面即可。

string solve(){
	int n ; cin >> n ;
	vct<int> a(n + 1 , 0) ;
	rep( i , 1 , n) cin >> a[i] ;
	int cnt = 0 ;
	rep(i , 1 , n){
		cnt += a[i] < 0 ; 
		a[i] = abs(a[i]) ;
	}
	
	rep(i , 1 , cnt) a[i] *= -1 ;
	
	rep(i , 1 , n - 1)
	if(a[i] > a[i + 1]) return "NO\n" ;
	return "YES\n" ;
	
}//code_by_tyrii 

标签:cnt,return,int,rep,Slim,Prof
来源: https://www.cnblogs.com/tyriis/p/16240879.html