摘要: 剪枝不好想啊。。。a到b别管绕多远,所走过的格子数的奇偶性和它俩最短路的奇偶性相同。代码。。。#include <stdio.h>#include <math.h>int d[4][2] = {{0,1},{0,-1},{-1,0},{1, 0}};int flag;int n, m, t, flag;int di, dj;char map[9][9];void dfs(int si, int sj, int cnt){ if(si == di && sj == dj && cnt == t) flag = 1; if(flag) ret 阅读全文
posted @ 2011-08-02 10:27 AC_Von 阅读(236) 评论(0) 推荐(1) 编辑
摘要: 这道题有很多种解法,可以用qsort,也可以用Trie树,Trie树做时需要开静态数组开辟空间,动态分配会TLE!在Discuss里看到两组数据,注意一下221122121NONO下面是Trie树做法,在做题之前被某人提醒静态数组不要开得太大,否则会MLE,结果我就悲剧的RE了一晚上!! 2780K110MSView Code #include <stdio.h>#include <string.h>typedef struct node{ int flag; struct node * next[10];}node;node num[500000];int x = 0 阅读全文
posted @ 2011-07-31 20:29 AC_Von 阅读(285) 评论(0) 推荐(0) 编辑
摘要: 大家都知道,Trie树(又称字典树)是一种树型数据结构,用于保存大量的字符串。它的优点是:利用字符串的公共前缀来节约存储空间。相对来说,Trie树是一种比较简单的数据结构,比较易于理解。话说上帝是公平的,简单的东西是要付出相应的代价的!Trie树也有它的缺点,它的内存消耗非常大。下面介绍一个减小内存消耗的小技巧。 我们先看看这个题目:http://acm.sdut.edu.cn/judgeonline/showproblem?problem_id=1500 看看这段程序:#include <stdio.h>#include <string.h>#include < 阅读全文
posted @ 2011-07-31 18:35 AC_Von 阅读(2577) 评论(2) 推荐(1) 编辑
摘要: 使用并查集查找时,如果查找次数很多,那么使用朴素版的查找方式肯定要超时。比如,有一百万个元素,每次都从第一百万个开始找,这样一次运算就是10^6,如果程序要求查找个一千万次,这样下来就是10^13,肯定要出问题的。 这是朴素查找的代码,适合数据量不大的情况:int findx(int x){ int r=x; while(parent[r] !=r) r=parent[r]; return r;} 下面是采用路径压缩的方法查找元素:int find(int x) //查找x元素所在的集合,回溯时压缩路径{ if (x != parent[x]) { parent[x] = find(pare. 阅读全文
posted @ 2011-07-31 16:02 AC_Von 阅读(5668) 评论(1) 推荐(4) 编辑
摘要: 结构体能自由组装数据,是一种很常见的数据打包方法。当我们定义一个结构体后,没有初始化就使用,就会使用到垃圾数据,而且这种错误很难发现。对于定义的任何变量,我们最好都先初始化。除了使用memset和ZeroMemory之外,有没有更简单的方法初始化呢?因为有时候每定义一个结构体,就使用一次memset,也会觉得很繁琐。我这里总结三种方法,如果大家有什么好的方法,不妨加上去。1、结构体的构造函数中初始化。2、继承模板类初始化3、定义时初始化在C++中,结构体与类在使用上已没有本质上的区别了,所以可以使用构造函数来初始化。如下代码所示:struct Stu{intnNum;boolbSex;char 阅读全文
posted @ 2011-07-30 17:01 AC_Von 阅读(30110) 评论(1) 推荐(4) 编辑
摘要: 注意将后一个数插到前一个数上,然后用队列每次存储入度为0的数,累加同一工资级别的人的工资View Code #include <stdio.h>#include <stdlib.h>#include <string.h>#define N 10005typedef struct node //邻接表节点{ int adj; //节点值 struct node * next;}node;struct //顶点{ int in; //入度 node * next;}v[N];int visited[N], queue[N], front, rear;void i 阅读全文
posted @ 2011-07-30 16:42 AC_Von 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 转载自大牛Matrix67的博客http://www.matrix67.com/blog/archives/115 如果机房马上要关门了,或者你急着要和MM约会,请直接跳到第六个自然段。我们这里说的KMP不是拿来放电影的(虽然我很喜欢这个软件),而是一种算法。KMP算法是拿来处理字符串匹配的。换句话说,给你两个字符串,你需要回答,B串是否是A串的子串(A串是否包含B串)。比如,字符串A="I'm matrix67",字符串B="matrix",我们就说B是A的子串。你可以委婉地问你的MM:“假如你要向你喜欢的人表白的话,我的名字是你的告白语中的子 阅读全文
posted @ 2011-07-30 11:46 AC_Von 阅读(617) 评论(0) 推荐(1) 编辑
摘要: 邻接表实现图的深度遍历,纠结的问题啊。。。。。View Code #include <stdio.h>#include <malloc.h>#define MAX 100typedef struct arcnode/*表节点*/{ int adjvex; /*邻接点*/ struct arcnode *nextarc;/*指向下一条弧的指针*/}arcnode;typedef struct vnode /*头结点*/{ int data; /*定点信息*/ arcnode * firstarc; /*指向第一个依附该顶点的弧的指针*/}vnode, adjlist[MA 阅读全文
posted @ 2011-07-29 19:59 AC_Von 阅读(676) 评论(0) 推荐(0) 编辑
摘要: 确定比赛名次Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3389Accepted Submission(s): 1213Problem Description有N个比赛队(1<=N<=500),编号依次为1,2,3,。。。。,N进行比赛,比赛结束后,裁判委员会要将所有参赛队伍从前往后依次排名,但现在裁判委员会不能直接获得每个队的比赛成绩,只知道每场比赛的结果,即P1赢P2,用P1,P2表示,排名时P1在P2之前。现在请你编程序确 阅读全文
posted @ 2011-07-29 14:25 AC_Von 阅读(305) 评论(0) 推荐(0) 编辑
摘要: 大明A+BTime Limit: 3000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3081Accepted Submission(s): 947Problem Description话说,经过了漫长的一个多月,小明已经成长了许多,所以他改了一个名字叫“大明”。这时他已经不是那个只会做100以内加法的那个“小明”了,现在他甚至会任意长度的正小数的加法。现在,给你两个正的小数A和B,你的任务是代表大明计算出A+B的值。Input本题目包含多组测试数据,请处理到文件结束。每 阅读全文
posted @ 2011-07-29 08:01 AC_Von 阅读(273) 评论(0) 推荐(0) 编辑
摘要: Truck HistoryTime Limit:2000MSMemory Limit:65536KTotal Submissions:9665Accepted:3556DescriptionAdvanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. 阅读全文
posted @ 2011-07-28 11:11 AC_Von 阅读(565) 评论(0) 推荐(1) 编辑
摘要: 转载:http://blog.csdn.net/akof1314/article/details/4388304 图的存储方式可以用邻接矩阵来表示,我们假定顶点序号从0开始,即图G的顶点集的一般形式是V(G)={v0,vi,…,Vn-1}。以下代码测试过,为图的邻接矩阵表示方式。测试结构如下(含测试数据):View Code /************************************************************************//* 图的邻接矩阵存储结构 *//********************************************. 阅读全文
posted @ 2011-07-28 08:10 AC_Von 阅读(973) 评论(0) 推荐(0) 编辑
摘要: 转载:http://blog.sina.com.cn/s/blog_616694280100f06p.html图的两种存储方式:邻接矩阵和邻接表;两种遍历方式:深度优先和广度优先;首先以一个结构体存储一个图:struct MGraph{int vertex[maxvertex];//存顶点int arc[maxvertex][maxvertex];//存边(邻接矩阵)int vertexnum,arcnum;//顶点数和边数};其次是对图的初始化:void CreatMGraph(MGraph *&G){int i,j;cin1>>G->vertexnum>&g 阅读全文
posted @ 2011-07-27 15:28 AC_Von 阅读(5721) 评论(0) 推荐(0) 编辑
摘要: Is there a tree?Time Limit : 2000/1000ms (Java/Other)Memory Limit : 65536/32768K (Java/Other)Total Submission(s) : 19Accepted Submission(s) : 3Font:Times New Roman|Verdana|GeorgiaFont Size:←→Problem DescriptionA tree is a well-known data structure that is either empty (null, void, nothing) or is a s 阅读全文
posted @ 2011-07-25 17:45 AC_Von 阅读(329) 评论(0) 推荐(0) 编辑
摘要: 最优合并问题Time Limit:1000MS Memory Limit:65536KTotal Submit:19 Accepted:8Description给定k 个排好序的序列s1, s2,……, sk, 用2 路合并算法将这k 个序列合并成一个序列。假设所采用的2 路合并算法合并2 个长度分别为m和n的序列需要m + n -1次比较。试设计一个算法确定合并这个序列的最优合并顺序,使所需的总比较次数最少。为了进行比较,还需要确定合并这个序列的最差合并顺序,使所需的总比较次数最多。对于给定的k个待合并序列,计算最多比较次数和最少比较次数合并方案。Input输入数据的第一行有1 个正整数k( 阅读全文
posted @ 2011-07-24 16:53 AC_Von 阅读(2523) 评论(0) 推荐(1) 编辑
摘要: 代码+注释:#include <stdio.h>#define N 10000int num[N], a[N];void heap_adjust(int x, int y){ int i = x, tmp = num[x]; int j = i<<1; //j左移一位,即i*2 while(j <= y) //当未超过堆底时 { if(j < y && num[j+1] < num[j]) j++; //如果右孩子比左孩子小,j++ if(tmp > num[j]) //升序 { num[i] = num[j]; i = j; j 阅读全文
posted @ 2011-07-24 15:43 AC_Von 阅读(209) 评论(0) 推荐(0) 编辑
摘要: View Code #include<stdio.h>#define N 100#define MAX 10000000void Merge(int a[], int low, int mid, int high){ int n1 = mid-low+1; int n2 = high-mid; int i; int x[N],y[N];//将要合并的两部分存放到两个数组中 for(i = 1; i <= n1; i++) { x[i] = a[i+low-1]; } for(i = 1; i <= n2; i++) { y[i] = a[low+n1+i-1]; } i 阅读全文
posted @ 2011-07-24 11:34 AC_Von 阅读(215) 评论(0) 推荐(0) 编辑
摘要: 递归建立二叉树,中序遍历。。。。View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#define N 10000int l[N], r[N], key[N], flag;void insert(int index, int x){ if(x <= key[index]) { if(l[index] == -1) l[index] = flag; else insert(l[index], x); } else { if(r[index] == -1) r[index] = 阅读全文
posted @ 2011-07-24 10:03 AC_Von 阅读(288) 评论(0) 推荐(0) 编辑
摘要: Linear Cellular AutomataA biologist is experimenting with DNA modification of bacterial colonies being grown in a linear array of culture dishes. By changing the DNA, he is able ``program" the bacteria to respond to the population density of the neighboring dishes. Population is measured on a f 阅读全文
posted @ 2011-07-23 20:47 AC_Von 阅读(574) 评论(0) 推荐(1) 编辑
摘要: Number SequenceTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40967Accepted Submission(s): 8785Problem DescriptionA number sequence is defined as follows:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7.Given A, B, and n, you are to 阅读全文
posted @ 2011-07-23 20:17 AC_Von 阅读(259) 评论(0) 推荐(0) 编辑
摘要: Let the Balloon RiseTime Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30537Accepted Submission(s): 9980Problem DescriptionContest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time i 阅读全文
posted @ 2011-07-23 19:21 AC_Von 阅读(248) 评论(0) 推荐(0) 编辑
摘要: 注:网上搜的第一篇1001这个就不用说了吧1002简单的大数1003DP经典问题,最大连续子段和1004简单题1005找规律(循环点)1006感觉有点BT的题,我到现在还没过1007经典问题,最近点对问题,用分治1008简单题1009贪心1010搜索题,剪枝很关键10111012简单题1013简单题(有个小陷阱)1014简单题1015可以看作搜索题吧1016经典的搜索1017简单数学题1018简单数学题1019简单数学题1020简单的字符串处理1021找规律的数学题1022数据结构的题(栈的应用)1023特殊的数(Catalan Number)1024经典DP,最大M子段和1025经典DP,最 阅读全文
posted @ 2011-07-23 18:46 AC_Von 阅读(441) 评论(0) 推荐(1) 编辑
摘要: SnowflakeSnowSnowflakesTime Limit: 4000MSMemory Limit: 65536KTotal Submissions: 18478Accepted: 4770DescriptionYou may have heard that no two snowflakes are alike. Your task is to write a program to determine whether this is really true. Your program will read information about a collection of snowfl 阅读全文
posted @ 2011-07-23 17:27 AC_Von 阅读(356) 评论(0) 推荐(1) 编辑
摘要: Message FloodTime Limit:1500MS Memory Limit:65536KTotal Submit:284 Accepted:40DescriptionWell, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits people a lot". However, If you ask Merlin this question on the New Year& 阅读全文
posted @ 2011-07-23 14:51 AC_Von 阅读(463) 评论(0) 推荐(0) 编辑
摘要: Hangman JudgeIn ``Hangman Judge,'' you are to write a program that judges a series of Hangman games. For each game, the answer to the puzzle is given as well as the guesses. Rules are the same as the classic game of hangman, and are given as follows:The contestant tries to solve to puzzle by 阅读全文
posted @ 2011-07-23 08:22 AC_Von 阅读(524) 评论(0) 推荐(0) 编辑