http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no思路:既然a[k]前面数相减等于这个数,则所有减去的数之和sum一定数偶数。其中最大的减数的2倍一定要小于这个sum,如果不满足就不可能从a序列到b序列。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

  1. 3
  2. 3 2
  3. 4 2
  4. 5 2
  5. 3
  6. 2 0
  7. 7 1
  8. 3 1

Sample Output

  1. YES
  2. NO
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <algorithm>
  4. using namespace std;
  5. int max(int x,int y)
  6. {
  7. if(x>y)
  8. return x;
  9. else
  10. return y;
  11. }
  12. int main()
  13. {
  14. long long maxn,a[10000],b[10000],sum,q;
  15. int t,i;
  16. while(~scanf("%d",&t))
  17. {
  18. sum=maxn=0;
  19. for(i=0;i<t;i++)
  20. {
  21. scanf("%lld%lld",&a[i],&b[i]);
  22. q=a[i]-b[i];
  23. sum+=q;
  24. maxn=max(maxn,q);
  25. }
  26. if(sum%2!=0)
  27. printf("NO\n");
  28. else if(2*maxn>sum)
  29. printf("NO\n");
  30. else
  31. printf("YES\n");
  32.  
  33. }
  34. return 0;
  35. }
  36. /*
  37. 6
  38. 10 1
  39. 5 3
  40. 16 5
  41. 9 3
  42. 9 2
  43. 14 1
  44. */

zoj 3672 Gao The Sequence的更多相关文章

  1. zoj Gao The Sequence

    Gao The Sequence Time Limit: 2 Seconds      Memory Limit: 65536 KB You are given a sequence of integ ...

  2. ZOJ 3408 Gao

    ZOJ题目页面传送门 给定一个有向图\(G=(V,E),n=|V|,m=|E|\)(可能有重边和自环,节点从\(0\)开始编号),以及\(q\)组询问,对于每组询问你需要回答有多少条从节点\(0\)开 ...

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

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 三角形的总数=格子中任取3个点的组合数-同一横行任取3个点数目-同一纵行 ...

  4. zoj3672 Gao The Sequence

    原地踏步了半年,感觉一切都陌生了~ 题意:a[i]-一个任意的数,这个数要等于a[1]~a[i-1]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no. 一开始各种分 ...

  5. zoj 3672 思考题

    http://acm.zju.edu.cn/onlinejudge/showProblem.do? problemId=4915 真是老了.脑子不会动了,可是事实上就算如今搜了题解A了,还是没总结出思 ...

  6. zoj 3647 Gao the Grid

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 先求出从所有点随机找出三个点的组合数,然后去掉共线的,平行好去掉,斜线就 ...

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

    题目大意: 用集合A中的串构造出一个串,使之让很多其它的setB中的串成为他的子串. 思路分析: 和 Codeforces 86C 几乎相同. 只是这里是要用A中的构造. 先用A 和 B的串构造一个自 ...

  8. 【ZOJ 4060】Flippy Sequence

    [链接] 我是链接,点我呀:) [题意] [题解] 按照两个区间的排列方式 我们可以分成以下几种情况 会发现这两个区间的作用 最多只能把两段连续不同的区间变为相同. 那么写个for处理出连续不相同的一 ...

  9. ZOJ 2421 Recaman's Sequence

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1421 题目大意: 定义a^m为 a^m = a^(m-1) - m  如果a^ ...

随机推荐

  1. css 选择符

    css参考手册:css.doyoe.com 在css3中,不同的浏览器可能需要不同的前缀,它表示该css属性或规则尚未成为W3C标准的一部分,是浏览器的私有属性,虽然目前较新版本的浏览器都是不需要前缀 ...

  2. MVC+MEF+UnitOfWork+EF架构,网站速度慢的原因总结!(附加ANTS Memory Profiler简单用法)

    (最近使用内存分析工具ANTS Memory Profiler,以及其他网友提供的意见发现最终导致内存泄漏的就是MEF,在此特地更新下,与大家分享!最下面红色字体) 最近参考使用了郭明峰的一套架构来做 ...

  3. Java方法-数组

    [Java数组] 1. 用sort()方法对Java数组进行排序,及如何使用 binarySearch() 方法来查找数组中的元素 binarySearch() 返回值: 如果它包含在数组中,则返回搜 ...

  4. 安卓开发service

    如果把Activity比喻为前台程序,那么service可以看做是一个后台程序.Service跟Activity一样也由Intent调用. 在工程里想要添加一个Service,先新建继承Service ...

  5. python 数据结构

    Python的数据结构主要分为set(),list[],和dict{}.这篇文章主要记载这几种结果在使用过程中的一些技巧或其中一些函数的用法区别. 1.函数get()与setdefault()区别: ...

  6. golang bufio writer,reader 缓存规则

    读,写,缓冲区可以杜绝频繁的读,写动作1.写缓存,如果一次write的长度大于buffer长度那么久发送当前缓冲区的内容并且发送要写入的内容,就是不在缓存了.如果发送的内容小于buffer长度,就按缓 ...

  7. IIS 服务器用OFFIC 2007 组件 WORD转PDF配置记录

    <system.web> <identity impersonate="true" userName="accountname" passwo ...

  8. Java字符串学习

    Java中字符串是String类的实例,字符串也是对象,所以 Java将字符串作为对象进行管理 Java使用java.lang 包中的String类来创建字符串. 1.定义字符串: 使用 " ...

  9. CSS响应式web设计

    参考 1. 响应式web设计之CSS3 Media Queries http://www.cnblogs.com/mofish/archive/2012/05/23/2515218.html 2. 用 ...

  10. MFC之MessageBox用法

    一    函数原型及参数 function MessageBox(hWnd: HWND; Text, Caption: PChar; Type: Word): Integer; hWnd:对话框父窗口 ...