zoj - 3672 - Gao The Sequence
来源:互联网 发布:法院执行难 知乎 编辑:程序博客网 时间:2024/05/02 06:45
题意:有两个序列A和B(下标从1开始),问能否经过有限次的下列操作,把A变成B(1 <= 序列长度N <= 10000,0 ≤ Bi ≤ Ai ≤ 4294967296)。
操作:任意选择A中的第i个数A[i],定义一个变化量delta,任意选择A[1], A[2], ..., A[i-1]中一些数减小它们的值,使得变化量和等于delta,A[i]自己也减去delta。
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4915
——>>1、每一次操作,总共减去2个delta,是个偶数,所以最后的增量和一定是偶数。
2、如果存在A[i]与B[i]使得2 * (A[i] - B[i]) > sum(sum为总增量),那么要使A[i]变成B[i],总的A就会减去2 * (A[i] - B[i])(一半是A[i]自己的,一半是牵连的),但总增量并没有那么大,这种情况一定不能实现变换。
注意:程序中用到了64位整数,在zoj上,若用scanf,用的应是%lld,而不是%I64d。用%I64d会出现随机AC与WA的现象。
#include <iostream>#include <algorithm>using namespace std;int N;void solve(){ bool ok = 1; long long A, B, sum = 0, Max = -1, dis; for(int i = 1; i <= N; i++){ cin >> A >> B; dis = A - B; sum += dis; Max = max(Max, dis); } if(sum & 1 || 2 * Max > sum) ok = 0; if(ok) cout << "YES" << endl; else cout << "NO" << endl;}int main(){ while(cin >> N) solve(); return 0;}
- zoj 3672 Gao The Sequence
- zoj - 3672 - Gao The Sequence
- ZOJ 3672 Gao The Sequence
- ZOJ3672:Gao The Sequence
- ZOJ 3647 Gao the Grid
- ZOJ 3647 Gao the Grid
- zoj 3647 Gao the Grid
- ZOJ-3647 Gao the Grid
- ZOJ 3647 Gao the Grid
- ZOJ 3535 Gao the String II
- ZOJ 3648 Gao the Grid II
- Zoj 3647 Gao the Grid (数论?)
- zoj 3535 Gao the String II(ac自动机+dp)
- zoj 3533 Gao the String I(伸展树+字符串hash)
- zoj 3535 Gao the String II(AC自动机+DP)
- Zoj 3535 Gao the String II (AC自动机+dp)
- ZOJ 3647 Gao the Grid(居然是暴力)
- zoj 3535 Gao the String II (ac自动机+dp)
- hdu 1284 钱币兑换问题 完全背包
- c++ 消息处理
- android handler和looper
- SNR BER Eb/N0之间的区别与联系
- CAS SSO改造步骤(3)
- zoj - 3672 - Gao The Sequence
- ckeditor的详细配置 js版
- shell命令
- 写个图片爬虫,scrapy,python第一次接触(停止更新)
- 一位获全额奖学金到北美留学的学长花四天写下的东西 ~~~此文涉及人生、考研、出国,值得一看
- hdu(3335)Divisibility
- CKEditor 3.x 在Java中配置、包括图片上传、支持FTP、图片压缩
- perl 模式匹配总结
- 接口转换--适配器模式