11 2012 档案
UVA532-Dungeon Master(三维迷宫)
摘要:还是广搜的题,只不过题意有点吓人,什么三维的迷宫,搜索最短的路径。题目不难。不作多余的解释;代码如下:#include #include using namespace std; struct Node{ int x,y,z,len; }; char ch[40][40][40]; bool vis[40][40][40]; int go[6][3] = {{-1,0,0},{1,0,0},{0,-1,0},{0,1,0},{0,0,1},{0,0,-1}};//需要遍历的六个方向 int l, r, c, x_, y_ , z_; Node node[30000];//用于存储节... 阅读全文
posted @ 2012-11-29 12:48 Primo... 阅读(175) 评论(0) 推荐(0)
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... 阅读(122) 评论(0) 推荐(0)
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... 阅读(127) 评论(0) 推荐(0)
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... 阅读(160) 评论(0) 推荐(0)
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... 阅读(129) 评论(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... 阅读(134) 评论(0) 推荐(0)
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... 阅读(162) 评论(0) 推荐(0)
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... 阅读(112) 评论(0) 推荐(0)
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... 阅读(147) 评论(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... 阅读(126) 评论(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... 阅读(194) 评论(0) 推荐(0)
UVA540 - Team Queue
摘要:这个题是我放了好久才过的:开始的时候,我的思路并没有错误,不过程序的逻辑上有问题,对于,team_num.cout 在data出栈时我忘了变化。后来,我花费了一个晚上,终于找到错误所在,真的是找自己的错误比挑别人的错误难的多啊,顺着自己的思路找了好久也没找到。最后,在大神的一组数组测试下。我终于找到了wrong;由此,我在说一句我颇有感触的一句话:对于一个看着非常复杂的题或者一个程序,从心底里你不能害怕它,要勇敢的面对才是。先插入一组测试数据:4 4 0 1 2 3 4 4 5 6 7 4 8 9 10 11 4 12 13 14 15 ENQUEUE 6 ENQUEUE 14 ENQUEUE 阅读全文
posted @ 2012-11-05 21:26 Primo... 阅读(162) 评论(0) 推荐(0)
UVA699 - The Falling Leaves
摘要:这个题我WA了5遍。知道为什么吗?第一个空格输出的不符合要求:如果在b[]中,空格,我确实讨论了。而且确信无的正确、但是如果这棵树只有右儿子的话,在输出a[] 我却忘了讨论。早知这样,还不如把左右儿子放到一个数组中呢。思路:不用建树,只需用先序的方法遍历一遍即可。把所有的叶子堆,放到数组中,仔细观察便可得出所有叶堆间的规律。发话不多说,代码如下:#include #include using namespace std; int a[85], b[85], alen, blen;//定义a ,b两个数组,分别记录标号为正和为负的叶堆; int move(int x) { int d... 阅读全文
posted @ 2012-11-04 18:55 Primo... 阅读(132) 评论(0) 推荐(0)
UVA712 S-Trees
摘要:对于这道题,真的不知道我是该说这道题太坑了,还是说我太水了!!!看了三四遍愣是没把f()函数的意思看懂,搜了一篇题解才知道这道题是这么个意思。给出一颗完全二叉树的所有末节点,然后按照路径输出对应节点的值;0->left: 1->right;代码也不长,就是理解题意花费的时间长,无奈,英语不好,只能认了!!!代码如下:#include #include using namespace std; bool node[1>n&&n) { ++x; cout>s; for(int i = 0; i >m; while(m--... 阅读全文
posted @ 2012-11-03 14:43 Primo... 阅读(127) 评论(0) 推荐(0)
UVA 297 - Quadtrees
摘要:我自己的神码,祸害了我两天的时间:各种逻辑错误,小型代码错误:思路倒不难,只是这段时间代码敲的少,能力严重下降了!!!主要是用递归函数来模拟人的比较方法。和二叉树的逻辑差不多的。代码如下:#include #include using namespace std; string s1, s2; int black; int s1n, s2n; int mypow(int e, int n)//我自己写的pow()函数; { int sum= 1; for(int i = 0; i >num; while(num--) { black = s1... 阅读全文
posted @ 2012-11-02 22:18 Primo... 阅读(158) 评论(0) 推荐(0)