题目链接 比较棒的一道题, 题意: 给你一个N个数的数组,让你用尽量少的操作使整个数组的gcd大于1,即gcd(a1 ,a2,,,,an) > 1 如果可以输出YES和最小的次数,否则输出NO 首先我们来看一下这个操作, 如果对   a b 老两个数进行操作 第一次为 a-b a+b 第二次为 -2b  2a 由此可见,任何两个数最多进行两次操作,可以让他们都能被2整除. 所以也就没有NO的情况. 那么我们只需要预处理一下gcd,如果>1了,直接输出0次. gcd=1的话,那么就需要我们去处理…
题目 (智商题 or 糟心的贪心) 题意: 有一个数列a1,a2,...,an,每次操作可以将相邻的两个数x,y变为x-y,x+y,求最少的操作数使得gcd(a1,a2,...,an)>1.gcd(a1,...,an)表示最大的非负整数使得所有ai都能被gcd(a1,...,an)整除. 分析: 首先,如果原来gcd就不是1那么答案就是0.如果gcd是1:相邻两数x和y的变化方法为:x,y=>x-y,x+y设新的gcd值为d,那么x-y和x+y能被d整除,因此2x和2y能被d整除,因此d最大是…
C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: standard input output: standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful…
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers…
C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #include<cstdio> #include<string> #include<cstring> #include<algorithm> #include<cmath> using namespace std; ; int a[maxn]; int gcd(…
题目:Mike and gcd problem 题意:给一个序列a1到an ,如果gcd(a1,a2,...an)≠1,给一种操作,可以使ai和ai+1分别变为(ai+ai+1)和(ai-ai+1);问需要执行几次这个操作才能使得gcd(a1,a2,...an)>1. 分析: 1.首先,答案总是YES. 2,假设gcd(a1,a2,...an)=1,在一次对ai和ai+1的操作后新的gcd为d,则d满足:d|ai - ai + 1 and d|ai + ai + 1  d|2ai and d|2…
/* 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都是奇数,只需变换一次 所以每次先…
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Mike has a sequence A = [a1, a2, ..., an] of length n. He considers the sequence B = [b1, b2, ..., bn] beautiful if…
题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 并且把 ai - a(i + 1), ai + a(i + 1) 放入原来的位置.问是否能够在几步操作后使得串的gcd大于1然后要求最小的操作数. 题解:偶数=偶数*偶数 or 奇数*偶数,奇数=奇数*奇数. 如果整个字符串全是偶数的话肯定gcd是大于1的.介于题目要求的操作,奇数-(or)+奇数=…
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1,可以执行一次操作使ai,ai+1变为ai - ai + 1, ai + ai + 1.求出使得gcd(a1,a2,....an)>1所需要的最小操作数. 解题思路:首先,要知道如果能够实现gcd(a1,a2,....an)>1,那么a1~an肯定都是偶数(0也是偶数),所以我们的目的就是用最少的操…