代码编织梦想

先贴图:

思路:这种计算圆周率的方法源于一种以概率统计理论为指导的一类非常重要的数值计算方法。是指使用随机数(或更常见的伪随机数)来解决很多计算问题。在正方形内随机撒点,落在圆内的点 / 落在正方形内的点(全部的点),就约等于圆的面积 / 正方形的面积 = π / 4。

大概过程是这个样子:(偷的图)

 大致实现过程:

double calculatePI(double n)
{
	int i = 0;
	int count = 0;
	double pi = 0;
	double x = 0;
	double y = 0;
	srand((unsigned)time(NULL));
	for(int i=0;i<n;i++)
	{
		x = rand() / (double)(RAND_MAX);
		y = rand() / (double)(RAND_MAX);
		if ((x * x) + (y * y) < 1)
		{
			count++;
		}
	}
	pi = 4 * (count / n);
	return pi;
}

 结果:

这里挖了几个坑,有机会要补一下。

 

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/s_young31/article/details/127158109

安卓程序退出的讨论-爱代码爱编程

http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238#2034238 Moving on in my attempt to learn Andro

i was throwing strikes._iteye_2143的博客-爱代码爱编程

PARADISE VALLEY, Ariz. cheap jerseys from china . (AP) -- The head of the committee that developed Major League Baseballs plan to expand instant replay says he is optimistic the s

http://www.highlandermagazine.com/christianlouboutinreplica.html-爱代码爱编程

This writer has regrettably failed to find the opportunity to give it a thorough listen, but I might have to remedy that this weekend The name of the county comes from the city

如何启动软件YouTube频道-爱代码爱编程

Hi, I’m Beau and I run the freeCodeCamp.org YouTube channel. 嗨,我是Beau,我运行了freeCodeCamp.org YouTube频道 。 For the first few years of our channel’s life, we had less than 100,

滴滴入职要学位证吗学位证_我如何在没有技术学位或工作经验的情况下找到全职开发人员工作...-爱代码爱编程

滴滴入职要学位证吗学位证 by Charlie Jeppsson 查理·杰普森(Charlie Jeppsson) 我如何在没有技术学位或工作经验的情况下找到全职开发人员工作 (How I landed a full stack developer job without a tech degree or work experience)

SitePoint播客#81:Doom,Gloom和Rainbow Tweets-爱代码爱编程

Episode 81 of The SitePoint Podcast is now available! This week your hosts are Patrick O’Keefe (@iFroggy), Stephan Segraves (@ssegraves), and Kevin Yank (@sentience). SitePoint

SitePoint Podcast#122:重要吗? 没有!-爱代码爱编程

Episode 122 of The SitePoint Podcast is now available! This week the panel is made up of Patrick O’Keefe (@ifroggy), Brad Williams (@williamsba), and Kevin Yank (@sentience).

Sixth season fifth episode,Joey got a Porsche?????-爱代码爱编程

[Scene: Monica and Rachel's, the gang is there except for Rachel and Ross, who both come storming in. Rachel is still going off about Ross's secret marriage.] Rachel: I cannot be

newsgroup_txt-爱代码爱编程

Why is the mirror of journey to the West useless to monkey king? |||0 First couplet: one night spring breeze to go, how to the second couplet? |||0 What do relatives say makes you

takeoff process of rookie _day2_babayaga_s的博客-爱代码爱编程

 先贴图: 思路:使用面向对象的方法解决问题,先确定对象的属性和在这些属性上进行的操作(就是方法)。对象是抽纸,抽纸要有张数,和进行抽纸这个动作。先定义一个结构体表示"抽纸",那成员就是抽纸的"张数"和"抽纸的动作"。 大致实现过程: 生成随机数表示每次抽纸的张数(范围在10-20之间,上厕所又不是大出血,应该够用了): int RandomN

takeoff process of rookie _day1_babayaga_s的博客-爱代码爱编程

先贴图: 实现思路:先创建7个数组用来单独保存A B C D……,每个数组的长度n随机产生。再n*3保证元素个数是3的整数倍,对数组进行赋值。此时每个数组里面的值都是一样的(这里给随机数设定了范围是1-16,不然太长了。。。)。将这7个数组拼接到一个数组arrDe[ ]里面,此数组的长度为7个数组长度之和。此时数组仍是有顺序的,用一个最易于理解的打乱方式

takeoff process of rookie _day3-爱代码爱编程

先贴图: 思路:这个问题一开始并没有什么思路,之前听说sqrt函数好像可以用二分法实现求算数平方根,但是并没有细想,对于二分法只是也只是浅尝辄止用来进行简单的查找,所以下面这个做法是白嫖的别人的方法。 double mysqrt(long n) { double low=1,up=n; double mid=(low+up)/2; doubl