水题/hdu 1012 u Calculate e

题意

  求n=0~9时的sigma(1/n!)

分析

  因为刚学c++ 所以对浮点操作还是很不熟练,正好来了这么一道题

Accepted Code

 1 /*
 2     PROBLEM:hdu 1012
 3     AUTHER:Nicole Lam
 4     MEMO:水题
 5 */
 6 #include<iostream>
 7 #include<iomanip>
 8 using namespace std;
 9 double a[10];
10 int main()
11 {
12     cout<<"n e"<<endl;
13     cout<<"- -----------"<<endl;
14     a[0]=1;
15     double temp=1.0;
16     cout<<"0 1"<<endl;
17     for (int i=1;i<=9;i++)
18     {
19         temp=temp*i;
20         a[i]=a[i-1]+(double)1/temp;
21         if (i==1) cout<<"1 2"<<endl;
22         else if (i==2) cout<<"2 2.5"<<endl;
23         else cout<<i<<" "<<fixed<<setprecision(9)<<a[i]<<endl;
24     }
25     return 0;
26 }
时间: 2024-10-13 10:42:03

水题/hdu 1012 u Calculate e的相关文章

hdu 1012:u Calculate e(数学题,水题)

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28686    Accepted Submission(s): 12762 Problem Description A simple mathematical formula for e iswhere n is allowed to go to infinit

poj 1517 &amp; hdu 1012 u Calculate e(简单阶乘)

POJ链接 :http://poj.org/problem?id=1517 HDU链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 Description A simple mathematical formula for e is e=Σ0<=i<=n1/i! where n is allowed to go to infinity. This can actually yield very accurate approximations o

HDU 1012 u Calculate e(简单阶乘计算)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1012 u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 52607    Accepted Submission(s): 24106 Problem Description A simple mathematical

水题/hdu 1004 Let the Balloon Rise

题意 给出n个字符串,输出出现次数最多的那个 分析 存下字符串后排序,再统计,输出 Accepted Code 1 /* 2 PROBLEM:hdu1004 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 7 #include<iostream> 8 #include<cstring> 9 #include<string> 10 #include<algorithm> 11 using namespace std; 12 13 in

水题/hdu 1001 Sum Problem

题意 给出一个数n,求1+2+??+n=? 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1001 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 9 int main() 10 { 11 int n; 12 while (scanf("%d",&n)!=EOF) 13 { 14 int s=0; 15 for (int i=1;i<=n;i++) s+=

水题/hdu 1000 A + B problem

题意 输入a,b,输出a+b: 分析 注意多case Accepted Code 1 /* 2 PROBLEM:hdu1000 3 AUTHER:NicoleLam 4 MEMO:水题 5 */ 6 7 #include<cstdio> 8 int main() 9 { 10 int a,b; 11 while (scanf("%d%d",&a,&b)!=EOF) printf("%d\n",a+b); 12 return 0; 13 }

HDU 1012 u Calculate e【暴力打表,水】

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46844    Accepted Submission(s): 21489 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

HDU 1012.u Calculate e【水】【8月16】

u Calculate e Problem Description A simple mathematical formula for e is where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n. Output Output the approximations of e generat

Hdu 1012 u Calculate e

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46276    Accepted Submission(s): 21237 Problem Description A simple mathematical formula for e is where n is allowed to go to infini