09 2014 档案

摘要:同样是确定某位上的数,当确定某一位后,其后面的排列数是确定的,所以可以用除法和取余数的方法来确定这一位的值#include #include #include using namespace std;int lim[10];bool vis[20];int ans[20],ansl;void ini... 阅读全文
posted @ 2014-09-28 21:52 chenjunjie1994 阅读(233) 评论(0) 推荐(0)
摘要:其实求的这个数的式子化简一下,就是C(N,M).....#include #include #include #define LL __int64using namespace std;LL N,M;LL myc(LL n,LL r){ LL sum=1; for(LL i=1;i<=r;i++) ... 阅读全文
posted @ 2014-09-27 11:11 chenjunjie1994 阅读(200) 评论(0) 推荐(0)
摘要:枚举病的组合,再把牛的状态与之作或运算,若值仍是病组合的状态,则可以加1,否则,跳过。#include #include #include using namespace std;int cow[1100],n,D,K;int ans;int hm(int k){ int h=0; while(k)... 阅读全文
posted @ 2014-09-27 10:55 chenjunjie1994 阅读(197) 评论(0) 推荐(0)
摘要:简单求组合数,直接运用公式。注意C(n,k)=C(n,n-k)。#include #include #include #define LL __int64using namespace std;LL myc(LL n, LL r){ LL sum=1; for(LL i=1;in-r?n-r:r; ... 阅读全文
posted @ 2014-09-27 09:20 chenjunjie1994 阅读(141) 评论(0) 推荐(0)
摘要:按字典序选一个六组合。简单DFS#include #include #include using namespace std;int se[20];int ans[20];void dfs(int ps,int position,int k){ if(position>k){ if(ps==6){... 阅读全文
posted @ 2014-09-27 09:12 chenjunjie1994 阅读(181) 评论(0) 推荐(0)
摘要:开始时竟然用了分情况讨论。仔细思考一下,哈哈,发现不过是多重集合的组合数而已。#include #include #include using namespace std;typedef __int64 u_int;u_int myc(u_int n,u_int r){ u_int sum=1; ... 阅读全文
posted @ 2014-09-26 23:33 chenjunjie1994 阅读(189) 评论(0) 推荐(0)
摘要://可能相当计算题了。按递增量为1,2,3,4,5划分,记录下第一个数字串的长度以及开始的位置。//然后判断出给出的位置属于增量的哪一段,再按等差数列计算它属于哪一个数字串,按在该数字串的位置计算数字,即可。#include #include #include #include #include u... 阅读全文
posted @ 2014-09-26 21:01 chenjunjie1994 阅读(127) 评论(0) 推荐(0)
摘要:看见discuss 上说买一送一,果然是这样的。与POJ 1850相同--!#include #include #include #include #include using namespace std;int M[30][30];char s[30];int num[30];void initi... 阅读全文
posted @ 2014-09-25 20:33 chenjunjie1994 阅读(195) 评论(0) 推荐(0)
摘要:逐位确定其上可填的字母,组合数学题。注意:当不符合规则时,要求输出0;#include #include #include #include #include using namespace std;int M[30][30];char s[30];int num[30];void initial(... 阅读全文
posted @ 2014-09-25 20:31 chenjunjie1994 阅读(141) 评论(0) 推荐(0)
摘要:折腾了很久。注意到,每一个数总是这样的形式的:1010101100100。。如,当110000到111000时,我们可以看成是从110000到110111的计数。最后特判111000即可。这时,我们需要记下前三们110中1与0的个数之差,以决定后三位取0的个数。所以,不妨预处理出0,1,10,100... 阅读全文
posted @ 2014-09-25 16:03 chenjunjie1994 阅读(196) 评论(0) 推荐(0)
摘要:使用STL中的next_permutation(opt1,opt2)函数更容易实现。opt1为数组头地址,opt2为数组长度。排列是按字典序的。当找到下一个排列时,返回真,否则返回假,此时,把原数组重排一次。#include #include #include using namespace std... 阅读全文
posted @ 2014-09-24 20:11 chenjunjie1994 阅读(148) 评论(0) 推荐(0)
摘要:第一题组合数学题。可以使用递推,设1与其他各数分别连边,假设N=3;若1-4,则圆分成两部分计数,此时可以利用乘法原理。(高精度)#include #include #include #include using namespace std;const int maxn = 200;struct b... 阅读全文
posted @ 2014-09-24 19:41 chenjunjie1994 阅读(270) 评论(0) 推荐(0)
摘要:挺水的一题。其实只要理解了RSA算法,就知道要使用大整数分解的方法来直接模拟了。不过,要注意两个INT64的数相乘来超范围#include #include #include #include #include #include #define LL __int64 using namespace ... 阅读全文
posted @ 2014-09-17 22:26 chenjunjie1994 阅读(325) 评论(0) 推荐(0)
摘要:水。模拟即可。使用EXGCD求逆元#include #include #include #include #define LL __int64using namespace std;LL p,q,e,n,f,d;void exgcd(LL a,LL b,LL &x,LL &y){ if(b==0){... 阅读全文
posted @ 2014-09-17 21:15 chenjunjie1994 阅读(181) 评论(0) 推荐(0)
摘要:用了一点群论中的置换群的知识,仅是一点,找出循环节,取模即可。初次接触群论,等做完余下一点东西后就系统一点学习组合数学的内容#include #include #include #include using namespace std;int n;int chan[210];int partic[2... 阅读全文
posted @ 2014-09-17 11:28 chenjunjie1994 阅读(184) 评论(0) 推荐(0)
摘要:稍加分析后,你会发现,就是统计次数而已#include #include using namespace std;int a[110],b[110];int aa[30],bb[30];char cipher[110],m[110];int main(){ while(scanf("%s",ciph... 阅读全文
posted @ 2014-09-16 22:32 chenjunjie1994 阅读(146) 评论(0) 推荐(0)
摘要:水题一道,注意取模时不能为0#include #include #include #include #include using namespace std;char s[150];char ans1[150],ans2[150],ans3[150];int mark[150];int p1,p2,... 阅读全文
posted @ 2014-09-16 22:12 chenjunjie1994 阅读(195) 评论(0) 推荐(0)
摘要:第一道简单密码学的题,太水了,本不打算做,第一道,还是纪念一下。#include #include #include #include #include using namespace std;char trans[30]={'V','W','X','Y','Z','A','B','C','D','... 阅读全文
posted @ 2014-09-15 22:07 chenjunjie1994 阅读(174) 评论(0) 推荐(0)
摘要:看见别人的用的莫比乌斯来做,我看了好久也没明白,实在佩服,看到是组合数学的内容,只好先留着,待我学了组合数学后再用莫比乌斯来写。求GCD(X,Y)=K.其实即是在[1,X/K]和[1,Y/K]的区间内求GCD(X,Y)=1的对数。这样,假设X/K#include #include #include ... 阅读全文
posted @ 2014-09-14 22:03 chenjunjie1994 阅读(151) 评论(0) 推荐(0)
摘要:模拟题#include #include #include using namespace std;int p[1000000];int main(){ int n; while(scanf("%d",&n)!=EOF){ memset(p,0,sizeof(p)); int i; for(i... 阅读全文
posted @ 2014-09-14 21:56 chenjunjie1994 阅读(148) 评论(0) 推荐(0)
摘要:由算术基本定理N=p1^e1*p2^e2....ps^es,可知一个素的因子个数为(e1+1)*(e2+1)*...*(es+1)。而N的一人因子必定也有n=p1^k1*p2^k2。。。。*ps^ks的形式。因子个数形式同上。而事实上,即是从ei中选取其中一些来充当k1。那么,所有的因子的个数之和必... 阅读全文
posted @ 2014-09-13 21:32 chenjunjie1994 阅读(152) 评论(0) 推荐(0)
摘要:利用x#include #include #include #include #define LL __int64using namespace std;const LL N=10000005;bool isprime[N];int pme[N],np;void initial(){ memset(... 阅读全文
posted @ 2014-09-13 20:41 chenjunjie1994 阅读(179) 评论(0) 推荐(0)
摘要:可以容易得知,F=sum(p*phi(n/p))。思路就断在这里了。。。看过别人的,才知道如下:由于gcd(i,n*m)=gcd(i,m)*gcd(i,n),所以gcd为积性函数。而积性函数之和为积性函数。所以F=sum(gcd(i,n))为积性函数。n=p1^k1*p2^k2....所以f(p1^... 阅读全文
posted @ 2014-09-13 15:30 chenjunjie1994 阅读(120) 评论(0) 推荐(0)
摘要:和上题一样,不过,更简单了#include #include #include #include #include using namespace std;const int MOD=29;int quick(int a,int b,int m){ int res=1; while(b){ if(... 阅读全文
posted @ 2014-09-13 10:53 chenjunjie1994 阅读(165) 评论(0) 推荐(0)
摘要:此题需要注意的一个细节时,若MOD|P或MOD|(P-1),此时不能应用费马小定理求逆元的方法。这时,就要回到求解因子和的初始公式是,即那个等比数列相加的公式。这时,若MOD|P,即,余为1,若MOD|(P-1),即为K个1之和。如此,可求了。#include #include #include #... 阅读全文
posted @ 2014-09-13 09:46 chenjunjie1994 阅读(131) 评论(0) 推荐(0)
摘要:此题A得艰难,应该是有很多组数据吧,使得容易超时。直接求出组合数是不可能的,因而,只能把各个数都计算其各素因子个数,再计算即可。而直接计算,必定是要超时的,所以,只好先预处理所有结果,再输出了。首先筛选素数,分解0~440的素因子。然后,Cnk=(n*(n-1)*(n-2)*...(n-k+1))/... 阅读全文
posted @ 2014-09-12 21:24 chenjunjie1994 阅读(252) 评论(0) 推荐(0)
摘要:此题的主要还是如何把小数化作分数来解答。设p/q。对于二进制(三进制,四进制一样),若p>q便商1,取mod,p*2-->p,然后再作p/q,若p#include #include #include #define LL __int64using namespace std;LL fac[10000... 阅读全文
posted @ 2014-09-12 19:39 chenjunjie1994 阅读(226) 评论(0) 推荐(0)
摘要:这里面的一个转换的小技巧很重要,把888...8转换成(10^x-1)/9*8。神来之笔,佩服。这样有(10^x-1)/9*8=L*p得10^x-1=L*p*9/8,设m=9*L/gcd(L,8)。这一步如何想到的呢?其实是为了使m与10互质而做的。因为这样必有m*p1=10^x-1。使得同余方程1... 阅读全文
posted @ 2014-09-12 11:02 chenjunjie1994 阅读(297) 评论(0) 推荐(0)
摘要:所谓可见点,即是(a,b)=1的点,使用欧拉函数,求出比之小的与之互质的个数即可,又对称,所以乘2,最后要+1.#include #include #include #include using namespace std;const int N=1050;int phi[N];void initi... 阅读全文
posted @ 2014-09-10 15:05 chenjunjie1994 阅读(195) 评论(0) 推荐(0)
摘要:使用递推求欧拉函数,因为FN就是欧拉函数的累加和。#include #include #include #include using namespace std;const int Max=1000010;int phi[Max];int main(){ for(int i=1;i<Max;i++)... 阅读全文
posted @ 2014-09-10 11:33 chenjunjie1994 阅读(156) 评论(0) 推荐(0)
摘要:想了很久,只想到枚举的方法,估计会超时吧。原来有这样一条性质:p为素数,则p有phi(p-1)个原根Orz...#include #include #include #include using namespace std;int main(){ int n; while(scanf("%d",&n... 阅读全文
posted @ 2014-09-10 10:33 chenjunjie1994 阅读(171) 评论(0) 推荐(0)
摘要:裸 的求欧拉函数#include #include #include #include #include using namespace std;int main(){ int n; while(scanf("%d",&n),n){ int res=n; int L=(int)sqrt(n*1.... 阅读全文
posted @ 2014-09-09 21:50 chenjunjie1994 阅读(128) 评论(0) 推荐(0)
摘要:使用Pollard_rho算法分解lcm/gcd的质因数,原因不说也明白了。然后排序,把相同的质因子合并,因为如果相同的质因子分落在两个因数,会使ab的GCD值改变。然后,枚举各种组合,呃。。。。这个实在想不到好方法,只好枚举了,真想不明白,那么两位数时间的是怎么样做到的。#include #inc... 阅读全文
posted @ 2014-09-08 20:24 chenjunjie1994 阅读(255) 评论(0) 推荐(0)
摘要:使用Pollard_rho算法就可以过了#include #include #include #include #include #include #include #define LL __int64using namespace std;LL ans;const LL C=201;LL rand... 阅读全文
posted @ 2014-09-08 20:20 chenjunjie1994 阅读(218) 评论(0) 推荐(0)
摘要:因为规模小,使用试除法即可#include #include #include #include using namespace std;const int Maxn=100;int prime[Maxn];int main(){ int n,m; while(scanf("%d",&n)!=EOF... 阅读全文
posted @ 2014-09-07 21:06 chenjunjie1994 阅读(204) 评论(0) 推荐(0)
摘要:很明显可以转化为反素数的题目。由于有n种不同的方式,所以,数的约数可以为2*n或者2*n-1#include #include #include #define LL __int64using namespace std;LL p[16]={2,3,5,7,11,13,17,19,23,29,31,... 阅读全文
posted @ 2014-09-06 20:08 chenjunjie1994 阅读(151) 评论(0) 推荐(0)
摘要:了解反素数的定义:反素数是指[1,n]内,比n小的数的约数个数都比n的约数个数要少。注意n其实是最后一个。而在区间内,[a,b]是明显无法满足条件的。注意了最大才5000.所以,不妨使用枚举。#include #include #include using namespace std;const i... 阅读全文
posted @ 2014-09-06 16:30 chenjunjie1994 阅读(199) 评论(0) 推荐(0)
摘要:注意题目中的一句话:If a number m has bigger evaluating value than all the numbers smaller than it。。。这让我重新想过反素数的定义,应该 是比n小的数的约数的个数都 小于 n。所以,应该取最小的一个值#include #i... 阅读全文
posted @ 2014-09-06 16:15 chenjunjie1994 阅读(240) 评论(0) 推荐(0)
摘要:在讲解反素数之前,我们先来看反素数的概念。反素数的定义:对于任何正整数,其约数个数记为,例如,如果某个正整数满足:对任意的正整 数,都有,那么称为反素数。从反素数的定义中可以看出两个性质:(1)一个反素数的所有质因子必然是从2开始的连续若干个质数,因为反素数是保证约数个数为的这个数尽量小(2)同样的... 阅读全文
posted @ 2014-09-06 15:45 chenjunjie1994 阅读(219) 评论(0) 推荐(0)
摘要:可以先找出回文数,再用素数测试来判是否为素数即可。打回文数时,因为左右对称,可以只枚举后半部,然后通过逆转得到前半部分。#include #include #include #include #include using namespace std;const int Max=200000;int ... 阅读全文
posted @ 2014-09-06 11:30 chenjunjie1994 阅读(202) 评论(0) 推荐(0)
摘要:这题用MILLER测试应该是不可避免的。#include #include #include #include #define LL __int64using namespace std;LL random(LL n){ return (LL)((double)rand()/RAND_MAX*n+0... 阅读全文
posted @ 2014-09-06 09:43 chenjunjie1994 阅读(147) 评论(0) 推荐(0)
摘要:主要是为了试一下MILLER-RABIN的方法#include #include #include #include #define LL __int64using namespace std;const LL TIME=1000;LL random(LL n){ return (LL)((doub... 阅读全文
posted @ 2014-09-06 09:23 chenjunjie1994 阅读(184) 评论(0) 推荐(0)
摘要:快速幂模+佩尔方程#include #include #include #include const int Mod=8191;struct Matrax { int m[3][3];};Matrax a,per;void slove(int d,int &x1,int &y1){ y1=1; wh... 阅读全文
posted @ 2014-09-04 21:04 chenjunjie1994 阅读(135) 评论(0) 推荐(0)
摘要:作弊了--!该题可以通过因式分解得到一个佩尔方程。。。。要不是学着这章,估计想不到。。得到x1,y1后,就直接代入递推式递推了x[n]=x[n-1]*x[1]+d*y[n-1]*y[1]y[n]=x[n-1]*y[1]+y[n-1]*x[1]#include #include #include #i... 阅读全文
posted @ 2014-09-04 20:33 chenjunjie1994 阅读(183) 评论(0) 推荐(0)
摘要:求本原毕达三原组的个数以及不是毕达三元组的数。这道题需要把规模降下来,由x=m^2-n^2y=2mnz=m^2+n^2由有x+y#include #include #include #include using namespace std;const int Maxn=1000010;bool fl... 阅读全文
posted @ 2014-09-04 19:56 chenjunjie1994 阅读(120) 评论(0) 推荐(0)
摘要:这题确实是好。其实是求x1*a1+x2*a2+....M*xn+1=1有解的条件。很明显,就是(a1,a2,...M)=1了。然后,可以想象,直接求有多少种,很难,所以,求出选择哪些数一起会不与M互质。。。好吧,思路就到这里了。。。T_T经过人提示,若(a1,a2,,,,an)与M不互质,则最大公约... 阅读全文
posted @ 2014-09-04 15:57 chenjunjie1994 阅读(278) 评论(0) 推荐(0)
摘要:这道题的难点在于求|x|+|y|的为最小的值吧。想了好久才想出来,发现自己的数学能力确实跟不上。可知。x=x0+b/d*t;y=y0-a/d*t;则为|x0+b/d*t|+|y0-a/d*t|,仔细想想,可以看成的是两条直线方程y绝对值之和。那么,必然最小值只能出现在两条直线方程的两个零点之间,则枚... 阅读全文
posted @ 2014-09-04 11:33 chenjunjie1994 阅读(159) 评论(0) 推荐(0)
摘要:再不能直视这道题,换INT64就过了。。。。。。。同样可以使用矩阵的方法。构造1*5的D[N],a[n],b[n],a【n】*b[n],1接着你应该就会了。#include #include #include #define LL __int64using namespace std;const L... 阅读全文
posted @ 2014-09-03 20:05 chenjunjie1994 阅读(165) 评论(0) 推荐(0)
摘要:昨晚苦恼了一晚,因为即将大三了,必须要准备实习什么的事了。一般都会去公司实习吧,但是看看自己的简历,实在拿不出手,因为大一大二都在搞ACM(虽然真正搞的只有大二一年),但却没有什么成绩,又不愿意做项目,因为只想一心搞ACM。可到了现在,如果真的没点什么的话,可能就去不了做实习生了。但是,想想自己,这... 阅读全文
posted @ 2014-09-03 16:30 chenjunjie1994 阅读(228) 评论(0) 推荐(0)
摘要:简单的矩阵构造题,参看我前几篇的谈到的矩阵的构造法。#include #include #include #include using namespace std;int Mod;struct Matrax { int m[15][15];};Matrax a,per;int ats[15],an[... 阅读全文
posted @ 2014-09-02 16:41 chenjunjie1994 阅读(292) 评论(0) 推荐(0)
摘要:可以利用DP的思想来做,不过是在DP时加上了矩阵乘法的思想而已,但乘法不是真的乘法,而是mp[a][i]+mp[i][b]I=0的话,则会一直不动,所以要初始化到I->I=INF;#include #include #include using namespace std;const int inf... 阅读全文
posted @ 2014-09-02 16:04 chenjunjie1994 阅读(211) 评论(0) 推荐(0)
摘要:呃,离散数学课上直接就有这样的题#include #include #include using namespace std;const int Mod=1000;struct Matrax { int m[25][25];};Matrax a,per;int n,m;void initial(){... 阅读全文
posted @ 2014-09-02 13:36 chenjunjie1994 阅读(134) 评论(0) 推荐(0)
摘要:知道了怎么置换之后,就可以用矩阵来置换了,但这道题一直关于置换的地方读不明白。#include #include #include using namespace std;const int Maxn=100;int pn[Maxn],xn[Maxn],bn[Maxn];int ansp[Maxn]... 阅读全文
posted @ 2014-09-02 10:18 chenjunjie1994 阅读(181) 评论(0) 推荐(0)
摘要:利用矩阵来做变换,参考Max大神的思想的,虽然不是同一道题。-----------给定n个点,m个操作,构造O(m+n)的算法输出m个操作后各点的位置。操作有平移、缩放、翻转和旋转这里的操作是对所有点同时进行的。其中翻转是以坐标轴为对称轴进行翻转(两种情况),旋转则以原点为中心。如果对每个点分别进行... 阅读全文
posted @ 2014-09-02 08:51 chenjunjie1994 阅读(210) 评论(0) 推荐(0)
摘要:先转一些 http://www.cnblogs.com/frog112111/archive/2013/05/19/3087648.htmlFibonacci数列:F(0)=1 , F(1)=1 , F(n)=F(n-1)+F(n-2)我们以前快速求Fibonacci数列第n项的方法是 构造常系数矩... 阅读全文
posted @ 2014-09-01 21:10 chenjunjie1994 阅读(202) 评论(0) 推荐(0)
摘要:必须MARK下:任何时候都要保持清醒头脑,不要被题目绕了。。其实就是求最小公倍数。#include #include #include using namespace std;__int64 v[20];__int64 gcd(__int64 a,__int64 b){ if(b==0) retur... 阅读全文
posted @ 2014-09-01 11:02 chenjunjie1994 阅读(205) 评论(0) 推荐(0)
摘要:直接使用中国剩余定理#include #include #include using namespace std;int r=3;int m[4]={0,23,28,33};int a[4]={0};void exgcd(int a,int b,int &d,int &x,int &y){ if(b... 阅读全文
posted @ 2014-09-01 10:25 chenjunjie1994 阅读(140) 评论(0) 推荐(0)