摘要: #include #include #include int a[100010],l,r,n,m;int check(int mon){ int i=1,j,s; for(j=0,s=0;jl) l=a[i]; r+=a[i]; } t=binary_search(); printf("%d\n",t); } return 0;} 阅读全文
posted @ 2014-01-22 18:40 单调的幸福 阅读(166) 评论(0) 推荐(0) 编辑
摘要: #include #include int N,m;structnode{ int a,b; int ci,pi,ri;}maps[20];int minS,flag[11];void dfs(int pos,int res){ if(pos==N) { if(res<minS) minS=res; return; } for(int i=1;i<=m;i++) { if(pos==maps[i].a && flag[maps[i].b]<=3) { i... 阅读全文
posted @ 2014-01-21 21:30 单调的幸福 阅读(126) 评论(0) 推荐(0) 编辑
摘要: #include#include#includeusing namespace std;int R,C,dp[110][70][70],stk[70],top,cur[110],num[110];char s[110][20];bool fit(int x,int k) //判断状态x是否与第k行匹配{ if(cur[k]&x) return 0; return 1;}int main(){ int i,j,k,t; while(scanf("%d%d",&R,&C)==2) { top=0; int total=1<<C,x,cnt; 阅读全文
posted @ 2014-01-21 19:23 单调的幸福 阅读(281) 评论(0) 推荐(0) 编辑
摘要: 快速幂参考的百度文库的一个文章,写的很详细http://wenku.baidu.com/view/2384ecc02cc58bd63186bdf6.html#include#includevoid Mul(int a[2][2],int b[2][2],int c[2][2]){ int i,j,k,sum; for(i=0;i=0 ) { int a[2][2]={ {1,1},{1,0} }; if(n==0) printf("0\n"); else { Pow(a,n); printf("%d\n",a[0][1]); } } return 0;} 阅读全文
posted @ 2014-01-21 17:59 单调的幸福 阅读(113) 评论(0) 推荐(0) 编辑
摘要: #include#include#include#includeusing namespace std;int main(){ int i,d; char s[80]; while(scanf("%s",s)!=EOF && s[0]!='*') { int len=strlen(s); bool mark=true,sign; if(lenflag; sign=true; for(i=0;i<=len-d-2;i++) { char pair[3]={s[i],s[i+d+1],'\0'}; if(!flag[ pai 阅读全文
posted @ 2014-01-21 16:55 单调的幸福 阅读(147) 评论(0) 推荐(0) 编辑
摘要: 将a进行质因数分解,则 a=(p1^k1)*(p2^k2)*...*(pn^kn); 故 a^b= p1^(a1*B) * p2^(a2*B) *...* pn^(an*B);根据公式,所有因子之和为sum=(1+p1+p1^2+...p1^k1)*(1+p2+p2^2+...p2^k2)*...*(1+pn+pn^2+...+pn^kn)计算1+p+p^2+...p^n可以利用二分进行加速当n为奇数时,例如n=5则1+p+p^2+p^3+p^4+p^5=(1+p+p^2)+p^3*(1+p+p^2)=(1+p+p^2)*(1+p^3)可以发现1+p+p^2+...p^n=(1+p+p^... 阅读全文
posted @ 2014-01-21 10:41 单调的幸福 阅读(270) 评论(0) 推荐(0) 编辑
摘要: #include __int64 C(__int64 a,__int64 b){if(b==0)return 1;else if(b==1)return a;elsereturn C(a-1,b-1)*a/b;}int main(){__int64 n,m;while(scanf("%I64d%I64d",&n,&m)!=EOF && (n||m) )printf("%I64d\n",C(n+m,n<m?n:m)); //C(m+n,n)= C(m+n,m)return 0;} 阅读全文
posted @ 2014-01-21 08:28 单调的幸福 阅读(114) 评论(0) 推荐(0) 编辑
摘要: #include#includeusing namespace std;int c[35][35];void Init(){ int i,j; for(i=0;i<33;i++) { c[i][0]=c[i][i]=1; for(j=1;j<i;j++) c[i][j]=c[i-1][j]+c[i-1][j-1]; }}int slove(int n){ int len=0,bit[35],i,j,sum=0,one=1,zero=0; while(n) { bit[++len]=n%2;... 阅读全文
posted @ 2014-01-20 20:27 单调的幸福 阅读(170) 评论(0) 推荐(0) 编辑
摘要: #include #include int T,grid[30][30],color[30],ret[30];void dfs(int x){ int c[30]={0},i; for (i=0;i<T;i++) if (grid[x][i]) c[color[i]] = 1; for (i=1;i<=T;i++) if (!c[i]) { color[x] = i; if (!ret[i]) ret[i] = 1; ... 阅读全文
posted @ 2014-01-20 18:14 单调的幸福 阅读(160) 评论(0) 推荐(0) 编辑
摘要: strncpy可以替代strcpy来防止缓冲区越界。但是如果还要考虑运行效率的话,也许strlcpy是一个更好的方式。1. strcpy我们知道,strcpy 是依据 /0 作为结束判断的,如果 to 的空间不够,则会引起 buffer overflow。strcpy 常规的实现代码如下(来自 OpenBSD 3.9):char *strcpy(char *to, const char *from){ char *save = to; for (; (*to = *from) != '/0'; ++from, ++to); return(save);}但通常,我们的 from 阅读全文
posted @ 2014-01-17 11:52 单调的幸福 阅读(224) 评论(0) 推荐(0) 编辑