自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(49)
  • 收藏
  • 关注

原创 poj 1386 单词连接 欧拉图+并查集判连通

点击打开链接#include #include #include #include using namespace std;const int M =30;int in[M],out[M],vis[M],fa[M];void Init(){ for(int i=0;i<26;i++) { fa[i]=i; }}int find(int x){ if(x

2016-07-31 22:03:28 440

原创 hdu 3294 Manacher模版题

点击打开链接#include #include #include using namespace std;const int M =1010000;char s[M],t[M],c;int len,p[M]; // p[i] 以i为中心的回文 i到最右端长度 void Init(){ int i; t[0]='@'; for(int i=1;i<=2*len;i+=2)

2016-07-29 17:16:37 510 1

原创 hdu 3336 Kmp+dp

点击打开链接#include #include #include #include #include using namespace std;const int M =211000;char s[M];int l;int fail[M];int dp[M]; //dp[i]:以s[i-1]结尾的子串的合法个数 //题意 : 求和所有前缀相同的子串个数 // 求s[

2016-07-29 14:55:23 321

原创 hdu 2594 next数组简单运用

点击打开链接#include #include #include #include #include using namespace std;const int M =111000;char s1[M],s2[M];int l1,l2;int fail[M];// 题意: 求与s2后缀相等的s1的最长前缀// 连接接s1,s2 求出 next[l1+l2]中不大于mi

2016-07-28 22:38:23 313

原创 hdu 3068最长回文 Manacher算法

点击打开链接参考Manacher 通过记录已匹配的最右位置和对应的对称中心 利用和对称性来跳过一些没用的比较#include #include #include #include using namespace std;const int M =111000;char s[M];char t[2*M]; //转换后字符串长度为奇数 int p[2*M];//

2016-07-28 18:23:28 367

原创 hdu 1358 KMP循环节

点击打开链接#include #include #include #include using namespace std;const int M =1100000;int Next[M];char s[M];int n; void Get(){ int i=0,k=-1; Next[0]=-1; while(i<n) { if(k==-1||s[i]==s[

2016-07-28 13:27:28 274

原创 hdu 1251 Trie入门(统计前缀出现次数)

点击打开链接#include #include #include #include #include #include using namespace std;const int M = 26;typedef struct Trie{ Trie *next[M]; //节点的子树 int v;//权值 }Trie;Trie root;void Insert(

2016-07-27 16:20:51 361

原创 hdu 1050 Moving Tables暴力法

点击打开链接#include #include #include #include using namespace std;const int M =210;int seg[M];// 问题 :给出区间 问至少选多少次才能全部选完,要求每次选的区间不相交 // 贪心: 选择不相交区间法 右端点排序 "第一个区间必选"(给其他区间留出更多的位置) 重复ans次// 暴力

2016-07-26 15:40:11 255

原创 hdu 2037贪心(选择不相交区间)

点击打开链接#include #include #include #include using namespace std;const int M =210;struct Point{ int a; int b;}p[M];bool cmp(Point x,Point y){ return x.b<y.b;}int main(){ int n; while(c

2016-07-26 14:49:09 318

原创 poj 2287 田忌赛马 贪心

点击打开链接#include #include #include using namespace std;const int M =1100;int a[M],b[M],n,used[M]; int main(){ while(cin>>n&&n) { memset(used,0,sizeof(used)); for(int i=0;i<n;i++) { c

2016-07-26 11:59:55 448

原创 poj 2406 KMP求循环节

点击打开链接#include #include #include #include using namespace std;const int M =10000100;char s[M];int fail[M];int len;void Fail(){ int i=0,k=-1; len=strlen(s); fail[0]=-1; while(i<len) {

2016-07-25 16:36:42 379

原创 hdu 1712 分组背包(入门)

点击打开链接#include #include #include using namespace std;const int M =110;int a[M][M],n,m; // a[i][j] 学习i课程j天所得的利益int l[M];//l[i] 第i门课的数量 int dp[M][M]; // 每门课最多学习一次 -> 对每门课程进行决策:dp[k][v] 前k组

2016-07-23 11:39:49 337

原创 hdu 5742 简单贪心

点击打开链接 #include #include #include #include using namespace std; const int M =1100; int a[M]; int gcd(int a,int b) { if(a%b==0) return b; else { return gcd(b,a%b); } } int

2016-07-22 21:35:58 282

原创 hdu 1198 dfs水(连通性)

