• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
tmeteorj
Nothing is so big that it is impossible to get over, and hurt only serves to make us stronger. 没有什么事是大到无法战胜的,痛苦也只会让我们变得更加坚强。
博客园 | 首页 | 新随笔 | 新文章 | 联系 | 订阅 订阅 | 管理

随笔分类 -  ACM 搜索

1 2 下一页

 
POJ 3519
摘要:题意:模拟大富翁,求在t步之内走到终点的概率。题解:记忆化搜索,dp[p][k]为在p点走了k步且最后到达终点的概率,其它都是简单模拟。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const double eps=1e-8; 6 const int N=105; 7 double dp[N][N]; 8 int v[N]; 9 int n,t;10 int next(int p,int s)11 {12 p+=s 阅读全文
posted @ 2012-11-05 17:50 tmeteorj 阅读(289) 评论(0) 推荐(0)
POJ 2662
摘要:题意:求无向图中从1走到2的满足条件的路径条数,条件:从A能到B,当且仅当B到终点的最短路径小于A到终点的最短路径。题解:spfa预处理所有点到终点的距离,记忆化搜索统计个数。View Code 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 const int N=1005,M=4000000; 6 int dist[N],head[N],list[N],dp[N],r,f,nc; 7 bool vis[N]; 8 struct Ed 阅读全文
posted @ 2012-10-19 12:57 tmeteorj 阅读(204) 评论(0) 推荐(0)
POJ 3497
摘要:题意:给出预算b以及电脑零件n,每种类型均要买一个,求在预算范围内,所有零件配置最低的最大值。题解:二分答案View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<map> 5 #include<string> 6 #include<vector> 7 using namespace std; 8 map<string,int> MP; 9 const int inf=0x3f3f3f3f;10 stru 阅读全文
posted @ 2012-10-18 17:26 tmeteorj 阅读(356) 评论(0) 推荐(0)
POJ 3232
摘要:题意:有一个含有n辆车的车队,当前距离终点的距离已知,有m个加速器,每个加速器在一个时刻只能给一辆车用,一旦使用就会使得其速度由1变成k,加速器可以重复使用,问最快所有车辆到达终点的时间。题解:二分答案,通过在这个时间内加速器能够使用的个数来进行判断。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=100005; 6 int a[N],n,m,k; 7 bool check(int ti) 8 阅读全文
posted @ 2012-10-17 15:26 tmeteorj 阅读(194) 评论(0) 推荐(0)
POJ 2956
摘要:题意:求第n个各位不重复的数。题解:以1,2...9作为初始结点,bfs依次从0到9加入其它的数,条件是这个数未在结点中出现过。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 struct data 6 { 7 int v,s; 8 data(){} 9 data(int _v,int _s){v=_v,s=_s;}10 }po[1001000];11 int main()12 {13 int f,r;14 f... 阅读全文
posted @ 2012-10-17 12:42 tmeteorj 阅读(457) 评论(0) 推荐(0)
POJ 2718
摘要:题意:给出最多10个数字,将它们划分为两个整数,求差异值最小的值(除非只有一位数,否则不允许出现先导0)题解:很显然如果总共有n个数,必然有一个整数长n/2,另一个长n-n/2,dfs搜一遍即可。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int inf=0x3f3f3f3f; 6 int a[12],b[12],n,ans; 7 bool vis[12]; 8 void solve(int aa) 阅读全文
posted @ 2012-10-16 16:27 tmeteorj 阅读(1474) 评论(0) 推荐(0)
POJ 1856
摘要:题意:给出一个r*c的矩形,问有多少不相交的矩形。矩形:‘#’组成,且必须是实心。相交:有边、或者点相邻。题解:对于每一个含'#'且未被访问过的点进行一次dfs,并标记此次dfs所能到的最小最大x,y和总共访问了多少个点(ret),如果Δx*Δy=ret,则答案加1,否则,就是错误的。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int maxx,maxy,minx,miny,r,c; 6 char 阅读全文
posted @ 2012-10-11 18:54 tmeteorj 阅读(265) 评论(0) 推荐(0)
POJ 3435
摘要:题意:一扫而过,吓我一跳,100*100的数独有木有!dancing link空间都开不下!!再看一眼,= =!只用看当前状态是不是合法的啊。。。题解:按照数独的定义一个个的检查,突发奇想的问大牛能不能提前判断是否有解,结果被告知唯有dancing link可以检验了。。以前的一道dancing link16*16,就给了5S,我说呢,100*100怎么可能才给2sView Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 in 阅读全文
posted @ 2012-10-10 11:36 tmeteorj 阅读(215) 评论(0) 推荐(0)
POJ 3192
摘要:题意:给定n个DNA字符串,然后可以让两个DNA端点部分交叉,条件是这端点部分能够匹配。问将n个DNA连成一串的最小长度。题解:像这种n那么小的题就是在诱惑人去暴力,枚举n个DNA的构造顺序,然后依次连接。View Code 1 #include<cstdio> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 bool vis[10]; 6 char s[10][10]; 7 int n,ans,per[10]; 8 void link(char s1[],char s2[ 阅读全文
posted @ 2012-10-09 19:11 tmeteorj 阅读(294) 评论(0) 推荐(0)
POJ 2817
摘要:题意:给出n个字符串,把它们排成n列。相邻两列上下有k个字母对应相同就可以获得k分,并可以添加前导空格。问最高分数。题解:n最大才10,10!枚举排列,然后预处理任意两串字母的最大得分即可。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 char s[12][12]; 6 int n,res; 7 int cac[12][12]; 8 bool vis[12]; 9 void dfs(int k,int lx,int 阅读全文
posted @ 2012-10-09 13:21 tmeteorj 阅读(435) 评论(7) 推荐(0)
POJ 3193
摘要:题意:判断一些句子是不是另一些句子的前缀,并统计是的个数。题解:将被匹配串读入结构体中排序,然后对于每个匹配串,通过二分在结构体中找。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int M=1005,N=10005; 6 struct data 7 { 8 char s[100]; 9 bool operator<(const data &ne)const10 {11 return st 阅读全文
posted @ 2012-10-07 16:48 tmeteorj 阅读(242) 评论(0) 推荐(0)
POJ 3600
摘要:题意:给一个小矩形,一个大矩形,均是01矩阵,然后问从大矩形中删除一些行一些列是否能得到小矩形。题解:先枚举小矩形由大矩形哪些列组成,然后在判断这些列能否组成小矩形,判断方法为:先将小矩形每一行当做2进制数存入一个一维数组中(长r),在对每一个已经枚举好的大矩形的列也同样按此操作,得到一个长为R的数组,如果第一个数组是第二个数组的子序列,那么就是可行的。这样,枚举列的复杂度O(Choose(C,c)),至多十几万,判断子序列是O(r+R)View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algo 阅读全文
posted @ 2012-10-05 19:07 tmeteorj 阅读(205) 评论(0) 推荐(0)
POJ 2286
摘要:题意:一个#型的棋盘,上面有1、2、3各8个,要求通过8种操作使得最后中间的八个格子数字相同。题解:IDA*搜索,首先,每个格子有三种状态,总共有3^24种状态,即使通过1、2、3都只有8个排除一些内存也是不够的,相反,此题给了15s的时限,便可以用时间效率不如bfs,但是空间上完爆bfs的IDA*了。 1、记录八种旋转的改变数组位置,然后在设定的depth范围内dfs。 2、两个剪枝:a)当前操作是上一次操作的逆操作。b)当前状态最好情况也无法在depth之内完成任务,即使中间8个格子中最多的数字在最好情况下凑成目标态也超过了depth。View Code 1 #include<c.. 阅读全文
posted @ 2012-10-05 15:58 tmeteorj 阅读(1054) 评论(0) 推荐(0)
POJ 1184
摘要:题意:中文题,略。题解:实际上原状态每个数在最后都对应着目标态相应位置,所以可以先通过不改变的移动达到相应位置,然后再增减数字得到目标态,这样bfs状态量就会一下降很多,6个数的排列也就6!,另外最后要求增减数字,所以光标必须到过那个地方,所以还需要一维记录光标到过的地方,由于光标移动受一定限制,所以最后只有10中光标访问位置的状态,即从6!排列中的一些光标状态中选出最优更改,事实证明,只有500多种状态。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 usin 阅读全文
posted @ 2012-10-03 16:30 tmeteorj 阅读(558) 评论(0) 推荐(0)
POJ 1167
摘要:题意:从0到59分内,来了n辆公交车,求最少公交车路线。每条公交线的发车时间间隔都一样,且在这段时间内每条路线至少发车两次,公交车路线最多为17.题解:预处理公交车可行路线的发车时间、间隔与车次,通过dfs求最小路线。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int n,tot[70],top,ans; 6 struct Data 7 { 8 int start,ti,num; 9 bool operator& 阅读全文
posted @ 2012-10-03 12:23 tmeteorj 阅读(314) 评论(0) 推荐(0)
POJ 1143
摘要:题意:两个人玩游戏,初始集合S为大于1的正整数集,轮流写出一个大于1的数然后将:“1、所有这个数的倍数;2、这个数的倍数与前面已经删去的数的和”从集合S中删去,现在告诉你S的现状,求所有必胜走法的第一步。题解:数的数量小于20,可以用位压缩dp,记录S中还剩哪些元素时是否是必胜态,然后通过记忆化搜索求出所有走第一步后是必败态的策略。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 int dp[(1<<20 阅读全文
posted @ 2012-10-02 10:23 tmeteorj 阅读(627) 评论(0) 推荐(0)
POJ 1033
摘要:题意:磁盘n个块,有m个文件,各自被分割成许多块分散在磁盘之中,要求通过最少移动次数使得第1个文件的占1,2,3...f1块,第二个文件占f1+1,f1+2...f1+f2块。。。题解:dfs(k)为将k位置的文件移到它该去的地方,标记dfs过的点,若发生重复则说明有环,就让当前dfs点移到最大一个空闲块,否则,必定能将链还原。View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=10005; 6 阅读全文
posted @ 2012-10-01 19:43 tmeteorj 阅读(643) 评论(0) 推荐(0)
POJ 1156
摘要:题意:求矩形中差异值最大不超过c的子矩阵的最大面积。题解:枚举子矩形左右两列,然后记录每行位于这两列之间的最大最小值,建两个单调队列,从上往下一次扫描时,判断差异值是否超过了c,以此来维护队列,再加最优化剪枝。View Code #include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=705;int row,col,c;int map[N][N],_min[N],_max[N];//min/max:第i行[a,b]区间最大/小值int Q1[N*2 阅读全文
posted @ 2012-10-01 18:34 tmeteorj 阅读(388) 评论(0) 推荐(0)
POJ 2034
摘要:题意:给定区间[n,m]和d求一个排列使得连续的小于等于d且大于1长度的序列之和为合数。题解:dfs+剪枝即可View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int mr=10050; 6 bool notp[mr]; 7 int pr[mr]; 8 int pn; 9 void getpri()//筛素数10 {11 memset(notp,0,sizeof(notp));12 pn=0;13 for( 阅读全文
posted @ 2012-10-01 12:55 tmeteorj 阅读(339) 评论(1) 推荐(0)
POJ 2329
摘要:题意:把矩阵n*n中所有的0改成它最接近的正数,若有两个及以上都满足,则不变。题解:bfs每个0View Code 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int N=50000; 6 int map[300][300],ans[300][300]; 7 int po[N][2]; 8 int stk[N][3]; 9 int dr[][2]={0,1,0,-1,1,0,-1,0};10 bool mark[300] 阅读全文
posted @ 2012-09-28 20:53 tmeteorj 阅读(293) 评论(0) 推荐(0)
 

1 2 下一页

公告


博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3