Codeforces Round #410 (Div. 2) C
Description
Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if the gcd of all its elements is bigger than 1, i.e. .
Mike wants to change his sequence in order to make it beautiful. In one move he can choose an index i (1 ≤ i < n), delete numbers ai, ai + 1and put numbers ai - ai + 1, ai + ai + 1 in their place instead, in this order. He wants perform as few operations as possible. Find the minimal number of operations to make sequence A beautiful if it's possible, or tell him that it is impossible to do so.
is the biggest non-negative number d such that d divides bi for every i (1 ≤ i ≤ n).
The first line contains a single integer n (2 ≤ n ≤ 100 000) — length of sequence A.
The second line contains n space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.
Output on the first line "YES" (without quotes) if it is possible to make sequence A beautiful by performing operations described above, and "NO" (without quotes) otherwise.
If the answer was "YES", output the minimal number of moves needed to make sequence A beautiful.
2
1 1
YES
1
3
6 2 4
YES
0
2
1 3
YES
1
In the first example you can simply make one move to obtain sequence [0, 2] with .
In the second example the gcd of the sequence is already greater than 1.
题意:要使得,我们可以这样修改 ai - ai + 1, ai + ai + 1,问最少修改次数
解法:按照上面操作把所有的数字变成偶数就行了
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
int x[maxn];
int n;
int num;
int sum;
int main()
{
cin>>n;
cin>>x[];
num=x[];
for(int i=; i<=n; i++)
{
cin>>x[i];
num=__gcd(x[i],num);
}
// cout<<num<<endl;
if(num>)
{
cout<<"YES\n0\n";
return ;
}
for(int i=; i<n; i++)
{
while(x[i]%)
{
int pos=x[i];
x[i]-=x[i+];
x[i+]+=pos;
sum++;
}
}
// cout<<x[n]<<endl;
while(x[n]%)
{
int pos=x[n-];
x[n-]-=x[n];
x[n]+=pos;
sum++;
}
cout<<"YES\n";
cout<<sum<<endl;
return ;
}
Codeforces Round #410 (Div. 2) C的更多相关文章
- Codeforces Round #410 (Div. 2)
Codeforces Round #410 (Div. 2) A B略..A没判本来就是回文WA了一次gg C.Mike and gcd problem 题意:一个序列每次可以把\(a_i, a_{i ...
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #410 (Div. 2)A B C D 暴力 暴力 思路 姿势/随机
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2) A
Description Mike has a string s consisting of only lowercase English letters. He wants to change exa ...
- Codeforces Round #410 (Div. 2) A. Mike and palindrome【判断能否只修改一个字符使其变成回文串】
A. Mike and palindrome time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- Codeforces Round #410 (Div. 2)D题
D. Mike and distribution time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces Round #410 (Div. 2)C题
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces Round #410 (Div. 2) B
B. Mike and strings time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 项目Beta冲刺(团队7/7)
项目Beta冲刺(团队7/7) 团队名称: 云打印 作业要求: 项目Beta冲刺(团队) 作业目标: 完成项目Beta版本 团队队员 队员学号 队员姓名 个人博客地址 备注 221600412 陈宇 ...
- 《从零開始学Swift》学习笔记(Day 61)——Core Foundation框架之内存管理
原创文章,欢迎转载. 转载请注明:关东升的博客 在Swift原生数据类型.Foundation框架数据类型和Core Foundation框架数据类型之间转换过程中,尽管是大部分是能够零开销桥接,零开 ...
- 自己定义msi安装包的运行过程
有时候我们须要在程序中运行还有一个程序的安装.这就须要我们去自己定义msi安装包的运行过程. 比方我要做一个安装管理程序,能够依据用户的选择安装不同的子产品.当用户选择了三个产品时,假设分别显示这三个 ...
- VC FTP服务器程序分析(四)
下面是数据传输的重点-CDataSocket类,函数不多,都比较重要. 1.OnAccept 数据tcp服务器被连接的虚函数,由框架调用. void CDataSocket::OnAccept(in ...
- C.Candy
There are NN children standing in a line. Each child is assigned a rating value. You are giving cand ...
- Delphi服务端和PHP客户端通过Socket通信
在开始之前看下效果 PHP页面作为客户端发送请求给作为服务端的Delphi应用程序 PHP客户端页面打开如下 Delphi服务端应用程序打开如下 每次PHP页面刷新一下,Delphi的文本框都显示&q ...
- 没有该栏目数据可能缓存文件(data/cache/inc_catalog_base.inc)没有更新请检查是否有写入权限
dedecms系统搬家后或在系统还原后,重新更新栏目或文件的时候,有时会出现这样的错误提示:没有该栏目数据可能缓存文件(data/cache/inc_catalog_base.inc)没有更新请检查是 ...
- html5--6-53 阶段练习4-画廊
html5--6-53 阶段练习4-画廊 学习要点 运用所学过的知识完成一个简单的小练习,理解对过渡动画的应用. @charset "utf-8"; /* CSS Document ...
- java 后台的学习步骤
一.JavaWeb部分 第一阶段:JavaWeb前端技术 web前端技术 HTML, CSS, JavaScript基础, jQuery基础, BootStrap. 第二阶段:服务器端技术 Mysql ...
- 「网络流24题」「LuoguP4016」 负载平衡问题
Description GGG 公司有 nnn 个沿铁路运输线环形排列的仓库,每个仓库存储的货物数量不等.如何用最少搬运量可以使 nnn 个仓库的库存数量相同.搬运货物时,只能在相邻的仓库之间搬运. ...