自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 hdu 2819 二分匹配

首先判断是否能行,只要行与列二分匹配。然后对匹配结果ma按从小到达排序,记录排序时的交换即可。由于M#include#include#include#includeusing namespace std;const int nMax=105;int a[nMax][nMax],ma[nMax],vis[nMax],ans[nMax][2],N;int dfs(int u){

2013-06-27 11:05:23 450

原创 hud 2825 AC自动机dp

dp[i][j][k] 表示长度为i,以第j个节点为结尾,当前所用单词状态为k时的结果数目,其中单词只有10个,可以状态压缩。然后利用AC自动机转移。#include#include#includeusing namespace std;const int M=20090717;const int nMax=105;const int SON=26;int dp[30][nM

2013-06-27 09:15:18 457

原创 poj 3111 迭代法

给N个珠宝,每个珠宝有v与w两个参量,从中取K个使得∑v/∑w 最大。利用迭代法,首先任取K个最为初始值,计算s,然后对每个珠宝计算其y=v-s*w的值,根据y值对其排序,然后取前K个作为本次选取的K个,直到选取的K个珠宝计算出的s值不再增加为止。明显只需要证明s是单调递增的即可。对于当前K个珠宝计算值s有∑v-s*∑w=0,即∑y=0,但是根据y排序后选取的前K个必有∑y>=0, 即∑v

2013-04-10 22:28:15 941

原创 poj 2978 最大权闭图

在一个图中,我们选取一些点构成集合,记为V,且集合中的出边(即集合中的点的向外连出的弧),所指向的终点(弧头)也在V中,则我们称V为闭合图。最大权闭合图即在所有闭合图中,集合中点的权值之和最大的V,我们称V为最大权闭合图。  上图中闭合图有     {5}、{2,5}、{4,5}     {2,4,5}、{3,4,5}     {1,2,3,4,5}、{1,2,4,5}

2013-03-31 17:31:17 472

原创 poj 2886 数组数组+约瑟夫环

需要用到反素数表,先打个表。首先最大值是可以事先求出来。然后开始模拟,每次利用树状数组+二分确定当前出来的人的实际位置,其相对于起始的位置可以直接求。确定实际位置时二分枚举可能位置,如果其相对位置与前面已经出去的人数之和   与当前枚举位置相等   并且当前枚举位置未被占用则为其实际位置。#include#include#include#include#includeusing

2013-03-28 22:34:57 439

原创 poj 2778 AC自动机+矩阵乘法

首先利用病毒串建立tire图,没个节点代表某种后缀,然后利用AC自动机对各个后缀进行转移,得到一个矩阵,然后利用快速幂求解矩阵连乘。#include#include#include#includeusing namespace std;const int nMax=105;const int S_NUM=4;const int N_NUM=105;const int M=100

2013-03-26 21:04:12 541

原创 poj 1204 AC自动机

利用要匹配的串建立tire树,然后枚举四周的字母分别向8个方向做多模式串匹配。#include#include#include#includeusing namespace std;const int nMax=2000000;const int S_NUM=26;int gx[8]={-1,-1,0,1,1,1,0,-1};int gy[8]={0,1,1,1,0,-1,-1

2013-03-26 11:59:35 401

原创 poj 3225 线段树注意lazy标记

题意令人很忧伤,理解了题意就好办了。题目中集合中的数不只是整数,将线段扩大两倍用于表示开区间,然后用个懒惰标记就ok了。#include#include#include#includeusing namespace std;const int nMax=140005;const int N=65535*2+2;int res,vis[nMax];struct Tree{

2013-03-20 19:31:35 477

原创 poj 3667 线段树合并区间

经典问题,每个节点记录最大连续长度,从最左边开始最大连续长度与从右边开始的最大连续长度,和一个cov,0表示全未被覆盖,1表示全被覆盖,2表示部分被覆盖。#include #include #include using namespace std;const int maxn=50005;int N,M;struct Tree{ int l,r; int rc

2013-03-20 13:01:21 457

原创 poj 1177 经典线段树+扫描线就周长并

可以参考陈宏的论文,就是将矩形的线段按x轴排序后每次利用前后直接线段覆盖y值的差值计算竖线的长度,利用前后两直线直接的x周距离乘不相交线段的条数计算横线的长度。具体可以看代码。本题坐标范围较小,可以不用离散化。#include#include#include#include#includeusing namespace std;const int nMax=5005;cons

2013-03-18 20:27:49 727

原创 poj 2668

给你两个数D,N,让你求D/1+D/2+.....D/N,每次计算结果向上取整。首先D,N规模很大,由于向上取整,会有大量重复结果,则首先从最小结果即ceil(D/N) 开始计算,每次将结果加1,大约计算到N#include#include#include#include#includeusing namespace std;int D,N;long long ans;vo

2013-03-17 16:45:34 597

原创 poj 2635 同余模定理

