zoukankan      html  css  js  c++  java
  • 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
    ");
    31         else printf("YES
    ");
    32     }
    33     return 0;
    34 }
  • 相关阅读:
    1-直播转点播
    3-美团 HTTP 服务治理实践
    3-SSDB 高性能NoSQL数据库, 用于替代 Redis.
    配置kubectl在Mac(本地)远程连接Kubernetes集群
    4-rocketmq 发送时异常:system busy 和 broker busy 解决方案
    3-RocketMQ 简单梳理 及 集群部署笔记
    2-Rocketmq产品架构(参考阿里云)
    1-RocketMq 学习 中文文档(一)
    tar命令参数详解
    Ubuntu 安装 .bundle 文件
  • 原文地址:https://www.cnblogs.com/tom987690183/p/3724303.html
Copyright © 2011-2022 走看看