zoukankan      html  css  js  c++  java
  • zoj 3672 Gao The Sequence

    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

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

    Sample Output

    YES
    NO
    #include <stdio.h>  
    #include <string.h>  
    #include <algorithm>  
    using namespace std;  
    int max(int x,int y)
    {
    	if(x>y)
    		return x;
    	else
    		return y;
    }
    int  main()
    {
        long long maxn,a[10000],b[10000],sum,q;
    	int t,i;
        while(~scanf("%d",&t))
        {
               sum=maxn=0;
            for(i=0;i<t;i++)
              {
                 scanf("%lld%lld",&a[i],&b[i]);
                  q=a[i]-b[i];
                  sum+=q;
                  maxn=max(maxn,q);
              }
              if(sum%2!=0)
                  printf("NO
    ");
              else if(2*maxn>sum)
                   printf("NO
    ");
                else
                printf("YES
    ");
    
    
        }
        return 0;
    }
    /*
    6
    10 1
    5 3
    16 5
    9 3
    9 2
    14 1
    */
    
  • 相关阅读:
    linux 安装 apache2.2.31
    如何在高并发环境下设计出无锁的数据库操作(Java版本) 转载
    一些需要注意的点
    一些卡常技巧
    【CF809E】Surprise me! 树形DP 虚树 数学
    ISAP算法
    【AGC013C】Ants on a Circle 弹性碰撞
    【CF768G】The Winds of Winter 可持久化线段树 DFS序
    【CF633D】Fibonacci-ish
    【BZOJ4042】【CERC2014】parades 状压DP
  • 原文地址:https://www.cnblogs.com/cancangood/p/3728571.html
Copyright © 2011-2022 走看看