摘要: 题目链接:http://poj.org/problem?id=1129思路:根据图的四色定理,最多四种颜色就能满足题意,使得相邻的两部分颜色不同。而最多又只有26个点,因此直接dfs即可。 1 #include 2 #include 3 #include 4 #include 5 using namespace std; 6 7 bool map[33][33]; 8 int mark[33]; 9 char str[33];10 int n,ans;11 12 bool Judge(int x,int color)13 {14 for(int i=0;i<n;i++){15 ... 阅读全文
posted @ 2013-09-01 20:42 ihge2k 阅读(842) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=3414思路:bfs简单应用,增对瓶A或者瓶B进行分析就可以了,一共6种状态。 1 #include 2 #include 3 #include 4 #include 5 #include 6 using namespace std; 7 8 struct Node{ 9 int a,b,step; 10 char str[111][111]; 11 }; 12 13 int A,B,C; 14 bool mark[111][111]; 15 bool bfs() 16 { 17 mem... 阅读全文
posted @ 2013-09-01 10:27 ihge2k 阅读(815) 评论(0) 推荐(0) 编辑
摘要: 题目链接:http://poj.org/problem?id=2662思路:首先路径的选择,如果B点到终点的距离比A点到终点的最短距离短,那么就从A走到B,换句话说,就是每次都是择优选择更靠近终点的点。于是我们可以从终点2跑一次Dijkstra,求出每个点到终点的最短距离,然后就是从起点1开始记忆化搜索,如果满足上面条件的,就dfs. 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 using namespace std; 8 #define MAXN 1111 9 #define inf 1 >G; 阅读全文
posted @ 2013-09-01 09:16 ihge2k 阅读(257) 评论(0) 推荐(0) 编辑