点击打开链接#include #include #include #include using namespace std;const int M =60;int g[M][M];// g[i][j] 中存的是PIPE的种类 typedef struct{ int x; int y;}move1;move1 Move[4]={{-1,0},{1,0},{0,-1},{0,

2016-07-22 20:45:46 273

原创 hdu 1258 Sum it up dfs+剪枝

点击打开链接#include #include #include using namespace std;const int M =20;int a[M],s,n,res[M],visit[M],flag;bool check(int x,int y){ for(int i=x;i<y;i++) { if(a[i]==a[y]) return 1; } retur

2016-07-22 17:14:19 299

原创 hdu 5744 思维题

点击打开链接#include #include using namespace std;// 题意 给出每个字符数量 求这些 把字符构成回文串后 最小的一组做为每组的ans 求最大的ans int main(){ int t; cin>>t; while(t--) { int sum=0; // 统计偶数字符个数 int odd=0; //奇数组数 int

2016-07-22 11:30:22 404

原创 poj 2752 KMP(next数组的运用)

点击打开链接#include #include #include #include using namespace std;const int M =410000;char b[M];int Next[M],ans[M],lb;void Get_Next(){ int i=0,k=-1; Next[0]=-1; while(i<lb) { if(k==-1||b

2016-07-21 22:57:23 331

原创 hdu 3033 分组背包+01背包

点击打开链接#include #include #include using namespace std;const int M =110;typedef struct{ int volum; int val;}Data;Data dat[M][M]; // dat[i][j] 第i组种物品中第j件的数据 int dp[M][11000]; // dp[i][j] 前i组

2016-07-21 20:10:08 327

原创 hdu 1175 连连看dfs(记录转弯次数)

点击打开链接#include #include #include using namespace std;const int M =1100;typedef struct{ int x; int y;}Move;Move movE[4]={{-1,0},{1,0},{0,-1},{0,1}};int g[M][M],n,m,flag,visit[M][M];

2016-07-21 14:57:57 331

原创 hdu 1686 kmp(求子串出现个数)

点击打开链接#include #include #include using namespace std;const int M =1010000;char a[M],b[10100];int Next[M],n,m,lb,la;void Get(){ Next[0]=-1; int i=0,k=-1; while(i<lb) { if(k==-1||b[i]==b

2016-07-21 10:44:54 501

原创 HDU 1711 kmp入门

点击打开链接#include #include #include #include using namespace std;const int M = 1001000;int n,m; int a[M],b[10100];int Next[10100];// next[j]=k 当b[j]失配时 应回溯到k继续匹配 //条件: 若b[j] 与 a[i] 失配时能 如果能

2016-07-20 18:17:48 280

原创 hdu 1384逆序数 暴力法

点击打开链接#include #include #include #include #include #include using namespace std;const int M = 10100;int a[M];int main(){ int n; while(cin>>n) { int sum=0; for(int i=1;i<=n;i++)

2016-07-20 09:00:48 347

原创 hdu 1166 线段树(单点更新,区间求和)

点击打开链接#include #include #include #include using namespace std;const int M = 50100;int dat[4*M];//dat[i] i号节点权值 int n;void Push_up(int rt){ dat[rt]=dat[rt*2]+dat[rt*2+1];}void Build(int

2016-07-19 15:56:13 301

原创 hdu 5289 RMQ运用

点击打开链接#include #include #include #include using namespace std;const int M = 110000;int n,m,a[M],Min[M][30],Max[M][30]; // Min[i][j] 以i开头 ~ i+2^j -1 结尾中的最小值 void RMQ(){ for(int i=1;i<=n;i++

2016-07-19 10:43:31 290

原创 hdu 1754 线段树入门(单点替换,区间最值)

点击打开链接#include #include #include using namespace std;const int M = 200000;const int inf=-1<20;int dat[4*M+10];//dat[i] 节点i的权值 long n,m;void Push_up(int rt){ dat[rt]=max(dat[rt*2],dat[rt*2+

2016-07-18 21:38:39 287

原创 hdu 5718 大数模拟

点击打开链接#include #include #include #include #include #include using namespace std;const int M = 10010000;int num[10],f[M],index; // num[i] 数字i出现的个数 char data[M]; void Add(int x){ int t

2016-07-18 13:23:28 278

原创 hdu 2817 快速幂入门

点击打开链接#include #include #include #include #include #include using namespace std;const int M = 10010;const int Mod=200907;typedef long long LL;LL pow(LL x,LL n) //二分快速幂 { if(n==0) retu

2016-07-17 21:38:45 336

原创 poj 3169 BellmanFord—差分约束

