zoj 1242 Carbon Dating

#include
#include
#define d0 810
#define half_life 5730
int main(void)
{
	int w, d,count=0,age;
	double year;
	while (scanf("%d%d", &w, &d) && w && d)
	{
		count++;
		year = (log((double)d0 * w /d ) / log(2.0))*half_life;                    //log()计算以2为底的自然对数,即log()=ln();
		if (year > 10000)
			age = 1000 * (int)(year / 1000 + 0.5);
		else
			age = 100 * (int)(year / 100 + 0.5);
		printf("Sample #%d\nThe approximate age is %d years.\n\n", count, age);
	}
	return 0;
}
注:1.以上C-14半衰期公式引自  
                                     http://blog.sina.com.cn/s/blog_69f23b380100o0to.html
        2.四舍五入方法引自
                                     http://blog.csdn.net/zxy_snow/article/details/5728636

你可能感兴趣的:(ACM)