CF798 C. Mike and gcd problem
/*
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的更多相关文章
- 【算法系列学习】codeforces C. Mike and gcd problem
C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #includ ...
- 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#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); ...
- 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 ...
- #410div2C. Mike and gcd problem
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 798C - Mike and gcd problem(贪心+数论)
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1, ...
- 【codeforces 798C】Mike and gcd problem
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...
- codeforces 798 C. Mike and gcd problem(贪心+思维+数论)
题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...
- codeforces798C - Mike and gcd problem (数论+思维)
原题链接:http://codeforces.com/contest/798/problem/C 题意:有一个数列A,gcd(a1,a2,a3...,an)>1 时称这个数列是“漂亮”的.存在这 ...
随机推荐
- 分享小知识:善用Group By排序
以下列举了公用表/临时表/聚合函数三个因素为例子(覆盖索引因素除外,有利用此类索引都会以索引顺序) 环境: Microsoft SQL Server 2014 (SP1-GDR) (KB319472 ...
- mui和zepto的tap事件
zepto.js和mui一起使用的时候,tap事件会发生两次,这时只要不引用zepto.js的touch.js就可以了,只用mui的tap事件转自[B5教程网]:http://www.bcty365. ...
- 我的日志文件java logger
操作读取日志文件, 1.使用默认的日志文件,并验证默认级别 public void originalConfig() { Logger logger = Logger.getLogger(Logger ...
- iOS开发之UITableView及cell重用
1.UITanleview有的两种风格 一种是Plain,一种是Grouped,可以从这里设置风格: 他们样式分别如下: Plain: Grouped: 2.tableView展示数据的过程: (1) ...
- css——样式表分类,选择器
一,样式表分类 (1)内联样式[优先级最高][常用][代码重复使用性最差] (当特殊的样式需要应用到个别元素时,就可以使用内联样式. 使用内联样式的方法是在相关的标签中使用样式属性.样式属性可以包含任 ...
- jquery-scrollstop
$(window) .on("scrollstart", function() { // Paint the world yellow when scrolling starts. ...
- 【已解决】Windows下 MySQL大小写敏感 解决方案及分析
Windows下 MySQL大小写敏感配置 zoerywzhou@163.com http://www.cnblogs.com/swje/ 作者:Zhouwan 2017-3-27 最近在window ...
- laravel 框架memcache的配置
Laravel5框架在Cache和Session中不支持Memcache,看清了是Memcache而不是Memcached哦,MemCached是支持的但是这个扩展真的是装的蛋疼,只有修改部分源码让其 ...
- Akari谜题(关灯问题)的开灯解法
提高解时预处理的速度 本方法的结果是得到满足所有黑色有数字方块的一个带有未照亮的块的可能解集. 解集大小为 4~(3号块数量+1号块数量)+6~(2号块数量)-灯互相照射到的解的集合.集合中的灯为黄色 ...
- js面向对象二级菜单
<!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title> ...