ZOJ Problem Set
来源:互联网 发布:设置数据库单用户模式 编辑:程序博客网 时间:2024/06/06 03:15
Until the second half of the 20th century, determining the actual age of an archaeological find had been more or less a matter of educated guessing. Comparing finds to previous, already dated, ones and evaluation of the surroundings of a find were the best available techniques.
But nowadays, there is a much more reliable method: carbon dating. Carbon dating works as follows: Naturally occurring carbon is a mixture of stable isotope (mostly 12C) and the unstable, radioactive, isotope 14C. The ratio between the two is almost constant in living organisms: 14C slowly decays, but at the same time, the radiation of the sum produces the same amount in the upper atmosphere, which is taken in by the organisms.
But when, for example, a tree is felled and made to wood, it does not receive any new 14C, and the amount present in the wood becomes less and less due to radioactive decay. In this problem, you are to write a program that uses information about the amount of remaining 14C to determine the approximate age of sample. The following facts must be used:
The amount of 14C present in a sample halves every 5730 years (this is called the half-life of 14C).
The rate of decay (measured in decays per hour per gram of carbon) is proportional to the amount of 14C left in the sample.
In living organisms (age zero), there are 810 decays per hour per gram of carbon.
So, for example, if we measure in a sample of one gram of carbon 405 decays per hour, we know that it is approximately 5730 years old.
Input
The input contains the measurements taken of several samples we want to date. Every line contains two positive integers, w and d. w is the amount of carbon in the sample, measured in grams, and d is the number of decays measured over one hour.
The input is terminated by a test case starting with w = d = 0.
Output
For each sample description in the input, first output the numnber of the sample, as shown in the sample output.Then print the approximate age in the format
The approximate age is x years.
If the age is less than 10,000 years, x should be rounded to the colsest multiple of 100 years (rounding up in case of a tie). If the age is more than 10,000 years, round it to the closest multiple of 1000 years (again rounding up in case of a tie).
Print a blank line after each sample.
Sample Input
1 405
5 175
0 0
Sample Output
Sample #1
The approximate age is 5700 years.
Sample #2
The approximate age is 26000 years.
解题报告:
题目主要意思就是根据C14计算文物年龄,根据公式即可r=ln(810/v) / ln2 衰变的次数r,速率v=d/w
还有要注意的就是输出了。
#include<iostream>#include<cmath>#include<cstdio> using namespace std;int main(){double d,w,r,Y;int num=0;while(cin>>w>>d){if(w==0&&d==0) break;num++;r=log((810.0*w/d))/log(2); //r=ln(810/v) / ln2 衰变的次数 v=d/w Y=5730*r;if(Y<=10000) //小于10000年的,输出100的倍数 列如5730输出5700; { Y/=100; Y+=0.5; Y=(int)Y; Y*=100; } else if(Y>10000) //大于10000年的,输出1000的倍数 { Y/=1000; Y+=0.5; Y=(int)Y; Y*=1000; } cout<<"Sample #"<<num<<endl; cout<<"The approximate age is "<<(int)Y<<" years."<<endl; cout<<endl; } return 0;}
- ZOJ Problem Set - 2060
- ZOJ Problem Set - 2972
- ZOJ Problem Set - 1037
- ZOJ Problem Set - 1048
- ZOJ Problem Set - 1049
- ZOJ Problem Set - 1051
- ZOJ Problem Set - 1067
- ZOJ Problem Set - 1115
- ZOJ Problem Set - 1151
- ZOJ Problem Set - 1205
- ZOJ Problem Set - 1025
- ZOJ Problem Set - 1029
- ZOJ Problem Set - 1076
- ZOJ Problem Set - 1117
- ZOJ Problem Set - 1041
- ZOJ Problem Set - 1004
- ZOJ Problem Set - 1005
- ZOJ Problem Set - 1016
- 【计网】HTTP与WebSocket的区别
- QT生成静态动态库
- 树:二叉树几种形态(满二叉,完全二叉,线索二叉,二叉排序,平衡二叉,哈夫曼)
- httpclient中禁止301、302自动重定向
- Student s = new Student();在内存中做了哪些事情?
- ZOJ Problem Set
- Linux静态库和动态库区别
- sql语句整理1--统计当月签到次数最多
- Spark读写HBASE
- codeforces 813e 莫队算法
- Scala入门到精通——第十四节 Case Class与模式匹配(一)
- 使用springMVC + Spring进行web开发时,aop不生效的问题
- Unity3D中使用git
- nginx 做proxy 不转发 http header问题解决