CF1110E Magic Stones

题目链接:(http://codeforces.com/problemset/problem/1110/E?csrf_token=c50ced6ad87d78ffc77d786512a94249 )


E. Magic Stones
time limit per test1 second
memory limit per test256 megabytes
inputstandard input
outputstandard output
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”.


解法:


说一下自己在解这一道题的时候出现的问题:
想法上的错误:

  1. 对于差分序列的转换,求出两个差分序列中的数字di,di+1,应该是始终只变换ci这一个数字,这样子的话就可以发现在ci变换过之后就是di和di+1变了一下位置,但是差分序列始终没有变化,所以,根据这一个发现,就可以通过二者差分序列在排序之后是否相等判断ci是否可以通过变化变成ti。
  2. 对于开头来说,没有ci-1,结尾也不能操作,应该也是要判的。但是自己认为结尾是直接包含在差分序列中的,这个思想是错误的,结尾从意义看是不能操作的,只要不能操作,那维护就没有意义,也是不能维护的。

code

#include<bits/stdc++.h>
using namespace std;const int nn=1e5+10;int n;
int c[nn],t[nn];
int b1[nn],b2[nn];inline int read()
{int x=0,f=1; char ch=getchar();while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}return x*f;
}int main()
{n=read();for(int i=1;i<=n;++i) c[i]=read(),b1[i]=c[i]-c[i-1];for(int i=1;i<=n;++i)    t[i]=read(),b2[i]=t[i]-t[i-1];if(c[1]!=t[1]||c[n]!=t[n]){printf("No\n");return 0;}sort(b1+1,b1+1+n);sort(b2+1,b2+1+n);for(int i=1;i<=n;++i)if(b1[i]!=b2[i]){printf("No\n");return 0;}printf("Yes\n");return 0;
}

今天也有进步哦,加油!

CF1110E Magic Stones相关推荐

  1. CF1110E Magic Stones(构造题)

    这场CF怎么这么多构造题-- 题目链接:CF原网 洛谷 题目大意:给定两个长度为 $n$ 的序列 $c$ 和 $t$.每次我们可以对 $c_i(2\le i<n)$ 进行一次操作,也就是把 $c ...

  2. 【CF1110E】Magic Stones

    题目 题意翻译 题意: 一次操作选择1<i<n1<i<n,使c_ic i ​ 变为c_i'c i ′ ​ ,c_i'=c_{i+1}+c_{i-1}-c_ic i ′ ​ =c ...

  3. 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 ...

  4. Codeforces.1110E.Magic Stones(思路 差分)

    题目链接 听dalao说很nb,做做看(然而不小心知道题解了). \(Description\) 给定长为\(n\)的序列\(A_i\)和\(B_i\).你可以进行任意多次操作,每次操作任选一个\(i ...

  5. AT2164 AGC006C Rabbit Exercise

    AT2164 AGC006C Rabbit Exercise 数轴上有 \(n\) 个点,每个点的坐标为 \(a_i\) .一轮操作包含 \(m\) 次变换,第 \(i\) 次将 \(b_i(1< ...

  6. CodeForces - 1110E-Magic Stones(差分+思维)

    Grigory has nn magic stones, conveniently numbered from 11 to nn. The charge of the ii-th stone is e ...

  7. 做题记录 To 2019.2.13

    2019-01-18 4543: [POI2014]Hotel加强版:长链剖分+树形dp. 3653: 谈笑风生:dfs序+主席树. POJ 3678 Katu Puzzle:2-sat问题,给n个变 ...

  8. CF刷题(03)——难度2100~2400

    这个博客记录2100到2400共17个题 2100 1.B. Maximum Value 题意:You are given a sequence a consisting of nnn integer ...

  9. mysql在哪执行sql语句_mysql从命令行执行sql语句

    Codeforce Round #218 Div2 A:没个元素的个数少的变成多的和就是了 B:居然被systemtest搓掉了- -分东西,我改的代码,还是shit一样的过的...别人的直接两个操作 ...

最新文章

  1. SAP LSMW 导入Open PO时价格不对问题之对策
  2. Nginx+FastCGI运行原理
  3. 可逆神经网络(Invertible Neural Networks)详细解析:让神经网络更加轻量化
  4. JS 时间和时间戳相互转换
  5. ASP.NET Core分布式项目实战(详解oauth2授权码流程)--学习笔记
  6. 中职学校计算机应用基础教学初探,中职学校计算机应用基础教学初探
  7. bcscale php,【PHP开发】bcscale timezone charset的设定说明
  8. matlab ode45三体问题,“毕达哥拉斯3Body Proxblem”ODE解算器测试的下一步
  9. php usort的用法,PHP usort()用法及代码示例
  10. TCP/IP 域名系统DNS
  11. spring5.0学习笔记10
  12. js动态填充select
  13. 西南科技大学OJ题 平衡二叉树的判定1077
  14. GEOTIF转nc文件
  15. AT070TN83 V1.0 背光不亮
  16. 基于NNIE神经网络引擎_海思hi3516DV300方案硬件平台适合做哪些开发
  17. 【Unity】制作一个商店场景
  18. windows中查看端口占用情况以及删除端口
  19. 《编程之美》背后的作者之美
  20. Java 开发环境搭建

热门文章

  1. 2021年度个人心目中的三张最佳专辑
  2. iOS CocoaPods第三方库加载本地文件或服务器上的zip文件(二)
  3. Switch控件详解
  4. 软件接口趣事:业务和技术人员眼中五彩斑斓的黑
  5. 全氟己基碘烷行业研究及十四五规划分析报告
  6. Lighting - 光的亮度衰减
  7. 【软考中级】多媒体应用设计师复习笔记第一章
  8. python期末大作业-图形化爬虫
  9. 线性代数|学习笔记|18.065MIT公开课 lecture05
  10. 如何将域名解析到网站上?