2012年11月29日

UVA439- Knight Moves

摘要: 此题卡住我的地方有:一:理解题意,一开始压根看不懂题意,看了解释,才知道是马走日的搜索;二:开始的时候用dfs水过的的,代码烂的不堪入目,所以,此处不再粘了,然后自己慢慢摸索了好久,才用bfs过的。代码如下:边遍历,边搜索;#include #include using namespace std; int x, y, min_n; int node[100][3], vis[10][10]; int pan(int i, int j) { if(i>=1&&j>=1&&i=rear) { int a = node[rear][0], b = nod 阅读全文
posted @ 2012-11-29 10:13 Primo... 阅读(120) 评论(0) 推荐(0)
2012年11月27日

UVA705-Slash Maze

摘要: 摘文:~很有意思的题目,无从下手,看到别人的用0,1的方式表示/ \感觉豁然开朗了许多,这个题目可以把原题放大即可,放大2倍每次需要考虑8个方向,放大三倍每次考虑四个方向放大2倍图\ 10 / 01 0110放大3倍图\ 100 / 001 010 010 001 100只需要把没个斜杠按放大图转化为0,1的矩阵,0表示可走,1表示不可走,剩下的就和以前一样了。放大2倍的代码:#include #include #define max 80 using namespace std; int data[max*2][max*2], vis[max*2][max*2], flag, w, h,.. 阅读全文
posted @ 2012-11-27 12:05 Primo... 阅读(124) 评论(0) 推荐(0)
2012年11月18日

UVA11234 - Expressions

摘要: 这个又是放了好久才做的题,最近刚学到二叉树,对遍历熟悉了以后,发现给出的第一的入栈序列正着读的话不是正经的后序遍历,但是,如果反过来去读的话,你会发现这是一个标准的先序遍历,(不知有多少人发现了这个规律)故,我是反序读入建树的,这样就省了调用栈,也省不少用时。这个问题,解决了以后,bfs是我最大的障碍,自学了bfs以后我才把这道题A掉的。代码如下:#include #include #include #include using namespace std; struct node{ char data; node *lnode, *rnode; }; int leng... 阅读全文
posted @ 2012-11-18 11:30 Primo... 阅读(159) 评论(0) 推荐(0)
2012年11月16日

UVA 784 - Maze Exploration

摘要: 水题,了解了dfs后,这样的题就水的很了。代码如下:#include #include #include using namespace std; char ch[50][100]; void dfs(int i, int j) { if(ch[i][j] == '#'||ch[i][j]=='X')return; ch[i][j] = '#'; dfs(i-1, j-1);dfs(i-1, j);dfs(i-1, j+1); dfs(i, j-1); dfs(i, j+1); dfs(i+1, j-1);dfs(i+1,... 阅读全文
posted @ 2012-11-16 21:01 Primo... 阅读(127) 评论(0) 推荐(0)

UVA657 - The die is cast

摘要: 这个水题还是让我WA了好几遍,原因是没读清题意。思路很简单,就是DFS两遍就行了代码如下:#include #include using namespace std; char ch[55][55]; int count, pot[7];//用pot[1],pot[2……]分别储存点数为1,2……出现的次数;然后就很容易的由小到大的输出了; bool vis[55][55],visx[55][55]; void input(int w, int h) { for(int i = 1; i >w>>h&&w&&h) { cin.ignore(); 阅读全文
posted @ 2012-11-16 20:01 Primo... 阅读(129) 评论(0) 推荐(0)
2012年11月11日

POJ2259-Team Queue

摘要: 以前在uva上做过这个题,一模一样的,但是这次还是弄了个RE,而且这次的错误与上次完全不同;以前的错误是逻辑错误,这次的而代码错误,只是少个else。用了一晚上的时间,用神一样的测试数据终于揪出了这个错误。错误见代码《测试数据见UVA540.#include #include #include #include using namespace std; struct node { int data; node *next; }; struct zu { int count; node *tail, *head; }; int cla[1000050]; ... 阅读全文
posted @ 2012-11-11 21:14 Primo... 阅读(158) 评论(0) 推荐(0)
2012年11月10日

SGU-302. BHTML 1.0

摘要: #include #include #include using namespace std; stack zhan; int main () { string s1, s2; while(cin>>s1) { s2.clear(); for(int i = 0; i ='A'&&s1[i]='a'&&s1[i]<='z')?0:32)); } } cout<<s2<<endl; } return 0; } 思路较简单,不做多余解释》 阅读全文
posted @ 2012-11-10 21:52 Primo... 阅读(108) 评论(0) 推荐(0)
2012年11月8日

UVA10562 - Undraw the Trees

摘要: 又是递归函数的简单应用。思路较简单,卡到我的地方是我定义的二维数组来读取数据,但是开始的时候我认为每行宽度都相同,后来我才发现每行的宽度不一定相同,我便定义了一个数组,用来记录每行的宽度,此题编过。代码如下:#include #include using namespace std; char ch[250][250]; int deep, w[250];//记录各行的宽度 void go(int k, int i, int j) { int left, right; cout0?left+1:0), (right>n,cin.ignore(); while(n--... 阅读全文
posted @ 2012-11-08 22:59 Primo... 阅读(144) 评论(0) 推荐(0)

UVA839 - Not so Mobile

摘要: 题目较为简单,不做多余解释,递归函数的简单应用代码如下:#include using namespace std; int cacult(int &qual) { int w1, d1, w2, d2, temp; if(cin>>w1>>d1>>w2>>d2 == 0)return -1; if(!w1) w1 = cacult(temp); if(!w2) w2 = cacult(temp); if(w1*d1 == w2*d2&&temp)qual = 1; else qual = 0; retu... 阅读全文
posted @ 2012-11-08 21:20 Primo... 阅读(122) 评论(0) 推荐(0)

UVA327 - Evaluating Simple C Expressions

摘要: 题目很简单,不过需要考虑全面才可、个人觉得题目表达的不是很准确,其中没有考虑到a与--之间有空格的情况就是我第一次RTE的原因所在】因此,我先进行空格剔除,在进行其他操作。代码如下:#include #include #include using namespace std; int ch[30], sum, length; string s; int cacultor(int a, char c, int b)//计算函数 { switch (c) { case '+': return a+b; case '-': ret... 阅读全文
posted @ 2012-11-08 00:13 Primo... 阅读(191) 评论(0) 推荐(0)