首页 > 代码库 > ZOJ 3625 Geek's Collection (数学公式,注意long double输出格式,附输出格式总结)

ZOJ 3625 Geek's Collection (数学公式,注意long double输出格式,附输出格式总结)

题目:

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3625

 

题意:

 

注意:

1、欧拉常数为$euler=0.57721566490153286060651209$

2、用long double

3、输出方法:两种

cout << setprecision(12) << setiosflags(ios::scientific) << ret << endl;
printf("%.12Le\n", ret);

 

总结:

C的printf控制符:

输出long double:%Ld科学计数法输出long double:%Le科学计数法输出double:%e

C++的cout控制符:

需要

#include <iomanip>
setprecision(n) 设显示小数精度为n位setw(n) 设域宽为n个字符setioflags(ios::fixed) 固定的浮点显示setioflags(ios::scientific) 指数表示setiosflags(ios::left) 左对齐setiosflags(ios::right) 右对齐setiosflags(ios::skipws 忽略前导空白setiosflags(ios::uppercase) 16进制数大写输出setiosflags(ios::lowercase) 16进制小写输出setiosflags(ios::showpoint) 强制显示小数点setiosflags(ios::showpos) 强制显示符号

 

 

 

方法:输出公式结果

$({2.0}^{t}-1.0)\times euler$

 

代码:

C:

 1 /******************************************** 2 *ACM Solutions 3 * 4 *@Title: ZOJ 3625 Geek‘s Collection 5 *@Version: 1.0 6 *@Time: 2014-xx-xx 7 *@Solution: http://www.cnblogs.com/xysmlx/p/xxxxxxx.html 8 * 9 *@Author: xysmlx(Lingxiao Ma)10 *@Blog: http://www.cnblogs.com/xysmlx11 *@EMail: xysmlx@163.com12 *13 *Copyright (C) 2011-2015 xysmlx(Lingxiao Ma)14 ********************************************/15 // #pragma comment(linker, "/STACK:102400000,102400000")16 #include <cstdio>17 #include <iostream>18 #include <cstring>19 #include <string>20 #include <cmath>21 #include <set>22 #include <list>23 #include <map>24 #include <iterator>25 #include <cstdlib>26 #include <vector>27 #include <queue>28 #include <stack>29 #include <algorithm>30 #include <functional>31 using namespace std;32 typedef long long LL;33 typedef long double LD;34 #define pb push_back35 #define ROUND(x) round(x)36 #define FLOOR(x) floor(x)37 #define CEIL(x) ceil(x)38 const int maxn = 0;39 const int maxm = 0;40 const int inf = 0x3f3f3f3f;41 const LL inf64 = 0x3f3f3f3f3f3f3f3fLL;42 const double INF = 1e30;43 const double eps = 1e-6;44 const int P[4] = {0, 0, -1, 1};45 const int Q[4] = {1, -1, 0, 0};46 const int PP[8] = { -1, -1, -1, 0, 0, 1, 1, 1};47 const int QQ[8] = { -1, 0, 1, -1, 1, -1, 0, 1};48 const double euler = 0.57721566490153286060651209;49 int kase;50 double x;51 void init()52 {53     kase++;54 }55 void input()56 {57     //58 }59 void debug()60 {61     //62 }63 void solve()64 {65     LD ret = (LD)pow(2.0, x) - (LD)1.0;66     ret *= (LD)euler;67     printf("%.12Le\n", ret);68 }69 void output()70 {71     //72 }73 int main()74 {75     // int size = 256 << 20; // 256MB76     // char *p = (char *)malloc(size) + size;77     // __asm__("movl %0, %%esp\n" :: "r"(p));78 79     // std::ios_base::sync_with_stdio(false);80 #ifdef xysmlx81     freopen("in.cpp", "r", stdin);82 #endif83 84     kase = 0;85     while (~scanf("%lf", &x))86     {87         init();88         input();89         solve();90         output();91     }92     return 0;93 }
ZOJ 3625 C

C++:

 1 /******************************************** 2 *ACM Solutions 3 * 4 *@Title: ZOJ 3625 Geek‘s Collection 5 *@Version: 1.0 6 *@Time: 2014-xx-xx 7 *@Solution: http://www.cnblogs.com/xysmlx/p/xxxxxxx.html 8 * 9 *@Author: xysmlx(Lingxiao Ma)10 *@Blog: http://www.cnblogs.com/xysmlx11 *@EMail: xysmlx@163.com12 *13 *Copyright (C) 2011-2015 xysmlx(Lingxiao Ma)14 ********************************************/15 // #pragma comment(linker, "/STACK:102400000,102400000")16 #include <cstdio>17 #include <iostream>18 #include <cstring>19 #include <string>20 #include <cmath>21 #include <set>22 #include <list>23 #include <map>24 #include <iomanip>25 #include <iterator>26 #include <cstdlib>27 #include <vector>28 #include <queue>29 #include <stack>30 #include <algorithm>31 #include <functional>32 using namespace std;33 typedef long long LL;34 typedef long double LD;35 #define pb push_back36 #define ROUND(x) round(x)37 #define FLOOR(x) floor(x)38 #define CEIL(x) ceil(x)39 const int maxn = 0;40 const int maxm = 0;41 const int inf = 0x3f3f3f3f;42 const LL inf64 = 0x3f3f3f3f3f3f3f3fLL;43 const double INF = 1e30;44 const double eps = 1e-6;45 const int P[4] = {0, 0, -1, 1};46 const int Q[4] = {1, -1, 0, 0};47 const int PP[8] = { -1, -1, -1, 0, 0, 1, 1, 1};48 const int QQ[8] = { -1, 0, 1, -1, 1, -1, 0, 1};49 const double euler = 0.57721566490153286060651209;50 int kase;51 double x;52 void init()53 {54     kase++;55 }56 void input()57 {58     //59 }60 void debug()61 {62     //63 }64 void solve()65 {66     LD ret = (LD)pow(2.0, x) - (LD)1.0;67     ret *= (LD)euler;68     cout << setprecision(12) << setiosflags(ios::scientific) << ret << endl;69 }70 void output()71 {72     //73 }74 int main()75 {76     // int size = 256 << 20; // 256MB77     // char *p = (char *)malloc(size) + size;78     // __asm__("movl %0, %%esp\n" :: "r"(p));79 80     // std::ios_base::sync_with_stdio(false);81 #ifdef xysmlx82     freopen("in.cpp", "r", stdin);83 #endif84 85     kase = 0;86     while (~scanf("%lf", &x))87     {88         init();89         input();90         solve();91         output();92     }93     return 0;94 }
ZOJ 3625 C++

 

ZOJ 3625 Geek's Collection (数学公式,注意long double输出格式,附输出格式总结)