摘要: A factory produces products packed in square packets of the same height h and of the sizes 1x1, 2x2, 3x3, 4x4, 5x5, 6x6. These products are always delivered to customers in the square parcels of the same height h as the products have and of the size 6x6. Because of the expenses it is the interest of 阅读全文
posted @ 2011-05-13 15:29 Ac_smile 阅读(287) 评论(0) 推荐(0) 编辑
摘要: 判断数N在k进制下是否为回文数,其中k∈[2,16],输出K。wa了一次,原因:在如果不存在k的情况下,不小心在n前面加了个& 输出了n的地址,导致错误。#include"stdio.h"int s[50000];int main(){ //freopen("1078b.txt","w",stdout); int n; while(scanf("%d",&n)!=EOF,n) { int base[16]; int i,k=0; for(i=2;i<=16;i++) { int j=0,tmp 阅读全文
posted @ 2011-05-13 11:42 Ac_smile 阅读(305) 评论(0) 推荐(0) 编辑
摘要: zoj控制格式真的很严格,PE了一次。#include"iostream"using namespace std;int s[30]={0};int before(int j){ int k=j; for(j;j>=0;j--) if(s[j]){ s[j]--; break; } return k-j+1;}int main(){ int t; cin>>t; while(t--) { int n,p[30],w[30],i; cin>>n; for(i=0;i<n;i++) { cin>>p[i]; if(i==0) s[ 阅读全文
posted @ 2011-05-12 16:03 Ac_smile 阅读(338) 评论(0) 推荐(0) 编辑
摘要: 是不是zoj不能添加注释的啊?很奇怪。这是1057的AC代码#include"stdio.h"#include"math.h"int main(){ int n,j; for(j=0;;j++) { scanf("%d",&n); if(n==0) break; if(j) printf("\n"); int a[20],b[20],i; int aa=0,bb=0; for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i+ 阅读全文
posted @ 2011-05-12 09:04 Ac_smile 阅读(479) 评论(0) 推荐(0) 编辑
摘要: john 必胜:1,所有均为1且SG值为0;2,有些堆大于1且SG值不为0。#include"iostream"using namespace std;int main(){ int k; cin>>k; while(k--) { int flag=1,n,i,s[50],ans=0; cin>>n; for(i=0;i<n;i++) { cin>>s[i]; if(s[i]!=1) flag=0; ans^=s[i]; } if(flag) { if(!ans) cout<<"John"<&l 阅读全文
posted @ 2011-05-11 15:44 Ac_smile 阅读(246) 评论(0) 推荐(0) 编辑
摘要: Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p = 1, does his multiplication, then Ollie multiplies the number, then Stan and so on. Before a game starts, they draw an integer 1 < n < 4294967295 and the winner i 阅读全文
posted @ 2011-05-11 15:01 Ac_smile 阅读(247) 评论(0) 推荐(0) 编辑
摘要: 利用积性函数的优化.这个文章主要介绍了3算法1线性时间筛素数2线性时间求前n个数的欧拉函数值3线性时间求前n个数的约数个数一、首先介绍下积性函数。下面是wiki的条目:在非数论的领域,积性函数指有对于任何a,b都有性质f(ab)=f(a)f(b)的函数。在数论中的积性函数。对于正整数n的一个算术函数f(n),当中f(1)=1且当a,b互质,f(ab)=f(a)f(b),在数论上就称它为积性函数。若某算术函数f(n)符合f(1)=1,且就算a,b不互质,f(ab)=f(a)f(b),称它为完全积性的。例子φ(n)-欧拉φ函数,计算与n互质的正整数之数目μ(n)-默比乌斯函数,关于非平方数的质因子 阅读全文
posted @ 2011-05-10 21:07 Ac_smile 阅读(637) 评论(0) 推荐(0) 编辑
摘要: 假若相遇,则存在 x+ms≡y+ns(mod l)=>(x+ms)-(y+ns)=kl;=>x-y-(n-m)s=kl;(已知x,y,n,m,l)=>kl+(n-m)s=x-y;即求满足 kl+bs=a(已知 l,b,a)最小的s;——————————扩展欧几里德算法-求解不定方程,线性同余方程:解不定方程ax + by = n的步骤如下:(1)计算gcd(a, b). 若gcd(a, b)不能整除n,则方程无整数解;否则,在方程的两边同除以gcd(a, b), 得到新的不定方程a'x + b'y = n',此时gcd(a', b') 阅读全文
posted @ 2011-05-10 20:06 Ac_smile 阅读(263) 评论(0) 推荐(0) 编辑
摘要: 求N个同余方程,用扩展欧几里得。扩展欧几里得算法是用来在已知a,b的情况下求解一组x,y 使得 ax+by = gcd(a,b)原理:gcd(a,b) = gcd(b, a%b)=> ax+by = gcd(a,b) = gcd(b, a%b);=>ax+by=bx+(a%b)y;=>ax+by=bx1+(a-(a/b)*b)y1=ay1+bx1-(a/b)*by1;=>x=y1;y=x1-(a/b)*y1;#include"iostream"using namespace std;__int64 egcd(__int64 a,__int64 b,_ 阅读全文
posted @ 2011-05-10 16:09 Ac_smile 阅读(319) 评论(0) 推荐(0) 编辑
摘要: 典型的中国余数定理的应用。设m1,m2,..,mk是k个两两互素的正整数,m=m1*m2*...*mk,Mi=m/mi(i=1,2,..,k)。则同余方程组x≡b1(mod m1)x≡b2(mod m2)......x≡bk(mod mk)有唯一解。x≡M'1M1b1+…+M'kMkbk (modm),其中M'iMi≡1 (modmi),i=1,2,…,k举个最经典的例子,今有物不知其数,三三数之余二 ,五五数之余三 ,七七数之余二,问物几何?除数序列{3,5,7};对应的余数序列{2,3,2}接下来我们需要求一个数k1满足k1 %3==1&&k1%5= 阅读全文
posted @ 2011-05-10 14:20 Ac_smile 阅读(151) 评论(0) 推荐(0) 编辑