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个点数目-同一纵行 ...
随机推荐
- 前端新手分析 AJAX执行顺序,数据走向
我是一名前端的newer 在刚学习AJAX和eJS的时候,对于顺序上面有很大迷惑,现在稍微清楚了一点, 理解不对的地方,还请各位大牛帮助给我指导一下. 总的 服务器和客户端的顺序 一. 除了必要的 ...
- UVa10023手动开大数平方算法
题目链接:UVa 10023 import java.math.BigInteger; import java.util.Scanner; public class Main { public sta ...
- VS2012离线安装Xamarin (含破解补丁)
Xamarin离线安装包 来源于 忘忧草 特此感谢! 离线安装不成功:参考源 http://www.cnblogs.com/zjoch/p/3937014.html / http://www.cnb ...
- paper 48: Latex中如何制作参考文献
文章写到现在,最后一步就要大功告成了!reference,let's go! 一.用Google来做Latex的bib文件 1. 打开scholar.google.com 2. 定制 Schola ...
- oracle的索引维护
索引重建 Alter index idx_name rebuild partition index_partition_name [online nologging] 需要对每个分区索引做rebuil ...
- ORACLE 默认密码确认
select USER_NAME USER_WITH_DEFAULT_PASSWORD from ( select fnd_web_sec.validate_login('AME_INVALID_AP ...
- springmvc处理ajax请求
1.controller将数据封装成json格式返回页面 @RequestMapping("/dataList") public void datalist(CsoftCunsto ...
- XAMPP和Bugfree详细教程
一.XAMPP安装配置 xampp是一款跨平台的集成 apache + mysql + php环境,是的配置AMP服务器变得简单轻松,支持windows,solaris, 下载地址:http://so ...
- LR 常见问题收集及总结
一:LoadRunner常见问题整理 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消掉 2.在系统属性-高级-性能-数据执行保护中,添加loadrunner安装目录中的vugen. ...
- Server.MapPath()获取本机绝对路径
1. Server.MapPath("/") 应用程序根目录所在的位置 如 C:\Inetpub\wwwroot\ 2.Server.MapPath("./&qu ...