10 2013 档案
摘要:1 #include 2 #include 3 #include 4 #include 5 #define mod 1000000007 6 long long dp[1010]; 7 void getdp() 8 { 9 memset(dp,0,sizeof(dp));10 dp[1]=1;11 for(int i=2;i<=1000;i++)12 {13 for(int j=1;j<=i;j++)14 {15 if ((i-1)%j==0) dp[i]+=dp[j],dp[i]=dp[i]%mod;1...
阅读全文
摘要:1 //http://www.cnblogs.com/yefeng1627/archive/2013/04/24/3040112.html 2 #include 3 #include//最好开这个库//数学计算交c++更快 4 #include 5 #include 6 #include 7 #define maxn 410000 8 double F[maxn]; 9 void builtF()10 {11 F[1]=0;12 for(int i=1;i log(C(m,n))=log(n!)-log(m!)-log((n-m)!) 要知道log(10000!)都是很小的,...
阅读全文
摘要:1 #include 2 #include 3 #include 4 using namespace std; 5 struct Node 6 { 7 int r;//余数 8 int f;//父亲节点 9 int n;//数字10 Node(){};11 Node(int r1,int f1,int n1){r=r1;f=f1;n=n1;}12 }node[10010<<2];13 int d[11];14 bool rem[11000];15 int n,m;16 void print(int f)17 {18 if (node[f].f!...
阅读全文
摘要:并查集:我们知道p[x]中存储的是x的根节点,或者说,我们要的目的是所有在一棵树上的节点,他们的p[x]必须是相同的并查集的代码很简单,但在使用时很难达到上述结果,或者说,稍有不慎,就会出错。也许你会说我只要判断find(i)==find(1)都成立就好了,但这往往只能判断一个连通集的问题。所以具体的方法是什么?我们先描述方法,再证明。步骤:int find(int x){return x==p[x]?x:p[x]=find(p[x]);}read(u,v);f1=find(u);f2=find(v);if(f1!=f2) p[f2]=f1;for(i=1;i13423结果: x 1 2 ..
阅读全文
摘要:double func(double a, double b, double x) { double r = a * exp(- x*x) + b * sqrt(x); return r*r;//return的积分常数,例如这里f(x*x)dx|[0,h]}double integrate(double a, double b, double h) { unsigned long steps = 1, it = 1; double V = h * (func(a, b, 0) + func(a, b, h)) / 2.0; double Vold; do { double t...
阅读全文
摘要:最小生成树,一道边有点多的题目,需要优化。DescriptionIn 2100, since the sea level rise, most of the cities disappear. Though some survived cities are still connected with others, but most of them become disconnected. The government wants to build some roads to connect all of these cities again, but they don’t want to ta
阅读全文
摘要:第一道最小生成树问题 1 #include 2 #include 3 #include 4 #include 5 #define maxn 10000+100 6 using namespace std; 7 int r[maxn]; 8 int u[maxn]; 9 int v[maxn];10 int w[maxn];11 int p[maxn];12 int map[110][110];13 bool inmap[110][110];14 int cmp(const int i,const int j){return w[i]<w[j];}15 int find(int x)16
阅读全文
摘要:1 #include 2 #define maxn 1005 3 #include 4 #include 5 #include 6 using namespace std; 7 8 9 int f[maxn],v[maxn],p[maxn],numcount;10 int F[maxn];11 bool vis[maxn*100];12 int n,w,k,a,b;13 14 int maxx(int a,int b)15 {16 if (a>=b) return a;else return b;17 }18 int find(int x){19 if(x==f[x]) ...
阅读全文
摘要:Description CX是要赶去上课,为了不迟到必须要以最短的路径到达教室,同时CX希望经过的路上能看到的学妹越多越好。现在把地图抽象成一个无向图,CX从1点出发,教室在N号点,告诉每个点上学妹的数量,每条边的长度。请你求出CX以最短路径赶到教室最多能看到多少学妹。Input 多组输入数据(最多20组),输入到文件结束。 每组数据第一行两个正整数N,M其中N代表点的个数(2 2 #include 3 #include 4 using namespace std; 5 typedef long long LL; 6 const int maxn=1000+5; 7 const long lo
阅读全文
摘要:Description zzy今天刚买了两个水瓢A和B,容量都是为1升,童心未泯的他打算用这个水瓢来玩游戏。 首先zzy准备了一个容量可看作无穷大的水缸,刚开始水缸是空的,然后用水瓢A往水缸里加水,用水瓢B把水缸里的水舀出去,当使用 水瓢B把水舀出去时水缸里必须要至少有1升的水。这样子使用N次水瓢A,也使用N次水瓢B,最后水缸会依旧空的。Input 输入有多个例子,直到文件结束。 每个例子仅含一个数N(0 2 #include 3 #include 4 #define mod 1000000007 5 #define maxn 10000+10 6 #define LL long long 7
阅读全文