Codeforces 839D Winter is here】的更多相关文章

赛后听 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 >=…
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, he is going to get ready for the attack of the White Walkers. He has created a m…
D. Winter is here time limit per test:3 seconds memory limit per test:256 megabytes input:standard input output:standard output Winter is here at the North and the White Walkers are close. John Snow has an army consisting of n soldiers. While the res…
[题目链接] http://codeforces.com/contest/839/problem/D [题目大意] 给出一些数,求取出一些数,当他们的GCD大于0时,将数量乘GCD累加到答案上, 求累加和. [题解] 我们枚举GCD,统计为其倍数的数字数量,先假定其能组成的集合数为贡献, 但是我们发现在统计的过程中有多余统计的部分,比如4和8是2的倍数, 然而它们的GCD等于4,所以我们对于每个集合数的贡献要减去所有其倍数的集合数的贡献, 倒着容斥即可. [代码] #include <cstdi…
链接:CF839D 题目大意 给定一个数组大小为\(n(1\leq n\leq 200000)\)的数组\(a\),满足\(1\leq a_i \leq 1000000\). 选择其中任意\(len\)个数字,若\(gcd>1\),则该组数字对答案贡献为\(len*gcd\),求最终答案对\(1e9+7\)取模. 题目分析 因为\(gcd\)的本质是因数分解,可以想到,如果不考虑算重,那么: 对于一个\(gcd\)的结果\(x\),若有\(num\)个数含有\(x\)这个因数,则被选择的数可形成…
题目链接:http://codeforces.com/problemset/problem/747/D 题意:冬天有n天,冬天用的轮胎总共能用k天,一开始车子用的是夏天的轮胎. 给出n天的平均气温,温度小于0的时候必须换上冬天用的轮胎,冬天用的轮胎 任何温度下都可以使用,问最少交换机次轮胎. 首先要找到第一个温度小于0的日子,那天肯定要换上冬天用的轮胎,然后再找 最后一个温度小于0的日子,因为在那之后就用不到冬天用的轮胎了.设最早小 于0的日子为sta,最后为end. 大情况稍微分一下 设温度小…
贪心. 只考虑负数的位置,先填间隔较小的,再填间隔较大的.如果填不满就不填,如果有多余就留给最后一个负数到终点这段路. #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<queue> #include<algorithm> #include<set> using namesp…
题意:如果一个子序列的GCD为1,那么这个子序列的价值为0,否则子序列价值为子序列长度*子序列GCD 给出n个数,求这n个数所有子序列的价值和 题解:首先得想到去处理量比较少的数据的贡献,这里处理每个gcd的贡献.我们定义f(i)为gcd==i的倍数时的贡献,那么f(i)=c(0,n)*0+c(1,n)*1+...c(n,n)*n ,这里的n为能够整除i的数的个数.然后利用容斥把gcd==i的贡献筛出来(这里无非就是要把其倍数处理掉~). 然后结合c(1,n)+c(2,n)+....c(n,n)…
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,…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output The winter in Berland lasts n days. For each day we know the forecast for the average air temperature that day. Vasya has a new set of winter tir…