void-man

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

文章分类 -  数学类(数论+大数)

1 2 下一页

摘要:一根木棒受热会拱起来,现在给你原始长度和拱起来的弧形长度,然你算出鼓起的中点到水平的距离假设加热后的长度是L,原始是l,则角度a=L/R,R=l/(2*sin(a/2));然后得到2*L/l=a/sin(a/2)用二分求出a的值,最后用公式得出结果#include <iostream>#include <cmath>#include <algorithm>using namespace std;int main(int argc, char* argv[]){ double N,C,L; while(scanf("%lf%lf%lf",& 阅读全文
posted @ 2011-05-08 23:19 void-man 阅读(331) 评论(0) 推荐(0)

摘要:给出K,M,求最小的n使之M^n的第K位是7.大数相加,然后判断k位,仍用数组存储,一个元素存储一位View Code 1 #include <cstdio> 2 #include <cstdlib> 3 #include <iostream> 4 #include <string.h> 5 #include <math.h> 6 using namespace std; 7 int num[1000]; 8 int main() 9 {10 int k,m,n,len,i;11 while( scanf("%d%d&quo 阅读全文
posted @ 2011-05-08 18:05 void-man 阅读(272) 评论(0) 推荐(0)

摘要:大数的斐波那契数列,目前处理大数还不算顺手还要多练,大数的处理有多种办法一种是用字符串转换成整数一位一位的加,然后在转换成字符串返回,还有一种是用整形数组,根据题目的不同要求选择合适方法,比如这道题斐波那契数列,给出的是n,让你求第n项,我们可以用二维数组,fb[n][k]的值就是第n项第k位的数是多少这里可以直接用memcpy()函数,算的时候可以直接把后一项叠加到前一项上面,这样就不用计算时候用两项相加了View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <iostream> 4 阅读全文
posted @ 2011-05-08 15:19 void-man 阅读(835) 评论(0) 推荐(0)

摘要:给出一个进制,以及它的位数,让你求他总共有多少种这个数最后发现找规律,跟斐波那契差不多的规律,直接打表过了View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <iostream> 5 #include <algorithm> 6 #include <queue> 7 #include <stack> 8 #include <math.h> 9 10 using namespace 阅读全文
posted @ 2011-05-07 16:50 void-man 阅读(144) 评论(0) 推荐(0)

摘要:求解fib(n)中,n的所有因子的个数,题目n<700,本来以为用大数做,但是看了某个大牛的算法,就是牛,利用和求余的算法fib[i][j]表示fib(i)%j的值直接上代码吧#include <stdio.h>#include <math.h>int fab[800][800];int main(){ int n,m,num,N; for(int i=2;i<=700;i++) { fab[0][i]=1; fab[1][i]=1; for(int j=2;j<=700;j++) fab[j][i]=(fab[j-1][i]+fab[j-2][i]) 阅读全文
posted @ 2011-04-17 15:09 void-man 阅读(240) 评论(0) 推荐(0)

摘要:给出两个数,求出这两个数之间有多少个fib数, 但是题目给出的数是10^100所以要用大数来处理用大数相加算法,求出fib[1024]之内的所有数,然后再找出两数之前多少个开始统计#include <iostream>#include <string>using namespace std;string operator +(const string &a, const string &b){ int i; int sum[2001] = {0}; int len1 = strlen(a.c_str()); int len2 = strlen(b.c_s 阅读全文
posted @ 2011-04-17 13:03 void-man 阅读(671) 评论(0) 推荐(0)

摘要:按题目要求列方程,然后求解一次方程组的求解,直接上代码吧 1 #include <iostream> 2 3 #include <iomanip> 4 5 #include<math.h> 6 7 using namespace std; 8 9 10 int main()11 12 {13 14 int t;15 16 double n,m,a,b,c,d,x,y;17 18 cin>>t;19 20 while(t--)21 22 {23 24 cin>>n>>a>>b>>c>>d; 阅读全文
posted @ 2011-04-16 22:54 void-man 阅读(123) 评论(0) 推荐(0)

