Posts Tagged ‘数值计算’

August 7, 2009

其实,我最初写的不是这样子滴,对比上面的程序,看看下面这个哪里会出问题?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
string multiply(const string &l, const string &r)
{
	size_t lenl = l.size();
	size_t lenr = r.size();
	string result(lenl+lenr, '\0');
	for(size_t i = 0; i < lenl; ++i)
		for(size_t j = 0; j < lenr; ++j)
		{
			result[i + j + 1] += ctoi(l[i]) * ctoi(r[j]);
		}
	for(size_t i = lenl + lenr-1 ; i > 0; --i)
	{
		result[i - 1] += (unsigned char)result[i] / 10;
		result[i] = (unsigned char)result[i] % 10 + '0';
	}
	if(result[0] == 0)
		result.erase(0, 1);
	else
		result[0] += '0';
 
	return result;
}
Tags: ,,. 15 views
July 12, 2009

ZOJ上的一道题(illusive chase)让我憋了一整天才AC了,而且用了224行,最后优化到115行!我真真是没救了,也只能做做小儿科的题目了!sucks……这里有上次百度之星的一道水题……

题目描述:

一个正整数有可能可以被表示为n(n>=2)个连续正整数之和,如:

15=1+2+3+4+5
15=4+5+6
15=7+8
Tags: ,. 111 views
June 23, 2009
1
2
3
4
5
6
7
8
9
10
11
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <limits>
#include <string>
#include <sstream>
 
 
#include "matrix.hpp"
#include "vector.hpp"
Tags: ,. 81 views
June 22, 2009
1
2
3
4
5
6
//! 作者:Hou Fenglin
//! 程序名:euler.cpp
//! euler预测-校正法解微分方程
#include <iostream>
#include <cmath>
#include <iomanip>
Tags: . 60 views
April 22, 2009

Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
#include <cmath>
 
using namespace std;
double Sqrt(double x);
int main()
{
	double x;
	cin>>x;
	cout<<Sqrt(x)<<endl;
	return 0;
}
 
double Sqrt(double x)
{
	const double eps = 1E-6;
	double x0 = x / 2, x1 = (x0 + x / x0) / 2;
	while(fabs(x1 - x0) > eps)
	{
		x0 = x1;
		x1 = (x0 + x / x0) / 2;
	}
	return x0;
}
Tags: ,. 7 views
Page 1 of 11