题意 一个长度为 \(n\) 的序列 \(A\) ,定义一个 \(1\) 到 \(n\) 的排列 \(p\) 是合法的,当且仅当 \(\forall i \in [1, n − 1], A_{p_i} × A_{p_i+1}\) 不是完全平方数. 求有多少合法的排列,对 \(10^9 + 7\) 取模. \(n \le 300, A_i \le 10^9\) 题解 对于每个元素去掉它的平方质因子,问题转化为有多少排列 \(p\) 满足 \(\forall i \in [1, n − 1], A_…
题目大意是给你n个数,求相邻两数相乘不是完全平方数的排列数. 一开始看到这题的时候,本人便想给相乘为完全平方数的数对建边,然后就写萎了... 后来通过集体智慧发现这个重要性质:对于自然数a,b,c,若a*b为完全平方数,且b*c为完全平方数,那么a*c就是完全平方数.(我居然没想到)因此就可以对这n个数进行分组,使得每一组中两个数两两相乘为完全平方数,不同组的数两两相乘不是完全平方数.假设分成tot组,第i组的数的个数为num[i].这也就等同于相同的数不能相邻的排列问题. 于是通过PY就得到了…
E. On the Bench time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output A year ago on the bench in public park Leha found an array of n numbers. Leha believes that permutation p is right if for al…
思路来自FXXL中的某个链接 /* CodeForces 840C - On the Bench [ DP ] | Codeforces Round #429 (Div. 1) 题意: 给出一个数组,问有多少种下标排列,使得任意两个相邻元素的乘积不是完全平方数 分析: 将数组分组,使得每组中的任意两个数之积为完全平方数 由唯一分解定理可知,每个质因子的幂次的奇偶性相同的两个数之积为完全平方数 即按每个质因子的幂次的奇偶性分组,故这样的分组唯一 然后问题归结于每组中的数不能相邻的排列有几种 设 d…
思路来自这里,重点大概是想到建树和无解情况,然后就变成树形DP了- - /* CodeForces 840B - Leha and another game about graph [ 增量构造,树上差分 ] | Codeforces Round #429(Div 1) 题意: 选择一个边集合,满足某些点度数的奇偶性 分析: 将d = 1的点连成一颗树,不在树上的点都不连边. 可以发现,当某个节点u的所有子节点si均可操控 (u, si) 来满足自身要求 即整棵树上至多只有1个点不满足自身要求,…
/* CodeForces 840A - Leha and Function [ 贪心 ] | Codeforces Round #429 (Div. 1) A越大,B越小,越好 */ #include <bits/stdc++.h> using namespace std; const int N = 2e5+5; int a[N], b[N], c[N], n; int aa[N], bb[N]; bool cmp1(int x, int y) { return a[x] > a[y…
Hard problem 题目链接: http://codeforces.com/contest/706/problem/C Description Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help. Vasiliy is given n strings consisting of lowercase Engl…
[Link]:http://codeforces.com/contest/841/problem/A [Description] [Solution] 模拟,贪心,每个朋友尽量地多给气球. [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #define LL long l…
PROBLEM A/_ - Generous Kefa 题 OvO http://codeforces.com/contest/841/problem/A cf 841a 解 只要不存在某个字母,它的个数大于k,即可 #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include <cmath> using namespace std;…
[Link]:http://codeforces.com/contest/841/problem/C [Description] [Solution] 看到最大的和最小的对应,第二大的和第二小的对应. 贪心,排个序. [NumberOf WA] [Reviw] [Code] #include <bits/stdc++.h> using namespace std; #define lson l,m,rt<<1 #define rson m+1,r,rt<<1|1 #de…