codeforces
本栏收录div2中C、D、E难度不等的一些经典题解,希望大家多多关注,谢谢。
FZH_SYU
在这个时代,每个人怀揣着梦想,坚持地迈着步子走。这个时代,正因如此,才会愈发精彩。
展开
-
codeforces 987-C. Three displays(思维)
http://codeforces.com/problemset/problem/987/C解题思路:枚举中间的节点 j,然后往左边扫一遍i,再往右边扫一遍k即可#include<iostream>#include<algorithm>#include<cstring>#include<vector>#include<set...原创 2018-08-17 09:06:14 · 246 阅读 · 0 评论 -
codeforces 986-A. Fair(bfs)
http://codeforces.com/problemset/problem/986/A做法:对于每一种k,bfs每个镇上要取得的最短路径,最后对于每个镇根据k的值sort排序取s个输出即可。#include<iostream>#include<algorithm>#include<cstring>#include<vector&...原创 2018-08-17 09:08:39 · 324 阅读 · 0 评论 -
codeforces 732-D. Exams (二分)
http://codeforces.com/problemset/problem/732/D题目大意:一个人有m门科目需要考试,每一门科目需要a[i](1<=i<=m)的复习时间,并且有份n天的考试安排表,其中d[i](1<=i<=n)假如为0,就代表这一天没有任何科目的考试。试求这个人最少在第几天顺利通过所有考试?解题思路:想了好久的贪心,排序各种做法,总...原创 2018-08-11 20:18:11 · 360 阅读 · 0 评论 -
codeforces 1019-A. Elections (暴力模拟)
http://codeforces.com/problemset/problem/1019/A题目大意:某个国家有n位候选人以及每位候选人的投票数,现在要求编号为1的候选人票数最高(即比其他任何票数都要至少多1)。你可以花一些钱收买那些投票的人,改投编号为1的党派。问最少需要多少钱收买,才能让编号为1的党派候选人当选(即票数最高)解题思路:刚开始做的时候一脸懵逼,其实是因为不确定投...原创 2018-08-12 20:05:04 · 703 阅读 · 0 评论 -
codeforces 855-B. Marvolo Gaunt's Ring(背包问题)
http://codeforces.com/problemset/problem/855/B解题思路:可以把p,q,r看成三个物品,当做背包问题处理。#include<iostream>using namespace std;#define INF 0x3f3f3f3f3f3f3f3ftypedef long long ll;const int maxn=1e5+1...原创 2018-08-14 08:14:09 · 644 阅读 · 0 评论 -
codeforces 858-C. Did you mean...(暴力模拟)
http://codeforces.com/problemset/problem/858/C解题思路:根据题目大意设置两个变量进行模拟即可。#include<iostream>#include<cstdio>using namespace std;string s;char a[]={'a','e','i','o','u'};int Judge(char ...原创 2018-08-14 08:16:18 · 437 阅读 · 0 评论 -
codeforces 1005-D. Polycarp and Div 3(贪心)
http://codeforces.com/problemset/problem/1005/D题目大意: 给出一个很大很大的数,可以无限次分割,求最后所有分割而成的数中能被3整除的数量最多。解题思路: 贪心做法。 把每个数位上的数看成一个数,对3取余,如果能整除3,则数量直接加一。接着统计余数为2的连续出现的数目,如果接下来出现的数字为1,则贪心判断连...原创 2018-07-10 20:41:43 · 459 阅读 · 0 评论 -
codeforces 1005-C. Summarize to the Power of Two(打表+暴力)
http://codeforces.com/problemset/problem/1005/C题目大意: 如果一个数组中,存在着这个数不管加上数组中其他任何数,其和都不是2的次幂,那么这个数就需要删除,问这个数组中需要删除多少个这样的数。解题思路: 数据的范围是1e9,那么2的次幂打表到2e9即可,用set和map分别处理判断这个数与2的次幂之差是否能在数组中找到,...原创 2018-07-10 20:45:07 · 422 阅读 · 0 评论 -
codeforces 615-B. Longtail Hedgehog(dp)
http://codeforces.com/problemset/problem/615/B题目大意:给出一个n个点m条边的无向无环图(不一定全联通),求一条递增链长度与尾节点个数乘积的最大值。解题思路:设dp[i]表示以节点i结尾的最长的递增链长度,那么只要比较每个点的dp[i]值与对应点的节点个数乘积即可。#include&lt;iostream&gt;#include&...原创 2018-08-08 10:53:50 · 276 阅读 · 0 评论 -
codeforce 615-D. Multipliers(唯一分解定理+费马小定理+快速幂)
http://codeforces.com/problemset/problem/615/D题目大意:给出若干个素因子,这些素因子连乘会形成一个很大很大的数M,问这个M所有因子连乘的结果对1e9+7是多少?解题思路:枚举素因子出现的种类以及每种出现的素因子个数。接下来可以利用唯一分解定理求因子个数的,假设M = p1^a1 * p2^a2 * ... * pk^ak那...原创 2018-08-08 11:09:35 · 281 阅读 · 0 评论 -
codeforces 615-E. Hexagons(二分+模拟)
http://codeforces.com/problemset/problem/615/E题目大意: 略解题思路:首先二分判断n所在的层数,然后根据层次k算出六个点的坐标;接下来将n减去k-1层内所有步数,对k整除和取膜,模拟判断六种情况,算出坐标即可#include<iostream>#include<cmath>using namespace ...原创 2018-08-08 11:14:02 · 216 阅读 · 0 评论 -
codeforces 1016-C. Vasya And The Mushrooms(dp+前缀和)
http://codeforces.com/problemset/problem/1016/C题目大意:从一个2*n格子的左上角出发,要求每个点都有且必须只能访问一次,并且每次访问一个点都会得到此点上的数与基数的乘积,问最后最大的乘积和为多少?解题思路:其实自己模拟一下就很容易发现,只有两种走法:① 按照 ‘下左右上’ 四次一个循环,重复地走; ② 按照’一直往左再拐回一直往...原创 2018-08-08 13:42:28 · 380 阅读 · 0 评论 -
codeforce 996-B. World Cup(模拟)
http://codeforces.com/problemset/problem/996/B解题思路:定义一个查找指针p初始化为1,循环节为n,然后找出最小数字,判断指针p,在这个数变成0的时候,是否不超过这个数的位置,如果不超过,则答案即为这个数所在的位置,否则对下一轮模拟一遍才能得出答案。#include<iostream>#include<algorithm&...原创 2018-08-08 20:35:14 · 245 阅读 · 0 评论 -
codeforces 997-A. Convert to Ones(dp)
http://codeforces.com/contest/998/problem/C解题思路:查找连续‘0’出现的区间的个数(假设为cnt),枚举cnt,将初始化为正无穷的ans与前i个连续出现‘0’的区间采用反转,后cnt-i+1采用翻转方法所耗费的值进行比较,取较小值。#include&amp;amp;lt;iostream&amp;amp;gt;#include&amp;amp;lt;algorithm&amp;amp;g原创 2018-08-08 20:41:06 · 337 阅读 · 0 评论 -
codeforces 991-D. Bishwock(模拟)
http://codeforces.com/problemset/problem/991/D解题思路:对各种情况简单归类模拟一遍即可。#include<iostream>#include<algorithm>#include<vector>#include<map>#include<set>#include<c...原创 2018-08-09 14:28:02 · 277 阅读 · 0 评论 -
codeforces 959-B. Mahmoud and Ehab and the message(map)
http://codeforces.com/problemset/problem/959/B题目大意: 给出一个字典,有n个单词,另外给出每个单词与另外单词之间的值替代,求给出一个新的句子最少需要的值为多少?解题思路: map映射#include<iostream>#include<algorithm>#include<ma...原创 2018-07-02 10:55:52 · 417 阅读 · 0 评论 -
codeforces 959-D. Mahmoud and Ehab and another array construction task(素数打表+乱搞)
http://codeforces.com/problemset/problem/959/D题目大意: 给出一个串数a,要求构造一个相同个数的数组b,保证b中的数互相互素。解题思路: 首先素数打表,然后枚举a数组中的数,判断是否都在数组中,然后分两类处理即可;#include<iostream>#include<vector>#in...原创 2018-07-02 11:00:55 · 372 阅读 · 0 评论 -
codeforces 962-B. Students in Railway Carriage(暴力+贪心)
http://codeforces.com/problemset/problem/962/B题目大意: 一辆列车上有n个座位,但是有些座位放了东西不能够坐。现在有A类和B类数人,给他们安排座位,并且A类的人不能喝B类的人直接相邻坐,计算最多能够坐多少人。解题思路: 枚举每个放了东西不能做的点,将两个放了东西不能坐的点之间区间值保存到vec数组中,然后贪心安排A和B...原创 2018-07-02 11:07:14 · 319 阅读 · 0 评论 -
codeforces 962-C. Make a Square(暴力)
http://codeforces.com/problemset/problem/962/C题目大意: 给出一个个数,要求可以删除任意个任意数位上的数,是否存在一个最少的删除,使得操作之后的数为一个平方数。要求操作后的数不能有前导零。输出最少删除的个数。解题思路: 因为数值只有9位,因此可以暴力枚举2^len,其中len为数的长度。考虑前导零的特殊情况即可;#...原创 2018-07-02 12:12:33 · 431 阅读 · 1 评论 -
codeforces 995-B. Suit and Tie(暴力+思维)
http://codeforces.com/problemset/problem/995/B题目大意: 有1~n的n对数字任意排列,每次操作可以将任意相邻的两个数进行对换,问最少需要多少次操作使得每一对数字都相邻?解题思路: 因为需要每一对数字都相邻,那么不重复的数字一定在奇数位,因此可以从头枚举每一个不重复的数字,记录已经配好对的数字,用vis数组标记,然后对还...原创 2018-07-03 21:30:34 · 478 阅读 · 0 评论 -
codeforces 841B. Godsend(思维)
题目链接 http://codeforces.com/problemset/problem/841/B题目大意:一组数据,两个人轮流取连续的数,要求A取出来的连续的数之和为奇数,B取出来的连续的数之和为偶数,谁先不能取谁输。解题思路:只要里面存在奇数,A就能赢!!!(为什么大家可以自己想想看)#include<iostream>#include<cstdio> usin...原创 2018-03-13 13:12:03 · 266 阅读 · 0 评论 -
codeforces 935B. Fafa and the Gates(简单)
题目链接 http://codeforces.com/problemset/problem/935/B解题思路:每次判断当前状态下的小三角形直角边的长度关系。#include<iostream> using namespace std; char s[100005];int main(){ int n; while(cin>>n) {...原创 2018-03-13 13:18:10 · 323 阅读 · 0 评论 -
codeforces 940-E. Cashback(dp)
http://codeforces.com/problemset/problem/940/E题目大意:给出大小为n的一个数组,可以分成任意段,每一段的长度为k(k可以为不同值),每次在区分的段内减去最小的(k+1)/c个数,问最后划分的数组值的和最小为多少?解题思路:用贪心的思想,要求所有和的最小值,每次划分的段长一定不能大于c,那么就一定是若干个长度为1的段和若干个长度为c的段,设d[i...原创 2018-04-19 00:42:18 · 278 阅读 · 0 评论 -
codeforces 933-A.A Twisty Movement (dp)
http://codeforces.com/problemset/problem/933/A题目大意:给出一个长度为n的数组,求经过一次任意区间的翻转之后,最大的非递减子序列。解题思路:只要对这个数组正序求非递减子序列、逆序求非递增子序列,然后遍历一次即可。#include<iostream>#include<vector>using namespace std;const int N=200原创 2018-04-20 18:40:40 · 434 阅读 · 1 评论 -
codeforces 919-D.Substring(拓扑排序+dp)
http://codeforces.com/problemset/problem/919/D题目大意:给出n个点,m条边,n个点用长度为n的一个字符串表示,字符串中只有26个小写字母,问任意一条联通路径中出现相同字母次数最多的值是多少?如果有无穷大,输出-1,。解题思路:用拓扑排序或者dfs跑一跑判断是否有环,d[i][j]表示前i个点联通的路径中字母j出现相同次数的最大值。#include<ios原创 2018-04-20 18:46:02 · 276 阅读 · 0 评论 -
codeforces 915-D. Almost Acyclic Graph(拓扑排序)
http://codeforces.com/problemset/problem/915/D题目大意:输入数据表示一个有向图,问是否能够至多删除其中的任意一条边,让这个图不存在环?解题思路:首先拓扑排序判断是否存在环,如果不存在,枚举每一个点,因为删除一条边,实际上就是让这条边的后继点的入度值减一,因此每次枚举继续拓扑排序一下判断是否存在环,如果不存在,则输出YES,否则最后输出NO。#includ原创 2018-04-25 17:35:56 · 262 阅读 · 0 评论 -
codeforces 804A. Find Amir(思维)
题目链接: http://codeforces.com/problemset/problem/804/A题目大意:有编号为1~n的n个学校,且从编号为i的学校到编号为j的学校需要花费(i+j)%(n+1),问不规定起点和终点,遍历所有学校所需要的最少花费为多少?解题思路:对于编号为1,2,3,...,n的学校:①从1出发,去向n 花费为0②从n继续,去向2 花费为1③从2继续,去向n...原创 2018-03-13 13:05:49 · 313 阅读 · 0 评论 -
codeforces 367E. Sereja and Intervals(DP)
题目链接 http://codeforces.com/problemset/problem/367/E解题思路: 题意大意是给出一个区间,在这个区间内选n个L和R值,使得这n个L,R不能存在包含关系,问一共有多少种方法。设dp[i][l][r] 表示当前区间长度为i的时候左节点有l个,右节点有r个的方法数那么状态转移方程可以分为四种:①第i个数可能为左边界②第i个数可能为右边界③第i个数可能既为左...原创 2018-03-07 21:00:37 · 377 阅读 · 0 评论 -
codeforces 869B. The Eternal Immortality(思维)
题目链接 http://codeforces.com/problemset/problem/869/B解题思路:可以发现,只要a和b两个数之差超过9,那么最后一个数一定是‘0’,因此只要考虑两个数只差小于10的情况,剩下的遍历一下就可以了。#include<iostream>using namespace std;typedef long long LL;int main(){...原创 2018-03-13 13:15:08 · 349 阅读 · 0 评论 -
codeforces 918C. The Monster(思维)
题目链接 http://codeforces.com/problemset/problem/918/C解题思路:暴力枚举区间(i,j)是否合格,对于区间内的‘?’,先假设都为‘)’,对于不合适的就改为‘(’,再判断即可。#include<iostream>using namespace std;char s[5005];int main(){ while(cin>>s) {原创 2018-03-13 13:27:51 · 369 阅读 · 0 评论 -
Codeforeces 703B Mishka and trip(路径权值的计算)
Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country.Here are some interesting原创 2016-08-20 10:09:44 · 456 阅读 · 0 评论 -
codeforces-754A-Lesha and array splitting(简单分类处理)
Lesha and array splittingOne spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possi原创 2017-01-14 20:52:46 · 822 阅读 · 0 评论 -
Codeforces-754B-Ilya and tic-tac-toe game(简单模拟判断)
Ilya and tic-tac-toe gameIlya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became t原创 2017-01-14 20:54:30 · 974 阅读 · 0 评论 -
Codeforces-743B-Chloe and the sequence(二进制思维题)
Chloe and the sequenceChloe, the same as Vladik, is a competitive programmer. She didn’t have any problems to get to the olympiad like Vladik, but she was confused by the task proposed on the olympiad.原创 2017-01-14 20:58:04 · 573 阅读 · 0 评论 -
codeforces-755-B PolandBall and Game
PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can’t say a new wo原创 2017-01-17 03:00:17 · 1033 阅读 · 0 评论 -
codeforces-755D-PolandBall and Polygon(数学题)
PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments.He chose a number k such tha原创 2017-01-17 03:22:26 · 1023 阅读 · 0 评论 -
codeforces-760-B Frodo and pillows(二分+数学)
n hobbits are planning to spend the night at Frodo’s house. Frodo has n beds standing in a row and m pillows (n ≤ m). Each hobbit needs a bed and at least one pillow to sleep, however, everyone wants a原创 2017-01-25 17:44:33 · 890 阅读 · 0 评论 -
codeforces-758-B Blown Garland(简单数学)
Nothing is eternal in the world, Kostya understood it on the 7-th of January when he saw partially dead four-color garland.Now he has a goal to replace dead light bulbs, however he doesn’t know how man原创 2017-01-25 17:52:33 · 586 阅读 · 0 评论 -
codeforces-757-B Bash's Big Day(简单题)
Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu’s Lab. Since Bash is Professor Zulu’s favourite student, Zulu allows him to take原创 2017-01-25 18:00:13 · 805 阅读 · 0 评论 -
codeforces-762A k-th divisor(数学题)
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn’t exist.Divisor of n is any such natural number, that n can be divided by it without remainder. InputThe fi原创 2017-01-26 00:50:18 · 1279 阅读 · 0 评论