您的位置:首页 > 其它

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

2014-08-28 21:21 411 查看
题目:

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:

/********************************************
*ACM Solutions
*
*@Title: ZOJ 3625 Geek's Collection
*@Version: 1.0
*@Time: 2014-xx-xx
*@Solution: http://www.cnblogs.com/xysmlx/p/xxxxxxx.html *
*@Author: xysmlx(Lingxiao Ma)
*@Blog: http://www.cnblogs.com/xysmlx *@EMail: xysmlx@163.com
*
*Copyright (C) 2011-2015 xysmlx(Lingxiao Ma)
********************************************/
// #pragma comment(linker, "/STACK:102400000,102400000")
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <set>
#include <list>
#include <map>
#include <iomanip>
#include <iterator>
#include <cstdlib>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long LL;
typedef long double LD;
#define pb push_back
#define ROUND(x) round(x)
#define FLOOR(x) floor(x)
#define CEIL(x) ceil(x)
const int maxn = 0;
const int maxm = 0;
const int inf = 0x3f3f3f3f;
const LL inf64 = 0x3f3f3f3f3f3f3f3fLL;
const double INF = 1e30;
const double eps = 1e-6;
const int P[4] = {0, 0, -1, 1};
const int Q[4] = {1, -1, 0, 0};
const int PP[8] = { -1, -1, -1, 0, 0, 1, 1, 1};
const int QQ[8] = { -1, 0, 1, -1, 1, -1, 0, 1};
const double euler = 0.57721566490153286060651209;
int kase;
double x;
void init()
{
kase++;
}
void input()
{
//
}
void debug()
{
//
}
void solve()
{
LD ret = (LD)pow(2.0, x) - (LD)1.0;
ret *= (LD)euler;
cout << setprecision(12) << setiosflags(ios::scientific) << ret << endl;
}
void output()
{
//
}
int main()
{
// int size = 256 << 20; // 256MB
// char *p = (char *)malloc(size) + size;
// __asm__("movl %0, %%esp\n" :: "r"(p));

// std::ios_base::sync_with_stdio(false);
#ifdef xysmlx
freopen("in.cpp", "r", stdin);
#endif

kase = 0;
while (~scanf("%lf", &x))
{
init();
input();
solve();
output();
}
return 0;
}


ZOJ 3625 C++
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: