CodeForces 747D Winter Is Coming】的更多相关文章

题目链接: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…
赛后听 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 >=…
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…
http://codeforces.com/problemset/problem/747/D 题意:有n天,k次使用冬天轮胎的机会,无限次使用夏天轮胎的机会,如果t<=0必须使用冬轮,其他随意.问最少的换胎次数. 思路:先数冬天的天数tol,如果天数>k的话,那么就不可能度过.否则,最坏情况下,每到冬天就换一次冬天轮胎,然后度过冬天就换夏天轮胎,所以答案是2*tol.然后考虑尽量让每段冬天连续,这样可以减少换胎次数,于是算出冬天之间的间隔,然后从小到大排序,每次减少一段间隔,ans就可-2.然…
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…
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…
[题目链接] 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\)这个因数,则被选择的数可形成…
CF-补题1 1.CodeForces 735C    题意:n个人淘汰赛,两个人可以比赛的条件是:两人打过的场数之差绝对值<2.求冠军最多可以打多少场.  总结:看了题解,转换一下思路.求n个人最多打几场 -> 打x场最少要几个人. 要最少,则f[x]=f[x-1]+f[x-2](即和打了x-1场和x-2场的胜者打).然后对n二分就行. 注:很巧妙,变成fibonacci了. 2.CodeForces 742D   题意:请客可容总量w,每个人量wi.魅力值bi.特殊在有朋友圈,同一朋友圈中…