二分之一

news/2024/10/23 5:42:09/

题目描述

输入n,牛牛想知道0.5的n次方的精确值。 注意是精确值,也就是小数有多少位,就要输出多少位,不四舍五入。(当然也不输出多余的0) 对于100%的数据,1 <= n <= 1000 对于60%的数据,1 <= n <= 27 对于30%的数据,1 <= n <= 4

输入描述:

输入一行一个整数n。

输出描述:

输出0.5的n次方的精确值。

示例1

输入

2

输出

0.25

示例2

输入

77

输出

0.00000000000000000000000661744490042422139897126953655970282852649688720703125

说明

精确值

开个数组存每一位有点像高精度

#include<bits/stdc++.h>
using namespace std;
int i,m,n,j,k,a[1000001],b[10001];
char c[10001];
void cheng(int *a,int *b)
{int t[100001];memset(t,0,sizeof(t));for(int i=1;i<=a[0];i++)for(int j=1;j<=b[0];j++) t[i+j-1]+=a[i]*b[j],t[i+j]+=t[i+j-1]/10,t[i+j-1]%=10;a[0]=a[0]+b[0];while(!t[a[0]]) a[0]-=1;for(int i=1;i<=a[0];i++)a[i]=t[i];
}
void ksm(int n)
{a[0]=1;a[1]=5;b[0]=1;b[1]=1;for(n;n>1;n>>=1){if(n&1) cheng(b,a);cheng(a,a);}cheng(a,b);
}
int main()
{scanf("%d",&n);ksm(n);printf("0.");int k=n;for(k;k>a[0];k--) printf("0");for(i=a[0];i>=1;i--) printf("%d",a[i]);return 0;
}

来源:nkw


http://www.ppmy.cn/news/703485.html

相关文章

CSS画特殊边框

例如如图所示边框 .card-middle {width: 672px;height: 486px;border: 1px solid #5fadec;border-radius: 5px;position: relative; }.card-middle::before {content: ;position: absolute;top: -4px;left: -4px;width: 680px;height: 448px;border: 25px solid transparent;b…

1823. 数塔II

单点时限: 2.0 sec 内存限制: 1024 MB 有一个由正整数组成的三角形&#xff0c;第一行只有一个数&#xff0c;除了最下行之外每个数的左下方和右下方各有一个数&#xff0c;如下图所示。 1 3 2 4 10 1 4 3 2 20 从第一行的数开始&#xff0c;除了某一次可以走到下一行的任意…

hdu1823:luck and love

题目大意&#xff1a;请写一种二维的数据结构&#xff0c;支持&#xff1a; 1&#xff09;修改某个点 2&#xff09;查询某一块内的最大值 solution&#xff1a; 这题网上的solution有些错了2333&#xff0c;写这个的目的也是给大家做一个参考。 既然二维树状数组无法解决&…

1823政府经济学 (2)

客观题 单项选择题&#xff08;共10题&#xff0c;共10分&#xff09; 1. 政府经济的依据主要是&#xff08; &#xff09;。 A 私人财产所有权 B 社会公共权力 C 道德劝说 D 法律制度 参考答案&#xff1a;B&#xff1b;考生答案&#xff1a;B&#xff1b;试题分数&a…

MATLAB R2023a更新了哪些好玩的东西?

R2023a来啦&#xff01;&#xff01;废话不多说看看新版本有啥有趣的玩意和好玩的特性叭&#xff01;&#xff01;把绘图放最前面叭&#xff0c;有图的内容看的人多。 1 区域填充 可以使用xregion及yregion进行区域填充啦&#xff01;&#xff01; x -10:0.25:10; y x.^2; pl…

【POJ1823】Hotel

题目链接&#xff1a;http://poj.org/problem?id1823 题意&#xff1a; 有三种操作 1 A M 表示从 A 到 AM-1 住进M个人2 A M 表示从 A 到 AM-1 搬到M个人3 表示查询这个hotel 连续的空房间有多少 题解&#xff1a; 区间合并问题 线段树维护从左端/右端/整段最多连续0的个…

Leetcode 1823.找出游戏的获胜者

原题链接&#xff1a;Leetcode 1823. There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i1)th friend for 1 …

poj1823 - hotel

http://poj.org/problem?id1823 Hotel Time Limit: 5000MS Memory Limit: 30000K Total Submissions: 2389 Accepted: 1044 Description The “Informatics” hotel is one of the most luxurious hotels from Galaciuc. A lot of tourists arrive or leave this hotel i…