
uva
文章平均质量分 81
wjjayo
这个作者很懒,什么都没留下…
展开
-
uva 208
<br />可能是因为从1到终点的路上并不包括所有的结点,所以需要预处理下,把路径上的所有点给挑出来,然后在这个路径上进行回溯就OK了,直接回朔是要TLE的......<br />#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std ;const int maxn = 22 ;int g[maxn][maxn原创 2011-03-22 20:09:00 · 503 阅读 · 0 评论 -
uva 131
<br />不解释,枚举子集<br />#include <iostream>#include <cstring>#include <cstdlib>using namespace std ;struct poke { char f ; char s ; int v ; } ;poke hand[5] , deck[5] , temp[5] ;char Ans[][20] = { "straight-flush" , "four-of-a-kin原创 2010-11-06 15:17:00 · 923 阅读 · 0 评论 -
uva 11205
<br />正如acb0y所说,很黄很暴力,学到了枚举子集<br />#include <iostream>#include <cstring>#include <cstdlib>using namespace std ;int ncase ;int p , n , c ;char data[101][16] ;bool vis[16] ;int a[40000][20] ;char tem[101][16] ;int ans ;void input(原创 2010-10-26 12:38:00 · 1259 阅读 · 0 评论 -
uva 10054
<br />还是欧拉回路,师兄帮忙,嘿嘿.........<br />#include <iostream>#include <cstring>using namespace std ;const int maxn = 50 + 10 ;int G[maxn][maxn] ;int d[maxn] ;bool visit[maxn] ;int cnt ;int node ;int bu ;void init(){ memset( G ,原创 2010-08-18 13:36:00 · 1393 阅读 · 1 评论 -
uva 10596
<br />这道题据说有问题,但是是欧拉回路一类的问题是确定无疑的<br />#include <iostream>#include <cstring>using namespace std ;const int maxn = 200 + 10 ;bool G[maxn][maxn] ;bool visit[maxn] ;int d[maxn] ;int cnt ;void init(){ memset( G , false , sizeof( G原创 2010-08-18 13:32:00 · 880 阅读 · 0 评论 -
uva 10004
<br />一次遍历,直接得出结果,厉害!<br />#include <iostream>#include <cstring>#include <queue>using namespace std ;const int maxn = 200 + 10 ;int nn , ne ;bool G[maxn][maxn] ;int c[maxn] ;void init(){ memset( G , false , sizeof( G ) ) ;原创 2010-08-14 14:26:00 · 520 阅读 · 0 评论 -
uva 10305
<br />基本的拓扑排序<br />#include <iostream>#include <cstring>using namespace std ;const int maxn = 100 + 10 ;bool G[maxn][maxn] ;int c[maxn] ;int arr[maxn] ;int cnt ;bool dfs( int u , int n ){ c[u] = -1 ; for( int v = 1 ; v <原创 2010-08-14 14:23:00 · 1497 阅读 · 0 评论 -
uva 10047
哈哈,错了错了,全错了.......... 做这道题给我的启发不少,首先,我对visit数组的认识有了一个新的认识,以前一直认为它仅仅是标记一下到没到过一个占,现在才知道理解错了,以前仅仅是巧合.......我是水货......呵呵,不过现在知道了,它是用来表示某个状态是否出现过,也就是说同一个状态不能出现两次,明白了这点,就知道visit应该是个四维数组(在一个格子里,坐标,方向,颜色)........明白这点,以后的就和一以前的差不多了 但是,需要注意的是优先队列的使用,非常关键,我们需要每次都用最原创 2010-08-13 15:26:00 · 1690 阅读 · 1 评论 -
uva 705
<br />这道题是非常有意思的一道题,平常我们只在横竖之间徘徊,所以乍一看还真有些不会做,但事实上是真不会做,脑子一天总有些稀奇古怪的想法,但是当真正用到它们的时候,一个个全跑光了,太不仗义了,所以我去搜了下,发现竟然有人把一个点分成了四个,然后搜索。后来发现有更牛的,把一个点分成九个!这个太帅了,而且符合我的思想,所以就用它了。不管怎么样,他们都用到了一个思想,那就是把图给放大了,然后这些陌生的图就变为我们经常见到的东西。也就是说,不会斜的,我们可以把它给变直了,甚至可以把图给变成0和1这个总该会了吧?原创 2010-08-10 18:09:00 · 1174 阅读 · 0 评论 -
uva 216
一维数组上的回溯#include #include #include #include using namespace std ;const int maxn = 8 + 2 ;int n , vis[maxn] ;int x[maxn] , y[maxn] , ans[maxn] , tans[maxn] ;double d[maxn][maxn] ;double mmin ;double dis( int a , int b , int c , i原创 2011-03-05 09:34:00 · 879 阅读 · 0 评论 -
uva 639
#include #include #include #include #define m mapusing namespace std ;const int maxn = 5 ;int n , ans , vis[maxn][maxn] ;char map[maxn][maxn] ;void init(){ ans = 0 ; memset( vis , 0 , sizeof( vis ) ) ; memset( m原创 2011-03-05 09:35:00 · 527 阅读 · 0 评论 -
uva 208
<br />可能是因为从1到终点的路上并不包括所有的结点,所以需要预处理下,把路径上的所有点给挑出来,然后在这个路径上进行回溯就OK了,直接回朔是要TLE的......<br />#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std ;const int maxn = 22 ;int g[maxn][maxn原创 2011-03-18 09:42:00 · 1015 阅读 · 0 评论 -
uva 193
<br />需要注意的是要检查所有与当前结点cur相连接的结点,如果有黑色的(vis[v] == 1)则这个结点只能是白色的,否则,可以是黑色的,也可以是白色的......<br />#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>using namespace std ;const int maxn = 100 + 10 ;int g[ma原创 2011-03-16 15:02:00 · 684 阅读 · 0 评论 -
uva 140
<br />男人嘛,就应该暴力点<br />#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <algorithm>#include <cmath>using namespace std ;const int maxn = 100 + 10 ;char str[maxn] ;int ans , order[maxn] , torder[maxn] ,原创 2011-03-14 13:32:00 · 844 阅读 · 0 评论 -
uva 167
<br />正宗的八皇后,需要注意vis[i]中的元素个数一定是超过八个的<br />#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace std ;int map[8][8] , ans , vis[3][30] , ncase , c[8] ;void init(){ ans = 0 ;原创 2011-03-11 13:25:00 · 828 阅读 · 0 评论 -
uva 331
<br />绪哥说回溯一定是基于树上的,还说回溯一定是在枚举所有的排列......那这道题就应该是枚举的是应该交换的所有数对<br />#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std ;const int maxn = 6 ;int ans , a[maxn] , n , icase = 0 ;原创 2011-03-09 17:34:00 · 606 阅读 · 0 评论 -
uva 10344
<br />一道让我差点吐血的题呀,不是说有多么难想,而是因为有一个小细节卡了我好长时间,而如果好好读题或者养成一个良好的编程习惯的话是完全可以避免这种问题的,这个问题就是ftans中参数的顺序不同就能导致不同的中间结果呀....吐血一分钟<br />#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <cstdlib>using namespace std ;int a原创 2011-03-08 16:02:00 · 723 阅读 · 0 评论 -
uva 301
<br />还是回溯<br />#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <cmath>using namespace std ;const int maxn = 23 ;struct Order { int s , d , num ; } order[maxn] ;int n , b , o , ans , vis[maxn] ;v原创 2011-03-06 19:39:00 · 701 阅读 · 0 评论 -
uva 539
<br />还是回溯,但是需要注意的是因为起点不同能够导致结果不同,所以每个点都要作为起点然后枚举,找到最大的,输出就O了<br />#include <iostream>#include <cstring>#include <cstdio>#include <cmath>using namespace std ;const int maxn = 26 ;int g[maxn][maxn] , vis[maxn][maxn] ;int n , m , ans ,原创 2011-03-05 16:16:00 · 595 阅读 · 0 评论 -
uva 439
跳马问题,只要把方向数组给写好了,一切都制定。经典bfs#include #include #include using namespace std ;const int maxn = 8 + 2 ;struct Node { int r ; int c ; int step ; } node1 , node2 ;queue q ;bool visit[maxn][maxn] ;int dr[] = { -2 , -2 , -1 , -1 , 1 ,原创 2010-08-09 09:35:00 · 620 阅读 · 0 评论 -
uva 532
<br />这道题是最基本的bfs,但是在三维上玩,所以有必要说一下三维数组在计算机里的存储与我们逻辑上存储的不同。<br />在计算机里,所有的存储都不会超过一维,所谓的维,只是在你自己脑子里想象出来的(我想象过四维,但是失败了.....),它只会一行一行地帮你把数据压入栈堆,说这么抽象干嘛,举个例子吧<br />比如说,在你想象中二维数组是这么存的<br />1 2 3<br />4 5 6<br />7 8 9<br />但是它们在计算机中是这么存的: 1 2 3 4 5 6 7 8 9<br />可原创 2010-08-09 09:33:00 · 650 阅读 · 0 评论 -
uva 712
首先得读懂题意,然后就非常好办了,用到一个性质:如果我们把一棵二叉树的结点按照从上到下,从左到右的顺序编号(1.......n)那么第 i个结点的左儿子的编号是 i * 2 , 右儿子的编号是 i * 2 + 1 。#include #include #include using namespace std ;const int maxn = 1024 ;char node[maxn] ;//叶子结点int map[7] ;//初始化void init(){原创 2010-08-06 10:20:00 · 810 阅读 · 0 评论 -
uva 10050
<br />大水题,不想说什么,我在头脑非常不清醒的状态下1A<br />#include <iostream>using namespace std ;const int maxn = 100 + 10 ;int party[maxn] ;bool visit[36500 +10] ;void init(){ memset( party , 0 , sizeof( party ) ) ; memset( visit , 0 , sizeof( v原创 2010-08-03 14:14:00 · 729 阅读 · 0 评论 -
uva 540
<br />题目的意思很明显,每个队列在一个大队列排队,如果有队友,则加入队友在大队列(队列的队列)的后面,所以想到了用二维队列,每一行的队列都应该有一个头指针与队尾指针,而且有个二维队列的头指针.........如果题目要求的话,也可以加个二维队列的队尾指针<br />#include <iostream>#include <string>using namespace std ;const int maxn = 1000 + 10 ;int r , c ;int qfro原创 2010-08-04 09:12:00 · 1607 阅读 · 0 评论 -
uva 11234
<br />关键是建表达式树,这个太厉害了,树一有,层次遍历就能得出结果,建树部分是学ACboy 的.....呵呵,不会就要学嘛<br />#include <iostream>#include <cstring>#include <cstdlib>using namespace std ;const int maxn = 10000 + 10 ;struct Node { Node * left ; Node * right ; char op ; } node ;原创 2010-08-03 14:09:00 · 1064 阅读 · 0 评论 -
uva 673
<br />一看就知道用栈模拟,如果题目中有除了括号外的其他字符,把is_ok函数加上即可<br />#include <iostream>using namespace std ;const int maxn = 128 + 10 ;struct { char str[maxn] ; int top ; } Stack ;char str[maxn] ;void init(){ memset( str , 0 , sizeof( str ) ) ;原创 2010-08-01 12:41:00 · 1241 阅读 · 0 评论 -
uva 10152
<br />这道题的关键是如何确定最短的顺序?<br />答案是:只有当他们的相对顺序的不对的时候(当前元素与栈顶元素在当前序列与最终序列的相对前后不一样),就进行题中所说的操作(让栈顶乌龟爬到最前)<br />另外,因为题目中说的操作是从当前位置爬到最顶,所以用栈的数据结构了........(个人看法,而且是和同学讨论得出,惭愧)<br />#include <iostream>#include <map>#include <vector>#include <queue>using n原创 2010-08-01 11:03:00 · 940 阅读 · 0 评论 -
uva 133
<br />这个题是我一个人写出来的第一道数据结构题,太不容易了,呵呵,虽然中间有想放弃,但还是坚持下来了,不错!<br />大体是猴子选山大王那个意思, 不过在找完后要有相应的操作........<br />如果wa,可以试下下面的测试数据,我写的<br />Sample input<br />10 4 2<br />10 5 2<br />10 4 3<br />10 5 3<br />10 1 2<br />10 2 3<br />10 3 4<br />10 4 5<br />10 5 6<br /原创 2010-07-31 17:21:00 · 1386 阅读 · 2 评论 -
uva 11111
<br />这个题可以把一对正负数看成一个括号,都说这么明显了,其他的就不用说了吧.........呵呵,需要注意的是在字符串里把数字给分离出来的方法( 两个数字中间有多个空格的情况在测试数据中有可能出现 ) ,而且也有可能有空行..........<br />#include <iostream>#include <cstring>#include <cstdlib>using namespace std ;const int maxn = 100000 + 10 ;str原创 2010-08-02 08:41:00 · 1163 阅读 · 0 评论 -
uva 442
<br />#include <iostream>using namespace std ;const int maxn = 26 + 10 ;struct Matrix { char name ; int r ; int c ; int num ; } mat , node1 , node2 , node ;struct { char str[100+10] ; int top ; } pStack ;struct { Matrix mat[maxn] ; int top原创 2010-08-01 15:45:00 · 1024 阅读 · 0 评论 -
uva 112
<br />这个题目考的就是仔细程度,树结点为空必须赋为null,因为ans可能为0呵呵,就是这个让我wa的好多次(我将空结点的数值全赋为0),还有就是负数的问题了(这个我是想到了的,嘿嘿)<br />#include <iostream>#include <cstring>#include <cstdlib>using namespace std ;const int maxn = 10000 + 10 ;struct Node { Node * left ; Node *原创 2010-08-04 15:38:00 · 2654 阅读 · 2 评论 -
uva 548
亮点是递归构造二叉树,还有就是有一个非常重要的知道点,某个子树后序遍历的最后一个结点一定是该子树的根结点,而中序遍历中左子树全位于根结点的左侧,右子树全位于根子树的右侧#include #include #include using namespace std ;const int maxn = 10000 + 10 ;struct Node { Node * left ; Node * right ; int data ; } ;char str1[maxn*10]原创 2010-08-05 11:36:00 · 2037 阅读 · 1 评论 -
uva 297
<br />建造四叉树是个难点,何时知道有四个儿子结点已经入栈呢?答案是当栈顶连续四个结点都是某个结点的儿子时,就应该将其出栈合成一个父亲结点,并且入栈。而且如果某层的结点是黑,那么它下方的结点就不用再考虑了,因为合成时是优先选择面积最大的黑色块<br />#include <iostream>#include <cstring>#include <cstdlib>using namespace std ;const int maxn = 2048 + 10 ;struct原创 2010-08-05 19:09:00 · 1222 阅读 · 2 评论 -
uva 784(dfs)
<br />#include <iostream>#include <cstring>using namespace std ;const int maxx = 30 + 10 ;const int maxy = 80 + 10 ;struct Node { int x ; int y ; } node1 , node2 ;int r ;int bx ; int by ;char map[maxx][maxy] ;bool visit[maxx][ma原创 2010-08-08 13:31:00 · 933 阅读 · 0 评论 -
uva 784(bfs)
这个题刚开始用手动队列写的(数组版),但是运行错误不知道为什么,后来改成stl 的过了,有谁拿数组写的过了请教下我,谢谢#include #include #include using namespace std ;const int maxx = 30 + 10 ;const int maxy = 80 + 10 ;struct Node { int x ; int y ; } node1 , node2 ;queue q ;int r ;int原创 2010-08-08 13:29:00 · 491 阅读 · 0 评论 -
uva 657
<br />题目大致是说要你在一个大图里搜四连块(每个四连块表示一个色子面)的个数,在每个四连块里搜色子的点数,点数只能是1到6之间的数.......<br />#include <iostream>#include <cstring>using namespace std ;const int maxn = 50 + 10 ;char map[maxn][maxn] ;bool visit[maxn][maxn] ;int ans[maxn * maxn] ;int原创 2010-08-08 09:49:00 · 1242 阅读 · 2 评论 -
uva 10562
<br />这是一个很有意思的题目,一看就知道是递归的一个过程,但是要注意的是这句话:<br />The labels of each of node can be any printable character except for the symbols '-', '|', ' ' (space) and '#'.<br />所以不一定只有字母才是结点,晕......<br />#include <iostream>#include <cstring>using namespace std原创 2010-08-07 17:51:00 · 921 阅读 · 0 评论 -
uva 839
<br />不需要建设树不需要建树呀,高人指点.......<br />#include <iostream>#include <cstring>using namespace std ;int ok = 0 ;int dfs(){ int a , b , c , d ; cin >> a >> b >> c >> d ; if( a && b && c && d )//如果都不为0说明到达叶子结点 { if( a * b原创 2010-08-07 13:14:00 · 1143 阅读 · 0 评论 -
uva 327
<br />这个题我不知道它为什么会放在数据结构里,反正我是想不出来。如果说表达式里有乘除号或者括号的话,那我还能想到建立表达式树,但是这个.........<br />刚开始是想建树来着,后来发现没必要,但是又有非常麻烦的加加减减,所以想如果是 a + b 这样的多好,所以就要把各个数据给分离出来,然后一次扫描得出结果<br />如果有人有更简洁或者更高级的方法的话,请教下我,谢谢.......嘿嘿<br />#include <iostream>#include <cstring>#includ原创 2010-08-06 18:08:00 · 843 阅读 · 0 评论 -
uva 699
<br />读入数据与标记结点的列数在解决这道题的过程中是个非常重要的问题<br />#include <iostream>#include <cstring>using namespace std ;const int maxn = 10000 + 10 ;struct Node { Node * left ; Node * right ; int data ; bool visit ; int cul ; } ;Node * Stack[maxn] ;int an原创 2010-08-06 15:13:00 · 949 阅读 · 0 评论