摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=5递归模拟, 记录pair<a,b>是否被访问过。View Code const int MM = 111111;#define debug puts("wrong")#define clr(a) memset(a,0,sizeof(a))bool vis[1005][1005];int op[MM];int Ca, Cb, N;bool ff;void gao(int x) { if(x==1) puts("fill A") 阅读全文
posted @ 2013-04-17 17:12 zhang1107 阅读(148) 评论(0) 推荐(0) 编辑
摘要: 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 阅读(172) 评论(0) 推荐(0) 编辑