打个1-1000000的素数表,然后利用同余模定理判断。判断是后用十进制会TLE,我用的1000000进制,尽量减少取模次数。#include#include#include#include#includeusing namespace std;const int nMax=1000005;int tag[nMax],p[100000],L,cnt,dit;long long

2013-03-16 21:18:11 726

原创 poj 1733 并查集

首先将数据离散化,然后r[x]表示x节点与根节点关系,左闭右开,这样每次输入时y++,求关系时候异或就行。每次合并时让大节点合并到小节点上去。#include#include#include#includeusing namespace std;const int nMax=10005;int p[nMax],r[nMax],x[nMax],y[nMax],ty[nMax],sot

2013-03-15 17:35:25 442

原创 poj 2425&&poj1338

给出三个质数,找出只以三个质数为因子的第K大的数。用三个指针依次指向三个质数要乘的数,然后每次取最小并移动响应指针,注意判重。#include#include#include#includeusing namespace std;const int nMax=11000;const long long inf=((long long)1<<60)-1;long long res[

2013-03-14 21:07:39 553

原创 poj 2478

欧拉函数简单应用。#include#include#include#includeusing namespace std;const int nMax=1000005;int tag[nMax],p[100000],N;long long F[nMax];void get_prime(){ int cnt = 0; tag[1] = 1; for (int i

2013-03-13 20:41:31 655

原创 poj 2440 矩阵乘法

#include#include#include#includeusing namespace std;const int M=2005;const int N=4;int L;struct Mat{ int mat[N][N],n,m;//n行m列矩阵 void init(int r,int c) { n=r;m=c; } void init_e() { f

2013-03-13 19:44:16 629

原创 poj 2402

数位统计问题,求出第K个回文数字。定义dp[i][j]表示i位数字以j作为开始和结尾的回文数字个数,则dp[i][j]+=dp[i-2][k](k=0-9)。然后从高位开始一次确定每一位的数字。一些中间变量要超long long。#include#include#include#include#includeusing namespace std;const int inf=2

2013-03-11 21:19:34 624

原创 poj 2362 深搜

直接暴力就过了哈哈#include#include#include#includeusing namespace std;int a[25],vis[25],T,N,flag,len;void dfs(int sum,int n,int cnt){ if(flag || sum>len) return; if(sum==len) { if(

2013-03-10 09:57:16 417

原创 poj 2337 欧拉回路

#include#include#include#include#includeusing namespace std;int par[30],in[30],out[30],first[30],res[1005],cnt,T,N,size;struct A{ char w[30];}a[1005];struct Edge{ int v,next,flg;}edge

2013-03-08 21:31:03 445

原创 poj 2353 简单dp

对于每一层,从两头分别计算一遍就行。#include#include#include#includeusing namespace std;const long long inf=((long long)1<<63 - 1);int path[105][505],a[105][505],M,N;long long dp[105][505];void print(int i,in

2013-03-08 12:09:50 608

原创 poj 3286 数位dp

按位统计,从后向前分别递归处理每一位。 #include#include#include#includeusing namespace std;long long a,b,cnt;void slove(long long a,long long d,long long d1,long long k){ if(a<0) return; long long t;

2013-03-07 23:47:19 900

原创 poj 2299 递归排序

一个数列,只能交换相邻两个数值来排序,计算需要的交换数目使得序列有序。在归并排序的同时计算需要交换的数值。#include#include#include#includeusing namespace std;int a[500005],N,T[500005];long long count(int x,int y){ if(x<y) { in

2013-03-06 19:19:41 424

原创 poj 2263 dij

求从起始点到终点经过的路径中最短的路径值最大,dist[u]表示起点到u的路径中最短值的最大值dist[v]=max(min(dist[u],mat[u][v]),dist[v]) 其他的与dij一样了。应该最大生成树也可以AC#include#include#include#includeusing namespace std;const int nMax=205;const

2013-03-06 17:45:06 582

原创 poj 1014 背包

dp[i][j]表示前i钟物品能否满足V/2的容量,对于是dp值为bool的多重背包,可以用标记数组直接优化为0(NV)的复杂度#include#include#include#includeusing namespace std;const int nMax=20005;int dp[nMax*6],a[7],used[nMax*6];int main(){// fr

2013-03-05 22:25:19 511

原创 poj 2195 最小费用流

#include#include#include#include#includeusing namespace std;const int ma=510;const int inf=100000000;queue Q;int first[ma],vis[ma],dist[ma],pre[ma][2];int S,T,N,M,size;char a[ma][ma];struc

2013-03-05 16:31:22 502

原创 poj 2192 dp

dp[i][j] 表示字符串a的前i个字符和字符串b的前j个字符能不能组成c的前i+j个字符。#include#include#include#includeusing namespace std;int dp[205][205],T;char a[205],b[205],c[500];int main(){// freopen("test.txt","r",stdin

2013-03-04 19:59:28 221

原创 poj 2033 dp

