HDU 3215 The first place of 2^n (数论-水题)
The first place of 2^n
LMY discovers that for every consecutive 3 or 4 results, there must be one among them whose first digit is 1, and comes to the conclusion that the first digit of 2n isn’t evenly distributed between 1 and 9, and the number of 1s exceeds those of others. YY now
intends to use statistics to prove LMY’s discovery.
End of input is indicated by a line consisting of -1.
0
1
3
10
-1
1 0 0 0 0 0 0 0 0
1 1 0 0 0 0 0 0 0
1 1 0 1 0 0 0 1 0
4 2 1 1 1 1 0 1 0
题目大意“:
妈呀,这是我们大东华09年出的题啊,好厉害,事实上是好水啊。
题目大意就是计算2^0到2^n这n个数首位为1的次数,2的次数,...9的次数。
解题思路:
我是不会告诉你log10一下就会找到你想要的东西的。
解题代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std; const int maxn=10010;
const double lg2=log10(2.0);
int a[maxn]; void ini(){
a[0]=1,a[1]=2,a[2]=4,a[3]=8;
for(int i=4;i<maxn;i++){
double x=i*lg2-int(i*lg2+1e-7);
a[i]=pow(10.0,x);
}
//for(int i=0;i<20;i++) cout<<"2^"<<i<<" :"<<a[i]<<endl;
} int main(){
ini();
int n;
while(scanf("%d",&n)!=EOF && n!=-1){
int cnt[10]={0};
for(int i=0;i<=n;i++){
cnt[a[i]]++;
}
printf("%d",cnt[1]);
for(int i=2;i<=9;i++){
printf(" %d",cnt[i]);
}
printf("\n");
}
return 0;
}
HDU 3215 The first place of 2^n (数论-水题)的更多相关文章
- hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0
H - National Day Parade Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- HDU 1576 A/B 数论水题
http://acm.hdu.edu.cn/showproblem.php?pid=1576 写了个ex_gcd的模板...太蠢导致推了很久的公式 这里推导一下: 因为 1 = BX + 9973Y ...
- HDU - 4788 Hard Disk Drive (成都邀请赛H 水题)
HDU - 4788 Hard Disk Drive Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I ...
- hdu 4524 郑厂长系列故事——逃离迷宫 小水题
郑厂长系列故事——逃离迷宫 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) To ...
- hdu 5038 (2014北京网络赛G 排序水题)
题意:有n个数字,带入10000 - (100 - ai) ^ 2公式得到n个数,输出n个数中频率最大的数,如果有并列就按值从小到大都输出输出,如果频率相同的数字是全部的n个数,就输出Bad....题 ...
- hdu 2553:N皇后问题(DFS遍历,水题)
N皇后问题 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4662 MU Puzzle (2013多校6 1008 水题)
MU Puzzle Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 4639 Hehe (2013多校4 1008 水题)
Hehe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- HDU 6322.Problem D. Euler Function -欧拉函数水题(假的数论题 ̄▽ ̄) (2018 Multi-University Training Contest 3 1004)
6322.Problem D. Euler Function 题意就是找欧拉函数为合数的第n个数是什么. 欧拉函数从1到50打个表,发现规律,然后勇敢的水一下就过了. 官方题解: 代码: //1004 ...
随机推荐
- 字串乱序 PHP&JS
<?php /** * 字串乱序 PHP&JS * * php 中把字串乱序后输出给客户机的 JAVASCRIPT , JAVASCRIPT 中恢复 * 在指定长度提取一个字符,并把这一 ...
- MYSQL添加远程用户或允许远程访问三种方法
添加远程用户admin密码为password GRANT ALL PRIVILEGES ON *.* TO admin@localhost IDENTIFIED BY \'password\' WIT ...
- JS学习笔记 - 面向对象 - 选项卡 (普通选项卡改写)
选项卡3 <script> window.onload=function () { new TabSwitch('div1'); }; function TabSwitch(id) // ...
- 11.5 Android显示系统框架_Vsync机制_代码分析
5.5 surfaceflinger对vsync的处理buffer状态图画得不错:http://ju.outofmemory.cn/entry/146313 android设备可能连有多个显示器,AP ...
- 卫星网络中使用TCP协议的劣势(所以才有TCP优化版用来卫星通信啊,比如TCP-Peach和ADolar)
卫星网络中使用TCP协议的劣势 为了避免产生网络拥塞,原TCP协议综合采用了慢启动.拥塞避免.快速重传以及快速恢复等算法.但这些算法应用的前提是网络发生拥塞造成丢包,然而在误码率相对较高的卫星通信系统 ...
- JAVA 如何将String进行大小写转换
private String convertString(String str, Boolean beginUp){ char[] ch = str.toCharArray(); StringBuff ...
- word多出空标题,样式是列出段落 - -显示时,选择不勾选“隐藏文字”
word多出空标题,样式是列出段落
- image-base64互转
package base64StringToImage; import java.awt.image.BufferedImage; import java.io.ByteArrayInputStrea ...
- Ditto —— windows 剪贴板增强小工具(复制粘贴多条记录)
Windows 虽然不断在升级,但系统自带的剪贴板功能却仍然弱爆了 (只能保留一条记录). Ditto 下载地址:http://sourceforge.net/projects/ditto-cp/fi ...
- IIS服务器能支持10万并发
服务器能支持10万并发由于一个项目的访问量越来越大,从原来的几百个,增加到现在50多万个每天,所以阿里的服务器也扛不住了,于是就想办法,查了N多资料,总结了以下方法,才解决这问题,每天一共访问量50多 ...