【Codeforces Global Round 1 E】Magic Stones
【链接】 我是链接,点我呀:)
【题意】
你可以把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的更多相关文章
- 【Codeforces Global Round 1 C】Meaningless Operations
[链接] 我是链接,点我呀:) [题意] 给你一个a 让你从1..a-1的范围中选择一个b 使得gcd(a^b,a&b)的值最大 [题解] 显然如果a的二进制中有0的话. 那么我们就让选择的b ...
- 【 Codeforces Global Round 1 B】Tape
[链接] 我是链接,点我呀:) [题意] x轴上有m个连续的点,从1标号到m. 其中有n个点是特殊点. 让你用k段区间将这n个点覆盖. 要求区间的总长度最小. [题解] 一开始假设我们需要n个胶带(即 ...
- 【Codeforces Global Round 1 A】Parity
[链接] 我是链接,点我呀:) [题意] 给你一个k位数b进制的进制转换. 让你求出来转成10进制之后这个数字是奇数还是偶数 [题解] 模拟一下转换的过程,加乘的时候都记得对2取余就好 [代码] im ...
- 【Codeforces Beta Round #45 D】Permutations
[题目链接]:http://codeforces.com/problemset/problem/48/D [题意] 给你n个数字; 然后让你确定,这n个数字是否能由若干个(1..x)的排列连在一起打乱 ...
- 【Codeforces Beta Round #88 C】Cycle
[Link]:http://codeforces.com/problemset/problem/117/C [Description] 问你一张图里面有没有一个三元环,有的话就输出. [Solutio ...
- 【手抖康复训练1 】Codeforces Global Round 6
[手抖康复训练1 ]Codeforces Global Round 6 总结:不想复习随意打的一场,比赛开始就是熟悉的N分钟进不去时间,2333,太久没写题的后果就是:A 题手抖过不了样例 B题秒出思 ...
- CodeForces Global Round 1
CodeForces Global Round 1 CF新的比赛呢(虽然没啥区别)!这种报名的人多的比赛涨分是真的快.... 所以就写下题解吧. A. Parity 太简单了,随便模拟一下就完了. B ...
- Codeforces Global Round 1 (A-E题解)
Codeforces Global Round 1 题目链接:https://codeforces.com/contest/1110 A. Parity 题意: 给出{ak},b,k,判断a1*b^( ...
- Codeforces Global Round 1 (CF1110) (未完结,只有 A-F)
Codeforces Global Round 1 (CF1110) 继续补题.因为看见同学打了这场,而且涨分还不错,所以觉得这套题目可能会比较有意思. 因为下午要开学了,所以恐怕暂时不能把这套题目补 ...
随机推荐
- ASP.NET_SessionId vs .ASPXAUTH why do we need both of them?
https://stackoverflow.com/questions/23758704/asp-net-sessionid-vs-aspxauth-why-do-we-need-both-of-th ...
- java 提取主域名
import com.google.common.net.InternetDomainName; public static void main(String[] args) { InternetDo ...
- Eclipse自定义HTML5,JSP模板
原文:http://blog.csdn.net/xz2585458279/article/details/78833893 我们知道在MyEclipse里面编写的html和jsp模板并不符合html5 ...
- E20170924-hm
literal adj. 照字面的; 原义的; 逐字的; 平实的,避免夸张; n. [印] 错排,文字上的错误; parameter n. [数] 参数; <物><数&g ...
- 让谷歌浏览器(chrome)保存调试代码workspace
方法/步骤 chrome浏览器早期版本的操作方法与我现在要讲的方法有所不同,因此操作前请注意浏览器的版本号. 示例中的版本号: 53.0.2785.116 m 任意打开一个需要调试的html文件 ...
- jsp文件就是Servlet,可以在tomcat里进行查看
D:\apache-tomcat-8.0.21\work\Catalina\localhost\springmvc2\org\apache\jsp\index_jsp.class
- hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)
首先hibernate级联删除的前提是,首先需要在映射文件中配置,配置多表之间的关联关系: 下面以部门表(Dept)和员工表(Emp)为例: 1.在Emp.hbm.xml映射文件中配置many-to- ...
- CSS——font
行高的量取方式: 1.第一行可设置margin-top值.然后将第一文字顶部到第二行文字顶部的值作为行高的值(要注意对齐方式) 2.将 3.电视上 font:12px/1.5//字体12px,行高1. ...
- HashTable, HashSet, HashMap的区别
HashTable, HashSet, HashMap的区别 hash是一种很常见也很重要的数据结构,是用hash函数根据键值(key)计算出存储地址,以便直接访问.由完美hash函数(即键值 ...
- [Windows Server 2003] 安装IIS6.0及FTP
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装IIS6. ...