UVA699 dfs and map】的更多相关文章

和书上的方法不一样... 因为我不知道节点,所以就直接用map来存左右了. #include<bits/stdc++.h> using namespace std; map <int, int> m; int l, r; int cnt; void dfs(int pos){ int t1; scanf("%d", &t1); ){ dfs(pos - ); l = min(l, pos - ); m[pos - ] += t1; } int t2; s…
解题报告:有一群人在打乒乓球比赛,需要在这一群人里面选出一个冠军,现在规定,若a赢了b,b又赢了c那么如果a与c没有比赛的话,就默认a赢了c,而如果c赢了a的话,则这三个人里面选不出冠军,还有就是如果一个人没有输给别人,但是存在一个人跟这个人之间的输赢关系不能确定的话,也是作为选不出冠军的情况,现在输入一群人的比赛情况,要你确定,利用这组比赛情况能不能确定一个冠军,能的话输出Yes,否则输出No. 感觉这题应该有很多种不同的解法,其中由于输入的是选手的名字,所以还要用到map容器.我的做法是枚举…
A. Andryusha and Socks time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Andryusha is an orderly boy and likes to keep things in their place. Today he faced a problem to put his socks in the…
D. Fibonacci-ish time limit per test 3 seconds memory limit per test 512 megabytes input standard input output standard output Yash has recently learnt about the Fibonacci sequence and is very excited about it. He calls a sequence Fibonacci-ish if th…
One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is related. The weight of a relation is defined to be the total time length of all the phone calls made b…
Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 632 Accepted Submission(s): 209 Problem Description You have just moved into a new apartment and have a long list of items you need to buy…
最大联通子数组,这次的题目,我采用的方法为dfs搜索,按照已经取到的数v[][],来进行搜索过程的状态转移,每次对v[][]中标记为1的所有元素依次取其相邻的未被标记为1的元素,将其标记为1,然而,这样会产生很大的子问题重合,所以必须利用dp来进行记忆化搜索,dp为一集合,集合中的元素为已在前面出现过的v[][]的状态, 然而v[][]为一个二维数组,很不方便存入set,所以使用将v[][]的行经行状态压缩,使用位运算,将行存入 long long 型数中,在按列存入vector中 #inclu…
题目链接:http://poj.org/problem?id=2386 Description Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either wa…
问题描述 地球人都知道,在国际象棋中,后如同太阳,光芒四射,威风八面,它能控制横.坚.斜线位置. 看过清宫戏的中国人都知道,后宫乃步步惊心的险恶之地.各皇后都有自己的势力范围,但也总能找到相安无事的办法. 所有中国人都知道,皇权神圣,伴君如伴虎,触龙颜者死...... 现在有一个n*n的皇宫,国王占据他所在位置及周围的共9个格子,这些格子皇后不能使用(如果国王在王宫的边上,占用的格子可能不到9个).当然,皇后也不会攻击国王. 现在知道了国王的位置(x,y)(国王位于第x行第y列,x,y的起始行和…
http://acm.hdu.edu.cn/showproblem.php?pid=1983 首先,题目要求出口和入口不能封闭,那么,只要把出口或入口的周围全给封闭了那盗贼肯定无法成功偷盗,出口或入口周围最多 会有四个点,所以初始答案ans=4(没必要计算出出口或入口可以封闭的最小值,就初始为4就好),然后从一到四枚举看有没有 最小的符合条件的值, 所以先用BFS查找出至少偷到一个宝石的最小时间的路径,记录下来,然后枚举封闭路径上的点递归回去,再BFS判断是否能偷盗 成功---DFS中插入BFS…