|
04 2011 档案
摘要:/*******************************************************************************************这里包含了rabinmiller素数测试与pollard算法求解最小质因数的方法,函数说明放到每个函数的前面*******************************************************************************************/不是自己写的学习一下View Code /*****************************************
阅读全文
摘要:View Code #include<stdio.h>#include<math.h>int prim(int p){ int t=(int)sqrt(1.0*p); int i; for(i=2;i<=t;i++) { if(p%i==0) return 0; } return 1;}int mon(int x,int exp,int p){ if(exp==0) return 1; __int64 ret=mon(x,exp>>1,p); ret=(ret*ret)%p; if(exp&1) { ret =(ret*x)%p; } retu
阅读全文
摘要:求超级素数的过程比较简单主要是求路径用pa[]随时记录前驱,就好了View Code #include<stdio.h>#include<math.h>int prim[109];int f[109];int pa[109];bool rprim[109];int isprim(int a){ int t=sqrt(a*1.0); int i; for(i=2;i<=t;i++) { if(a%i==0) return 0; } return 1;}int main(){ int n; scanf("%d",&n); int i,add
阅读全文
摘要:直接用欧几里得AX+BY=gcd(A,B);问题里s(n-m)+k*l=x-y所以存在s,k的整数解的话就要 (x-y)%gcd(n-m,l)再分情况考虑n-m是否是正负 枚举k得出解View Code #include<stdio.h>__int64 gcd(__int64 m,__int64 n){ __int64 t; while(n!=0) { t=m%n; m=n; n=t; } return m;}int main(){ __int64 x,y,m,n,l; while(scanf("%I64d%I64d%I64d%I64d%I64d",&x
阅读全文
摘要:自己的代码:用到了STL实现:把两个二分集合分别保存在两个set容器里在用queue实现可以对后面有影响的组合先进入set容器View Code #include<stdio.h>#include<set>#include<queue>#include<algorithm>#include<iostream>using namespace std;char hash[209][209];bool x[30009];struct data { int a,b;};int cmp(data x,data y){ return x.a<
阅读全文
摘要:做规律题是可以先暴力找规律发现规律在11111之类的数附近修改暴力程序继续找做规律题一定要把规律找透再写View Code #include<stdio.h>int main(){ int k; scanf("%d",&k); if(k==1) { printf("8\n"); return 0; } int n=(k-1)%6; if(n==1||n==2||n==4||n==5) printf("1\n"); else if(n==0) printf("4\n"); else printf(
阅读全文
摘要:1 2 3 4 5 6 7 8 99 8 7 6 5,4 3 2 15 6 7,8 9,1 2,3 47 6,5,9,8,2,1,4,36,7,5,9,8,2,1,4,3多次倒序Input9 4Output8折中枚举,两种情况,右边的,左边的……View Code #include<stdio.h>int main(){ int n,x,y; scanf("%d%d",&n,&y); int add=0; while(n>=2) { x=n+1-y; if(x>(n+1)/2) { y=x-(n+1)/2; add+=(n+1)/2;
阅读全文
摘要:列方程可知,最小点一定在给定的某点上先排序后枚举计算某点的权值枚举可以由前面的推出后面的,不必重复计算View Code #include<stdio.h>#include<iostream>#include<algorithm>using namespace std;struct data{ double x; int p;}map[15099];int cmp(data a,data b){ return a.x<b.x;}int main(){ int n; scanf("%d",&n); int i; for(i=0
阅读全文
摘要:给出数Q,求出最小的自然数N使得N!的末尾恰有Q个0,无解输出"No solution"对于一个数n,求出它的末尾有几个0,只需看n之内的数的质因子5的个数,因为2的个数远多于5。所以可知道一个数末尾0的个数Q = n/5 + n/(5^2) + n/(5^3) + ...Q = N(5^k - 1) / [4*(5^k)],由此得N = 4Q * [(5^k)/(5^k-1)]还有就是注意0不是自然数!View Code #include<stdio.h>int fun(int n){ int add=0; while(n) { add+=n/5; n/=5;
阅读全文
摘要:View Code #include<stdio.h>int main(){ int x,y; double z; scanf("%d%d%lf",&x,&y,&z); double t=(y-x)*60; t=(t-z)*(t-z)*1.0/t/t; printf("%.7lf\n",1-t);}
阅读全文
摘要:f(n)实际就是n%9但要注意n==0实际是9View Code #include<stdio.h>int ab[1009];int main(){ int t; scanf("%d",&t); while(t--) { int n,i,a; __int64 b; scanf("%d",&n); for(i=0;i<n;i++) scanf("%d",&ab[i]); b=ab[n-1]%9; for(i=1;i<n;i++) { b=(b+1)*ab[n-1-i]%9; } if(b=
阅读全文
摘要:组合问题里比较常用的数列1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862……令h(1)=1,h(0)=1,catalan数满足递归式:h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2)另类递归式:h(n)=((4*n-2)/(n+1))*h(n-1);View Code #include<stdio.h>int main(){ int k; scanf("%d",&k); int i,j; __int64 all=1; for(i=1;i<=k;i
阅读全文
摘要:View Code #include<iostream>#include<cstring>using namespace std;class mystring{public: mystring(char *s); mystring(); ~mystring();//虚构函数用来释放动态内存 void addstring(char *s);//连接两个字符串 void stringup(char *s);//字符串大写换小写 void change(char *s);//改变字符串 void show();//输出字符串private: int len; char *p;
阅读全文
摘要:主要是筛选法求素数 筛选法时间O(log(n)*n)两个素数和是素数,那其中一个必然是2View Code #include<stdio.h>#include<math.h>bool prim[1000009];int f[20009];//f记录可行解int main(){ int n; scanf("%d",&n); int i,j; int t=(int)sqrt(n*1.0);//筛选法大概选择1000,000要500ms for(i=2;i<=t;i++) { for(j=2;j*i<=n;j++) { prim[i*j
阅读全文
摘要://这题主要求S//结论:S=(251^(n+1)-1)*(2^(3n+1)-1)/250//是两个等比数列和相乘////推理://2008=2^3*251//所以2008^N有3N个2和N个251//所有仅由2组成的因子有//2^02^12^2...2^(3N)//设集合C={2^0,2^1,2^2...,2^(3N)};//SUM(C)=2^(3n+1)-1//跟251组合产生的因子有//251^0*C//251^1*C//...//251^N*C//所有因子和为://S=(251^(n+1)-1))/250*(2^(3n+1)-1)//计算S%K://S很大,不能保存在普通的数据类型中,
阅读全文
摘要:就是找必败态>=162为p(162/9)18——161为N 想要进入必败态你就赢了,所以范围大(17/2)9——17为P 进入N必胜态你就输了,玩家没办法才要进入,所以范围小(8/9)1——8为NView Code #include<stdio.h>int main(){ unsigned int n; while(scanf("%d",&n)!=EOF) { unsigned int i=1,t=n,add; while(t!=1) { if(i%2==1) { if(t%9>0) add=1; else add=0; t=t/9; t+=
阅读全文
摘要:先找必败态如:一堆石头有8个NO:0 1 2 3 4 5 6 7 8S :P N N N P N N N P即s=a%(b+1)if s==0 就为必败态在用nim博弈是s^(a%(b+1))即可View Code #include<stdio.h>int main(){ int t; scanf("%d",&t); while(t--) { int n; scanf("%d",&n); int i,a,b,s; for(i=1;i<=n;i++) { scanf("%d%d",&a,&
阅读全文
摘要:如将50倍化为二进制110010对应32 16 8 4 2 1就是50是由32+16+2组成(加法)而推广到乘法里2^50=(2^32)*(2^16)*(2^2)=2^(32+16+2)View Code #include<stdio.h>int main(){ int n,m,k; scanf("%d%d%d",&n,&m,&k); int i,add=0,t,j; for(i=1;i<=n;i++) { __int64 all,rall=1; scanf("%d",&t); all=t; int co
阅读全文
摘要:1*2+2*3+3*4+……+n*(n+1)=n*(n+1)*(n+2)/3注意数据大了,所以先n*(n+1)取% (20090524*3)保证后面的数可以被3除View Code #include<stdio.h>int t;int main(){ scanf("%d",&t); while(t--) { __int64 n; scanf("%I64d",&n); __int64 all=0; if(n==1) { printf("1\n"); continue; } all=(__int64)(n*(n
阅读全文
摘要:先暴力下8位数前为零9位时位8那10就为8*9=72那11位就为8*10*9以此类推……View Code #include<stdio.h>int main(){ int n; scanf("%d",&n); if(n<=8) printf("0\n"); else if(n==9) printf("8\n"); else if(n==10) printf("72\n"); else { printf("72"); int i; for(i=11;i<=n;i+
阅读全文
摘要:View Code #include<stdio.h>#include<math.h>bool prim(int z){ int i; int sz=sqrt(z*1.0); for(i=2;i<=sz;i++) { if(z%i==0) { return 0; } } return 1;}bool ji(int a){ int sa=sqrt(a*1.0); int i; for(i=2;i<=sa;i++) { if(prim(i)==1) { if(a%i==0) { if(prim(a/i)==1) return 1; } } } return 0;
阅读全文
摘要:View Code #include<iostream>using namespace std;class Car;//为了使class Boat中可以定义Car类,可以暂时先声明可以引用Car类class Boat{public: Boat(int tBweight=0) { Bweight=tBweight; } friend class Car; friend void getTotalWeight(Car &C,Boat &B);//共同友元函数在每个引用的类都要定义private: int Bweight;};class Car{public: Car(i
阅读全文
摘要:View Code #include<iostream>#include<string.h>using namespace std;class student{private: char name[10]; int score;public: char* gan(student &student1,student &student2); friend void disp(student &student1);//友元函数 student(char tname[10]="",int tscore=0)//构造函数 { strcm
阅读全文
|