zoj 1242 Carbon Dating

来源:互联网 发布:北微传感器 淘宝 编辑:程序博客网 时间:2024/03/29 18:26
//读了很久都找不出这题的公式,最后只有百度了!哎,笨啊!#include <iostream>#include <math.h>using namespace std;double d, w, age, temp;int main(){    int num=1;    while (scanf("%lf %lf", &w, &d), w&&d)    {        printf("Sample #%d\n", num++);        temp = d/w/810.0;        temp = log(temp);        age = temp/log(0.5)*5730.0;        if (age < 10000)        {            temp = int(age/100.0+0.5);            age = temp*100.0;        }        else        {            temp = int(age/1000.0+0.5);            age = temp*1000.0;        }        printf("The approximate age is %.lf years.\n\n", age);    }    return 0;}

原创粉丝点击