给你一个序列,让你对于所有gcd不为1的子序列,计算它们的gcd*其元素个数之和. 设sum(i)为i的倍数的数的个数,可以通过容斥算出来. 具体看这个吧:http://blog.csdn.net/jaihk662/article/details/77161436. 注意1*C(n,1)+2*C(n,2)+...+n*C(n,n)=n*2^(n-1). #include<cstdio> using namespace std; typedef long long ll; #define MOD…
D. Winter is here 题目连接: http://codeforces.com/contest/839/problem/D Description Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the rest of the world is fighting for the Iron Throne,…
赛后听 Forever97 讲的思路,强的一匹- - /* CodeForces 839D - Winter is here [ 数论,容斥 ] | Codeforces Round #428 (Div. 2) 题意: 给出数列a[N] 对每个子集,若 gcd(a[I1], a[I2], a[I3] ..., a[In]) > 1,则贡献为 n*gcd 求总贡献和 限制: N <= 2e5,a[i] <= 1e6 分析: 记录 num[i]数组为 i 的倍数的个数 则 gcd >=…
起初误以为到每个叶子的概率一样于是.... /* CodeForces 839C - Journey [ DFS,期望 ] | Codeforces Round #428 (Div. 2) */ #include <bits/stdc++.h> using namespace std; const int N = 100005; int n; vector<int> G[N]; double dp[N], val[N]; bool vis[N]; void dfs(int u, i…
血崩- - /* CodeForces 839B - Game of the Rows [ 贪心,分类讨论] | Codeforces Round #428 (Div. 2) 注意 2 7 2 2 2 2 2 2 2 这组- - */ #include <bits/stdc++.h> using namespace std; int n, n2, n4, a[105], k; bool solve() { n2 = 2*k; n4 = k; for (int i = 1; i <= n;…
题目链接:http://codeforces.com/contest/839 A. Arya and Bran 题意:每天给你一点糖果,如果大于8个,就只能给8个,剩下的可以存起来,小于8个就可以全部给完 解法:水题,按照题意模拟一下即可. #include <bits/stdc++.h> using namespace std; int n, k, a[110]; int main() { cin>>n>>k; int s = 0; for(int i=1; i<…
http://codeforces.com/contest/839/problem/E 最大团裸题= =,用Bron–Kerbosch算法,复杂度大多博客上没有,维基上查了查大约是O(3n/3) 最大团: V中取K个顶点,两点间相互连接 最大独立集: V中取K个顶点,两点间不连接 最大团数量 = 补图中最大独立集数 //#pragma comment(linker, "/stack:200000000") //#pragma GCC optimize("Ofast,no-st…
[Link]:http://codeforces.com/contest/839/problem/B [Description] 给你n排的如题目所示的位置; 同一排中(1,2) 算相邻; (3,4),(4,5),(5,6)算相邻,然后(7,8)算相邻; 这里的(x,y)表示某个人坐在x,另外一个人坐在y的话. 问你够不够安排k组的人; 使得相邻座位的人都是相同组的人; 是则输出YES-. [Solution] 中间的那4个位置; 是没办法用来放不同组的成对的. 也即 xxyy不能放在中间那4个…
[Link]:http://codeforces.com/contest/839/problem/C [Description] 给一棵树,每当你到一个点x的时候,你进入x的另外一每一个出度的概率都是相同的(但不能到你之前到过的点); 问你从1出发走过的路径的期望长度; [Solution] 从1出发,看看到达某个点的概率是多少; 到了叶子节点的时候,概率乘距离累加到答案上. [NumberOf WA] 0 [Reviw] [Code] #include <bits/stdc++.h> usi…
A. Arya and Bran time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bran and his older sister Arya are from the same house. Bran like candies so much, so Arya is going to give him some Candies…