摘要: /*POJ 1671 Rhyme Schemesresult:ACtime: 0MS*/#include"iostream"using namespace std;double f[55][55];int main(){ int n; while(cin>>n,n) { int i,j; double ans=0; for(i=1;i<=n;i++){ f[i][1]=1; for(j=1;j<i;j++) f[i][j]=f[i-1][j-1]+j*f[i-1][j];//求第二类stirling数 f[i][i]=1; } for(j=1;j&l 阅读全文
posted @ 2011-07-25 20:44 Ac_smile 阅读(445) 评论(0) 推荐(0) 编辑
摘要: 给定N颗星星和M个望眼镜,问望眼镜能看见的星星的颗数(其实就是就给定的星星与望眼镜的夹角是否小于给出的望眼镜的夹角)/*poj 3219 result:actime:47MS*/#include"stdio.h"#include"string.h"#include"math.h"struct point{ double x,y,z;}p[510];int use[510];double ACOS(point a,point b)//计算两点夹角{ double s1,s2,s3,d; s1=a.x*a.x+a.y*a.y+a.z*a. 阅读全文
posted @ 2011-07-16 01:21 Ac_smile 阅读(160) 评论(0) 推荐(0) 编辑
摘要: 最佳方案不假!修理牛棚 在一个暴风雨的夜晚,农民约翰的牛棚的屋顶、门被吹飞了。好在许多牛正在度假,所以牛棚没有住满。 剩下的牛一个紧挨着另一个被排成一行来过夜。 有些牛棚里有牛,有些没有。 所有的牛棚有相同的宽度。自门遗失以后,农民约翰很快在牛棚之前竖立起新的木板。 他的新木材供应者将会供应他任何他想要的长度,但是供应者只能提供有限数目的木板。农民约翰想将他购买的木板总长度减到最少。 给出 M(1<= M<=50),可能买到的木板最大的数目;S(1<=S<=200),牛棚的总数;C(1 <= C <=S) 牛棚里牛的数目,和牛所在的牛棚的编号stall_nu 阅读全文
posted @ 2011-06-13 21:14 Ac_smile 阅读(634) 评论(0) 推荐(0) 编辑
摘要: 用map,最后输出要按照顺序就先把字符串存起来。/*ID:zhlc881LANG:C++TASK:gift1*/#include"iostream"#include"stdio.h"#include"string"#include"map"using namespace std;int main(){ freopen("gift1.in","r",stdin); freopen("gift1.out","w",stdout); int 阅读全文
posted @ 2011-06-12 17:41 Ac_smile 阅读(180) 评论(0) 推荐(0) 编辑
摘要: 这道题之前做过的,但是晚上拿出来熟悉一下!但是runtime error!,很奇怪,查!坚决不看之前的代码。后来突然一个念头:会不胡hash数组没有初始化!加了个hash[110]={0};A了,忘记的是定义为全局性质的数组才会被编译器自动初始化为0;非全局的不会自动初始化!哎哎!!教训。/*poj 2960 result:ACtime:188MS*/#include"iostream"#include"algorithm"using namespace std;int s[110],k;int sg[10010];int getSg(int n){ i 阅读全文
posted @ 2011-06-01 23:45 Ac_smile 阅读(617) 评论(1) 推荐(0) 编辑
摘要: 数论,判断整数N的正约数之和和N之间的大小关系,先素数分解,然后用欧拉函数的一个变形就可以搞定了。注意输出的时候的格式要求,用setw/*time: 0MSresult:AC*/#include"iostream"#include"math.h"#include"iomanip"using namespace std;bool isprime[100];int prime[100];int k=0;struct p{ double x; double i;};void getprime(){ int i=2,j; for(i;i< 阅读全文
posted @ 2011-05-30 23:57 Ac_smile 阅读(504) 评论(0) 推荐(0) 编辑
摘要: Miller_Rabin大素数探定还有 pollard_rho质因数分解。TL了三次,肯定不是算法不行,应该是存在死循环了。/*poj 1811 prime testresult:ACtime:329MSlanguage:c++memory:168K*/#include"stdio.h"#include"time.h"#include"iostream"using namespace std;int pri[]={2,3,5,7,11,13,17,19,23,29};__int64 gcd(__int64 a,__int64 b){ 阅读全文
posted @ 2011-05-25 21:02 Ac_smile 阅读(354) 评论(0) 推荐(0) 编辑
摘要: /*O(lg(N)*/#include"iostream"using namespace std;long Countk2(long n,long k){ long count = 0; long i = 1; long current = 0,after = 0,before = 0; while((n / i) != 0) { current = (n / i) % 10; before = n / (i * 10); after = n - (n / i) * i; if (current > k) count = count + (before + 1) * 阅读全文
posted @ 2011-05-20 20:57 Ac_smile 阅读(435) 评论(0) 推荐(1) 编辑
摘要: 用归并排序求逆序对,用时391ms,但是用树状数组的话runtime error。#include <stdio.h> #include <string.h> const int N=500000;int a[N], b[N], n; __int64 Calc(int first, int last) { if (first == last-1) return 0; int mid = (first+last)/2, i = first, j = mid, k = first; __int64 res = Calc(first, mid)+Calc(mid, last) 阅读全文
posted @ 2011-05-18 18:33 Ac_smile 阅读(228) 评论(0) 推荐(0) 编辑
摘要: The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rational numbers a/b with 0 < a < b <= n and gcd(a,b) = 1 arranged in increasing order. The first few areF2 = {1/2}F3 = {1/3, 1/2, 2/3}F4 = {1/4, 1/3, 1/2, 2/3, 3/4}F5 = {1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 阅读全文
posted @ 2011-05-17 20:38 Ac_smile 阅读(485) 评论(1) 推荐(0) 编辑