自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(48)
  • 收藏
  • 关注

原创 hdu 1166

看起来是要模拟,但是如果用朴素数据结构(随机存取数组)的话肯定会超时,所以选择了树状数组#include #include #include #include #include using namespace std ;const int maxn = 50000+1;int ncase , tree[maxn] , n ;void init(){......

2011-03-22 20:11:00 635

原创 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 481

原创 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 994

原创 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 658

原创 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 820

原创 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 801

原创 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 586

原创 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 708

原创 hdu 1181

<br />dfs<br />#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace std ;const int maxn = 1000 + 10 ;char s[maxn] , e[maxn] ;char str[maxn] ;int cnt , flag , vis[maxn] ;void dfs

2011-03-06 19:44:00 1107

原创 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 682

原创 poj 1321

<br />回溯<br />#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <cmath>using namespace std ;const int maxn = 9 ;char map[maxn][maxn] , vis[maxn] ;int ans , n , k , cnt ;void init(){ memset( vi

2011-03-05 18:37:00 397

原创 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 573

原创 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 506

原创 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 846

原创 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 895

原创 4009

<br />因为只有二十四个数,并且答案唯一 , 所以可以将答案保存到ans数组中<br />#include <iostream>#include <cstring>using namespace std ;//以下为找答案的过程//int a[1 << 24 ][25] ;//int n , c ;//double ans = 0 ;//int data[25][25] ;////void printsubset( int n , int s )//{

2010-11-03 17:23:00 713

原创 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 1241

原创 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 1372 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 857

原创 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 503

原创 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 1477

原创 uva 10047

哈哈,错了错了,全错了..........  做这道题给我的启发不少,首先,我对visit数组的认识有了一个新的认识,以前一直认为它仅仅是标记一下到没到过一个占,现在才知道理解错了,以前仅仅是巧合.......我是水货......呵呵,不过现在知道了,它是用来表示某个状态是否出现过,也就是说同一个状态不能出现两次,明白了这点,就知道visit应该是个四维数组(在一个格子里,坐标,方向,颜色)........明白这点,以后的就和一以前的差不多了  但是,需要注意的是优先队列的使用,非常关键,我们需要每次都用最

2010-08-13 15:26:00 1652 1

原创 uva 705

<br />这道题是非常有意思的一道题,平常我们只在横竖之间徘徊,所以乍一看还真有些不会做,但事实上是真不会做,脑子一天总有些稀奇古怪的想法,但是当真正用到它们的时候,一个个全跑光了,太不仗义了,所以我去搜了下,发现竟然有人把一个点分成了四个,然后搜索。后来发现有更牛的,把一个点分成九个!这个太帅了,而且符合我的思想,所以就用它了。不管怎么样,他们都用到了一个思想,那就是把图给放大了,然后这些陌生的图就变为我们经常见到的东西。也就是说,不会斜的,我们可以把它给变直了,甚至可以把图给变成0和1这个总该会了吧?

2010-08-10 18:09:00 1137

原创 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 603

原创 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 633

原创 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 917

原创 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 476

原创 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 1212 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 906

原创 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 1118

原创 uva 327

<br />这个题我不知道它为什么会放在数据结构里,反正我是想不出来。如果说表达式里有乘除号或者括号的话,那我还能想到建立表达式树,但是这个.........<br />刚开始是想建树来着,后来发现没必要,但是又有非常麻烦的加加减减,所以想如果是 a + b 这样的多好,所以就要把各个数据给分离出来,然后一次扫描得出结果<br />如果有人有更简洁或者更高级的方法的话,请教下我,谢谢.......嘿嘿<br />#include <iostream>#include <cstring>#includ

2010-08-06 18:08:00 823

原创 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 930

原创 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 787

原创 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 1198 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 2021 1

原创 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 2635 2

原创 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 1587

原创 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 710

原创 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 1041

原创 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 1142

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除