hdu 1005
摘要:这一题用到了快速幂的方法,还有就是构造矩阵……#include "stdio.h"#include "string.h"void mult(int f[2][2],int y[2][2],int c[2][2])//求矩阵相乘{int i;int a[2][2],b[2][2];memcpy(a,f,sizeof(int)*4);//这里也,要将数组复制过来,否则是会出错的,因为传过来的有可能是相同的矩阵相乘……memcpy(b,y,sizeof(int)*4);for(i=0;i<2;i++){c[i][0]=(a[i][0]*b[0][0]+a
阅读全文
posted @
2012-02-15 14:57
Shirlies
阅读(419)
推荐(0) 编辑
hdu 1018
摘要:数学真是源远流长啊!!现在又有斯特林数log10(n!)=1.0/2*log10(2*pi*n)+n*log10(n/e)现在我对数学的崇拜又加深了!#include "stdio.h"#include "math.h"#define e 2.71828182int main(){int T;int n;double t;scanf("%d",&T);while(T--){scanf("%d",&n);t=(double)n*log10(n*1.0/e)+0.5*log10(2.0*n*3.1415
阅读全文
posted @
2012-02-14 16:30
Shirlies
阅读(589)
推荐(0) 编辑
hdu 1032
摘要:#include <iostream>using namespace std;int get_count(int a){int count=1;while(a!=1){if(a%2)a=3*a+1;elsea=a/2;count++;}return count;}int main(){int n,m;while(cin>>n>>m){int max=get_count(n);int i,j;if(n>m){i=m;j=n;}else{i=n;j=m;}for(int k=i;k<=j;k++){if(max<get_count(k))max
阅读全文
posted @
2012-02-13 19:23
Shirlies
阅读(113)
推荐(0) 编辑
hdu 1568
摘要:经典的数学题啊~~~题解:http://blog.csdn.net/cscj2010/article/details/6768395感触:数学还是得灵活应用啊,关键是这个公式啊……起初是打算用大数做的,觉得好麻烦,就搜了一下,看一下别人的思路,我晕,竟然可以这样思考,NB啊~~~还有就是因为后面约了一个式子,但是这个n得足够大,所以要先存储前面的几个数……#include "stdio.h"#include "math.h"int fib[50]={0,1};int main(){int n,i;double a;double ig,fp;for(i=2
阅读全文
posted @
2012-02-13 10:53
Shirlies
阅读(491)
推荐(0) 编辑
hdu 1271
摘要:看过别人的解题思路才做出来的,解题思路网上一大片……把这个代码贴出来,是觉得有个问题大家一定要注意,就是可能有重复的值……#include "stdio.h"#include "stdlib.h"#include "string.h"int ans[1000];int cmp(const void *a,const void *b){return (*((int *)a)-*((int *)b));}int main(){int n;int i,k,t,a,b,c;while(scanf("%d",&n)=
阅读全文
posted @
2012-02-12 11:00
Shirlies
阅读(497)
推荐(0) 编辑
hdu acm1071
摘要:数学题,求积分……#include "stdio.h"#include "math.h"int main(){int cn;scanf("%d",&cn);while(cn--){double x0,y0;double x1,y1,x2,y2;double a,b,c;scanf("%lf%lf",&x0,&y0);scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);a=(y1-y0)/((x1-x0)*(x1-x0
阅读全文
posted @
2012-01-19 22:07
Shirlies
阅读(204)
推荐(0) 编辑
UVa 10161
摘要:我是用笨方法做的,首先找出该值的范围,然后分奇数偶数讨论。#include "stdio.h"#include "math.h"int main(){int n;int temp;while(scanf("%d",&n)==1&&n){temp=(int)pow(n,0.5);if(temp*temp==n){if(temp%2==0)printf("%d 1\n",temp);elseprintf("1 %d\n",temp);continue;}if(temp%2==
阅读全文
posted @
2012-01-18 21:20
Shirlies
阅读(170)
推荐(0) 编辑
UVa 113
摘要:用double就可以了Double(双精度浮点型)变量存储为 IEEE 64 位(8 个字节)浮点数值的形式,它的范围在负数的时候是从 -1.79769313486232E308 到 -4.94065645841247E-324,而正数的时候是从 4.94065645841247E-324 到 1.79769313486232E308(来自百度)#include "stdio.h"#include "math.h"int main(){double n,p;double temp;while(scanf("%lf%lf",&n
阅读全文
posted @
2012-01-18 20:41
Shirlies
阅读(248)
推荐(0) 编辑