AtCoder Petrozavodsk Contest 001 B - Two Arrays
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
You are given two integer sequences of length N: a1,a2,..,aN and b1,b2,..,bN. Determine if we can repeat the following operation zero or more times so that the sequences a and b become equal.
Operation: Choose two integers i and j (possibly the same) between 1 and N (inclusive), then perform the following two actions simultaneously:
- Add 2 to ai.
- Add 1 to bj.
Constraints
- 1≤N≤10 000
- 0≤ai,bi≤109 (1≤i≤N)
- All input values are integers.
Input
Input is given from Standard Input in the following format:
N
a1 a2 .. aN
b1 b2 .. bN
Output
If we can repeat the operation zero or more times so that the sequences a and b become equal, print Yes
; otherwise, print No
.
Sample Input 1
3
1 2 3
5 2 2
Sample Output 1
Yes
For example, we can perform three operations as follows to do our job:
- First operation: i=1 and j=2. Now we have a={3,2,3}, b={5,3,2}.
- Second operation: i=1 and j=2. Now we have a={5,2,3}, b={5,4,2}.
- Third operation: i=2 and j=3. Now we have a={5,4,3}, b={5,4,3}.
Sample Input 2
5
3 1 4 1 5
2 7 1 8 2
Sample Output 2
No
Sample Input 3
5
2 7 1 8 2
3 1 4 1 5
Sample Output 3
No 如果a[i]>b[i],就需要a[i]-b[i]个b[i] + 1 操作,如果a[i] < b[i],就需要(a[i] - b[i])/2个a[i] + 2操作与其他的b[j] + 1操作进行组合,比如a[i] = 1,b[i] = 6,就需要2个第二种操作,加完后a[i]为5,比6差1,只需要a[i],b[i]同时再做一个操作就可以。根据题意需要第二个操作不少于第一个操作,才能保证两个操作一齐进行。
代码:
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iomanip>
using namespace std;
int n;
long long a[],b[];
long long z,f;
int main()
{
cin>>n;
for(int i = ;i < n;i ++)
{
cin>>a[i];
}
for(int i = ;i < n;i ++)
{
cin>>b[i];
if(b[i] - a[i] < )f += a[i] - b[i];
else if(b[i] - a[i] > )z += (b[i] - a[i]) / ;
}
if(z >= f)cout<<"Yes";
else cout<<"No";
}
AtCoder Petrozavodsk Contest 001 B - Two Arrays的更多相关文章
- 【AtCoder】AtCoder Petrozavodsk Contest 001
A - Two Integers 如果\(X\)是\(Y\)的倍数的话不存在 可以输出\(X \cdot (\frac{Y}{gcd(X,Y)} - 1)\) 代码 #include <bits ...
- AtCoder Petrozavodsk Contest 001
第一场apc,5H的持久战,我当然水几个题就睡了 A - Two Integers Time limit : 2sec / Memory limit : 256MB Score : 100 point ...
- AtCoder Petrozavodsk Contest 001 A - Two Integers
Time limit : 2sec / Memory limit : 256MB Score : 100 points Problem Statement You are given positive ...
- AtCoder Grand Contest 001 D - Arrays and Palindrome
题目传送门:https://agc001.contest.atcoder.jp/tasks/agc001_d 题目大意: 现要求你构造两个序列\(a,b\),满足: \(a\)序列中数字总和为\(N\ ...
- Atcoder Grand Contest 001 D - Arrays and Palindrome(构造)
Atcoder 题面传送门 洛谷题面传送门 又是道思维题,又是道把我搞自闭的题. 首先考虑对于固定的 \(a_1,a_2,\dots,a_n;b_1,b_2,\dots,b_m\) 怎样判定是否合法, ...
- AtCoder Grand Contest 001 C Shorten Diameter 树的直径知识
链接:http://agc001.contest.atcoder.jp/tasks/agc001_c 题解(官方): We use the following well-known fact abou ...
- Atcoder Grand Contest 001 F - Wide Swap(拓扑排序)
Atcoder 题面传送门 & 洛谷题面传送门 咦?鸽子 tzc 来补题解了?奇迹奇迹( 首先考虑什么样的排列可以得到.我们考虑 \(p\) 的逆排列 \(q\),那么每次操作的过程从逆排列的 ...
- AtCoder Grand Contest 001
B - Mysterious Light 题意:从一个正三角形边上一点出发,遇到边和已走过的边则反弹,问最终路径长度 思路:GCD 数据爆long long #pragma comment(linke ...
- 【刷题】AtCoder Regular Contest 001
A.センター採点 题意:给一个只包含1.2.3.4的字符串,求出现次数最多和最少的字符 做法:还能怎么做... #include<bits/stdc++.h> #define ui uns ...
随机推荐
- LeetCode:分割链表【86】
LeetCode:分割链表[86] 题目描述 给定一个链表和一个特定值 x,对链表进行分隔,使得所有小于 x 的节点都在大于或等于 x 的节点之前. 你应当保留两个分区中每个节点的初始相对位置. 示例 ...
- 【leetcode刷题笔记】Number of 1 Bits
Write a function that takes an unsigned integer and returns the number of ’1' bits it has (also know ...
- STM32f103的电阻触摸屏的五点校正算法
源:STM32f103的电阻触摸屏的五点校正算法 STM32f103的触摸屏的设置与使用
- linux基础三---网络基础&软件包管理
一 ifconfig:显示所有正在启动的网卡的详细信息或设定系统中网卡的IP地址. ifconfig eno16777736 down/up 关闭/开启 eno16777736 网卡 ifconf ...
- P3413 SAC#1 - 萌数
题目 洛谷 数位动规用爆搜真好玩 做法 含有回文串实际我们仅需判断是否有\(2/3\)回文串 \(Dfs(now,num,pre,ly,lead,prel,top)\): 在第\(now\)位 \(n ...
- 【转载】用Scikit-Learn构建K-近邻算法,分类MNIST数据集
原帖地址:https://www.jiqizhixin.com/articles/2018-04-03-5 K 近邻算法,简称 K-NN.在如今深度学习盛行的时代,这个经典的机器学习算法经常被轻视.本 ...
- juniper常用命令
Juniper防火墙基本命令 get interface ethernet0/0 查看 端口 常用查看命令 Get int 查看接口配置信息 Get int ethx/x 查看指定接口配置信息 G ...
- 【BZOJ2818】Gcd (欧拉函数)
网址:http://www.lydsy.com/JudgeOnline/problem.php?id=2818 一道数论裸题,欧拉函数前缀和搞一下就行了. 小于n的gcd为p的无序数对,就是phi(1 ...
- 好的SQL写法
DECLARE @beginTime VARCHAR(20)= '2017-12-20 00:00:00';DECLARE @endTime VARCHAR(20)= '2017-12-26 00:0 ...
- centos 验证mysql的安装
一.验证mysql是否安装 1.whereis mysql:如果安装了mysql就会显示mysql安装的地址 2.which mysql:查看文件的运行地址 3.chkconfig --list my ...