摘要: View Code inline bool scan_d(int &num) { // 外挂输入 char in;bool IsN=false; in=getchar(); if (in == EOF) return false; while (in!='-' &&( in<'0'||in>'9')) in=getchar(); if (in == '-') { IsN=true;num=0;} else num=in-'0'; while (in=getchar(),in> 阅读全文
posted @ 2013-04-20 19:33 zhang1107 阅读(110) 评论(0) 推荐(0) 编辑
摘要: http://codeforces.com/problemset/problem/50/C记录出轮廓线,计算出走的长度, ans+4View Code void get_data() { int64 i,j,k; for(i=0;i<N;i++) scanf("%I64d%I64d",&g[i].x,&g[i].y);}void solve() { int64 i,j,k,x,y,ans=0,cnt; cnt=graham(g,N,res); for(i=1;i<cnt;i++) { // printf("%d %d\n",r 阅读全文
posted @ 2013-04-20 14:18 zhang1107 阅读(175) 评论(0) 推荐(0) 编辑
摘要: Graham求凸包 O(N * logN)View Code /*==================================================*\| Graham求凸包 O(N * logN)| CALL: nr = graham(pnt, int n, res);|pnt[]为给定点集 n为点的个数 res[]为凸包点集;\*==================================================*/struct Tpoint {int x,y;}g[MM]; //注意点的类型Tpoint res[MM];bool mult(Tpoint 阅读全文
posted @ 2013-04-20 14:16 zhang1107 阅读(149) 评论(0) 推荐(0) 编辑
摘要: View Code //头文件:#include <algorithm>//O(N!)const int maxn = 1000; int num[maxn];void permut(int n) { //n:元素个数 int i,j,k; sort(num,num+n); //注意排序 do { for(i=0;i<n;i++) printf("%d ",num[i]); printf("\n"); }while(next_permutation(num,num+n));} 阅读全文
posted @ 2013-04-20 13:47 zhang1107 阅读(111) 评论(0) 推荐(0) 编辑
摘要: 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) 编辑