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

【题意】

你可以把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. iframe高度100%,自适应高度

    声明:有更好的方法在下一篇内容中 100% http://www.360doc.com/content/11/1102/15/55892_161105115.shtml iframe自适应高度 转自: ...

  2. 机器视觉: LBP-TOP

    之前介绍过机器视觉中常用到的一种特征:LBP http://blog.csdn.net/matrix_space/article/details/50481641 LBP可以有效地处理光照变化,在纹理 ...

  3. codeforce 杀题计划

    先尽量做Div 1 A B 想做难题时做C 全天学竞赛时每天至少两道Div2 (算法数据结构没学的先过,题面很长的......也先过  我的英语啊...)

  4. 如何解决error LNK2001(转载)

    转自:http://www.cnblogs.com/myzhijie/articles/1658545.html 解决外部符号错误:_main,_WinMain@16,__beginthreadex ...

  5. 【BZOJ2565】最长双回文串 (Manacher算法)

    题目: BZOJ2565 分析: 首先看到回文串,肯定能想到Manacher算法.下文中字符串\(s\)是输入的字符串\(str\)在Manacher算法中添加了字符'#'后的字符串 (构造方式如下) ...

  6. 传值:web.xml传递参数 即在Servlet中获取web.xml里的值

    传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param <servlet> ... <init-param> <param-nam ...

  7. 微信接口本地调试(IIS服务器)

    1.下载ngrok,并注册获得token.官网下载地址:https://ngrok.com/ 如果你是在官网下载的,到后面映射域名的时候会要求购买他们的服务. 这里我们用一个国内免费的ngrok服务器 ...

  8. MVC系列学习(十二)-服务端的验证

    在前一讲,提到过,客户端的东西永远可以造假,所以我们还要在服务端进行验证 注意:先加载表单,后添加js文件,才能有效:而先加载js,后添加表单,是没有效果的 1.视图与Model中的代码如下 2.一张 ...

  9. 屏蔽scrollview的滚动

    外层有scrollview时,手指移动方向跟滚动条方向相同时,会导致scrollview的滚动.此时如果不想滚动的话,可以在要接受ontouch的子视图,或者子子视图中的touch监听里加上v.get ...

  10. Eclipse + Pydev开发Python时import报错解决方法

    一.  原文链接:http://blog.csdn.net/lhanchao/article/details/51306626            用eclipse +PyDev开发python时, ...