B. Little Pony and Sort by Shift1200 / 思维

Posted 幽殇默

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了B. Little Pony and Sort by Shift1200 / 思维相关的知识,希望对你有一定的参考价值。

https://codeforces.com/problemset/problem/454/B

#include<bits/stdc++.h> 
using namespace std;
const int N=1e5+10;
int a[N],n;
int main(void)

	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i]; 
	int ans=0,index=-1,minv=1e9;
	for(int i=0;i<n;i++)
	
		minv=min(minv,a[i]);
		if(i+1<n&&a[i]>a[i+1])//找到分界点
		
			index=i+1;
			ans=i+1; 
			break;
		
	
	if(index!=-1)
	for(int i=index;i<n;i++)
		if(a[i]>minv||(i+1<n&&a[i]>a[i+1])) //判断是不是单调的,且比前面的最小值小
		
			cout<<-1;
			return 0;
		
	cout<<(n-ans)%n;
	return 0;

以上是关于B. Little Pony and Sort by Shift1200 / 思维的主要内容,如果未能解决你的问题,请参考以下文章

B. Little Pony and Sort by Shift1200 / 思维

B. Little Pony and Sort by Shift1200 / 思维

B. Little Pony and Harmony Chest(状压dp)

Codeforces 453B Little Pony and Harmony Chest:状压dp记录转移路径

CF453D Little Pony and Elements of Harmony

CF453D Little Pony and Elements of Harmony(FWT)