每日一题
文章平均质量分 75
daisylove
这个作者很懒,什么都没留下…
展开
-
1-20两两相邻和为素数的所有组合(深搜)
纯深搜#include#include#include#includeusing namespace std;int status[21]; //status[i]==0表示当前路径path包含iofstream out("output.txt");bool isPrime(int n){ if(n==2) return true; if(n==1||n%2==0)原创 2015-01-06 22:27:41 · 722 阅读 · 0 评论 -
ZOJ 2100 seed
挺简单的深搜题。。但是因为粗心,跑完一个test case后没有正确地更新field数组(开始时为求精简竟然在格子(i,j)为 false时不令field[i][j] = false,原因是我以为field[6][6]是全局变量,默认情况是初始化为false,所以想当然地以为如果格子(i,j)是false就不用多次一举。。可是我忘了每次运行一个test case后field会改的。。SB了原创 2015-04-04 21:25:04 · 536 阅读 · 0 评论 -
Best Time to Buy and Sell Stock
题目来源于leetcode. 实质与求最大连续k个子区间和问题类似Say you have an array for which the ith element is the price of a given stock on day i.Design an algorithm to find the maximum profit. You may complete原创 2015-02-26 13:30:17 · 434 阅读 · 0 评论 -
zoj 1832 file fragmentation
题目其实不算难。可以先把片段按长度排序,对于长度相同的则再按字符串比较,这样相同的片段就会在一起,从而可以大大减少不必要的搜索。几次提交得到WA,于是自己构造5000组测试用例结果显示没有错。以为是zoj数据太刁钻,调了几个小时还是WA,最后终于发现是输入输出格式问题。。。坑爹!格式控制仍然是心中的痛哎看上去很费时,其实搜索速度很快,提交通过时间0ms,内存276KB。#include原创 2015-02-13 14:43:37 · 459 阅读 · 0 评论 -
LRU Cache [leetcode]
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set.get(key) - Get the value (will always be positive) of the key if原创 2015-01-21 17:56:10 · 460 阅读 · 0 评论 -
Repeated DNA Sequences [leetcode]
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACGAATTCCG". When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.Wri原创 2015-02-07 00:11:23 · 1335 阅读 · 0 评论 -
ZOJ-1002
题目来源ZOJ-1002: 简单的深搜题#include#include#includeusing namespace std;int city[4][4];int n,res;//在(i,j)处放blockhouse是否合法bool isLegal(int i,int j){ if(city[i][j]!=0) return false; int k,m原创 2015-01-02 14:09:21 · 481 阅读 · 0 评论 -
One-move Checkmate (ZOJ 1598)
题目来源ZOJ 1598搜索题,算法很简单,就是让白后在每个方向上不断搜,直到搜到某个位置能够让黑王无路可走。但实现起来很麻烦,要考虑很多边界条件。 白后不能越过白王,更蛋疼的是黑王可以不动。。。#include#include#include#includeusing namespace std;int wk[2],bk[2],wq[2];int s[9][原创 2015-02-04 23:12:15 · 573 阅读 · 0 评论 -
ZOJ-1118 N-Credible Mazes
并查集的简单应用。zoj数据太弱,程序中判断是否找到路径的条件 /* aaaaaa */是错误的,比如对于下面这个例子:1 1 52 14 51 33 4它的输出是找不到连通路径,但事实上是能找到的。但是这个错误的程序能通过oj测评。#include#include#include#include#include#includeusi原创 2015-01-10 13:21:21 · 634 阅读 · 0 评论 -
ZOJ 1505跳子棋
题目地址ZOJ-1505 搜索问题,开始时是用STL,但效率太低。后改用一维数组,将二维坐标(row,col)映射成一维来存储,同时在使用一个哈希表用于记忆化搜索,哈希表的key是四个棋子坐标的编码,value为当前已经找到的到达目标格局需要移动的最少步数。 不过这题可以用双向bfs搜索,效率更高。 #include#include#in原创 2015-01-24 16:22:37 · 695 阅读 · 0 评论 -
zoj1008(深搜)
//不剪枝,纯深搜,一直超时。#include#include#include#include#include#includeusing namespace std;#define Top 0#define Right 1#define Buttom 2#define Left 3//vector tmpV;int n;int a[25][4];bool va原创 2015-01-06 13:30:28 · 552 阅读 · 0 评论 -
【ZOJ 2103】 Marco Popo the Traveler
题目来源继续深搜题,不算难,但又碰到恶心的WA,debug若干个小时后才发现没有把非连通图的情况考虑进去,在调用dfs前要调用check函数(也是深搜)检查是否为连通图,如不是则直接打印 "No"。思维严密性还是有点欠缺#include#include#include#include#include//#include//#include "debug.h"using原创 2015-04-06 15:02:37 · 424 阅读 · 0 评论