摘要:给出一个序列,然后求出转换后的序列,两种互相转换{ 5,9,1,8,2,6,4,7,3 }has the inversion table2 3 6 4 0 2 2 1 0since there are 2 numbers, 5 and 9, to the left of 1; 3 numbers, 5, 9 and 8, to the left of 2; etc.第二种就是逆过去,拿出一个数n,一直找到一个位置,他前面刚好n个空位置,那么这个数n就在此位置 1 #include <stdio.h> 2 #include <string.h> 3 int main() 阅读全文
posted @ 2011-04-16 22:49 void-man 阅读(119) 评论(0) 推荐(0)

摘要:给出球的种类和其个数,求出所取出每种颜色球个数组合的概率是多大组合问题,每取出一个球就可以计算出取出它的概率然后相乘就是所有取出要求所给求的种类和,然后除以总总和球里取出要求各种颜色球的和即可 1 #include <stdio.h>//考虑多种不可能出现情况,概率为1的 2 int color[100]; 3 int take[100]; 4 /*int fun(int n,int r) 5 { 6 7 if(r>n)//数学定义 8 return 0; 9 if(r==1||r==n-1)//根据组合定义,我们有C(n,1)=C(n,n-1)=n10 return n;1 阅读全文
posted @ 2011-04-16 22:42 void-man 阅读(136) 评论(0) 推荐(0)

摘要:给出一个数,求出它的各个因子的和,当然不包括本身...跟素数筛法差不多,因为题目给出的时间是5s,所以可以循环到500000 1 #include <stdio.h> 2 #include <string.h> 3 #define N 500001 4 int num[N]; 5 int main() 6 { 7 int n; 8 memset(num,0,sizeof(num)); 9 for(int i=1;i<=250000;i++)//两种方法实现 10 for(int j=2;i*j<=500000;j++)11 num[i*j]+=i;12 /* 阅读全文
posted @ 2011-04-16 22:31 void-man 阅读(401) 评论(0) 推荐(1)

