【HDOJ6217】BBP Formula(公式)
题意:给定一个无穷项的分式,它的和等于π,问π的十六进制表示的小数点后第n位是多少
1 ≤ n ≤ 100000
思路:From https://blog.csdn.net/meopass/article/details/78327614

C++double写起来细节真是烦
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 11000
#define M 41
#define eps 1e-8
#define pi acos(-1) int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} ll Pow(ll a,ll b,ll MOD)
{
ll ans=;
while(b)
{
if(b&) ans=ans*a%MOD;
a=a*a%MOD;
b>>=;
}
return ans;
} double BBP(int n,ll k,ll b)
{
double ans=;
for(int i=;i<=n;i++) ans+=(Pow(,n-i,*i+b)*1.0/(*i+b));
for(int i=n+;i<=n+;i++) ans+=(powf(,n-i)/(*i+b));
return k*ans;
} int main()
{
//freopen("hdoj6217.in","r",stdin);
//freopen("hdoj6217.out","w",stdout);
int cas;
scanf("%d",&cas);
for(int v=;v<=cas;v++)
{
int n;
scanf("%d",&n);
n--;
double ans=0.0;
ans=BBP(n,,)+BBP(n,-,)+BBP(n,-,)+BBP(n,-,);
ans-=int(ans);
if(ans<) ans++;
ans*=;
char ch;
int p=int(ans);
if(<=p&&p<=) ch=p+'';
else if(p==) ch='A';
else if(p==) ch='B';
else if(p==) ch='C';
else if(p==) ch='D';
else if(p==) ch='E';
else if(p==) ch='F';
printf("Case #%d: %d %c\n",v,n+,ch); }
return ;
}
【HDOJ6217】BBP Formula(公式)的更多相关文章
- hdu 6217 A BBP Formula 公式题
题意 已知公式:$\pi=\sum_{k=0}^{\infty}\left[\frac{1}{16^{k}}\left(\frac{4}{8 k+1}-\frac{2}{8 k+4}-\frac{1} ...
- HDU 6217 BBP Formula (数学)
题目链接: HDU 7217 题意: 题目给你可以计算 \(π\) 的公式: \(\pi = \sum_{k=0}^{\infty}[\frac{1}{16^k}(\frac{4}{8k+1})-(\ ...
- HDU-6217 BBP Formula 脑洞
题目链接:https://cn.vjudge.net/problem/HDU-6217 题意 已知: \[ \pi = \sum_{k=0}^{\infty }\frac{1}{16^{k}}(\fr ...
- UVALive-8201-BBP Formula
8201-BBP Formula Time limit: 3.000 seconds In 1995, Simon Plouffe discovered a special summation sty ...
- ACM-ICPC 2017 Asia Shenyang Solution
A: BBP Formula https://www.cnblogs.com/LzyRapx/p/7802790.html #include <bits/stdc++.h> using n ...
- [模拟电路] 2、Passive Band Pass Filter
note: Some articles are very good in http://www.electronics-tutorials.ws/,I share them in the Cnblog ...
- 【趣味分享】C#实现回味童年的24点算法游戏
一.24点游戏玩法规则效果展示 1.初始化界面 2.开始游戏界面 3.游戏超时界面 4.查看答案界面 5.答对界面 6.答错界面 7.计算表达式的验证界面 8.一副牌算完开始新一副牌界面 到这里24点 ...
- Design and Analysis of Algorithms_Fundamentals of the Analysis of Algorithm Efficiency
I collect and make up this pseudocode from the book: <<Introduction to the Design and Analysis ...
- 【Python】使用正则表达式实现计算器练习
已知有以下这样一个不太友好的公式: 1 - 2 * ( (60-30 +(-9-2-5-2*3-5/3-40*4/2-3/5+6*3) * (-9-2-5-2*5/3 + 7 /3*99/4*2998 ...
随机推荐
- Java的日期类和日期格式化类
日期类: Date date = new Date(); // 获取当前的系统时间 2 System.out.println("年份:"+ date.getYear()); Cal ...
- tensorflow目标检测API安装及测试
1.环境安装配置 1.1 安装tensorflow 安装tensorflow不再仔细说明,但是版本一定要是1.9 1.2 下载Tensorflow object detection API 下载地址 ...
- 初级练手项目——用Python一步一步实现“智能”贪吃蛇!
贪吃蛇作为一款经典的小游戏,想必大家一定并不陌生,今天我们就来用Python来设计与实现贪吃蛇游戏,回味一下童年的快乐.快跟着小编来看看吧! 基本环境配置 ●版本:Python3 ●系统:Wind ...
- huu 1251
#include <iostream> #include <cstdio> #include <cstring> #include <string> # ...
- linux学习-主机的细部权限规划:ACL 的使用
传统的权限仅有三种身份 (owner, group, others) 搭配三种权限 (r,w,x) 而已,并没有办法单纯的针对某一个使用者或某一个群 组来设定特定的权限需求,此时就得要使用 ACL 这 ...
- kettle-批量同步表数据
一.实验目标 利用kettle实现从mysql数据库中的dbf库批量同步表到dbm库(全量同步) 二.实验环境 dbf 库中表f1.f2.f3 .f1中1条数据,f2中100条数据,f3中2条数据 ...
- Win7里IIS7部署WebService
最近忙于一个Web的Bug修正,是先人写的一个东东,架构很简单,一个前端的项目,一个WebService的项目,以及后台的一些dll.之前一直很排斥这个产品,因为它没法启动,印象中没有跑得起来过的时候 ...
- 【报错】invalid or unexpected token
结果发现是把英文的,写成了中文字符,系统没法识别.
- org.hibernate.AnnotationException: No identifier specified for entity: com.example1.demo1.Entity.User错误
最近在公司带人,他们问我的问题在这里也顺便总结下. 此项目为SpringDataJpa项目. 出现的错误如下: Caused by: org.hibernate.AnnotationException ...
- edge浏览器识别ip地址为手机号的解决办法
edge浏览器识别ip地址为手机号的解决办法 今天突然发现类似101.231.70.242的ip地址会在edge浏览器里面识别为可点击的链接,后来看了一下,原因就是被识别为手机号了,因为我发现点击的时 ...