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
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL; LL a[];
int main()
{
LL n,i,x,y;
while(scanf("%lld",&n)>)
{
LL max1=-;
for(i=;i<=n;i++)
{
scanf("%lld%lld",&x,&y);
a[i]=x-y;
}
sort(a+,a++n);
max1=a[n];
LL sum=;
LL hxl=a[n];
for(i=;i<=n-;i++)
{
sum=sum+a[i];
hxl=(hxl+a[i])%;
}
if(max1>sum || hxl==) printf("NO\n");
else printf("YES\n");
}
return ;
}
zoj Gao The Sequence的更多相关文章
- zoj 3672 Gao The Sequence
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915题意:a[k]-一个任意的数,这个数要等于a[1]~a[k]每个数减去任意 ...
- zoj3672 Gao The Sequence
原地踏步了半年,感觉一切都陌生了~ 题意:a[i]-一个任意的数,这个数要等于a[1]~a[i-1]每个数减去任意一个数,经过多次这样的变换到达目标b序列,能到达就yes不能到达距no. 一开始各种分 ...
- ZOJ 4060 - Flippy Sequence - [思维题][2018 ACM-ICPC Asia Qingdao Regional Problem C]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4060 题意: 给出两个 $0,1$ 字符串 $S,T$,现在你有 ...
- ZOJ Monthly, November 2012
A.ZOJ 3666 Alice and Bob 组合博弈,SG函数应用 #include<vector> #include<cstdio> #include<cstri ...
- ZOJ Monthly, March 2018 题解
[题目链接] A. ZOJ 4004 - Easy Number Game 首先肯定是选择值最小的 $2*m$ 进行操作,这些数在操作的时候每次取一个最大的和最小的相乘是最优的. #include & ...
- 矩阵连乘积 ZOJ 1276 Optimal Array Multiplication Sequence
题目传送门 /* 题意:加上适当的括号,改变计算顺序使得总的计算次数最少 矩阵连乘积问题,DP解决:状态转移方程: dp[i][j] = min (dp[i][k] + dp[k+1][j] + p[ ...
- ZOJ - 4104 Sequence in the Pocket(思维+元素移至列首排序)
Sequence in the Pocket Time Limit: 1 Second Memory Limit: 65536 KB DreamGrid has just found an ...
- ZOJ 3408 Gao
ZOJ题目页面传送门 给定一个有向图\(G=(V,E),n=|V|,m=|E|\)(可能有重边和自环,节点从\(0\)开始编号),以及\(q\)组询问,对于每组询问你需要回答有多少条从节点\(0\)开 ...
- ZOJ 3647 Gao the Grid dp,思路,格中取同一行的三点,经典 难度:3
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4837 三角形的总数=格子中任取3个点的组合数-同一横行任取3个点数目-同一纵行 ...
随机推荐
- zjuoj 3600 Taxi Fare
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3600 Taxi Fare Time Limit: 2 Seconds ...
- fnd_profile.value('AFLOG_ENABLED')的取值 和配置文件相关SQL
SELECT * FROM FND_PROFILE_OPTIONS_VL TT WHERE TT.PROFILE_OPTION_NAME LIKE '%AFLOG%' FND:启用调试日志 详细的参考 ...
- access链接最原始代码,两种
using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web ...
- [tp3.2.1]sql查询语句(一)
基本查询方式 字符串条件查询, 索引数组条件查询 对象条件查询 SQL语句大小写是一样的,但是,执行的时候有一个小写到大写的转换,所以最好写大写 $condition=new ...
- 【ubuntu】首选项和应用程序命令(preference & application)
gnome-control-center 系统设置 gnome-control-center region 键盘布局 gnome-control-center screen 屏幕 gno ...
- Javascript之回调函数(callback)
1.回调函数定义: 回调函数就是一个通过函数指针调用的函数.如果你把函数的指针(地址)作为参数传递给另一个函数,当这个指针被用为调用它所指向的函数时,我们就说这是回调函数.回调函数不是由该函数的实现方 ...
- string与char之间的互相转换
string对象是一种很强大的存在哈~~ 1. string转const char* string s = "abc"; const char* c_s = s.c_str(); ...
- 利用VHD虚拟文件加密自己的个人信息
1.制作VHD磁盘 计算机—管理—磁盘管理—操作—创建VHD 2.挂载卸载VHD磁盘 磁盘管理—操作—附加VHD 选择只读则不允许修改文件内容 3.用途 这样一个虚拟磁盘就被建立出来.它实际上仅仅是一 ...
- Spring 复习笔记01
Spring 框架 1. core:整个Spring框架构建在Core核心模块上,它是整个框架的的基础. 2. AOP:AOP模块提供了一个轻便但功能强大强大的AOP框架,让我们可以以AOP的形式增强 ...
- IMG图片和文字同行显示
只要设定img标签的vertical-align CSS属性就好了,代码如下: <img src="images/untitled.png" style="widt ...