Codeforces-798C-Mike and gcd problem(贪心+数论)
来源:互联网 发布:数据大魔王 编辑:程序博客网 时间:2024/06/05 20:40
题目链接:Codeforces-798C-Mike and gcd problem
因为
所以要将
将奇奇变成偶偶需要一次操作,将奇偶或偶奇变成偶偶需要两次操作。所以先处理奇奇,然后再处理其他情况。
#include<bits/stdc++.h>using namespace std;typedef long long ll;int gcd(int a,int b){ return a%b?gcd(b,a%b):b;}int a[100007];int main(){ int n; scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); int k=gcd(a[1],a[2]); for(int i=3;i<=n;i++) k=gcd(k,a[i]); puts("YES"); if(k>1) { puts("0"); return 0; } int ans=0; for(int i=1;i<=n;i++) if(a[i]&1) a[i]=1; else a[i]=2; for(int i=2;i<=n;i++) if(a[i]%2&&a[i-1]%2) { ++ans; a[i]=a[i-1]=2; } for(int i=2;i<=n;i++) if((a[i]%2)^(a[i-1]%2)) { ans+=2; a[i]=a[i-1]=2; } printf("%d\n",ans); return 0;}
0 0
- Codeforces-798C-Mike and gcd problem(贪心+数论)
- Codeforces 798C:Mike and gcd problem【数论+贪心】
- Codeforces 798C Mike and gcd problem gcd+贪心
- Codeforces 798C Mike and gcd problem (贪心)
- Codeforces 798C Mike and gcd problem
- codeforces 798C Mike and gcd problem
- CodeForces 798C Mike and gcd problem
- Codeforces 798C Mike and GCD problem
- Codeforces 798C Mike and gcd problem【思维+贪心】好题!
- Mike and gcd problem CodeForces
- Codeforces Round #410 (Div. 2) C. Mike and gcd problem 贪心
- cf 798c Mike and gcd problem
- 798 C. Mike and gcd problem
- C. Mike and gcd problem-递推或者贪心
- codeforce 798C Mike and gcd problem (简单数学)
- CF#798 C. Mike and gcd problem(思维)
- C. Mike and gcd problem
- C. Mike and gcd problem
- 基于mysql数据库的Hibernate3的环境搭建
- linux 3.18 -- iic,input,misc,三轴加速度设备驱动(三)
- Python之创建tuple
- HTTPweb服务器——HTTP基本知识
- 【转】使用SYSTEMINFO类获取UNITY3D运行设备的各类信息(CPU类型,显卡类型等)
- Codeforces-798C-Mike and gcd problem(贪心+数论)
- Java中的异常
- org.apache.tomcat.util.bcel.classfile.ClassFormatException: Invalid byte tag in constant pool问题解决方案
- 通过监听手势滑动解决DrawerLayout只能边缘打开抽屉问题
- 快速排序的递归实现
- 单链表反转
- Material Design 兼容性控件学习
- 【bzoj3328】PYXFIB 题解
- HDU