
codeforces
文章平均质量分 92
fffalling
这个作者很懒,什么都没留下…
展开
-
CodeForces 275B Convex Shape(bfs)
B. Convex Shape time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputConsider an n × m grid. Initially all the cells of the grid are c...原创 2018-04-07 20:58:30 · 333 阅读 · 0 评论 -
Codeforces Educational 38 C. Constructing Tests ( 数学公式推导+暴力)
C. Constructing Tests time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputLet’s denote a m-free matrix as a binary (that is, consistin...原创 2018-04-25 19:17:28 · 196 阅读 · 0 评论 -
Educational Codeforces Round 38 (Rated for Div. 2) D. Buy a Ticket(最短路,建图)
D. Buy a Ticket time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputMusicians of a popular band “Flayer” have announced that they are...原创 2018-04-25 20:45:30 · 119 阅读 · 0 评论 -
Codeforces Round #476 (Div. 2) C. Greedy Arkady(二分)
C. Greedy Arkady time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputk people want to split ncandies between them. Each candy shoul...原创 2018-04-26 20:18:20 · 194 阅读 · 0 评论 -
Codeforces Round #476 (Div. 2) [Thanks, Telegram!] D. Single-use Stones(贪心)
D. Single-use Stones time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputA lot of frogs want to cross a river. A river is w units wid...原创 2018-04-26 20:54:48 · 344 阅读 · 0 评论 -
Codeforces Round #484 (Div. 2) C. Cut 'em all!(思维)
题目链接 题意:去除尽可能多的边,使得剩下的连通块里点的个数都为偶数 解析: n为奇数结果为-1 偶数的话从一个点开始递归找节点的子节点的数目(包含本身),如果是偶数则可以直接去除,因为只有n-1个边,也就是说剩下的一定是一个偶数的连通块#include <bits/stdc++.h>#define ll long long#define pb push_back#d...原创 2018-05-18 10:41:56 · 249 阅读 · 0 评论 -
Codeforces Round #479 (Div. 3) F - Consecutive Subsequence(思维)
the link题意:给定一串数组,求最长的每个数比其上一个数大一的子序列 解析: 刚开始以为是最长上升子序列的变形,然后就在网上找了半小时的代码,最后才发现是一道并不难的题#include <bits/stdc++.h>#define ll long long#define pb push_back#define inf 0x3f3f3f3f#define pll...原创 2018-05-07 11:08:38 · 489 阅读 · 0 评论 -
VK Cup 2018 Round 2: D. Riverside Curio(思维)
D. Riverside Curio time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputArkady decides to observe a river for n consecutive days. The river...原创 2018-04-28 22:07:52 · 229 阅读 · 0 评论 -
Codeforces Round #246 (Div. 2) C. Prime Swaps(素数,交换)
题目链接题目大意:给出一个序列,长度为n,要求用5n以内的交换次数使得序列有序,并且交换的i,j两个位置的数时要满足,j−i+1为素数。解析: 先用素数筛所有素数处理出来 然后输入时纪录每个数的位置, 枚举每个数字,如果这个数字的值i不等于它的位置 就找当前位置之前且大于等于这个数字正确位置的最小的位置进行交换,然后反复交换即可#include <bits/stdc+...原创 2018-05-20 10:51:31 · 163 阅读 · 0 评论 -
CodeForces 190D. Non-Secret Cypher(思维)
题目链接 题意:给出n个元素的数列(n<=4e5),问有多少个子区间满足至少有一个数值出现至少K次。 解析:#include <bits/stdc++.h>#define ll long long#define pb push_back#define inf 0x3f3f3f3f#define pll pair<ll,ll>#define rep(i...原创 2018-05-20 11:53:33 · 283 阅读 · 0 评论 -
Codeforces Round #482 (Div. 2) C. Kuro and Walking Route(思维)
题目链接 题意:不能经过x之后再经过y,问有多少条路径满足题意 解析:一点到其他一点都只有一条道路,所以我们把从x到y的路径找出来之后,统计y之后的点数,记为cnt,把x之前的点数记为cnt3,之后令cnt++,cnt3++,也就是把x,y算上 令总点数减去不满足的路径数即可#include <bits/stdc++.h>#define ll long long#defi...原创 2018-05-15 10:22:05 · 165 阅读 · 0 评论 -
Codeforces Round #478 (Div. 2) D. Ghosts(数学)
链接 题意:给你一条直线的斜率a和截距b,和某一时刻n个在直线上的点的横坐标,以及沿坐标轴方向的速度。问你这些点在(-∞,+∞)的时间内的碰撞次数。 解析: 设两个点在t时刻相碰,有: x1+vx1t=x2+vx2t y1+vy1t=y2+vy2t消去t,可以得到 x1−x2vx2−vx1=y1−y2vy2−vy1而在直线上有 y1−y2=a(x1−x2)进一步整理可以得...原创 2018-05-03 17:04:37 · 119 阅读 · 0 评论 -
Codeforces Round #480 (Div. 2): D. Perfect Groups(思维题)
D. Perfect Groups time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputSaMer has written the greatest test case of all time for one of his ...原创 2018-05-09 21:52:26 · 186 阅读 · 0 评论 -
Educational Codeforces Round 40 D. Fight Against Traffic(最短路)
D. Fight Against Traffic time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Little town Nsk consists of n junctions connected by m bidirectio...原创 2018-04-02 11:07:03 · 184 阅读 · 0 评论 -
Educational Codeforces Round 42 D. Merge Equals(vector,map)
D. Merge Equals time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputYou are given an array of positive integers. While there are at l...原创 2018-04-11 14:39:42 · 135 阅读 · 0 评论 -
Educational Codeforces Round 42 C. Make a Square(字符串操作)
C. Make a Square time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputYou are given a positive integer n, written without leading ze...原创 2018-04-11 16:32:06 · 480 阅读 · 0 评论 -
Codeforces Round #475 (Div. 2) C. Alternating Sum(求逆元)
C. Alternating Sum time limit per test 1 second memory limit per test 256 megabytes input standard input output standard outputYou are given two integers a and b. Moreover, you are given a ...原创 2018-04-18 09:29:30 · 305 阅读 · 0 评论 -
Codeforces Round #465 (Div. 2) C. Fifa and Fafa(计算几何)
链接 给你一个圆和一个点,让你在给定圆内画一个圆,使得答案圆不能包含给定点,而且使得给定圆没有被答案圆覆盖的面积最小。输出答案圆的圆心和半径即可。 解析:分三种情况考虑: 当点在圆外时: 那么给出的圆就符合条件,直接输出圆心和坐标即可 当给出的点和圆心重合时: 此时的坐标为(x1+r/2,y1),半径为r/2 当给出的点在圆内时: 这是半径好求,圆心就要用相...原创 2018-04-22 11:30:25 · 138 阅读 · 0 评论 -
Codeforces 960C - Subsequence Counting(构造题)
链接 题意: 对于一个数组,将这个数组的所有非空子序列写下,然后删掉满足:最大值与最小值的差大于等于d 的子序列。 最后剩下了X 个子序列。 请你给出原序列的一种合法排列。解析: k个x和一个x+d可以产生2的k次方的贡献,下一个可以为 k1个x+2d和一个x+3d产生2的k1次方的贡献,所以我们直接对x进行二进制拆分然后照这种模式构造即可#include<bit...原创 2018-04-19 18:17:31 · 422 阅读 · 0 评论 -
Codeforces 961C Chessboard(暴力)
链接 题意:给你四块分裂的小正方形,然后让你凑成一个大的正方形,并且相邻的位置不能相同,然后问你最小的变化次数是多少? 解析:我们,枚举出四个小块块组合的所有情况,然后按从0开始和从1开始枚举每一个方格,不满足条件+1,最后更新最小值即可#include<bits/stdc++.h>#define ll long long#define inf 0x3f3f3f3f#de...原创 2018-04-19 19:51:28 · 138 阅读 · 0 评论 -
Educational Codeforces Round 43 C. Nested Segments(思维)
C. Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputYou are given a sequence a1, a2, …, an of one-dimensional segm...原创 2018-05-01 15:59:12 · 232 阅读 · 0 评论 -
Codeforces Round #473 (Div. 2) D.Mahmoud and Ehab and another array construction task(素数筛,质因子)
链接 题意: 给出一个数组 a[],要你构造出一个互质的字典序最小的数组 b[],且 b[] 的字典序要大于等于 a[] 。 解析: 预处理素数,然后对于第 i 个数,它应该不包含前面 i-1 个数含有的质因子,满足这个条件后,我们贪心取最大的即可。且如果当前已经大于数组 a[] 了,那后面的就都贪心取最小的质数。#include<bits/stdc++.h>#defin...原创 2018-04-24 17:36:46 · 163 阅读 · 0 评论 -
codeforces 959E Mahmoud and Ehab and the xor-MST(找规律)
链接E. Mahmoud and Ehab and the xor-MST time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard outputEhab is interested in the bitwise-xor ope...原创 2018-04-24 17:51:02 · 237 阅读 · 0 评论 -
Codeforces Round #483 (Div. 2) C. Finite or not? (数学)
链接 题意:问p/q 再b进制下是否是有限小数 解析:我们把p/q化到最简形式,我们知道容易1/q是有限的,那么p/q也一定是有限的 在这里以十进制为例,10的质因子为2和5,如果十进制下的分母只有2和5两种质因子,那么这个小数就是有限的 所以如果在b进制下,如果分母只有b进制的质因子,那么有限 求1e18的质因子不现实 所以我们用q反复除以q与b的最大公约数,如果最后q为1 ,说明是...原创 2018-05-16 10:10:31 · 186 阅读 · 0 评论 -
Codeforces Round #483 (Div. 2) D. XOR-pyramid(dp)
题意: 定义一个函数f(b),b对应一个数组,作用方式见题意。给你一个长度为n的序列b,然后给你q次询问,对于每次询问,给你l r,问你在[l,r]这段区间内所有子串中f的最大值为多少。解析:定义f[l][r]为在[l,r]这个区间内函数f的结果,那么有: 当l=r时f[l][r]=b[l] 否则 f[l][r]=f[l][r−1]⊕f[l+1][r] 所以我们可以按长度枚举 ...原创 2018-05-16 13:10:49 · 450 阅读 · 2 评论 -
Codeforces Round #360 (Div. 2) E. The Values You Can Make(dp,滚动数组)
题意 给n个数,从中挑若干个元素使其和为k,组成集合S,S的某一子集元素之和为x,问所有x可能的值思路 dp,状态dp[i][j][p]为考虑到第i个数,当前所有数的和为j,组成和为p的子集是否可能。 如果不使用第i个数,dp[i][j][p]=dp[i-1][j][p] 如果使用第i个数但子集不取他,dp[i][j][p]=dp[i-1][j-ci][p] 如果使用第i个数且...原创 2018-07-20 18:07:04 · 139 阅读 · 0 评论 -
Educational Codeforces Round 21 E. Selling Souvenirs(背包)
题目:http://codeforces.com/contest/808/problem/E题目大意: 有n个物品,背包容量为m。 每个物品只会有1,2,3个单位占有空间,价值为c。 现在问如何可以使拿到的物品的价值最大。思路: 主要就是只有三种单位。这就简单了。 贪心的思想,在相同的占有空间的时候,一定选价值最大的。 所以给物品排一个序。 dp第1,2种单位的...原创 2018-07-15 16:29:06 · 171 阅读 · 0 评论 -
codeforces 554D Destroying Roads(最短路)
In some country there are exactly n cities and m bidirectional roads connecting the cities. Cities are numbered with integers from 1 to n. If cities a and b are connected by a road, then in an hour yo...原创 2018-07-15 16:34:39 · 251 阅读 · 0 评论 -
cf-645D. Robot Rapping Results Report(判断是否是惟一的拓扑序列)
题意】: 给出一个有向图,确定最小的k,通过前k条边就能确定唯一的拓扑序列。若整个图不存在唯一的拓扑序列,输出-1#include<bits/stdc++.h>using namespace std;#define ll long long#define pb push_back#define inf 2099999999#define rep(i,a,b) f...原创 2018-07-15 16:38:03 · 179 阅读 · 0 评论 -
CodeForces 478D-Red-Green Towers(滚动数组dp)
题意:给r个红格子,g个绿格子, 每层只有一种颜色,问有多少种可以达到最大层数的方法数解析:dp[i][j]表示从上到下摆到第i层用j个红格子的方法数 所以第i层摆红格子的话 dp[i][j]+=dp[i-1][j-i]; 不摆的话 就要摆绿格子 已经摆的绿格子为i(i-1)/2-j dp[i][j]+=dp[i-1][j]; 由于空间有限,...原创 2018-07-15 20:15:19 · 180 阅读 · 0 评论 -
Educational Codeforces Round 48 (Rated for Div. 2) D. Vasya And The Matrix(构造
D. Vasya And The Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Now Vasya is taking an exam in mathematics. In order to get a goo...原创 2018-08-04 08:51:18 · 340 阅读 · 0 评论 -
Educational Codeforces Round 48 (Rated for Div. 2) C. Vasya And The Mushrooms(思维)
C. Vasya And The Mushrooms time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Vasya’s house is situated in a forest, and there is a mushroom...原创 2018-08-04 16:44:46 · 308 阅读 · 0 评论 -
Codeforces Round #502 (in memory of Leopoldo Taravilse, Div. 1 + Div. 2) D. The Wu(思维)
D. The Wu time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Childan is making up a legendary story and trying to sell his forgery — a neckl...原创 2018-08-09 09:53:56 · 205 阅读 · 0 评论 -
Codeforces Round #499 (Div. 2) C. Fly(二分
C. Fly time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Natasha is going to fly on a rocket to Mars and return to Earth. Also, on the way t...原创 2018-07-31 11:50:54 · 190 阅读 · 0 评论 -
Codeforces Round #503 (by SIS, Div. 2) C. Elections(枚举+贪心)
题意:有n个学生,m个政党,每个学生有支持的政党,但是如果你给他一些钱,他就可以给你想让他投的党投票,现在想付出最少的钱使得1政党有绝对优势(票数严格大于其他党)。 分析:通过枚举政党 1 获取(1到n)票数所需花费的金币,对能获得票数最高的情况取最小花费即可。#include<bits/stdc++.h>#define INF 0x3f3f3f3f3f3f3f3f#de...原创 2018-08-14 17:38:58 · 165 阅读 · 0 评论 -
Codeforces Round #498 (Div. 3) F. Xor-Paths(折半搜索
链接 题意:问从1,1到n,m有多少条异或值为k的路径。 解析: 直接暴力为2^40 用折半搜索会降到2^21, 我们只需记录达到中间值x+y==(n+m+2)/2的异或值,反向搜索的时候捕获这个值即可, 需要注意的是中间点被异或了两次,所以要再异或一次#include<bits/stdc++.h>using namespace std;#define ll l...原创 2018-07-20 16:57:27 · 143 阅读 · 0 评论 -
Codeforces Round #498 (Div. 3) D Two Strings Swaps(思维)
这里链接 好像没什么说的。。直接看代码吧。 解析:#include<bits/stdc++.h>using namespace std;#define ll long long#define pb push_back#define inf 2099999999#define rep(i,a,b) for(int i=a;i<=b;i++)#define re...原创 2018-07-20 16:26:15 · 142 阅读 · 0 评论 -
codeforces #486(div3) E. Divisibility by 25(贪心)
水题,考虑四种情况25,50,75,00 最后把前缀零替换,无法替换就去掉该情况即可 能打这场目测加100+分?#include <bits/stdc++.h>#define ll long long#define pb push_back#define inf 0x3f3f3f3f#define pll pair<ll,ll>#define rep(...原创 2018-06-07 21:26:09 · 175 阅读 · 0 评论 -
Educational Codeforces Round 45 (Rated for Div. 2) D Graph And Its Complement(图的构造)
题意:构造一个图,使这个图的连通分量有a个,其补图的连通分量有b个,输出邻接矩阵 可以推出当min(a,b)!=1时输出no a=b=1且n=2或者n=3时也为no 其余只要把一个连通分量里的x个点用x-1条边串起来就好了 哎,最后想到n=3也为no,可惜了..#include <bits/stdc++.h>#define ll long long#define pb ...原创 2018-06-10 20:17:30 · 138 阅读 · 0 评论 -
Codeforces 486D Valid Sets(dfs)
题目大意:给定一棵树,每个节点有个权值,现在要选定一些节点,要求非空,并且maxVal-minVal不大于d。问说有多 少种选择方法。 解析: 枚举每个节点作为根节点 默认根节点为权值最大的节点 然后进行dfs 为了避免重复,在两个节点相等时,要求根节点大的时候才能继续进行 由于是乘法,所以longlong 很必要#include<b...原创 2018-07-16 14:28:40 · 182 阅读 · 0 评论