上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 22 下一页
摘要: http://poj.org/problem?id=1699状态压缩,预处理出任意两个串的最长前缀和后缀的公共部分,然后DP。View Code //POJ1699const int MM = 110;#define maxint 0x3f3f3f3fint N;int d[1<<11][11];char str[MM];int len[MM][MM];int fail[MM];char ch[21][MM];int cal(int s1,int s2) { int i,j,k,n,m,ans=0; n=strlen(ch[s1]+1); m=strlen(ch[s2]+1)... 阅读全文
posted @ 2013-04-17 13:42 zhang1107 阅读(264) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=3368一维RMQView Code //询问递增序列 [l,r] 间,出现次数最多的数的个数,分段后用RMQ询问最小值int id, d[MM][17], N, Q;int len[MM],pos[MM],b[MM];int log_2(int x) { int res=0; while(x>>=1) res++; return res;}void get_rmq() { int i,j,k,limit; for(i=1;i<=id;i++) d[i][0]=len[i]; k=log_2(id); ... 阅读全文
posted @ 2013-04-17 13:21 zhang1107 阅读(114) 评论(0) 推荐(0) 编辑
摘要: //phi[i]记录的是 0~i 之间与i互质的数的个数http://poj.org/problem?id=2478View Code const int MM = 1000005;typedef __int64 int64;int64 N;int64 phi[MM];void get_phi() { int64 i,j,k; for(i=1;i<MM;i++) phi[i]=i; for(i=2;i<MM;i+=2) phi[i]>>=1; for(i=3;i<MM;i++) { if(phi[i]==i) { for(... 阅读全文
posted @ 2013-04-17 13:09 zhang1107 阅读(166) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4778当存在一个sum+(s[N]-s[h-1])恒不大于M时return掉View Code const int MM = 111111;#define debug puts("wrong")typedef long long int64;int N,M,ans;int s[MM];int num[MM];bool cmp(int x,int y) {return x>y;}void get_data() { int i,j,k; s[0]=0; 阅读全文
posted @ 2013-04-17 12:43 zhang1107 阅读(183) 评论(0) 推荐(0) 编辑
摘要: View Code //头文件:#include <queue>struct Tpoint{ int val,dead; //Tpoint(int v,int d):val(v),dead(d) {} bool friend operator<(Tpoint x,Tpoint y) { if(x.val!=y.val) return x.val>y.val; else return x.dead>y.dead; }};//多个key,重载运算符,que.top()保存的是val最小的priority_queue<Tpoint>que; 阅读全文
posted @ 2013-04-17 12:34 zhang1107 阅读(162) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4778优先队列优化下的DP,dp[i]记录的是吃到i天的最小花费,最后dp[N]即为答案。View Code const int MM = 111111;#define debug puts("wrong")typedef long long int64;//typedef __int64 int64;int64 N, cnt;struct Info{int64 x,y;}p[MM];struct Tpoint{ int64 val,dead; //Tpo 阅读全文
posted @ 2013-04-17 12:28 zhang1107 阅读(171) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=2299View Code //POJ2299int f_min(int x,int y) {if(x<y)return x; else return y;}int f_max(int x,int y) {if(x<y)return y; else return x;}const int MM = 511111;typedef __int64 int64;#define maxint 0x3f3f3f3fint64 N;int64 num[MM];int64 L[MM], R[MM],ans;void get_data() { i 阅读全文
posted @ 2013-04-16 19:43 zhang1107 阅读(106) 评论(0) 推荐(0) 编辑
摘要: http://poj.org/problem?id=1753View Code struct GaussE { int a[MM][MM]; int x[MM]; // 解集 int equ, var; int free_x[MM]; // 记录不确定的变元. //初始化 GaussE(int e,int v):equ(e), var(v) {} void reset() { memset(a,0,sizeof(a)); memset(x,0,sizeof(x)); memset(free_x,0,sizeof... 阅读全文
posted @ 2013-04-15 16:08 zhang1107 阅读(145) 评论(0) 推荐(0) 编辑
摘要: View Code int gcd(int x,int y) { int tmp; while(y) { tmp=y; y=x%y; x=tmp; } return x;}int lcm(int a,int b) { return a/gcd(a,b)*b;} 阅读全文
posted @ 2013-04-15 12:58 zhang1107 阅读(157) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4969询问次数那么多,本能想到线段树。对区间重标号,区间询问, 更新。View Code int N,M,K, len;int ll[MM<<2], rr[MM<<2];int ff[MM<<2];int sum[MM<<2];vector<int>edge[MM];void dfs(int u) { int i,j,k,v; ll[u]=len++; for(i=0;i<edge[u].size();i++) 阅读全文
posted @ 2013-04-13 18:37 zhang1107 阅读(157) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 22 下一页