CodeForces专题提供CodeForces的最新资讯内容,帮你更好的了解CodeForces。
可以发现 f0(n)=2n的质因子个数 ,这是一个积性函数。而 fr=fr−1×1 ,因此也是积性函数。我们只需要对每个质因子单独考虑。 不难发现答案跟质因子到底是什么没有关系,只跟它的次数有关。因此我们可以dp,用 dp[i][j] 表示 fi(pj) ,那么 dp[i][j]=∑jk=0dp[i−1][k] 用前缀和优化一下可以做到 O(rlogn) 。 #include<cstdio> #i
D. Bash and a Tough Math Puzzle time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Bash likes playing with arrays. He has an array a1, a2, 
题目连接:http://codeforces.com/contest/766/problem/D —————————————————————————————-. D. Mahmoud and a Dictionary time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputs
题目链接:http://codeforces.com/problemset/problem/794/F —————————————————————————————————————— F. Leha and security system time limit per test2 seconds memory limit per test512 megabytes inputstandard inp
A. Mister B and Book Reading time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Mister B once received a gift: it was a book about aliens, which
题目链接: http://codeforces.com/contest/820/problem/B 题目大意: 用 ∠a1a2a3 表示一个角 a1 a2 a3 分别表示正多边形上的顶点。 输入正多边形的顶点数 a 和要得到的度数 n 输出用a1a2a3表示正多边形里最接近 n 的度数。输出任意一组答案即可。 input 3 15 output 1 2 3 input 4 67 output 2
由于没有人组队,基本自己思考,再加上之前调试网络,导致写题的时间只有一个小时多一点点了,比较疲倦所以就只写了三道题 A. I’m bored with life time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Holidays have
题目链接: http://codeforces.com/contest/820/problem/D 大意: 给一个数组 p[i] 求 值。 每次操作旋转一次数组(即最后一个数字变为第一个) 如 1 2 3 -> 3 1 2 求 的最小值 输出最小值和变换次数。 input 3 1 2 3 output 0 0 input 3 2 3 1 output 0 1 input 3 3 2 1 outpu
Description You are given a table consisting of n rows and m columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values
Description Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney’s not su
题目无聊到求多次快速幂… #pragma comment(linker, "/STACK:102400000,102400000") #include<cstdio> #include<algorithm> #include<cmath> #include<cstring> #include<vector> #include<map> #include<string> #include<iostr
题意:从上到下有n个杯子,编号从1到n。每个杯子有一定体积v[i]. 两种操作:1 x y, 向x水杯倒y水; 2 x, 询问x水杯有多少水. (水杯水溢出会往下流) n,q <= 2e5 思路:暴力倒水的话是n*q,很多次要经过满的水杯,很费时,可以用并查集维护每个水杯往下的第一个非满的水杯。 代码: #include<iostream> #include<cstdio> #include<cs
题意:给你n个数,让你选出k个,让这k个两两差的和最小。输出k个数的下标。(n<=3e5) 思路: 我们可以知道要选的k个肯定是排序后连续的k个。 所以我们可以O(n)以长度为k的尺子从头推到尾,但关键是每次向右挪一位,这个区间的两两差值和的变化怎么求。 首先得计算区间[1-k]的差值和,怎么计算?可以利用前缀和(sum数组), [1 - i]  推到 [1 - i+1] ,那么多加的差值就是a[
题意:给你两个数a b,每次操作可以将某个数整除2 或 整除3 或 整除5,问最少操作多少次可以使两个数相等,不能的话输出-1. 思路: 两个数可以看作 a = x * pow(2, m1) * pow(3, m2) * pow(5, m3) b = y * pow(2, n1) * pow(3, n2) * pow(5, n3) 要使两个数相等,x和y必须相同,x和y相同的条件下怎样操作次数最小
这是我第一次在半夜爬起来打的比赛。虽然最后的结果不那么近人意,但还是积累了不少经验的。 23:30 WenDavid打了3次QQ电话,终于把我这个正在熟睡的懒虫给叫醒了(话说比赛在24:45才开始,他辣么早叫我干啥。。。)。不过就算我那时不醒,我也在24点调了4个闹钟了。。。无论如何,在朦胧之中,我终于打开了电脑。 0:00 无聊死了。在班群上发了'Hi‘,居然还有人没有睡觉,和我说了一会话。 0
题目: A. Restaurant Tables time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In a small restaurant there are a tables for one person and b tabl
题目: B. Black Square time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Polycarp has a checkered sheet of paper of size n × m. Polycarp painted
题意:给你一些字符串,并告诉你他出现在哪些位置(可多次,可重叠),让你输出字典序最小的可能的字符串。保证有解,总长 度不超过1e6. 思路:跟前几天做的一个题很像点击打开链接,因为区间长度就1e6,经常会重复去填充,浪费时间,可以用一个数组维护当前位置 的下一个未填充的字符位置,这样就可以跳过很多重复操作降到O(n)复杂度了。 代码: #include<bits/stdc++.h> using n
题意: 给你一个只包含'A', 'T', 'G', 'C'的字符串,q次操作,有两种操作: 1 x ch : 将x位置改成ch 2 l r e:e为一个长度不超过10的字符串,问eeeee....与字符串的子串[l, r]有多少个匹配的字符(先将e的开头和l对齐) 思路: 一共就4种字符,可以分别考虑每个字符,e长度最大才10,可以分别考虑不同长度的e。 假设e长为len, 那么i , i+len
题目: A. Unimodal Array time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Array of integers is unimodal, if: it is strictly increasing in the b