UVa 474 - Heads / Tails Probability

题目:计算1/(2^n)的值的前4为有效数字以及位数。

分析:数论,大整数。直接用数组模拟即可。

说明:打表计算,查询输出。

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath> 

using namespace std;

double val[1000005];
int    bit[1000005];

int main()
{
	val[0] = 1;bit[0] = 0;
	for (int i = 1 ; i < 1000001 ; ++ i) {
		val[i] = val[i-1]/2;
		bit[i] = bit[i-1];
		if (val[i] < 1) {
			val[i] *= 10;
			bit[i] --;
		}
	}

	int n;
	while (~scanf("%d",&n))
		printf("2^-%d = %.3lfe%d\n",n,val[n],bit[n]);

	return 0;
}
时间: 2024-08-10 09:24:41

UVa 474 - Heads / Tails Probability的相关文章

UVA 474 - Heads / Tails Probability(递推)

UVA 474 - Heads / Tails Probability 题目链接 题意:给定n,求出2?n的科学计数法 思路:水水的,n最多到100w,那么先递推预处理出答案,然后输出即可 代码: #include <cstdio> #include <cstring> const int N = 1000001; const double eps = 1e-9; int n; struct Ans { double a; int b; } ans[N]; void build()

atcoderI - Coins ( 概率DP)

I - Coins Time Limit: 2 sec / Memory Limit: 1024 MB Score : 100100 points Problem Statement Let NN be a positive odd number. There are NN coins, numbered 1,2,…,N1,2,…,N. For each ii (1≤i≤N1≤i≤N), when Coin ii is tossed, it comes up heads with probabi

python编程快速上手之第10章实践项目参考答案

  本章主要讲了python程序的调试,当程序有BUG或异常的时候,我们如何调试代码找出问题点.其实在本章之前的章节我们做练习的时候都会遇到各种各样的错语和异常,最初当不知道程序哪里出错的情况下不可否认的都使用了print语句进行输出并调试代码.没错print也是调试代码的一种工具,直观简单,便也有缺点,就是调试好后要进行删除,也是件麻烦事,于是就有了本章介绍的assert(断言),logging(日志)以及各种调试工具的出现. 首先来回顾一下python的异常. 一.python常见的异常类型

[Swust OJ 795]--Penney Game

题目链接:http://acm.swust.edu.cn/problem/795/ Time limit(ms): 1000 Memory limit(kb): 65535 Description Penney’s game is a simple game typically played by two players. One version of the game calls for each player to choose a unique three-coin sequence su

[TypeScript] 1. Catching JavaScript Mistakes with TypeScript

The TypeScript compiler is a powerful tool which catches mistakes even in vanilla JavaScript. Try it online at the TypeScript Playground, zero setup required. Error version: var movie = { title: "Memento", year: 2000, IMDB: 8.5, title: "&qu

Sicily 2368. Penney Game

2368. Penney Game Constraints Time Limit: 1 secs, Memory Limit: 256 MB Description Penney's game is a simple game typically played by two players. One version of the game calls for each player to choose a unique three-coin sequence such as HEADS TAIL

【概率论与数理统计】小结6 - 大数定理与中心极限定理

注:这两个定理可以说是概率论中最重要的两个定理.也是由于中心极限定理的存在,使得正态分布从其他众多分布中脱颖而出,成为应用最为广泛的分布.这两个定理在概率论的历史上非常重要,因此对于它们的研究也横跨了几个世纪(始于18世纪初),众多耳熟能详的大数学家都对这两个定理有自己的贡献.因此,这两个定理都不是单一的定理.不同的大数定理和中心极限定理从不同的方面对相同的问题进行了阐述,它们条件各不相同,得到的结论的强弱程度也不一样. 1. 大数定理(law of large numbers,LLN) 图1-

iOS - Swift Enumerations or how to annoy Tom

@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(htt

Introduction to Writing Functions in R

在R中编写函数 为啥要用函数 为了代码更加可读,减少重复代码==lazy You can type less code, saving effort and making your analyses more readable. You can reuse your code from project to project. in R function are a type of variable ,so you assign functions using left arrow,just li