/*
CF798 C. Mike and gcd problem
http://codeforces.com/contest/798/problem/C
数论 贪心
题意:如果一个数列的gcd值大于1,则称之为美丽数列
给出数列a,可以将a_i 和 a_(i+1)换为其差和其和
如果可以变为美丽数列,输出YES并输出最少的变换次数
否则输出NO
思路:
如果变换a b
a b -> a-b a+b -> -2b 2a
因此变换两个可以把a b乘以2
而若a b都是奇数,只需变换一次
所以每次先找出相邻是奇数的情况ans++
然后找相邻是奇偶的情况ans+=2
然而
比赛的时候居然把ans=gcd(ans,num[i]) 写成了ans=gcd(ans,i)
这居然还过了40组数据,也是醉了,雪崩!
*/ #include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <map>
#include <set>
//#define test
using namespace std;
const int Nmax=1e6+;
int n;
long long num[Nmax];
long long gcd(long long a,long long b)
{
if(b==)
return abs(a);
return gcd(b,a%b);
}
int main()
{
#ifdef test
#endif
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%I64d",&num[i]);
long long ans=0LL;//初始化一定要看仔细
for(int i=;i<=n;i++)
{
ans=gcd(ans,num[i]);//num[i]一定不要写成i!!!!!
}
if(ans>)
{
printf("YES\n0\n");
return ;
}
ans=0LL;
for(int i=;i<n;i++)
{
if((num[i]&) && (num[i+]&))
{
ans++;
num[i]=;
num[i+]=;
}
}
for(int i=;i<=n;i++)
{
if(num[i]&)
{
ans+=;
}
}
printf("YES\n%I64d\n",ans);
return ;
}

CF798 C. Mike and gcd problem的更多相关文章

  1. 【算法系列学习】codeforces C. Mike and gcd problem

    C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #includ ...

  2. 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 ...

  3. codeforces#410C Mike and gcd problem

    题目:Mike and gcd problem 题意:给一个序列a1到an ,如果gcd(a1,a2,...an)≠1,给一种操作,可以使ai和ai+1分别变为(ai+ai+1)和(ai-ai+1); ...

  4. Codeforces 798C. Mike and gcd problem 模拟构造 数组gcd大于1

    C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: s ...

  5. #410div2C. Mike and gcd problem

    C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. Codeforces 798C - Mike and gcd problem(贪心+数论)

    题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1, ...

  7. 【codeforces 798C】Mike and gcd problem

    [题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...

  8. codeforces 798 C. Mike and gcd problem(贪心+思维+数论)

    题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...

  9. codeforces798C - Mike and gcd problem (数论+思维)

    原题链接:http://codeforces.com/contest/798/problem/C 题意:有一个数列A,gcd(a1,a2,a3...,an)>1 时称这个数列是“漂亮”的.存在这 ...

随机推荐

  1. Android四大组件详解

    注:本文主要来自网易的一个博主的文章,经过阅读,总结,故留下文章在此 Android四大基本组件介绍与生命周期 Android四大基本组件分别是Activity,Service服务,Content P ...

  2. 使用git克隆指定分支的代码

    今天想学习一下开源中国Android客户端的app源码,源码的Git地址:http://git.oschina.net/oschina/android-app,如下图所示: 由于Master主分支上没 ...

  3. 转载 感受K2.Net 2003工作流解决方案

    接触SourceCode公司的工作流产品K2.NET 2003有一段时间了,想把一些心得分享出来,和各位共同探讨一下,抛砖引玉,希望能对相关人士以启发. K2.Net 2003是基于微软.Net Fr ...

  4. bootstrap IE8 兼容性处理

    <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="utf-8& ...

  5. iOS开发之NSOperation & NSOperationQueue

    1.简介 (1) NSOperationQueue(操作队列)是由GCD提供的队列模型的Cocoa抽象,是一套Objective-C的API,为了使并发(多线程)编程变得更加简单,但效率比GCD略低. ...

  6. 使用 ipdb 调试 Python

    1.安装 pip install ipdb 2.使用 python -m ipdb xxx.py 程序内部: from ipdb import set_trace set_trace() 3.常用命令 ...

  7. iOS9,10没有问题,iOS8上面一登录就崩溃,原因Assets的问题

    在项目中开发中,打包成一个ipa的包,发现iOS9,10,运行非常流畅,iOS8上面一运行就崩溃,找了好久,才找到原因竟然是Assets的问题,一开始我把ipa包放在蒲公英上面托管扫码下载的,用iTu ...

  8. Linux环境下的IDE,极大提升编程效率

    "一个真正的程序员是不用IDE(译者注:集成开发环境)的,他们都是用带着某某插件的文本编辑器来写代码."我们总能在某些地方听到此类观点.然 而,尽管越来越多的人同意这样的观点,但是 ...

  9. C++ 虚函数相关,从头到尾捋一遍

    众所周知,C++虚函数是一大难点,也是面试过程中必考部分.此次,从虚函数的相关概念.虚函数表.纯虚函数.再到虚继承等等跟虚函数相关部分,做一个比较细致的整理和复习. 虚函数 OOP的核心思想是多态性( ...

  10. 老李分享:qtp自动化测试框架赏析-关键字自动化测试框架

    老李分享:qtp自动化测试框架赏析-关键字自动化测试框架   QTP从2005年继winrunner,robot逐渐退出历史舞台之后,占领主流自动化测试工具市场已经10年之久.当初为了提高在自动化测试 ...