CodeForces - 1110E-Magic Stones(差分+思维)
Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is equal to cici.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index ii, where 2≤i≤n−12≤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 cici changes to c′i=ci+1+ci−1−cici′=ci+1+ci−1−ci.
Andrew, Grigory's friend, also has nn stones with charges titi. 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 cici into titi for all ii?
Input
The first line contains one integer nn (2≤n≤1052≤n≤105) — the number of magic stones.
The second line contains integers c1,c2,…,cnc1,c2,…,cn (0≤ci≤2⋅1090≤ci≤2⋅109) — the charges of Grigory's stones.
The second line contains integers t1,t2,…,tnt1,t2,…,tn (0≤ti≤2⋅1090≤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
Input
4
7 2 4 12
7 15 10 12
Output
Yes
Input
3
4 4 4
1 2 3
Output
No
Note
In the first example, we can perform the following synchronizations (11-indexed):
- First, synchronize the third stone [7,2,4,12]→[7,2,10,12][7,2,4,12]→[7,2,10,12].
- Then synchronize the second stone: [7,2,10,12]→[7,15,10,12][7,2,10,12]→[7,15,10,12].
In the second example, any operation with the second stone will not change its charge.
代码:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
using namespace std;
int a[100005],b[100005],c[100005],d[100005];
int main()
{
int n;
cin>>n;
int flag=0;
for(int t=1;t<=n;t++)
{
scanf("%d",&a[t]);
}
for(int t=1;t<=n;t++)
{
scanf("%d",&b[t]);
}
for(int t=1;t<=n-1;t++)
{
c[t]=a[t+1]-a[t];
}
for(int t=1;t<=n-1;t++)
{
d[t]=b[t+1]-b[t];
}
if(a[1]!=a[1]||a[n]!=b[n])
{
flag=1;
}
sort(c+1,c+n);
sort(d+1,d+n);
for(int t=1;t<=n;t++)
{
if(c[t]!=d[t])
{
flag=1;
}
}
if(!flag)
{
puts("Yes");
}
else
{
puts("No");
}
return 0;
}
CodeForces - 1110E-Magic Stones(差分+思维)的更多相关文章
- Codeforces.1110E.Magic Stones(思路 差分)
题目链接 听dalao说很nb,做做看(然而不小心知道题解了). \(Description\) 给定长为\(n\)的序列\(A_i\)和\(B_i\).你可以进行任意多次操作,每次操作任选一个\(i ...
- E. Magic Stones CF 思维题
E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- 【CF1110E】 Magic Stones - 差分
题面 Grigory has n n magic stones, conveniently numbered from \(1\) to \(n\). The charge of the \(i\)- ...
- CF1110E Magic Stones 差分
传送门 将原数组差分一下,设\(d_i = c_{i+1} - c_i\) 考虑在\(i\)位置的一次操作会如何影响差分数组 \(d_{i+1}' = c_{i+1} - (c_{i+1} + c_{ ...
- Magic Stones CodeForces - 1110E (思维+差分)
E. Magic Stones time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
- CF 1110 E. Magic Stones
E. Magic Stones 链接 题意: 给定两个数组,每次可以对一个数组选一个位置i($2 \leq i \leq n - 1$),让a[i]=a[i-1]+a[i+1]-a[i],或者b[i] ...
- 【Codeforces 1110E】Magic Stones
Codeforces 1110 E 题意:给定两个数组,从第一个数组开始,每次可以挑选一个数,把它变化成左右两数之和减去原来的数,问是否可以将第一个数组转化成第二个. 思路: 结论:两个数组可以互相转 ...
- Codeforces 1108E2 Array and Segments (Hard version)(差分+思维)
题目链接:Array and Segments (Hard version) 题意:给定一个长度为n的序列,m个区间,从m个区间内选择一些区间内的数都减一,使得整个序列的最大值减最小值最大. 题解:利 ...
- Codeforces 1110E (差分)
题面 传送门 分析 一开始考虑贪心和DP,发现不行 考虑差分: 设d[i]=c[i+1]-c[i] (i<n) 那么一次操作会如何影响差分数组呢? \(c[i]'=c[i+1]+c[i-1]-c ...
随机推荐
- wdcp挂载数据盘为WWW以及之后出现的各种问题解决方法
昨天晚上突然有客户反映服务器访问不了,经检查后是因为磁盘满了! 购买阿里云的ECS选择linux系统的时候会赠送20G的系统盘,通常来讲自己用的话基本够了,但是我们作为网络公司,安装了一个WDCP后给 ...
- 性能优化之_android内存
优化内存使用主要是三个原则: CPU如何操纵特定的数据类型 数据和指令需要占用多少存储空间 数据在内存中的布局方式 处理大量数据时,使用可以满足要求的最小字节数据类型,能用short就不用int,能用 ...
- 浅谈android代码保护技术_加固
可看原文: http://www.cnblogs.com/jiaoxiake/p/6536824.html 导语 我们知道Android中的反编译工作越来越让人操作熟练,我们辛苦的开发出一个apk,结 ...
- FutureTask子任务取消执行的状态判断
示例代码可以从github上获取 https://github.com/git-simm/simm-framework.git 一.业务场景: 系统中存在多种场景并发操作事务执行时互锁的情况,导致任务 ...
- 第08章-使用Spring Web Flow
使用Spring Web Flow Spring Web Flow是Spring MVC的扩展,它支持开发基于流程的应用程序.它将流程的定义与实现流程行为的类和视图分离开来. 1 在Spring中配置 ...
- (转)EASYUI+MVC4通用权限管理平台
原文地址:http://www.cnblogs.com/hn731/archive/2013/07/15/3190947.html 通用权限案例平台在经过几年的实际项目使用,并取得了不错的用户好评.在 ...
- 企业管理系统——第三周需求&原型改进_张正浩,黄锐斌
企业管理系统——需求&原型改进,架构设计,测试计划 组员:张正浩,黄锐斌 一.需求&原型改进 1.给目标用户展现原型,与目标用户进一步沟通理解需求 我们的目标用户是公司管理员 场景:随 ...
- 【转】ANDROID自定义视图——onLayout源码 流程 思路详解
转载(http://blog.csdn.net/a396901990) 简介: 在自定义view的时候,其实很简单,只需要知道3步骤: 1.测量——onMeasure():决定View的大小 2.布局 ...
- SQL Server Profiler (SQl跟踪器)的简单使用
一.工具介绍 在实际开发中,我们的数据库应用系统因为不可避免会存在有大量表,视图,索引,触发器,函数,存储过程,sql语句等,所以会出现一系列问题,有问题不可怕,找对工具很重要.接下来我就介绍一款性能 ...
- LoadRunner---杂问题&接口测试
问题1] 响应时间是系统完成事务执行准备后所采集的时间戳和系统完成待执行事务后所采集的时间戳之间的时间间隔,是衡量特定类型应用事务性能的重要指标,标志了用户执行一项操作大致需要多长时间.[问题2] 系 ...