随笔分类 -  ACM — 搜索

摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=25662 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 #include 8 9 #define N 150 10 using namespace std; 11 12 struct Nod 13 { 14 int x,y,step; 15 }node[15000]; 16 17 int map[N][N]; 18 int mark[N][N]; 19 int p... 阅读全文
posted @ 2013-11-04 16:36 crazy_apple 阅读(309) 评论(0) 推荐(0)
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=33656【题解】:暴力搜索题【code】: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 char map[100][100]; 10 int vis[100][100]; 11 int n,m; 12 int B,F; 13 int cx[]={0,-1,1,-1,1,-1,0,1}; 14 int cy[]={1,0,1,-1,-1,1,-1... 阅读全文
posted @ 2013-10-05 15:06 crazy_apple 阅读(251) 评论(0) 推荐(0)
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4187【题意】:如题【题解】:取n,m的最小值进行遍历就可以了: 注意 0 1 这组测试数据【code】: 1 #include 2 #include 3 #include 4 #include 5 #include 6 7 using namespace std; 8 9 int main()10 {11 int t;12 scanf("%d",&t);13 while(t--)14 {15 int n,m;16 ch... 阅读全文
posted @ 2013-09-28 15:07 crazy_apple 阅读(239) 评论(0) 推荐(0)
摘要:http://www.bnuoj.com/bnuoj/contest_show.php?cid=2876#problem/31796【题意】: 如题,注意大小写情况【code】: 1 #include 2 #include 3 #include 4 #include 5 #include 6 #include 7 8 using namespace std; 9 10 struct Nod 11 { 12 int x,y,step; 13 }nd1,nd2; 14 15 int step[500][500]; 16 char temp[500]; ... 阅读全文
posted @ 2013-09-25 17:59 crazy_apple 阅读(404) 评论(0) 推荐(0)
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=1071【题意】:经过四个点的顺逆时针旋转,得到最终拼图【题解】:康拓展开+BFS,注意先预处理,得到所有状态,然后用hash来调用存在的状态【code】: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 #define N 363000 8 9 struct Nod 10 { 11 int b[10]; 12 int pos; 13 }nd1,nd2; 14 ... 阅读全文
posted @ 2013-09-21 19:40 crazy_apple 阅读(268) 评论(0) 推荐(0)
摘要:http://www.bnuoj.com/bnuoj/problem_show.php?pid=4358【题意】:给定起始位置和方向和目的地,按照左转、前进、右转、后退的优先级递减,也就是说能左转就左转,不能则继续前进,。。。,能走到T的位置输出YES,不能则输出NO。。。【题解】: 首先我们知道YES肯定就是走到了,若出现NO的情况,肯定是出现了死循环,这题主要考标记,什么时候表示已经进入了死循环呢?每个位置有一个方向,我们将这个位置第一次出现方向的时候标记下来,注意是第一次的方向噢,第二次经过的时候判断,是否方向相同,相同则表示出现了跟之前一样的状态,也就是说出现了循环。。。【code】. 阅读全文
posted @ 2013-09-17 20:31 crazy_apple 阅读(447) 评论(0) 推荐(0)
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4740【题意】: 森林里有一只驴和一只老虎,驴和老虎互相从来都没有见过,各自自己走过的地方不能走第二次,都会朝着一个方向走,直到这个方向不能走,然后转向,驴只会右转,老虎只会左转,当转过一次之后还是不能往前走,那么它就停下来不再移动了。。。问驴和老虎是否能相遇在一个坐标点。。。【题解】: 暴力搜索,模拟过程就能过,不存在超时问题【code】: 1 /* 2 JudgeStatus:Accepted time:15MS 3 Memory:4212K codeLenght:2591B... 阅读全文
posted @ 2013-09-15 17:22 crazy_apple 阅读(336) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=4707【题目大意】:Lin Ji 的宠物鼠丢了,在校园里寻找,已知Lin Ji 在0的位置,输入N D,N表示校园中点的个数,D表示宠物鼠不可能在距离D之内,接下来N-1行,输入x,y,表示x与y相邻,(相邻两点之间的距离为1,不相邻为inf),不存在环结构。【题解】:用邻接表存储树形结构,然后用DFS遍历图【code】: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 #define NN 100010 ... 阅读全文
posted @ 2013-09-09 21:23 crazy_apple 阅读(542) 评论(1) 推荐(0)
摘要:http://poj.org/problem?id=2186Popular CowsTime Limit:2000MSMemory Limit:65536KTotal Submissions:20191Accepted:8193DescriptionEvery cow's dream is to become the most popular cow in the herd. In a herd of N (1 7 #include 8 #include 9 #include 10 #include 11 #include 12 13 #define N 10010 14 using. 阅读全文
posted @ 2013-08-10 17:16 crazy_apple 阅读(222) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1659Frogs' NeighborhoodTime Limit:5000MSMemory Limit:10000KTotal Submissions:6050Accepted:2623Special JudgeDescription未名湖附近共有N个大小湖泊L1,L2, ...,Ln(其中包括未名湖),每个湖泊Li里住着一只青蛙Fi(1 ≤i≤N)。如果湖泊Li和Lj之间有水路相连,则青蛙Fi和Fj互称为邻居。现在已知每只青蛙的邻居数目x1,x2, ...,xn,请你给出每两个湖泊之间的相连关系。Input第一行是测试数据的组数T 阅读全文
posted @ 2013-08-07 18:26 crazy_apple 阅读(237) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3249Test for JobTime Limit:5000MSMemory Limit:65536KTotal Submissions:8206Accepted:1831DescriptionMr.Dog was fired by his company. In order to support his family, he must find a new job as soon as possible. Nowadays, It's hard to have a job, since there are swelling num 阅读全文
posted @ 2013-08-07 16:26 crazy_apple 阅读(345) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=3373Changing DigitsTime Limit:3000MSMemory Limit:65536KTotal Submissions:2719Accepted:863DescriptionGiven two positive integersnandk, you are asked to generate a new integer, saym, by changing some (maybe none) digits ofn, such that the following properties holds:mcontains 阅读全文
posted @ 2013-07-30 16:41 crazy_apple 阅读(430) 评论(0) 推荐(0)
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1560BFS题解:http://www.cnblogs.com/crazyapple/p/3218107.html构造一个串,使得它包含所有的给定DNA序列,并且要求长度最短。采用dfs策略,对于每个串定义1个指针,当全部指针为串尾时判断构造的长度,由于状态空间过大,但是又存在冗余搜索,可以用迭代加深将状态减少。最长待构造长度 + 当前长度 2 #include 3 #include 4 5 using namespace std; 6 7 struct Nod 8 { 9 int p... 阅读全文
posted @ 2013-07-27 12:18 crazy_apple 阅读(481) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1560DNA sequenceTime Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 732 Accepted Submission(s): 356 Problem DescriptionThe twenty-first century is a biology-technology developing century. We know that a gene 阅读全文
posted @ 2013-07-26 21:44 crazy_apple 阅读(958) 评论(0) 推荐(0)
摘要:http://acm.hdu.edu.cn/showproblem.php?pid=1043http://poj.org/problem?id=1077EightTime Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9173 Accepted Submission(s): 2473 Special JudgeProblem DescriptionThe 15-puzzle has been around for over 100 years; 阅读全文
posted @ 2013-07-25 16:06 crazy_apple 阅读(425) 评论(0) 推荐(0)
摘要:http://ac.nbutoj.com/Problem/view.xhtml?id=1479[1479] How many时间限制: 1000 ms 内存限制: 65535 K问题描述There are N numbers, no repeat. All numbers is between 1 and 120, and N is no more than 60. then given a number K(1 2 #include 3 #include 4 #include 5 6 using namespace std; 7 int dp[110]; 8 9 int main... 阅读全文
posted @ 2013-07-20 08:57 crazy_apple 阅读(212) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1191棋盘分割Time Limit:1000MSMemory Limit:10000KTotal Submissions:10776Accepted:3791Description将一个8*8的棋盘进行如下分割:将原棋盘割下一块矩形棋盘并使剩下部分也是矩形,再将剩下的部分继续如此分割,这样割了(n-1)次后,连同最后剩下的矩形棋盘共有n块矩形棋盘。(每次切割都只能沿着棋盘格子的边进行)原棋盘上每一格有一个分值,一块矩形棋盘的总分为其所含各格分值之和。现在需要把棋盘按上述规则分割成n块矩形棋盘,并使各矩形棋盘总分的均方差最小。均方差,其中平均 阅读全文
posted @ 2013-06-04 23:05 crazy_apple 阅读(208) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1426Find The MultipleTime Limit:1000MSMemory Limit:10000KTotal Submissions:14519Accepted:5893Special JudgeDescriptionGiven a positive integer n, write a program to find out a nonzero multiple m of n whose decimal representation contains only the digits 0 and 1. You may assu 阅读全文
posted @ 2013-06-03 22:13 crazy_apple 阅读(456) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=1321棋盘问题Time Limit:1000MSMemory Limit:10000KTotal Submissions:17792Accepted:8809Description在一个给定形状的棋盘(形状可能是不规则的)上面摆放棋子,棋子没有区别。要求摆放时任意的两个棋子不能放在棋盘中的同一行或者同一列,请编程求解对于给定形状和大小的棋盘,摆放k个棋子的所有可行的摆放方案C。Input输入含有多组测试数据。每组数据的第一行是两个正整数,n k,用一个空格隔开,表示了将在一个n*n的矩阵内描述棋盘,以及摆放棋子的数目。 n <= 8 阅读全文
posted @ 2013-06-02 21:54 crazy_apple 阅读(208) 评论(0) 推荐(0)
摘要:http://poj.org/problem?id=2488A Knight's JourneyTime Limit:1000MSMemory Limit:65536KTotal Submissions:24572Accepted:8305DescriptionBackground The knight is getting bored of seeing the same black and white squares again and again and has decided to make a journey around the world. Whenever a knig 阅读全文
posted @ 2013-05-30 21:03 crazy_apple 阅读(397) 评论(0) 推荐(0)