比赛的时候不知道怎么写... 太弱了. 看了别人的代码,觉得这个是个经典的知识点吧. gcd的巧妙运用 自己想的时候苦苦思考怎么用dp求解. 无奈字符串太长而想不出好的算法. 其实在把a和b字符串都分成以gcd(a,b)长度为单位的字符串时. 设为la=a/gcd(a,b) ,lb=b/gcd(a,b) . 明显可以知道的是gcd(la,lb)==1, 所以la与lb长度的字符串要分别拼接lb和la次才能拼成两个相等的串. 这样就有了解法. for(int i=0;i<lena;i++) dpa…
题目链接: B. Xenia and Hamming 题意: 要求找到复制后的两个字符串中不同样的字符 思路: 子问题: 在两串长度是最大公倍数的情况下, 求出一个串在还有一个串中反复字符的个数 CODE: #include <iostream> #include<stdio.h> #include<string> #include<string.h> using namespace std; #define M 1000006 int com[M][26]…
C. GCD Table Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/583/problem/C Description The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest c…
题目链接:http://codeforces.com/contest/583/problem/C C. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n …
题目链接:https://codeforces.com/contest/1370/problem/B 题意 给出 $2n$ 个数,选出 $2n - 2$ 个数,使得它们的 $gcd > 1$ . 题解 大于 $1$ 最好构造的 $gcd$ 就是 $2$ 了,根据奇偶将 $2n$ 个数分类,然后两个奇数一对,两个偶数一对即可. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >>…
B. GCD Arrays 题源:https://codeforces.com/contest/1629/problem/B 题目大意 给出一段区间[l, r],可以进行操作(把任意两个数拿出来,把他俩乘积放回去),如果经过 k 次该操作后,能找到两个数a, b, 使得 gcd(a, b) > 1,就输出"YES",否则输出"NO" 思路 如果要使得整个数组的GCD大于 1,每个元素都必须具有一个共同的质因数,因而很容易得出 2 是最常见的质因数. 又因为偶数…
C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the greatest common divisor (GCD) of two positive integers x and y is the greatest integer that is divisor of both…
A. GCD Table time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output The GCD table G of size n × n for an array of positive integers a of length n is defined by formula Let us remind you that the…
数学so奇妙.. 这题肯定会有一个循环节 就是最小公倍数 对于公倍数内的相同的数的判断 就要借助最大公约数了 想想可以想明白 #include <iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<stdlib.h> #include<vector> using namespace std; #define N 1000100 #defin…
A:超级大水题: 代码: #include<cstdio> #define maxn 105 using namespace std; int n,a[maxn],x,y,ans; int main() { scanf("%d",&n); ; i<=n; i++) { scanf("%d",&x); a[i]=a[i-]+x; ans+=x; } scanf("%d%d",&x,&y); int…