简单dp,注意0的情况即可#include#include#include#includeusing namespace std;const int nMax=100005;long long dp[nMax];char a[nMax];int main(){ // freopen("test.txt","r",stdin); while(scanf("%s",

2013-03-03 20:42:47 269

原创 poj 1861 最小生成树

最小生成树性质,最小生成树最大边的权值最小 #include#include#include#includeusing namespace std;const int nMax=1005;const int inf=10000000;int mat[nMax][nMax],vis[nMax],p[nMax],dist[nMax];int N,M;int MST(){

2013-03-02 21:22:25 214

原创 poj 2497 高斯消元解同余方程

高斯消元 直接套模板#include#include#include#includeusing namespace std;const int nMax=305;const int MOD=7;int freex[nMax],x[nMax],a[nMax][nMax],N,M;char week[7][10]={"MON","TUE","WED","THU","FRI","SA

2013-03-01 21:27:59 388

原创 poj 1201 差分约束

dist[i]表示[0,i)直接选择的数,则每个区间组成一个不等式,题目中要求最小值,则利用u-v>=w的形式求最长路。初始化dist[0]=0;题目中隐含不等式为0#include#include#include#include#includeusing namespace std;const int inf=10000000;const int nMax=50009;i

2013-02-19 14:51:55 216

原创 poj 1149 网络流构图

构图比较巧妙,添加超级源点和汇点某个屋子第一次被打开则在源点与当前顾客添加边,容量为此屋子初始猪数量。 再次被打开时在上一个打开此屋子的人与当前顾客添加边,容量无穷。在每个顾客与汇点间加边,容量为此顾客买猪数目。 之后就是模板了。#include#include#include#includeusing namespace std;const int MAXN=105;cons

2013-02-19 12:37:35 272

原创 poj 1118 最多共线的点

分别以每个点为基准,计算与其他点的斜率,将斜率排序后统计斜率最多的值。#include#include#include#includeusing namespace std;const double esp=1e-10;int x[800],y[800],N;double k[800];int main(){// freopen("test.txt","r",stdi

2013-02-19 11:26:07 335

原创 poj 3171 线段树+dp

将牛按t2升序排序,dp[i]表示M~i需要的最小花费,dp[i]=min(dp[i],c[i].w+dp[j](c[i].t1-1#include#include#include#includeusing namespace std;const long long inf=1000000000000;const int nMax=100005;long long dp[nMax

2013-02-16 13:39:45 323

原创 poj 3662 二分答案或二维dij

二维dij dist[v][k] 表示到达v,使用k条免费边后所经过路径最大值dist[v][k]=min(max(u->v,dist[u][k]),dist[v][k])  dist[v][k]=dist[u][k-1] 我用二分做的#include#include#include#includeusing namespace std;int vis[1005][1

2013-02-13 19:22:05 320

原创 poj 3277 区间覆盖

线段树+离散化#include#include#include#includeusing namespace std;const int nMax=80005;int sot[nMax],a[nMax],b[nMax],h[nMax],N,cnt;long long ret;struct Tree{ int l,r,h;}t[nMax<<2];#define mi

2013-02-12 12:12:52 278

原创 poj 3257 二维dp

二维dp[i][j]表示在j的预算内修前i米得到的最大fun。#include#include#include#includeusing namespace std;const int nMax=1005;int L,N,B;int e[nMax][nMax],cnt[nMax],dp[nMax][nMax];int x[10005],w[10005],f[10005],c[1

2013-02-10 22:48:46 292

原创 poj 3263 区间覆盖统计

线段树求区间覆盖,注意去重复区间。#include#include#include#include#includeusing namespace std;const int maxn=10005;typedef pair PII;set C;int cnt[maxn],N,I,H,R;struct Tree{ int l,r,cov;}t[maxn<<2];

2013-02-10 22:45:46 485

原创 poj 3254 状态压缩dp

#include#include#include#includeusing namespace std;const int MOD=100000000;int dp[13][1<<12],f[13],N,M,ans;int ok(int s){ int t,tp=0; for(int i=0;i<N;i++) { if(s&(1<<i)) t

2013-02-07 23:14:06 206

原创 poj 3415 长度超过K的公共子串个数

1.将两个字符串连接起来中间用一个未出现字符隔开求后缀数组。2.按K值将height数组分组,每组答案独立,分别统计3.每一组求解时维护一个按height值单调递增的栈,使得统计时可平摊保证o(n)的复杂度。#include#include#include#includeusing namespace std;const int nMax=210005;long long

2013-02-07 17:10:33 306

原创 poj 3294 在K个字符串中出现最长公共子串

后缀数组二分长度判定,然后将height数组通过二分得到长度分成几部分,检查每一部分是否有超过半数的字符串出现当前长度的公共子串。然后保存位置信息用于输出。#include#include#include#includeusing namespace std;const int nMax=101005;int pos[nMax],cnt,flag[105],cnt1,hash[nM

2013-02-05 13:57:22 329

空空如也

空空如也

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

TA关注的人

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