dfs Gym - 100989L】的更多相关文章

AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tries to make it correct as quickly as possible! Given an equation of the form: A1 o A2 o A3 o ... o An  =  0, where o is either + or -. Your task is to…
AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect equation and so he tries to make it correct as quickly as possible! Given an equation of the form: A1 o A2 o A3 o ... o An  =  0, where o is either + or -. Your task is to…
题目传送门 /* 题意:将字符串分割成一个全排列 DFS:搜索主要在一位数和两位数的处理,用d1, d2记录个数,在不饱和的情况下,两种都试一下 DFS还是写不来,难道是在家里懒? */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> using namespace std; ; const int INF = 0x3f3f3f3f; char s[MAXN…
After the data structures exam, students lined up in the cafeteria to have a drink and chat about how much they have enjoyed the exam and how good their professors are. Since it was late in the evening, the cashier has already closed the cash registe…
Board Game Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u  Gym 100935G Description standard input/outputStatements Feras bought to his nephew Saleem a new game to help him learning calculating. The game consists of a boa…
Evil Time Limit: 5 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Description Richard is evil. He wants to give another geometry problem to the participants of this contest and I’m afraid I have no choice but to comply. Wh…
J. Deck Shuffling Time Limit: 2   Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/problem/J Description The world famous scientist Innokentiy continues his innovative experiments with decks of cards. Now he has a deck of n cards and k…
Problem A. Poetry Challenge Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100500/attachments Description Let’s check another challenge of the IBM ICPC Chill Zone, a poetry challenge. One says a poetry string that starts with a…
Evil Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100463/attachments Description Richard is evil. He wants to give another geometry problem to the participants of this contest and I’m afraid I have no choice but to comply. W…
E. Arrange Teams time limit per test:2 seconds memory limit per test:64 megabytes input:standard input output:standard output Syrian Collegiate Programming Contest (SCPC) is the qualified round for the Arab Collegiate Programming Contest. Each year S…
BUPT2017 wintertraining(15) #4H Gym - 101116K 题意 给定一个菜谱,大写的单词代表混合物,小写的代表基础原料.每个混合物由其它混合物或基础原料组成,不会间接或直接地需要自己.制备每个混合物必须先制备组成它的混合物.且混合物都要用一个碗装,当它作为原料去合成其它混合物后,碗就空出来了.求合成第一个混合物最少需要用几个碗. 题解 假设合成一个混合物需要dfs(i)个碗. 因为最后需要合成第一个混合物,所以我们以它为根进行dfs. 假设当前混合物的原料里有t…
BUPT2017 wintertraining(15) #4 A - I.Cubes Gym - 101164I 题意 将n拆成最少个立方数相加的形式. 题解 根据n的范围,立方数最大不超过400的立方,并且个数也不会很多. dfs,设置一个深度的上限up.从大到小枚举立方数,剪枝条件:当前层数加上至少还需要的层数>=up就return. 代码 #include <cstdio> #include <cstring> using namespace std; int n,c[…
You'll be Working on the Railroad 题目连接: http://codeforces.com/gym/100646/attachments Description Congratulations! Your county has just won a state grant to install a rail system between the two largest towns in the county - Acmar and Ibmar. This rail…
http://codeforces.com/gym/101246/problem/D 题意: 给定一个无向有环图,大火从1点开始,每个时间点与它相邻的点也将会着火,现在有两个人轮流操作机器人,机器人从1点出发,每个人每次选择一个点走,谁最后被火烧了谁就输了. 思路: 博弈题. 我们先预处理求出每个点着火的时间点,然后根据时间点重建新图,也就是重新建一个有向无环图,原来图中相连的并且时间点相差1的相连,由时间低的连向时间高的. 接下来我们在新图上求每个点的SG值,SG值为0的点就是叶子结点,这样父…
http://codeforces.com/gym/101128 题目大意:给你一个a,b,e,p.有e个点,p条有向边,每条边为(x,y),表示x->y,每次我们都取出一个入度为0的,并且一次性取出来的个数为a(或b).当然,取出来的种类可能有很多种(即一个集合),问,这个集合中有多少个数字是相同的. 第一个输出集合长度为a的,第二个输出集合长度为b的,第三个输出无论如何都无法被取出的个数. 思路:建立正向图和反向图. 定义pair<int, int> interval[i] 表示第i…
题目链接:http://codeforces.com/gym/101466/problem/K 题目: 题意: 给你一棵有n个节点的树,根节点始终为0,有两种操作: 1.RAND:查询以u为根节点的子树上的所有节点的权值的乘积x,及x的因数个数. 2.SEED:将节点u的权值乘以x. 思路: 比赛时少看了因数不大于13这句话,然后本题难度增加数倍,肝了两个小时都没肝出来,对不起队友啊,今天的组队训练赛实力背锅…… 这题一眼线段树,由于是对一棵子树进行处理,因此我们采用常规套路,借助dfs序将子树…
题目链接:http://codeforces.com/gym/100187/problem/J 题目链接:问通过洗牌器,能否将编号为x的牌子转移到第一个位置? 根据 洗牌器,我们可以知道原本在第i位置的牌可以转移到第j个位置,且这种转移是单向的.如果要把在某个位置的牌转移到第一个位置,那么必须至少存在一条转换路径,其起点为这张牌的位置,起终点为第一个位置.所以就很自然想到建图,然后用dfs跑一遍. 代码如下: #include<iostream> #include<cstdio>…
http://codeforces.com/gym/101257/problem/B 题意:给出两棵叶子数一样的树,在将叶子合并之后,对这个图进行染色,相邻的结点颜色不能相同,问最少需要染的颜色数,并输出合并叶子的方案. 思路:画了好几个图找了下规律,发现对于任意一个这样的图,最多只需要染三种颜色,最少是染两种颜色. 如果合并后的图,每一条从一棵树的根节点走到另一棵树的根节点的路径长度的奇偶性相同,那么这个时候就是只需要染两种颜色. 剩下的情况就是染三种颜色了. 对于每棵树,随便找一个不是叶子结…
Artwork Gym - 102346A 题意:给n*m的地图,入口是(0,0),出口是(n,m),其中有k个监视器,坐标是(xi,yi),监视半径是r,问一个人能不能不被监视到,从起点到终点. 如果不能走到终点,无非便是监视范围把路全堵死了,所以开始的想法便是计算几何题,看多个圆能不能把横的和竖的都给覆盖了,但很明显行不通,然后想了想觉得这可以转换成一个图的题. 我们把每个监视器看出点,然后遍历每个监视器跟它相交(相切,包含)的其他点,已经看一下这个圆会涉及到那些边界.然后会把路封死的组合便…
题目链接:http://codeforces.com/gym/100989/problem/L / http://codeforces.com/gym/100989/problem/M 题目大意:给定一个具有N项的表达式,求出最少修改符号次数使得表达式的和为0. 题目分析: 1.两道题的题意一模一样,区别在于数据范围不同.L题N的范围在20以内,但是表达式中每一项的值范围在 1e9 之内.M题的N范围在300之内,每一项的值范围在300之内. 2.所以L题用枚举,枚举每一种修改的情况取最少修改次…
Artwork (Gym - 102346A) 题目链接 算法 DFS,连通块 时间复杂度:O(k*n + k * k) 1.这道题就是让你判断从(0,0)到(m,n),避开中途所有的传感器(传感器的检测范围为半径为s的圆)的检测区域,最终能否到达(m,n). 2.这道题很容易想到圆与圆相切或相交最后把能出去的路全堵上了,具体是把上下.左右.左下.右上这四个边界给堵掉一部分(只要满足前面四种情况的其中一个,就过不去).见下图. 很明显,这样堵绝对出不去.然而方法是有,但怎么实现它呢?由于当时以为…
Problem E: Reliable NetsYou’re in charge of designing a campus network between buildings and are very worried about itsreliability and its cost. So, you’ve decided to build some redundancy into your network while keeping itas inexpensive as possible.…
Problem H: Two EndsIn the two-player game “Two Ends”, an even number of cards is laid out in a row. On each card, faceup, is written a positive integer. Players take turns removing a card from either end of the row andplacing the card in their pile.…
Problem I. TV ShowTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88926#problem/I Description Charlie is going to take part in one famous TV Show. The show is a single player game. Initially the play…
The Game of EfilTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88443#problem/C Description Almost anyone who has ever taken a class in computer science is familiar with the “Game of Life,” John Conw…
Problem B: CountdownTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88443#problem/B Description Ann Sister owns a genealogical database service, which maintains family tree history for her clients. W…
Problem B. Blind WalkTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=86821#problem/B Description This is an interactive problem. Your task is to write a program that controls a robot which blindly wa…
emmmm.... 在被新生暴打后,我花了很久才补出这道DFS.由于WA1检查了半天,最后竟然是输出少了一个:   ,心态小崩. 这里普通的dfs算出的连通区域并不能直接当做最后的答案.所以需要类似模拟的DFS来处理. 代码如下: #include<iostream> using namespace std; int q[12][12];//用数组标记该位置是空地.食物.还是障碍. int pd[12][12];//判断有没有走过 int maxx=0;//记录最大路径长度 int a,b,m…
https://vjudge.net/problem/Gym-101147J 题意: 有n个城市,每个城市有一个权值,表示在这个城市的加油站可以加多少油. 现在要计算每个城市i,有多少个城市j可以到达它: ① j 是 i 的子树. ② 在城市 j 加满Xj的油后不再加油能到达 i 城市. 思路:我们从根结点出发,dfs整棵树,在dfs的过程中,我们维护一个道路长度的和sum[],sum[j]就是1到第j个城市的路径之和. 假如我们现在dfs到了第j个城市v,此时1~j的路径之和就是sum[j],…
题意:给你一张2-SAT,问你加至少几句a V b(不能用非运算)这样的语句,使得其无法全为真. 如果最开始没有左右两项都含非运算的析取表达式,则无解,因为显然你可以对每一项的不含非的那项规定为真,使得整个2-SAT成立. 由于规定了你添加的语句不能含有非运算,故添加的边一定从 非某 指向 某. 如果一开始就存在某个a,它和非a互相可达,则答案为0. 如果一开始某个非a能到达a,则答案为1:如果一开始存在某个非j,a能到达非j,并且存在某个i,i能到达非a,则答案也为1,显然可以添一条从非某指向…