上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2102本题又是一道BSF搜索求最短路,只是在遇到‘#’时空传输时要注意一下,如果‘#’所对应的另一个迷宫位置也是‘#’时是没有意思的。#include <iostream>#include <stdio.h>#include<stdlib.h>#include<string.h>#include <queue>#include <algorithm>using namespace std;char map[25][15];int T,co 阅读全文
posted @ 2011-03-30 15:14 CoderZhuang 阅读(151) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2141三个整数数列A,B,C。给若干个数X,若能找到Ai+Bj+Ck = X(Ai是数列A中的某一个数,Bj,Ck同理),输出YES,否则输出NO。先是做A和B数列各元素的和并排序,接下来只要二查找X-C,就可以了。#include <iostream>#include <stdio.h>#include<stdlib.h>#include<string.h>#include <queue>#include <algorithm>usin 阅读全文
posted @ 2011-03-30 10:12 CoderZhuang 阅读(126) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2614#include<stdio.h>#include<stdlib.h>int p[105][105],n,max,flag[105];void search(int a,int b,int c){ int i,f=1; for(i=0;i<n;i++) { if(p[a][i]<b||flag[i]) continue; flag[i]=1;f=0; search(i,p[a][i],c+1); flag[i]=0; } if(f) { if(c>m... 阅读全文
posted @ 2011-03-28 23:19 CoderZhuang 阅读(113) 评论(0) 推荐(0) 编辑
摘要: (x,y)为多边形的顶点,当k=m时,k+1为0,逆时针方向计算为正。 阅读全文
posted @ 2011-03-28 17:09 CoderZhuang 阅读(811) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1264这题很看郁闷,看了很久才明白是什么意思。大致就是有数个国家,每个国家有数个房子,房子相互连接组成的最小周长的多边形为该国家领土,当输入-1时国家输入完毕,接下来是多个炸弹的降落地点。国家的个数最多为20,炸弹可以无限个。若炸弹在某个国家的领土内爆炸(包括边),则可看成该国领土所有面积被炸(当然原文不是这样说),求所有被炸的面积。思路其实很明了,求出每个国家的凸包,若炸弹在凸包内,则计算所有这样凸包面积的和。要注意可能多个炸弹在落在同一个国家内,这时候只要算一个即可。判断点在多边形内的算法有很多种,这里用到的是外积法:设待判断的点为p, 阅读全文
posted @ 2011-03-28 16:59 CoderZhuang 阅读(447) 评论(0) 推荐(0) 编辑
摘要: 栈#include<stack> //头文件stack<char> st; //定义st.push(str1[0]); //入栈cur=st.top (); //取栈顶值st.pop(); //出栈st.empty ()//空为true队列#include<queue>queue<char>que;que.push(a);a=que.front();que.pop();que.empty ()优先队列bool operator < (const coor &a, const coor &b){ return a.time & 阅读全文
posted @ 2011-03-27 21:04 CoderZhuang 阅读(254) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1515http://www.cnblogs.com/liuqidong/archive/2010/07/26/1785076.html:本题并不是很难,就是输出所有能够目标WORD的可能。所以dfs+stack很容易解决。递归时有两种情况:第一:两个字符不相等(即栈顶字符与目标字符不相等);这种情况很容易处理,将匹配word的下一个字符入栈,指针向后挪已为继续递归。第二:两个字符相等(即栈顶字符与目标字符相等);这种情况有两种选择 (1)字符出栈,并将目标word的指针向后挪一位,继续递归;(2)将匹配wor 阅读全文
posted @ 2011-03-27 20:58 CoderZhuang 阅读(223) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1401转自:http://www.cppblog.com/IronOxide/archive/2010/08/19/123928.html在一个 8 * 8 的棋盘上,有四个棋子,每颗棋子可在上,下,左,右,四个方向进行四种操作,四种操作是一下的某一种: 1. 若相邻格有棋子,则可像跳棋一样,跳过去,到达对称的一格。 2.若相邻格为空,则可直接移过去。问能否从一种状态在8步之内变成另一种状态?题目分析: 明显的一道搜索题,但是应该选取怎样的策略去搜索呢? 估计一下普通广度优先搜索的复杂度:有4颗棋子,每个棋子 阅读全文
posted @ 2011-03-26 19:48 CoderZhuang 阅读(217) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2553//1.非递归:#include <cstdio>#include <cmath>using namespace std;#define N 13int x[N];bool isvalid(int k){ int i; for(i=0; i<k; i++) if(x[i]==x[k] || abs(x[i]-x[k])==abs(i-k)) return false; return true;}int queen(int n){ int k=0,count=0; x[k]= 阅读全文
posted @ 2011-03-24 23:14 CoderZhuang 阅读(129) 评论(0) 推荐(0) 编辑
摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1016输入n。从1到n的数组成一个环,环相邻的两个数之和为质数。输出所有的这种环。本人用深搜递归水过250ms#include <stdio.h>#include<stdlib.h>#include<string.h>#include <iostream>using namespace std;int n;int ans[25],p[50],flag[25];void dfs(int step){ int i; if(step==n) { if(p[ans[0] 阅读全文
posted @ 2011-03-24 11:24 CoderZhuang 阅读(109) 评论(0) 推荐(0) 编辑
上一页 1 ··· 3 4 5 6 7 8 9 10 11 12 下一页