zoj Gao The Sequence

Gao The Sequence


Time Limit: 2 Seconds
     Memory
Limit: 65536 KB


You are given a sequence of integers, A1,A2,...,An. And you are
allowed a manipulation on the sequence to transform the origin sequence into
another sequence B1,B2,...,Bn(Maybe the two sequences are same ).
The manipulation is specified as the following three steps:

1.Select an integer Ai and choose an arbitrary positive
integer delta as you like.

2.Select some integers Aj satisfying j < i, let‘s
suppose the selected integers are Ak1,Ak2,...,Akt , then
subtract an arbitrary positive integer Di from Aki
(1 ≤ i ≤ t)
 as long as sum(Di) = delta.

3.Subtract delta from Ai.

The manipulation can be performed any times. Can you find a way to
transform A1,A2,...,An to B1,B2,...,Bn ?

Input

The input consist of multiple cases. Cases are about 100 or so. For each
case, the first line contains an integer N(1 ≤ N ≤
10000)
 indicating the number of the sequence. Then followed by N
lines, ith line contains two
integers Ai and Bi (0 ≤ Bi ≤ Ai ≤
4294967296)
.

Output

Output a single line per case. Print "YES" if there is a certain way to
transform Sequence A into Sequence B. Print
"NO" if not.

Sample Input

3
3 2
4 2
5 2
3
2 0
7 1
3 1

Sample Output

YES
NO


 1 #include<iostream>
2 #include<stdio.h>
3 #include<cstring>
4 #include<cstdlib>
5 #include<algorithm>
6 using namespace std;
7 typedef long long LL;
8
9 LL a[10002];
10 int main()
11 {
12 LL n,i,x,y;
13 while(scanf("%lld",&n)>0)
14 {
15 LL max1=-1;
16 for(i=1;i<=n;i++)
17 {
18 scanf("%lld%lld",&x,&y);
19 a[i]=x-y;
20 }
21 sort(a+1,a+1+n);
22 max1=a[n];
23 LL sum=0;
24 LL hxl=a[n];
25 for(i=1;i<=n-1;i++)
26 {
27 sum=sum+a[i];
28 hxl=(hxl+a[i])%2;
29 }
30 if(max1>sum || hxl==1) printf("NO\n");
31 else printf("YES\n");
32 }
33 return 0;
34 }

zoj Gao The Sequence

时间: 2024-08-28 23:49:30

zoj Gao The Sequence的相关文章

ZOJ3672:Gao The Sequence

安装opencv2.0 解压OpenCV-2.0.0.tar.bz2 tar xvf OpenCV-2.0.0.tar.bz2 配置 ./configure --host=arm-linux \ --without-carbon \ --without-quicktime \ --without-1394libs \ --without-ffmpeg \ --without-python \ --without-swig \ --without-gtk \ --enable-static \ -

ZOJ 2105 Number Sequence(矩阵快速幂)

题意: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给定A,B,求f(n). 法一: 网上较多的题解都提到了寻找1 1循环节的方法,的确非常巧妙,每位0~6,共7种可能,相邻两位共49种可能,因此循环周期至多为49,一旦出现相同数对,那么其后必相同.但是,该方法只是简单提及了49,却并没有证明1 1循环节一定存在,没有排除可能前面一段不循环,后面一段开始周期性循环的可能性.(是我悟性太差吗,为什么大多数题解都只谈

zoj3672 Gao The Sequence

原地踏步了半年,感觉一切都陌生了~ 题意:a[i]-一个任意的数,这个数要等于a[1]~a[i-1]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no. 一开始各种分析,所有的差的和必须是偶数,sum(cha[1~i-1])>=cha[i](其中cha[i]=a[i]-b[i])等,后来想从最后一项的cha变0,然后同时消除紧邻着的cha,尽量消除,消除到最后不能消除就NO,华丽丽的WA了~ badcase: 33 02 01 0正确的答案是yes,第一项和第三

ZOJ Monthly, November 2012

A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int maxn = 10000 + 100; int SG[maxn]; vector<int> g[maxn]; int mex(int u) { //minimal exc

矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence

题目传送门 1 /* 2 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 3 矩阵连乘积问题,DP解决:状态转移方程: 4 dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[i-1] * p[k] * p[j]) (i<=k<j) 5 s[i][j] 记录断开的地方(即加括号的位置),回溯法输出结果 6 */ 7 #include <cstdio> 8 #include <cstring> 9 #include <stri

UVA 348 &amp; ZOJ 1276 Optimal Array Multiplication Sequence(dp , 矩阵链相乘问题)

Optimal Array Multiplication Sequence Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Description Given two arrays A and B, we can determine the array C = AB using the standard definition of matrix multiplication: The number of

Zoj 3535 Gao the String II (AC自己主动机+dp)

题目大意: 用集合A中的串构造出一个串,使之让很多其它的setB中的串成为他的子串. 思路分析: 和 Codeforces 86C 几乎相同. 只是这里是要用A中的构造. 先用A 和 B的串构造一个自己主动机.然后对于A集合的尾结点给出一个最大后缀匹配,对于B集合的尾结点给一个权值. dp[i][j][k] 表示已经构造出来了一个长度为i的串,如今走到了自己主动机的j结点.i长度后面有k个字符是没有匹配到的. 继续在自己主动机上走进行状态转移. if(isword >= k +1 )dp [i+

ZOJ 3647 Gao the Grid(居然是暴力)

A n * m grid as follow: Count the number of triangles, three of whose vertice must be grid-points. Note that the three vertice of the triangle must not be in a line(the right picture is not a triangle). Input The input consists of several cases. Each

ZOJ 3647 Gao the Grid dp,思路,格中取同一行的三点,经典 难度:3

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 三角形的总数=格子中任取3个点的组合数-同一横行任取3个点数目-同一纵行任取3个点数目-同一斜直线上任取3个点数目 同一横行和同一纵行都好求 同一斜行的距离最远的点必然是一个矩形的两个端点,设矩形的长宽为l,w,中间可以取的点数则是(gcd(l,w)-1),左上角或左下角的起点反而不重要. 能够取到该矩形的可能是 (n-l+1)*(m-w+1),因为左上角作为起点或左下