Codeforces Contest 1110 problem E Magic Stones —— 更改算式

2024-04-07 00:38

本文主要是介绍Codeforces Contest 1110 problem E Magic Stones —— 更改算式,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

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 —— 更改算式的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/881244

相关文章

如何更改pycharm缓存路径和虚拟内存分页文件位置(c盘爆红)

《如何更改pycharm缓存路径和虚拟内存分页文件位置(c盘爆红)》:本文主要介绍如何更改pycharm缓存路径和虚拟内存分页文件位置(c盘爆红)问题,具有很好的参考价值,希望对大家有所帮助,如有... 目录先在你打算存放的地方建四个文件夹更改这四个路径就可以修改默认虚拟内存分页js文件的位置接下来从高级-

PyCharm如何更改缓存位置

《PyCharm如何更改缓存位置》:本文主要介绍PyCharm如何更改缓存位置的实现方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录PyCharm更改缓存位置1.打开PyCharm的安装编程目录2.将config、sjsystem、plugins和log的路径

CentOS7更改默认SSH端口与配置指南

《CentOS7更改默认SSH端口与配置指南》SSH是Linux服务器远程管理的核心工具,其默认监听端口为22,由于端口22众所周知,这也使得服务器容易受到自动化扫描和暴力破解攻击,本文将系统性地介绍... 目录引言为什么要更改 SSH 默认端口?步骤详解:如何更改 Centos 7 的 SSH 默认端口1

更改docker默认数据目录的方法步骤

《更改docker默认数据目录的方法步骤》本文主要介绍了更改docker默认数据目录的方法步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录1.查看docker是否存在并停止该服务2.挂载镜像并安装rsync便于备份3.取消挂载备份和迁

csu 1446 Problem J Modified LCS (扩展欧几里得算法的简单应用)

这是一道扩展欧几里得算法的简单应用题,这题是在湖南多校训练赛中队友ac的一道题,在比赛之后请教了队友,然后自己把它a掉 这也是自己独自做扩展欧几里得算法的题目 题意:把题意转变下就变成了:求d1*x - d2*y = f2 - f1的解,很明显用exgcd来解 下面介绍一下exgcd的一些知识点:求ax + by = c的解 一、首先求ax + by = gcd(a,b)的解 这个

uva 10025 The ? 1 ? 2 ? ... ? n = k problem(数学)

题意是    ?  1  ?  2  ?  ...  ?  n = k 式子中给k,? 处可以填 + 也可以填 - ,问最小满足条件的n。 e.g k = 12  - 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12 with n = 7。 先给证明,令 S(n) = 1 + 2 + 3 + 4 + 5 + .... + n 暴搜n,搜出当 S(n) >=

[Gym103960B] Fun with Stones

并不是多困难或者有趣的题,写sol仅仅是因为觉得好笑()。 题目大意 三堆石子 Nim 游戏,第 i i i 堆石子数量在 [ l i , r i ] [l_i , r_i] [li​,ri​] 中随机,求先手必胜的概率,对 1 0 9 + 7 10^9+7 109+7 取模。 l i , r i ≤ 1 0 9 l_i , r_i≤10^9 li​,ri​≤109。 题解 说人

Codeforces Round #240 (Div. 2) E分治算法探究1

Codeforces Round #240 (Div. 2) E  http://codeforces.com/contest/415/problem/E 2^n个数,每次操作将其分成2^q份,对于每一份内部的数进行翻转(逆序),每次操作完后输出操作后新序列的逆序对数。 图一:  划分子问题。 图二: 分而治之,=>  合并 。 图三: 回溯:

Codeforces Round #261 (Div. 2)小记

A  XX注意最后输出满足条件,我也不知道为什么写的这么长。 #define X first#define Y secondvector<pair<int , int> > a ;int can(pair<int , int> c){return -1000 <= c.X && c.X <= 1000&& -1000 <= c.Y && c.Y <= 1000 ;}int m

Codeforces Beta Round #47 C凸包 (最终写法)

题意慢慢看。 typedef long long LL ;int cmp(double x){if(fabs(x) < 1e-8) return 0 ;return x > 0 ? 1 : -1 ;}struct point{double x , y ;point(){}point(double _x , double _y):x(_x) , y(_y){}point op