【链接】 我是链接,点我呀:)

【题意】

你可以把c[i]改成c[i+1]+c[i-1]-c[i]
(2

【题解】

```cpp
d[i] = c[i+1]-c[i]; (1 change c[i]

c[i]' = c[i+1]+c[i-1]-c[i];

d[i-1] = c[i]'-c[i-1];
= c[i+1]+c[i-1]-c[i]-c[i-1] == c[i+1]-c[i] = d[i];

d[i] = c[i+1]-c[i]'
= c[i+1]-c[i+1]-c[i-1]+c[i]
= c[i] - c[i-1];
= d[i-1];
也就是说对2..n-1进行操作的话
就是把相邻的d的值交换一下
显然这样的交换能让d变成任意顺序
因此,只要c[1]==d[1]并且c[n]==d[n]
然后排序后的c和排序后的d相同的话,就ok.

这里必须要用Integer的equals方法比较才不会超时。。

直接用int的a[i]!=b[i]会超时>_<

</font>

<font color = black size = 6> 【代码】</font>
```cpp
import java.io.*;
import java.util.*; //code start from here
/*
d[i] = c[i+1]-c[i]; (1<=i<=n-1) change c[i] c[i]' = c[i+1]+c[i-1]-c[i]; d[i-1] = c[i]'-c[i-1];
= c[i+1]+c[i-1]-c[i]-c[i-1] == c[i+1]-c[i] = d[i]; d[i] = c[i+1]-c[i]'
= c[i+1]-c[i+1]-c[i-1]+c[i]
= c[i] - c[i-1];
= d[i-1];
*/ public class Main { final static int N = (int)1e5;
static InputReader in;
static PrintWriter out;
static int n;
static Integer c[],t[],d1[],d2[]; public static void main(String[] args) throws IOException{
in = new InputReader();
//out = new PrintWriter(System.out);
c = new Integer[N+10];t = new Integer[N+10];
d1 = new Integer[N+10]; d2 = new Integer[N+10]; n = in.nextInt();
for (int i = 1;i <= n;i++) c[i] = in.nextInt();
for (int i = 1;i <= n;i++) t[i] = in.nextInt();
if (!c[1].equals(t[1]) || !c[n].equals(t[n])){
System.out.println("No");
return;
}
for (int i = 1;i <= n-1;i++) d1[i] = c[i+1]-c[i];
for (int i = 1;i <= n-1;i++) d2[i] = t[i+1]-t[i];
Arrays.sort(d1, 1,n);
Arrays.sort(d2, 1,n);
for (int i = 1;i <= n-1;i++)
if (!d1[i].equals(d2[i])) {
System.out.println("No");
return;
}
System.out.println("Yes");
} static class InputReader{
public BufferedReader br;
public StringTokenizer tokenizer; public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in),32768);
tokenizer = null;
} public String next(){
while (tokenizer==null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(br.readLine());
}catch(IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
} public int nextInt() {
return Integer.parseInt(next());
}
}
}

【Codeforces Global Round 1 E】Magic Stones的更多相关文章

  1. 【Codeforces Global Round 1 C】Meaningless Operations

    [链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...

  2. 【 Codeforces Global Round 1 B】Tape

    [链接] 我是链接,点我呀:) [题意] x轴上有m个连续的点,从1标号到m. 其中有n个点是特殊点. 让你用k段区间将这n个点覆盖. 要求区间的总长度最小. [题解] 一开始假设我们需要n个胶带(即 ...

  3. 【Codeforces Global Round 1 A】Parity

    [链接] 我是链接,点我呀:) [题意] 给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数 [题解] 模拟一下转换的过程,加乘的时候都记得对2取余就好 [代码] im ...

  4. 【Codeforces Beta Round #45 D】Permutations

    [题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...

  5. 【Codeforces Beta Round #88 C】Cycle

    [Link]:http://codeforces.com/problemset/problem/117/C [Description] 问你一张图里面有没有一个三元环,有的话就输出. [Solutio ...

  6. 【手抖康复训练1 】Codeforces Global Round 6

    [手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...

  7. CodeForces Global Round 1

    CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...

  8. Codeforces Global Round 1 (A-E题解)

    Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...

  9. Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)

    Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...

随机推荐

  1. git分支的合并和冲突解决【转】

    本文转载自:http://blog.csdn.net/Kingson_Wu/article/details/39227611 http://gitbook.liuhui998.com/3_3.html ...

  2. js获取后台数据

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>& ...

  3. Git学习之序

    最近在忙毕业论文的事,需要用NS2仿真,其中需要修改NS2的源码,故想藉此机会学习一下Git,方便代码的管理. 由于我在以前实习的时候接触过代码管理工具SVN,因此对代码管理的一些概念还是有的.如果从 ...

  4. Codeforces 718C 线段树+矩乘

    题意: 维护一个序列,支持两种操作:1.区间[l,r]的权值+x2.询问区间[l,r]的函数和,即∑fib(x)这里的函数即斐波那契函数数据范围:1≤n,q≤105 思路:一般求斐波那契函数的方法可以 ...

  5. Oracle(一)

    1.树形表,查询 所有的下边的记录 情景:根据当前记录的ID,要查询其所有子记录,每个子记录再查询当前子记录的所有子记录,如果有的话,一直迭代下去 当前表结构: CREATE TABLE " ...

  6. No operations allowed after connection closed--转

    https://www.jianshu.com/p/1626d41572f2 Spring boot的单数据源配置比较简单,只需要在application.properties配置相关的jdbc连接的 ...

  7. Debug无效,不起作用

    问题:debug调试时,红色断点空心,无效. 解决办法: 1.(工具 => 选项 =>调试 => 要求源文件与原始版本完成匹配 )去掉勾. 2.若是debug还是空心,不起作用,可以 ...

  8. MVC系列学习(七)-模板页

    1.新建一个MVC项目,选择基本 2.查看文件 看到VS为我们生成了一些东西 布局页面,Layout 指定了模板页 3.开始实例 首先控制器中的代码如下: 视图中代码如下: 1.在/Views/_Vi ...

  9. 搭建本地wordpress

    1.首先,下载xampp,安装按默认勾选即可. 2.安装完成后,启动Apache和MySQL这两个服务. 启动后变成绿色,表示启动成功. 3.点击MySQL项的Admin进入数据库后台. 4.点击用户 ...

  10. 挂载硬盘,提示 mount: unknown filesystem type 'LVM2_member'的解决方案

    问题现象:由于重装linux,并且加了固态硬盘,直接将系统装在固态硬盘中.启动服务器的时候, 便看不到原来机械硬盘的挂载目录了,不知如何访问机械硬盘了.直接用命令 mount /dev/sda3 /s ...