- 博客(214)
- 资源 (25)
- 收藏
- 关注
原创 【DFS】poj 1426 Find The Multiple
http://poj.org/problem?id=1426#include #include #include using namespace std;typedef __int64 LL;const int NM=205;int n,vis[NM];LL BFS(){ queueq1; LL t=1,x1,x2; int mod1,mod2; memse
2014-05-23 17:23:15
639
原创 【IDA*】hdu 1560
#include #include #include using namespace std;const int NM=10;char str[NM][NM],cs[4]={'A','C','T','G'};int v[NM],len[NM],sta[NM],dep,n;bool flag;int compare() //A*的估价函数{i
2014-05-23 17:01:46
519
原创 【DFS】poj 1190 生日蛋糕
http://poj.org/problem?id=1190#include #include using namespace std;const int MAX=0xfffffff;int mmins;int V,M;int Get_minV(int x){ return (x+1)*(x+1)*x*x/4;}/* V=PI*r^2*h; S(侧)=2*PI*r
2014-05-23 16:56:51
710
原创 【树形DP】hdu 1520 Anniversary party
http://acm.hdu.edu.cn/showproblem.php?pid=1520#include #include #include #include using namespace std;const int NM=6005;int dp[NM][2],f[NM],a[NM];vectorv[NM];int max(int x,int y){ ret
2014-05-23 16:51:59
495
原创 【拓扑排序】hdu 3342 Legal or Not
http://acm.hdu.edu.cn/showproblem.php?pid=3342#include #include #include using namespace std;const int NM=105;int a[NM][NM],indu[NM],n;bool Tuopu(){ int i,j,k,ling; memset(indu,0,sizeof(
2014-05-17 18:47:28
465
原创 nyoj 927 The partial sum problem
#include #include #include #include using namespace std;const int NM=30;int a[NM],sum,n;bool flag;bool comp(int x,int y){ return x>y;}void DFS(int res,int i){ if(flag || i>n) return;
2014-05-16 21:35:02
593
原创 nyoj 43 24 Point game
http://acm.nyist.net/JudgeOnline/problem.php?pid=43分析:#include #include #include #include using namespace std;const int NM=15;const double eps=1e-6;bool vis[NM],flag;double a[NM];int n,m
2014-05-14 19:10:46
469
原创 【KMP(循环节)】poj 2406 Power Strings(外:hdu 1358 Period)
http://poj.org/problem?id=2406#include #include #include using namespace std;const int NM=10000005;int next[NM];char str[NM];void get_next(){ int i,j,len; len=strlen(str); i=0;next
2014-05-12 20:01:18
526
原创 【并查集】hdu 1272 小希的迷宫
#include#include#includeusing namespace std;const int NM=100005;int father[NM];bool vis[NM],flag;int Find(int x){ int t,p1=x; while(p1!=father[p1]) p1=father[p1]; while(x!=p1) { t=fath
2014-05-08 17:51:50
522
原创 【DFS(记忆化)】zzuli 1430 多少个0
#include #include #include using namespace std;const int NM=105;const int MAX=0xfffffff;int dp[NM][NM][2],a[NM][NM],mmin,n,m;int c[2][2]={1,0,0,1};int MIN(int x,int y){ return x<y?x:y;}i
2014-04-23 11:06:30
511
原创 【DFS(记忆化)】hdu 2452 Navy maneuvers
http://acm.hdu.edu.cn/showproblem.php?pid=2452
2014-04-21 21:40:15
605
原创 【并查集】hdu 1856 More is better
#include #include #include using namespace std;const int NM=10000005;int father[NM],rank[NM],mmax;int Find(int x){ /*while(x!=father[x]) x=father[x]; return x; 超时*/ /*if(x!=father[x])
2014-04-21 19:45:24
449
原创 【DFS(记忆化)】hdu 1619 Unidirectional TSP
http://acm.hdu.edu.cn/showproblem.php?pid=1619
2014-04-16 20:37:38
608
原创 【最短路径-Dis】hdu 1311 Relative Relatives
http://acm.hdu.edu.cn/showproblem.php?pid=1311分析:
2014-04-12 14:19:18
715
原创 【DFS(记忆化)】hdu 1078 FatMouse and Cheese(poj 1088 滑雪)
#include #include #include #include using namespace std;const int NM=105;int a[NM][NM],vs[NM][NM],n,k,mmax;int d[4][2]={-1,0,1,0,0,-1,0,1};int max(int x,int y){return x>y?x:y
2014-04-10 17:20:01
560
原创 【DFS(记忆化)】hdu 1208 Pascal's Travels
http://acm.hdu.edu.cn/showproblem.php?pid=1208分析:注意当出现0时,
2014-04-10 16:14:40
560
原创 第四章 贪心算法
4.1 活动安排问题分析:按照结束时间非递减排序,再贪心。#include #include #include #include using namespace std;const int NM=105;bool x[NM];struct Node{ int s,f;}q[NM];bool comp(struct Node A,struct Node B){ re
2014-04-03 11:48:07
531
原创 【DFS】hdu 2616 Kill the monster
http://acm.hdu.edu.cn/showproblem.php?pid=2616分析:排列树水过#include #include #include using namespace std;const int NM=15;int cost[NM],x[NM],spe[NM],mmin,n;void DFS(int t,int MP,int cc){
2014-04-02 20:03:02
499
原创 hdu 2209 翻纸牌游戏
http://acm.hdu.edu.cn/showproblem.php?pid=2209分析:第1张牌的状态只受两种影响:自己和第2张牌;判断前一张牌是否为正面#include #include #include #include using namespace std;const int NM=25;int mmin,len,a[NM];bool flag
2014-04-01 18:33:33
667
原创 【DFS+BFS】hdu 1983 Kaitou Kid - The Phantom Thief (2)(迷宫)
http://acm.hdu.edu.cn/showproblem.php?pid=1983分析:最多只用封锁四个位置就可以了(封锁起点或终点);判断路径是否经过时,再加一层宝石状态来判断(可以重复走)#include #include #include #include using namespace std;const int NM=10;int a[4][2]=
2014-03-30 19:44:41
685
原创 【DFS(记忆化)】hdu 1501 Zipper
http://acm.hdu.edu.cn/showproblem.php?pid=1501分析:记忆化搜索注释掉后反而更快了#include #include //#include #include #include using namespace std;const int NM=205;char s1[NM],s2[NM],str[NM<<1];int
2014-03-28 16:39:12
503
原创 【Bellman_Ford】poj 1860 Currency Exchange
http://poj.org/problem?id=1860题意:A和B交换率相等(双向图),每次交换需要小费(可以交换多次),问经过一系列交换后(最后需要换回最开始的那种货币),资金能否增长?分析:寻找正权回路#include #include #include #include #include using namespace std;const int
2014-03-27 19:29:32
658
原创 【A*】hdu 1195 Open the Lock
http://acm.hdu.edu.cn/showproblem.php?pid=1195题意:每一位上的数字可以加1或减1;相邻的数可以交换(第1个和第4个不相邻),变换得到下面的密码。分析:两个评价函数:f=g+h(g:每一位上与答案不相同数字的个数;h:步数)#include #include #include #include using namespace
2014-03-27 19:18:04
473
原创 【BFS+Prim】poj 3026 Borg Maze
http://poj.org/problem?id=3026题意:从S开始找到一条到所有外星人A的通路,使得该通路总长度最短。分析:暴搜找出所有A/S之间的边,然后用prim把所有最短的边连接起来。#include #include #include #include using namespace std;const int NM=105;/*k:外星人的个数,
2014-03-26 20:53:18
479
原创 第三章 习题(三)
5-12 罗密欧与朱丽叶的迷宫问题注意:还可加入无解时的剪枝判断[cpp] view plaincopyprint?#include #include #include using namespace std; const int NM=25; int d[8][2]={-1,0,-1,1,
2014-03-23 23:33:46
1146
原创 第五章 习题(二)
5-9 拉丁矩阵问题#include #include #include using namespace std;const int NM=25;int x[NM][NM],n,m,num,sum;bool check(int line,int row,int k){ int i,j; for(i=0;i<line;i++){ if(x[i][row]==k) ret
2014-03-22 13:56:57
684
原创 第五章 习题(一)
5-1 子集和问题#include #include #include using namespace std;const int NM=25;int set[NM],x[NM],path[NM],n,Wleft,c;bool Backtrack(int cw,int t){ if(t>n){ for(int j=1;j<=n;j++) path[j]=x[j];
2014-03-18 14:50:37
746
原创 第五章 回溯法
5.2 装载问题#include #include #include using namespace std;const int NM=100;int wi[NM],path[NM],x[NM],n,bestmax,Wleft,c;void Backtrack(int cw,int i){ if(i>n){ bestmax=cw; for(int j=1;j<=n;
2014-03-13 13:02:55
585
原创 poj 3032 Card Trick
http://poj.org/problem?id=3032分析:如下图,模拟翻牌的过程#include #include #include #include using namespace std;int main(){ int T,i,j,n,t,a[20]; dequedq1; scanf("%d",&T); while(T--) { dq1.cl
2014-03-06 13:54:54
583
原创 poj 2456 Aggressive cows
http://poj.org/problem?id=2456题意:在n个位置放置c只牛,使得每只牛之间的间距最大,求满足条件的最小间距?#include #include #include #include using namespace std;const int NM=100005;int a[NM],n,c;//判断在整个长槽内,间距>=x,是否可以放下
2014-02-19 18:12:22
527
原创 【最大流(dinic)】poj 1273 Drainage Ditches
http://poj.org/problem?id=1273分析:最大流的dinic实现模板(邻接矩阵)#include #include #include #include using namespace std;const int NM=205;const int MAX=0xfffffff;int a[NM][NM],level[NM],n,m;inlin
2014-02-18 12:35:59
503
原创 【最大流(EK)】poj 1149 PIGS
http://poj.org/problem?id=1149题意:有M个猪圈、N个顾客,每个顾客有A把钥匙;只能在有钥匙的猪圈购买最多B只猪,顾客购买过后,可以对打开的猪圈内的猪重新分配;求最多可以卖出多少头猪?分析:经过大神的总结,得以建立以下图:1)在原先的图中添加源点(0)和汇点(n+1);2)源点连接的是每个猪圈的第一个顾客,如果一个顾客是多个猪圈的第一名买家,则将权值合并
2014-02-17 00:44:28
577
原创 【最大流(EK)】hdu 3549 Flow Problem
http://acm.hdu.edu.cn/showproblem.php?pid=3549分析:最大网络流的EK算法#include #include #include #include using namespace std;const int NM=20;const int MAX=0xfffffff;int a[NM][NM],pre[NM],n,m,ans
2014-02-15 18:45:19
578
原创 hdu 2817 A sequence of number
http://acm.hdu.edu.cn/showproblem.php?pid=2817题意:求等差数列和等比数列#include #include #include using namespace std;typedef __int64 LL;const int NN=200907;int main(){ LL x,y,z,k,t,r,T; while(
2014-02-10 20:44:49
484
原创 【线段树(线段离散化+lazy)】poj 2528 Mayor's posters
http://poj.org/problem?id=2528题意:有不同长度([x,y])的海报被贴在一个长墙上,求有多少个海报可以被看到(只要有一部分漏在外面就算)分析:离散化的时候是对线段而不是对点离散,否则会错误,因为即使是[1,1]也表示一个线段,比如下例:liri11013610清除相同项
2014-02-09 20:14:52
754
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人