摘要:求解约瑟夫问题,J(n)表示n个人第二个给踢掉的与瑟夫问题的解,然后要求求解m次此嵌套函数在网上搜到了两种办法,第一种直接通过递归求解约瑟夫的解讨论如下,假设原先有2n个人。那么,在绕第一圈之后,留下:[attach]76340[/attach]此时剩下n个人,分别为 第一个人1(2×1-1),第二个人3(2×2-1)。。。第n个人2n-1(2n-1),假设知道此时(n个人)将得到的幸存者为x,那么有:第x个(2x-1),明显的,n个人里的第x个也就是之前在2n个人的时候的第2x-1个,此时可以建立起从J(2n)到J(n)的关系:J(2n) = 2 * J(n)-1,(n≥ 阅读全文
posted @ 2011-04-16 22:07 void-man 阅读(289) 评论(0) 推荐(0)

摘要:MiYu原创, 转帖请注明 : 转载自 ______________白白の屋题目地址 :http://acm.hdu.edu.cn/showproblem.php?pid=1133题目描述:ProblemDescriptionThe"HarryPotterandtheGobletofFire"willbeonshowinthenextfewdays.AsacrazyfanofHarryPotter,youwillgotothecinemaandhavethefirstsight,won’tyou?Supposethecinemaonlyhasoneticket-office 阅读全文
posted @ 2011-04-15 22:43 void-man 阅读(303) 评论(0) 推荐(0)

摘要:给出新的数列:another kind of Fibonacci numbers: F(0) = 7, F(1) = 11, F(n) = F(n-1) + F(n-2) (n>=2)第n个斐波那契数列是否能被3整除...找规律问题,找出规律后发现8个行程循环,第三个和第七个可以被三整除1 #include <stdio.h>2 int main()3 {4 int n;5 while(scanf("%d",&n)!=EOF)6 if((n+1)%8==3||(n+1)%8==7)printf("yes\n");7 else p 阅读全文
posted @ 2011-04-15 22:30 void-man 阅读(333) 评论(0) 推荐(0)

摘要:给出一个数,要求分拆成最多的数的和,并且每一个数都不同...既然要求最多并且不同,那就尽量要连续给出,并且把剩余的数依次给最后的几个数上每次加一,得到序列即可 1 #include<stdio.h> 2 int main() 3 { 4 int n,arr[1001],i,j,t; 5 6 while(scanf("%d",&t)!=EOF){ 7 while(t--) 8 { 9 scanf("%d",&n);10 int wei=0,c=2;11 while(1)12 {13 if(n<c)break;14 arr[ 阅读全文
posted @ 2011-04-15 22:25 void-man 阅读(181) 评论(0) 推荐(0)

摘要:阶乘0的个数,就看乘数中出现5的因子个数为了求从1-n的之前的数中含有5的个数,可以依次把n除以5,所得结果相加即可 1 #include <stdio.h> 2 int main() 3 { 4 int t,n,k; 5 scanf("%d",&t); 6 while(t--) 7 { 8 k=0; 9 scanf("%d",&n);10 while(n)11 {12 n=n/5;13 k+=n;14 }15 printf("%d\n",k);16 17 }18 19 return 0;20 } 阅读全文
posted @ 2011-04-15 22:15 void-man 阅读(158) 评论(0) 推荐(1)

摘要:给出一个矩形箱子的长宽,然后再给出一个矩形的长宽,问你第二个是否能放到第一个里面,题目要求不能接触到box的trap比较简单,但是很多细节需要注意,当然斜着放是最容易进去,然后设角度theta,取值在0-90之前,依次逼近看是否能存在放进去的可能...首先可以确定如果y>B的话,它就肯定放不进去 1 #include<iostream> 2 #include<algorithm> 3 #include<math.h> 4 #include<stdio.h> 5 6 using namespace std; 7 8 #define PI ac 阅读全文
posted @ 2011-04-15 22:08 void-man 阅读(222) 评论(0) 推荐(0)

摘要:题目意思就是从2开始一次把其倍数的号码给踢掉,并且踢掉一次后对号码重新按1,2,3依次排序然后再次踢人然后问你最后不被踢掉数的序列,第n个是几刚开始我题目理解错了,以为是序列一直不边,就直接用筛法求出素数,然后压入一个数组,结果wa,后来才知道是踢掉后重拍了既然重拍就设计一个标记数组,用来标记是否被踢掉 1 #include <stdio.h> 2 #define N 35000 3 int main(){ 4 int arr[N]={0}; 5 int lucky[N]; 6 int i,j,k,n; 7 n = 0; 8 for (i=2;i<N;i++) 9 {10 i 阅读全文
posted @ 2011-04-14 23:40 void-man 阅读(177) 评论(0) 推荐(0)

摘要:题目大意,给出一个网格的长m和宽n,然后让你求出从左下角到右上角的走法的种类...这题高中时候做过,就是 组合数学,总共需要走m+n步,从这里面选出m步来走长的m步,即可 1 #include <stdio.h> 2 double c(double m,double n) 3 { 4 double a=1; 5 if(n>=m) 6 for(int i=1;i<=m;i++) 7 a=a*(n+i)/i; 8 else for(int i=1;i<=n;i++) 9 a=a*(m+i)/i;10 printf("%.0lf\n",a);11 1 阅读全文
posted @ 2011-04-14 23:16 void-man 阅读(120) 评论(0) 推荐(0)

摘要:题目给出如图所示的一个值,然后按照右图的值找出在左图的坐标很容易,但是规律很难找,我是copy别人代码,看了恍然大悟,就是分情况用if来判断 1 #include<stdio.h> 2 #include<stdlib.h> 3 int a[100005][5]; 4 int main() 5 { 6 int n; 7 a[1][1]=0; 8 a[1][2]=0; 9 a[2][1]=0; 10 a[2][2]=1; 11 //找到规律直接循环递归输出就ok 12 for(int i=3;i<=100000;i++) 13 { 14 if(a[i-1][1]< 阅读全文
posted @ 2011-04-14 23:07 void-man 阅读(133) 评论(0) 推荐(0)

摘要:给出一个布尔矩阵,由0,1组成,要求每行每列的和都为偶数,如果不满足,改动某一个位置状态可行的话就输出此位置,否则输出错误,如果不用改动就满足就输出ok。。。想法依然简单,我想的是输入数据时候就统计各行格列的和,用b[][]来存储,然后依次找出行列中和为奇数的个数,如果某个行或者列的统计个数等于n,矩阵长度,那么就是说此时没有可以有列或者行可以与此更改,就是错误,感觉这里可以再优化 1 #include <stdio.h> 2 int main() 3 { 4 int n,a[100][100]; 5 while(scanf("%d",&n)!=EOF, 阅读全文
posted @ 2011-04-14 22:51 void-man 阅读(204) 评论(0) 推荐(0)

1 2 下一页