点击打开链接#include #include #include #include using namespace std;const int M = 1100;const int inf=1000000000; int n,ml,md; int d[M];struct edge{ int to,cost; edge(int a,int b):to(a),cost(b)

2016-07-16 21:50:45 355

原创 poj 3268 Dijkstra运用

点击打开链接#include #include #include #include #include #include using namespace std;const int M = 10240;int n,m,x; struct edge{ int to,cost; edge() { } edge(int to, int cost) : to(

2016-07-15 21:44:30 300

原创 poj 3250 Floyd求负圈

点击打开链接#include #include #include #include using namespace std;const int M =510;int d[M][M];// d[i][j] i~j最短距离int n,m,w;int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d%d",

2016-07-14 20:49:34 369

原创 poj 2139 Floyd入门

点击打开链接#include #include #include using namespace std;const int M =310;int d[M][M];// d[i][j] i~j最短距离int n,m,a[110000];int main(){ cin>>n>>m; memset(d,0x3f,sizeof(d)); for(int i=1;i

2016-07-13 21:12:48 301

原创 poj 2395 MST的最大边(水)

点击打开链接题意:从源点能到任意一点且 每走1单位长度就要消耗一单位水,每到一个农场可以把自己的水充满,求至少要带的水。 思路:图要是连通的&&每条边尽量小 (若已经连通 在加边的只可能增大ans) -》 求MST的最大边即可#include #include #include using namespace std;const int M = 51010;struct ed

2016-07-13 10:56:13 265

原创 poj 3723 MST

点击打开链接#include #include #include using namespace std;const int M = 51010;struct edge{ long u; long v; long long cost; bool operator <(const edge &t)const { return cost>t.cost; }}e[M];

2016-07-13 10:20:19 267

原创 poj 2377最大生成树 Kruskal

点击打开链接#include #include using namespace std;const int M = 21010;struct edge{ int u; int v; long long cost; bool operator <(const edge &t)const { return cost>t.cost; }}e[M];int n,m,fa[

2016-07-12 21:34:00 327

原创 poj 1258 最小生成树Prim

点击打开链接#include #include using namespace std;const int M =110;long g[M][M]; // g[i][j] i->j 花费 long long d[M];// d[i] 点i到生成树距离 int main(){ int n; while(cin>>n) { for(int i=0;i<n;i++)

2016-07-12 20:43:57 362

原创 hdu 3530 Subsequence 单调队列

点击打开链接// 参考http://www.cnblogs.com/programCaiCai/archive/2012/08/30/HDU3530.html //1.假设我们现在知道序列(i,j)是符合标准的,那么如果第j+1个元素不比(i,j)最大值大也不比最小值小,那么(i,j+1)也是合法的//2.如果(i,j)不合法的原因是差值比要求小,那在(i,j)范围内的改动是无效的,需要

2016-07-12 15:48:56 432

原创 poj 2373 dp单调队列优化

点击打开链接#include #include #include using namespace std;const int M = 1001000;const long inf=1<<30;int n,l,a,b,flag[M]; // flag[i] =1 i点有解 int q[M],p[M]; //单调队列,下标 int head=1,tail=0;int dp[M];

2016-07-10 22:41:20 394

原创 FZU 2126 消去游戏

点击打开链接#include #include #include using namespace std;const long Mod=1000000007;const int M=1100;// 虚拟栈中球的个数 即为至少放入球的个数 使得全消 // 实际栈放一个球和栈顶不同 虚拟栈就增加k-1个球// 实际栈放一个球和栈顶相同 虚拟栈就减少一个球 long lon

2016-07-10 15:01:12 271

原创 poj 2832 Sliding Window 单调队列入门

点击打开链接//对于插入,//即元素在我们关注的指标下递增,从队尾插入新元素的时候可能要删除队尾的一些元素,//具体说来就是,找到第一个大于(在所关注指标下)新元素的元素,删除其后所有元素,并将新元素插于其后。//因为所有被删除的元素都比新元素要大,而且比新元素要旧,因此在以后的任何查询中都不可能成为答案,所以可以放心删除。#include #include #include

2016-07-09 18:30:49 299

原创 poj 2184 01背包应用

点击打开链接#include #include using namespace std;const int M =100000;const int inf=2*M;int s[M+10],f[M+10]; int dp[2*M+10]; // dp[i][j] 前i只牛的Smartness为 J时 最大的Funness // dp[i][j]= max(dp[i-1][j

2016-07-09 13:45:39 264

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除