Grigory has n magic stones, conveniently numbered from 1 to n. The charge of the i-th stone is equal to ci.

Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index i, where 2≤i≤n−1), and after that synchronizes it with neighboring stones. After that, the chosen stone loses its own charge, but acquires the charges from neighboring stones. In other words, its charge ci changes to c′i=ci+1+ci−1−ci.

Andrew, Grigory’s friend, also has n stones with charges ti. Grigory is curious, whether there exists a sequence of zero or more synchronization operations, which transforms charges of Grigory’s stones into charges of corresponding Andrew’s stones, that is, changes ci into ti for all i?

Input
The first line contains one integer n (2≤n≤105) — the number of magic stones.

The second line contains integers c1,c2,…,cn (0≤ci≤2⋅109) — the charges of Grigory’s stones.

The second line contains integers t1,t2,…,tn (0≤ti≤2⋅109) — the charges of Andrew’s stones.

Output
If there exists a (possibly empty) sequence of synchronization operations, which changes all charges to the required ones, print “Yes”.

Otherwise, print “No”.

Examples
inputCopy
4
7 2 4 12
7 15 10 12
outputCopy
Yes
inputCopy
3
4 4 4
1 2 3
outputCopy
No
Note
In the first example, we can perform the following synchronizations (1-indexed):

First, synchronize the third stone [7,2,4,12]→[7,2,10,12].
Then synchronize the second stone: [7,2,10,12]→[7,15,10,12].
In the second example, any operation with the second stone will not change its charge.

题意:

给你n个数,你可以在2到n-1之间选任意的数,让这个数a[x]变成a[x-1]+a[x+1]-a[x],问你最后能不能将这个数组变成接下来给你的数组。

题解:

也是想得到就很简单,想不到就凉凉的题目,a[x]’ = a[x-1]+a[x+1]-a[x]可以变成a[x]’-a[x-1]=a[x+1]-a[x],a[x+1]-a[x]’=a[x]-a[x-1],也就是将相邻的两个差交换一下。

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int c[N],t[N],dif1[N],dif2[N];
int main()
{int n;scanf("%d",&n);for(int i=1;i<=n;i++)scanf("%d",&c[i]),dif1[i]=c[i]-c[i-1];for(int i=1;i<=n;i++)scanf("%d",&t[i]),dif2[i]=t[i]-t[i-1];sort(dif1+1,dif1+1+n);sort(dif2+1,dif2+1+n);int flag=0;for(int i=1;i<=n;i++){if(dif1[i]!=dif2[i]){flag=1;break;}}if(!flag)printf("Yes\n");elseprintf("No\n");return 0;
}

Codeforces Contest 1110 problem E Magic Stones —— 更改算式相关推荐

  1. Codeforces Contest 1092 problem D1 Great Vova Wall (Version 1)

    Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, ...

  2. Codeforces Contest 1081 problem D Maximum Distance —— 并查集

    Chouti was tired of the tedious homework, so he opened up an old programming problem he created year ...

  3. Codeforces Contest 1138 problem B Circus —— 死亡1700,暴力

    Polycarp is a head of a circus troupe. There are n - an even number - artists in the troupe. It is k ...

  4. codeforces contest 869 problem C(组合数)

    The Intriguing Obsession time limit per test 1 second memory limit per test 256 megabytes input stan ...

  5. CF1110E Magic Stones

    CF1110E Magic Stones 题目链接:(http://codeforces.com/problemset/problem/1110/E?csrf_token=c50ced6ad87d78 ...

  6. 【codeforces 711B】Chris and Magic Square

    [题目链接]:http://codeforces.com/contest/711/problem/B [题意] 让你在矩阵中一个空白的地方填上一个正数; 使得这个矩阵两个对角线上的和; 每一行的和,每 ...

  7. codeforces contest 1166 E. The LCMs Must be Large---思维

    题目链接:https://codeforces.com/contest/1166/problem/E 题解: 代码: #include<bits/stdc++.h> using names ...

  8. CodeForces - 29A Spit Problem【水题】

    题目链接:https://codeforces.com/contest/29/problem/A #include <iostream> #include <cstdio> # ...

  9. 2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit

    The 2021 ICPC Asia Regionals Online Contest (II) Problem G. Limit 在欧教的指导下,复习了下高数知识,写下了这题的题解- 做这道题之前, ...

最新文章

  1. hadoop学习--多表关联
  2. Android O(29 )---MTK 平台代码同步
  3. 矢量合成和分解的法则_专题06 共点力的合成与分解
  4. Visual Studio 2008 SDK Version 和Microsoft Visual Studio 2008 Shell发布了
  5. 今天遇到个超郁闷的问题
  6. 百度地图API实现地理围栏
  7. PTA 7-1 输入名字,输出问候语
  8. 计算机应用研究参考文献格式,参考文献编写规则-计算机应用研究.PDF
  9. 【Mac使用技巧】Mac的VMware虚拟机系统时间如何调成不同步
  10. 小型固定翼无人机集群仿真演示平台
  11. SSLOJ·谷仓的安保【DFS】
  12. 求解一元高次多项式方程的所有实数根的算法
  13. Visio画UML类图
  14. 提高数据库效率的一些方法--eg:大批量循环插入数据的简化
  15. 频繁撤单有风险?--这些委托类型让您享受“撤单豁免权”
  16. 基于云计算与深度学习的常见作物害虫识别
  17. 这可能是全网最详细的计算机网络面经(笔记二)
  18. [渝粤教育] 西南科技大学 网站建设与维护 在线考试复习资料
  19. ubuntu 18.04.02 + GTX1660 + CUDA_10.0 + CUDNN_7.6.4 安装脱坑记
  20. MATLAB数字图像处理(一)

热门文章

  1. warning: statement has no effect [-Wunused-value]
  2. Java反序列化(一) - Java反射机制
  3. Html help安装步骤,Doxgen+Graphiz+htmlhelp配置
  4. ❤唯美满天星❤ html+css+js炫酷3D相册(含音乐/可自定义文字)程序员表白必备
  5. 问题解决:LaTeX biblatex 参考文献出现 [S.l.]: [s.n.]的问题
  6. decorate怎么读(decorated怎么读)
  7. 怎么做视频剪辑,教你几招
  8. Windows Server 2022 发布(正式版下载)
  9. 压控电流源等效成一个电阻
  10. 全球与中国PH和ORP通用分析仪市场深度研究分析报告