1. /*
  2. CF798 C. Mike and gcd problem
  3. http://codeforces.com/contest/798/problem/C
  4. 数论 贪心
  5. 题意:如果一个数列的gcd值大于1,则称之为美丽数列
  6. 给出数列a,可以将a_i 和 a_(i+1)换为其差和其和
  7. 如果可以变为美丽数列,输出YES并输出最少的变换次数
  8. 否则输出NO
  9. 思路:
  10. 如果变换a b
  11. a b -> a-b a+b -> -2b 2a
  12. 因此变换两个可以把a b乘以2
  13. 而若a b都是奇数,只需变换一次
  14. 所以每次先找出相邻是奇数的情况ans++
  15. 然后找相邻是奇偶的情况ans+=2
  16. 然而
  17. 比赛的时候居然把ans=gcd(ans,num[i]) 写成了ans=gcd(ans,i)
  18. 这居然还过了40组数据,也是醉了,雪崩!
  19. */
  20.  
  21. #include <cstdio>
  22. #include <algorithm>
  23. #include <cstring>
  24. #include <cmath>
  25. #include <vector>
  26. #include <queue>
  27. #include <iostream>
  28. #include <map>
  29. #include <set>
  30. //#define test
  31. using namespace std;
  32. const int Nmax=1e6+;
  33. int n;
  34. long long num[Nmax];
  35. long long gcd(long long a,long long b)
  36. {
  37. if(b==)
  38. return abs(a);
  39. return gcd(b,a%b);
  40. }
  41. int main()
  42. {
  43. #ifdef test
  44. #endif
  45. scanf("%d",&n);
  46. for(int i=;i<=n;i++)
  47. scanf("%I64d",&num[i]);
  48. long long ans=0LL;//初始化一定要看仔细
  49. for(int i=;i<=n;i++)
  50. {
  51. ans=gcd(ans,num[i]);//num[i]一定不要写成i!!!!!
  52. }
  53. if(ans>)
  54. {
  55. printf("YES\n0\n");
  56. return ;
  57. }
  58. ans=0LL;
  59. for(int i=;i<n;i++)
  60. {
  61. if((num[i]&) && (num[i+]&))
  62. {
  63. ans++;
  64. num[i]=;
  65. num[i+]=;
  66. }
  67. }
  68. for(int i=;i<=n;i++)
  69. {
  70. if(num[i]&)
  71. {
  72. ans+=;
  73. }
  74. }
  75. printf("YES\n%I64d\n",ans);
  76. return ;
  77. }

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. Calender设置固定时间遇到的问题

    在使用Calender获取实例,设置成UTC时区时,发现比我们常规的月份多了一个月: 示例代码如下: Calendar calendar = Calendar.getInstance(TimeZone ...

  2. Bootsrap 的 Carousel

    一.简介 Carousel 就是指轮播图,这里 有完整的代码例子.它可以很简单的就构造出来,结构如下: div.carousel.slide[data-ride="carousel" ...

  3. iOS开发之视频播放

    1.如何播放视频 iOS提供了MPMoviePlayerController.MPMoviePlayerViewController两个类,可以用来轻松播放视频和网络流媒体\网络音频. 提示:网络音频 ...

  4. pxe+kickstart cobbler无人值守装机

    环境准备: 一台服务器 [root@admin tftpboot]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core) [roo ...

  5. 机器学习 - pycharm, pyspark, spark集成篇

    AS WE ALL KNOW,学机器学习的一般都是从python+sklearn开始学,适用于数据量不大的场景(这里就别计较“不大”具体指标是啥了,哈哈) 数据量大了,就需要用到其他技术了,如:spa ...

  6. 通过取父级for循环的i来理解闭包,iife,匿名函数

    在使用for循环的时候,假如需要在循环体中添加一个匿名函数处理其他的事情,那么,在这个匿名函数内,如果需要用到对应的i,因为闭包的缘故,循环体循环结束后才返回i,所以i最终为最后一次++的数值.   ...

  7. 解锁ORACLE数据库

    1.查找锁定数据库的用户 select username,lock_date from dba_users where username='scott';   2.解锁 alter user scot ...

  8. Windows入门基础:2.vs2013中Icon显示

    第一:系统小图标的显示 wndclass.hIcon = LoadIcon(NULL,IDI_WARNING); //LoadIcon函数的第一的参数要为0,第二个参数是系统自定义的ID号: IDI_ ...

  9. HBase应用快速学习

    HBase是一个高性能.面向列.可伸缩的开源分布式NoSQL数据库,是Google Bigtable的开源实现. HBase的思想和应用和传统的RDBMS,NoSQL等有比较大的区别,这篇文章从HBa ...

  10. jdk1.8新特性,还不知道的朋友还不看看,1.9都快出来了

    一.接口的默认方法 Java 8允许我们给接口添加一个非抽象的方法实现,只需要使用 default关键字即可,这个特征又叫做扩展方法,示例如下:代码如下:interface Formula {     ...