【CF1110E Magic Stones】题解

题目链接

我要是在noip前做这道题就好了。

这道题的本质就是noip2021方差中的一个性质,对于每个数进行修改,就是把它左右的差进行交换。

注意的是首项一定要一样。

Code

// Problem: CF1110E Magic Stones
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/CF1110E
// Memory Limit: 250 MB
// Time Limit: 1000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define M
//#define mo
#define N 200010
int n, m, i, j, k; 
int a[N]; 
map<int, int>mp; 

signed main()
{
//	freopen("tiaoshi.in", "r", stdin); 
//	freopen("tiaoshi.out", "w", stdout); 
	n=read(); 
	for(i=1; i<=n; ++i) a[i]=read(); 
	k=a[1]; 
	for(i=1; i<=n; ++i) mp[a[i]-a[i-1]]++; 
	for(i=1; i<=n; ++i) a[i]=read(); 
	if(a[1]!=k) return printf("No\n"), 0; 
	for(i=1; i<=n; ++i) 
		if(mp[a[i]-a[i-1]]==0) return printf("No\n"), 0; 
		else mp[a[i]-a[i-1]]--; 
	printf("Yes"); 
	return 0; 
}

posted @ 2021-12-03 21:06  zhangtingxi  阅读(35)  评论(0编辑  收藏  举报