C. Madoka and Formal Statement

链接

Problem - 1717C - Codeforces

思路 : 

当有任意一个 ai​>bi​ 的时候,肯定是无法变为序列 b 的。

如果存在一个 i 使得−bi​−b(i-1)​>1,则如果我们想要改动 a(i-1)到b(i-1),就必须使得 ai≥​a(i-1)​,但是我们知道,如果在最后能够让 ai≥​a(i-1)​ 的话,ai​ 就必须大于 bi​,所以不可能成功

综上所述,如果存在 a[i]>b[i] or a[i]b[(i+1)%n]+1 就输出 NO,否则输出 YES

代码

#include
using namespace std;

const int N = 2e5 + 10 ;
int a[N] , b[N] ;

void solve(){
	// a[i] -> b[i];
	// a[i] 不能变小 , so a[i]>b[i]直接false 
	// a[i]<=a[i+1] a[i]++;
	int n ; cin >> n ;
	for(int i=0;i> a[i] ;
	for(int j =0;j> b[j];
	for(int i=0;ib[i] || (a[i]b[(i+1)%n]+1)){
			cout << "No" << endl;
			return ;
		} 
	}
	cout << "Yes" << endl;
	return ;
}

int main(){
	int t ; cin >> t ;
	while(t--){
		solve() ;
	}
	return 0 ;
}

你可能感兴趣的:(算法学习,灵茶,CF,算法,c++,codeforces)