/*
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. 四大组件之一---------activity的知识

    activity的生命活动 activity的四种启动模式 Android中以一个任务栈用来管理activity 一个栈的形式进行管理 在清单文件中,通过<activity>标签的andr ...

  2. javaList容器中容易忽略的知识点

    在集合类框架中,List是使用比较多的一种 List |---Arraylist 内部维护的是一个数组,查找快增删慢 |---LinkedList 底层是链表,增删快查询慢. |---Vctor线程安 ...

  3. iOS开发之NSTimer

    1.NSTimer叫做“定时器”,它的作用如下 Ø 在指定的时间执行指定的任务 Ø 每隔一段时间执行指定的任务 2.调用NSTimer下面的方法就会开启一个定时任务 + (NSTimer *)sche ...

  4. java设计模式之桥接模式

    桥接模式 桥接(Bridge)是用于把抽象化与实现化解耦,使得二者可以独立变化.这种类型的设计模式属于结构型模式,它通过提供抽象化和实现化之间的桥接结构,来实现二者的解耦.这种模式涉及到一个作为桥接的 ...

  5. Android注解使用之Dagger2实现项目依赖关系解耦

    前言: 最近牵头发起公司app的重构工作,如何通过重构让项目的耦合降低.开发效率提高,一直是我努力的方向,今天来学习一下一个注解框架Dagger2,然后看看如何使用它来降低项目的耦合. Dagger2 ...

  6. Android 学习笔记之 Actionbar作为回到上一级

    首先,给Actionbar添加返回图标: 代码: @Override protected void onCreate(Bundle savedInstanceState) { super.onCrea ...

  7. ado.net知识整理

    对ado.net总是半知半解,五大对象也总是混淆,近期自己做小项目练手,整理了一些知识点 ado.net的无要素(摘自其他博文) Connection 物件    Connection 对象主要是开启 ...

  8. kindeditor修改图片上传路径-使用webapi上传图片到图片服务器

    kindeditor是一个非常好用的富文本编辑器,它的简单使用我就不再介绍了. 在这里我着重介绍一些使用kindeditor修改图片上传路径并通过webapi上传图片到图片服务器的方案. 因为我使用的 ...

  9. 浅析Thread类run()和start()的区别

    1.先看看jdk文档 void run() If this thread was constructed using a separate Runnable run object, then that ...

  10. 利用 force recovery 解决服务器 crash 导致 MySQL 重启失败的问题

    小明同学在本机上安装了 MySQL 5.7.17 配合项目进行开发,并且已经有了一部分重要数据.某天小明在开发的时候,需要出去一趟就直接把电脑关掉了,没有让 MySQL 正常关闭,重启 MySQL 的 ...