2012年3月29日

poj 2488 DFS

摘要: 水题,注意字典序输出 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 const int maxx=50; 6 int dir[8][2]={{-2,-1},{-2,1},{-1,-2},{-1,2},{1,-2},{1,2},{2,-1},{2,1}}; 7 int n,m,p1[maxx*maxx+2],p2[maxx*maxx+2],cnt; 8 bool visit[maxx+2][maxx+2]; 9 10 bool 阅读全文

posted @ 2012-03-29 15:20 Inpeace7 阅读(124) 评论(0) 推荐(0) 编辑

POJ 1111 DFS

摘要: DFS 水题求周长:若当前状态旁边有k个x,则总周长加4-x 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 const int maxx=20; 7 int dir[8][2]={{0,-1},{1,0},{0,1},{-1,0},{1,-1},{1,1},{-1,1},{-1,-1}}; 8 int cnt,n,m; 9 char c[maxx+2][maxx+2];10 bool visit[maxx+2][maxx+ 阅读全文

posted @ 2012-03-29 10:52 Inpeace7 阅读(165) 评论(0) 推荐(0) 编辑

poj 2386 DFS

摘要: DFS 水题 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 const int maxx=100; 7 int n,m,cnt,dir[8][2]={{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}}; 8 char pool[maxx+2][maxx+2]; 9 bool visit[maxx+2][maxx+2];10 11 bool judge(int a,i 阅读全文

posted @ 2012-03-29 09:22 Inpeace7 阅读(109) 评论(0) 推荐(0) 编辑

2012年3月28日

poj 3620 DFS

摘要: 水题 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 const int maxx=100; 7 8 int dir[4][2]={{0,1},{1,0},{0,-1},{-1,0}}; 9 int n,m;10 bool wet[maxx+2][maxx+2],visit[maxx+2][maxx+2];11 int ans,cnt;12 struct A13 {14 int x,y;15 };16 A point[max 阅读全文

posted @ 2012-03-28 20:37 Inpeace7 阅读(140) 评论(0) 推荐(0) 编辑

2012年3月26日

hdu 2899 三分查找求极值

摘要: #include <iostream>#include <cmath>#include <stdio.h>using namespace std;#define eps 1e-6double f(double x,double y){ return 6.0*pow(x,7.0)+8.0*pow(x,6.0)+7.0*pow(x,3.0)+5.0*pow(x,2.0)-y*x;}int main(){ int t,tt; double sum,mid,tmid,l,r,y; freopen("in.txt","r",st 阅读全文

posted @ 2012-03-26 19:26 Inpeace7 阅读(156) 评论(0) 推荐(0) 编辑

2012年3月23日

poj 2909 哥德巴赫猜想

摘要: 水题#include <iostream>#include <stdio.h>#include <string.h>using namespace std;const int maxx=100000;bool prime[maxx+10];void getprime(){ memset(prime,1,sizeof(prime)); prime[0]=prime[1]=0; for(int i=2;i*i<=maxx;i++) if(prime[i]) for(int j=i*i;j<=maxx;j+=i) prime[j]=... 阅读全文

posted @ 2012-03-23 21:31 Inpeace7 阅读(377) 评论(0) 推荐(0) 编辑

hdu 3792 孪生素数

摘要: 求小于n的孪生素数的个数,求和用树状数组 1 #include <iostream> 2 #include <stdio.h> 3 #include <string.h> 4 using namespace std; 5 6 const int maxx=100000; 7 8 #define lowbit(i) (i&(-i)) 9 10 bool prime[maxx+10];11 int tree[maxx+10];12 void add(int i,int val)13 {14 while(i<=maxx)15 {16 tree[i]+ 阅读全文

posted @ 2012-03-23 21:09 Inpeace7 阅读(235) 评论(0) 推荐(0) 编辑

多边形数

摘要: 以下摘自维基百科1.三角形数: n(n+1)/2性质:(1)所有大于3的三角形数都不是质数(2)所有偶完全数都是三角形数2.四边形数(平方数)n*n(1)拉格朗日四平方和定理1)每个自然数均可表示成4个平方数之和。2)3个平方数之和不能表示形式如4k(8n+ 7)的数。3)如果在一个正整数的因数分解式中,没有一个数有形式如4k+3的质数次方,该正整数可以表示成两个平方数之和。(2)在十进制中,平方数只能以 00,1,4,6,9 或 25 结尾:若一个数以 0 结尾,它的平方数以 00 结尾,且其他数字也构成一个平方数若一个数以 1 或 9 结尾,它的平方数以 1 结尾,且其他数字构成的数能被 阅读全文

posted @ 2012-03-23 19:32 Inpeace7 阅读(2721) 评论(0) 推荐(0) 编辑

poj 1777梅森素数

摘要: 能力太水了,下个月的长春邀请赛可怎么办。。。。唉。。。梅森素数(把形如(2p-1)形式的素数称为梅森素数,p是素数),挺好的一道题,1.一个正整数n的所有约数和是2的幂<===>n能够被分解为若干个不同的梅森素数之积。2.约数和S=(1+p1+p12+…+p1a1 )( 1+p2+p22+…+p2a2)…(1+pk+pk2+…+pkak)3.输入p1,p2,…,pn,有非梅森素数或非梅森素数的乘积,去掉012345678素数指数pr235713171931mer 2pr-1373112781911310715242872147483647Hash mer(10)1248163264 阅读全文

posted @ 2012-03-23 17:21 Inpeace7 阅读(455) 评论(0) 推荐(0) 编辑

2012年3月20日

hdu 2815 baby_step c可为非素数

摘要: 解方程 a^x=b(mod c) c为可以为合数,参考AC大牛的http://hi.baidu.com/aekdycoin/blog/item/b317ca18bb24334942a9ad55.html 1 #include <iostream> 2 #include <stdio.h> 3 #include <cmath> 4 using namespace std; 5 typedef long long ll; 6 const int maxn=65535; 7 struct Hashh 8 { 9 int a,b,next; 10 }Hash[max 阅读全文

posted @ 2012-03-20 11:27 Inpeace7 阅读(227) 评论(0) 推荐(0) 编辑

导航