题目链接:http://codeforces.com/contest/1064/problem/D 题目大意:给你一个n*m的图,图中包含两种符号,'.'表示可以行走,'*'表示障碍物不能行走,规定最多只能向左走L个格子,向右R个格子,但是上下没有限制,现在给出出发点坐标(sx,sy),求能走的最大单元格数目. Examples Input Copy 4 53 21 2......***....***.... Output Copy 10 Input Copy 4 42 20 1......*.…
D. Labyrinth 题目链接:https://codeforces.com/contest/1064/problem/D 题意: 给出一个n*m的矩阵以及人物的起点,并且给出x,y,分别代表这个人向左最多走x步,向右最多走y步. 矩阵中存在障碍,问这个人最多能到达多少数量的格子. 题解: 就是一个bfs...只是要稍微剪枝一下,如果发现当前这个点所到达的格子已经被之前的一个点到达过,当且仅当当前点的x或y至少一个比之前到达的点大时,就将这个点入队. 只有这样才能保证解最优. 代码如下: #…
题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int gcd(int a,int b){return b?gcd(b…
Codeforces Round #599 (Div. 2) D. 0-1 MST Description Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a descr…
目录 Codeforces 1064 A.Make a triangle! B.Equations of Mathematical Magic C.Oh Those Palindromes D.Labyrinth(BFS) E.Dwarves,Hats and Extrasensory Abilities(交互 二分) F.Candies for Children D.Labyrinth E.Dwarves,Hats and Extrasensory Abilities Codeforces 1…
https://codeforces.com/contest/1064/problem/D 题意 给你一个有障碍的图,限制你向左向右走的次数,问你可以到达格子的个数 思路 可以定义状态为vi[x][y][l][r],状态唯一,理论上可以bfs或者dfs都可以搜出唯一结果,但是时间空间复杂度都不允许 进而要不改变状态定义或者找找规律或者思考贪心(调整访问顺序)在做这道题之前并不知道便利顺序对于搜索有这么大的影响 我尝试了重新定义状态为vi[x][y][dir],但是用了dfs还是wa 根本问题是,…
http://codeforces.com/contest/1064/problem/D 向上/向下加0,向左/右加1, step = 0,1,…… 求的是最少的步数,所以使用bfs. step=k -> step=k+1 1.step=k 使用一次左/右 到达 step=k+1 2.step=k+1 无限使用上下,得到所有 step=k+1 的状态 用dijkstra+堆优化 / spfa 超时. #include <bits/stdc++.h> using namespace std…
A. Drazil and Factorial 题目连接: http://codeforces.com/contest/516/problem/A Description Drazil is playing a math game with Varda. Let's define for positive integer x as a product of factorials of its digits. For example, . First, they choose a decimal…
比赛链接:传送门 A. Make a triangle!(简单思维) 题目大意: 给你三条边,问你最多加多少长度能使这三条边能构成三角形. 思路: 最大边小于答案加另外两条边的和. #include <bits/stdc++.h> using namespace std; int main() { int a, b, c; cin >> a >> b >> c; int _max = max(a, b); _max = max(_max, c); int s…
B. Ohana Cleans Up   Ohana Matsumae is trying to clean a room, which is divided up into an n by n grid of squares. Each square is initially either clean or dirty. Ohana can sweep her broom over columns of the grid. Her broom is very strange: if she s…
本题地址: https://codeforces.com/contest/1215/problem/B 本场比赛A题题解:https://www.cnblogs.com/liyexin/p/11535519.html B. The Number of Products time limit per test 2 seconds memory limit per test 256 megabytes input standard input output   standard output You…
题:https://codeforces.com/contest/1072/problem/C 思路:首先找到最大的x,使得x*(x+1)/2 <= a+b 那么一定存在一种分割使得 a1 <= a 且 b1 <= b 证明: 从x 到 1枚举过去,对于某个i 如果 a >= i, 那么这个i放在第一天 如果a < i,那么后面肯定会遇到一个a把第一天填满(因为我们是从大到小枚举的) 所以第一天可以填满,那么除了第一天剩下的加起来也小于等于b #include<bits…
题目链接:https://codeforces.ml/contest/1702/problem/E 题目大意: 每张牌上面有两个数字,现在有n张牌(n为偶数),问能否将这n张牌分成两堆,使得每堆牌中的数字不重复: 因为需要每堆牌不重复,那牌中的数字必须满足: 1.每个数字出现的次数刚好为2 2.同一张牌上出现的数字不同 因为每张牌上有两个数字,所以我们可以将每张牌连成一个环,然后对每张牌进行涂色,如果包含相同数字的牌被涂成了相同的颜色, 说明无论如何都不可能分为两堆: 1 # include<i…
题目:Report 题意:有两种操作: 1)t = 1,前r个数字按升序排列:   2)t = 2,前r个数字按降序排列: 求执行m次操作后的排列顺序. #include <iostream> #include <algorithm> #include <stdlib.h> #include <time.h> #include <cmath> #include <cstdio> #include <string> #inc…
题目链接 A. Make a triangle! 题意 让某段最少增加多少使得构成三角形 思路 让较小两段往最长段去凑 代码 #include <bits/stdc++.h> #define DBG(x) cerr << #x << " = " << x << endl; using namespace std; int a[5]; int main(){ scanf("%d%d%d",&a[1],…
A. Vasya and Football 题目连接: http://codeforces.com/contest/493/problem/A Description Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player wh…
[题意]定义函数F(n,k)为1~n的集合中选择k个数字,其中最小数字的期望. 给定两个数字集A,B,A中任意数字>=B中任意数字,要求重组A使得对于i=1~n,sigma(F(Ai,Bi))最大. [算法]数学结论+数学期望+排序 [题解]很无奈,这题放在div2 C,难以推导的期望公式,广为人知的结论,容易观察样例得出的做法,都体现了这道题的不合理性. F(n,k)=(n+1)/(k+1) 公式推导可能触及我的知识盲区了QAQ 得到公式后,显然要求k尽可能小,n尽可能大,经验告诉我们随着两数…
[题意]给定n个点和m条无向边(有重边无自环),每个点有权值di=-1,0,1,要求仅保留一些边使得所有点i满足:di=-1或degree%2=di,输出任意方案. [算法]数学+搜索 [题解] 最关键的一步:★[%2转取反]. 首先考虑在树上做这样的问题,就显得十分朴素了.每当选择一条边,边的两端点权值就会取反,所以做一次DFS,对儿子权值(变化后)为1的点连边,自身取反,儿子都处理完毕后再把自身的新权值反馈上去.这样本质上等同于,所有点权为1的点都通过路径将取反信息传递到根,若最终根权为0则…
A: 题目大意:给你$a,b,c$三条边,可以给任意的边加任意的长度,求最少共加多少长度使得可以构成三角形 题解:排个序,若可以组成,输出$0$,否则输出$c-a-b+1(设a\leqslant b\leqslant c)$ 卡点:无 C++ Code: #include <cstdio> #include <algorithm> #include <cstring> #include <queue> inline int min(int a, int b)…
题目链接 参考题解 题意: 给你 整形数组a 和 整形数组b ,要你c[i] = d * a[i] + b[i], 求  在c[i]=0的时候  相同的d的数量 最多能有几个. 思路: 1. 首先打开别人的博客. 2.......... 一开始尝试自己做了做 没做出来,看了别人博客的分析之后发现自己连  d= -b[i]/a[i]都推错了.  kx(大佬)告诉我这题用map存.  于是补了之后交一发,WA5,原因是没有考虑a[i]和b[i]等于0 的时候(这里注意如果a[i]和b[i]都等于0,…
C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist only of "0" and "1". We call these strings aa and bb. It is known that |b|≤|a||b|≤|a|, that is, the length of bb is at most the length…
 A. Strange Partition 题意:就是求最小和最大的bi/x向上取整的和. 思路:见题解:https://blog.csdn.net/qq_45900709/article/details/112341661 当时没想到的:就是不是说能够代替,不应该是平均以后再向上取整吗,尤其是等式的后一部分 代码: 1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 #include<…
题意:有一些无向边m条权值是给定的k条权值在[l,r]区间可以由你来定,一个点s1 出发一个从s2出发  问s1 出发的能不能先打到f 思路:最短路. 首先检测能不能赢 在更新的时候  如果对于一条边 a->b  如果dis1[a] <dis2[a]  那么选择这条边就选择   l  因为这条边对于s1有利 如果两个起点都选择了这条边  则说明s1 赢定了,所以要让他们尽量走这条,所以边权越小越好.跑完之后检测 如果  dis1[f]<dis2[f] 那么 就赢了. 接下来判断能不能平局…
D. Sea Battle time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Galya is playing one-dimensional Sea Battle on a 1 × n grid. In this game a ships are placed on the grid. Each of the ships con…
A. Kyoya and Photobooks   Kyoya Ootori is selling photobooks of the Ouran High School Host Club. He has 26 photos, labeled "a" to "z", and he has compiled them into a photo booklet with some photos in some order (possibly with some pho…
B. Jzzhu and Sequences time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Jzzhu has invented a kind of sequences, they meet the following property: You are given x and y, please calculate fn m…
A:开场懵逼.然后发现有人1min过,于是就sort了一下,于是就过了.正经证明的话,考虑回文串两端点一定是相同的,所以最多有Σcnti*(cnti+1)/2个,cnti为第i种字母出现次数.而sort是可以达到这个最大值的. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> #include<cstring> #include<algorithm&g…
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output ZS the Coder loves to read the dictionary. He thinks that a word is nice if there exists a substring (contiguous segmen…
#include<bits/stdc++.h>using namespace std;int order[300007];long long t[300007],ans[300007];int main(){    int n;    long long m; scanf("%d%lld",&n,&m); for(int i=1;i<=n;i++)  scanf("%lld",&t[i]); t[n+1]=2e18; for…
#include <bits/stdc++.h> using namespace std; *1e5+; vector<int>p[maxn]; vector<int>c; bool check[maxn]; void dfs(int x) { check[x] = true; c.push_back(x); ; i < p[x].size(); i++) { int y = p[x][i]; if (!check[y]) { dfs(y); } } } int…