上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 22 下一页
摘要: View Code /*==================================================*\| Polya计数| c种颜色的珠子, 组成长为s的项链, 项链没有方向和起始位置;\*==================================================*/// 注意超long longint Polya(int c,int s) { int i,j,k,p[64], count; p[0]=1; // power of c for(k=1; k<=s ;k++) p[k]=p[k-1]*c; //reflecti... 阅读全文
posted @ 2013-04-20 13:41 zhang1107 阅读(159) 评论(0) 推荐(0) 编辑
摘要: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4801每个位置记录的是左边做靠近他的和他相同大小的id,线段树维护的是最大的id (id最大也即最早出现)View Code const int MM = 555555;#define debug puts("wrong")#define L(i) i<<1#define R(i) i<<1|1int N,M;int hash[MM];int num[MM];int val[MM<<2];map<int,int&g 阅读全文
posted @ 2013-04-20 13:25 zhang1107 阅读(155) 评论(0) 推荐(0) 编辑
摘要: 容斥原理, 纠结好久, 求N以内和N不互质的所有数的和。http://acm.hdu.edu.cn/showproblem.php?pid=3501View Code int64 tp[MM], mm;void solve() { int64 i,j,k,ans=0,tmp=N,tt,t1,ret=1; for(i=mm=0;i<cnt;i++) { if(tmp%prm[i]==0) { tp[mm++]=prm[i]; while(tmp%prm[i]==0) tmp/=prm[i]; } } ... 阅读全文
posted @ 2013-04-20 00:39 zhang1107 阅读(138) 评论(0) 推荐(0) 编辑
摘要: View Code const int maxn = 11111; //文本最大长度int fail[maxn]; //失败了应该跳的位置char str[maxn], text[maxn]; //输入文本和待匹配的字符串//初始位置从0开始void get_next(int n) { int i, j=-1; for(fail[0]=-1, i=1;i < n; i++) { while(j>=0 && str[i]!=str[j+1]) j=fail[j]; if(str[j+1]==str[i]) j++; fail[... 阅读全文
posted @ 2013-04-19 16:13 zhang1107 阅读(136) 评论(0) 推荐(0) 编辑
摘要: 模拟栈View Code const int MM = 555555;#define debug puts("wrong")int to[MM], cnt, ans;char str[MM], ch[MM];char st[MM]; int top;void solve() { int i,j,k, n=strlen(str+1), m=strlen(ch+1); ans=0; top=0; str[0]='#'; for(i=1;i<=m;i++) { if(ch[i]==str[n]) { for(j=n-1;j>0;j--) i... 阅读全文
posted @ 2013-04-18 22:04 zhang1107 阅读(151) 评论(0) 推荐(0) 编辑
摘要: View Code /*================================*\| 筛素数 [1..n]\*================================*/bool isp[MM]; int prm[MM];int get_prime(int n) { int i,j,k=0; int s, e=(int)(sqrt(0.0+n)+1); for(i=0;i<=n;i++) isp[i]=true; prm[k++]=2; isp[0]=isp[1]=false; for(i=4;i<n;i+=2) isp[i]=false; ... 阅读全文
posted @ 2013-04-18 19:34 zhang1107 阅读(129) 评论(0) 推荐(0) 编辑
摘要: //组合数 com(n,r)View Code /*==========================*\| 组合数 com(n,r)\*==========================*/const int maxn = 100; //元素个数int com[maxn][maxn]; //注意 long longvoid get_com() { int i,j,k; for(i=0;i<maxn;i++) { com[i][0]=1; for(j=1;j<=i;j++) com[i][j]=com[i-1][j-1]+com[i-1][j]; ... 阅读全文
posted @ 2013-04-18 11:31 zhang1107 阅读(125) 评论(0) 推荐(0) 编辑
摘要: http://codeforces.com/problemset/problem/51/B利用stack类似与括号匹配,每个<table>ROWS</table> 划分一个模块,一个<td>TABLE</td>记录多少个CELL, stack中存的是模块的序号。View Code const int MM = 511111;const double esp=1e-8;const double lep=0.0000001;#define maxint 0x3f3f3f3ftypedef __int64 int64;#define debug put 阅读全文
posted @ 2013-04-18 10:50 zhang1107 阅读(200) 评论(0) 推荐(0) 编辑
摘要: http://codeforces.com/problemset/problem/51/C两次二分+贪心, 被卡精度卡了好久,发现整数点的话,结果不是整数就是 xxx.5的直接整数解决,就不会有精度问题啦。以后注意利用题目条件, double代码留作纪念。View Code const int MM = 511111;const double esp=1e-8;const double lep=0.0000001;#define debug puts("wrong")#define clr(a) memset(a,0,sizeof(a))int N,M,mm;int x[M 阅读全文
posted @ 2013-04-18 10:35 zhang1107 阅读(197) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑
上一页 1 ··· 5 6 7 8 9 10 11 12 13 ··· 22 下一页