1202: 2018四川理工学院大学生ACM程序设计:The wheat of the prime minister

时间限制: 1 Sec  内存限制: 128 MB
提交: 4  解决: 3
[提交][状态][讨论版][命题人:liangxingjian]

题目描述

Sissa Ben, a minister in ancient India, invented the game of chess. The king intended to reward him because of it. The minister said, “I want nothing but some wheat. Please put a grain of wheat on the first square of the chessboard, two on the second, four on the third, eight on the fourth, ..., and so on, doubling the number for each following square, and give me enough grains to cover the 64 squares of the chessboard.” The king ordered a bag of wheat brought to the palace. But when the counting began with one gain for the first square, two for the second, four for the third, and so on, the bag was emptied before the 20th square. More bags were brought but the number of grain needed for the following squares increased so rapidly that the king soon realized that he was not able to keep his promise even with all the crops in the whole India!
        Suppose the king had n wheat, which square should the last one cover?

输入

the number of wheat: n(n<2^63-1), end by 0

输出

which square should the last one cover

样例输入

35
123456
0

样例输出

6
17 题目大意:
  ①、求A[1] = 1, A[2] = 2, A[3] = 4, ..., A[64]酱紫的序列 A{n} = pow(2, n-1)
  ②、S[1] = A[1], S[2] = A[1] + A[2], S[3] = A[1] + A[2] + A{3} ..., S{64} 前n项和
  ③、S[n]第一次 >= 题目输入的数据是在第几位 核心代码:
  
 void cal_excel()
{
A[] = ;
for(int i = ; i <= ; ++ i)
{
A[i] = A[i-] + pow(, i-);
}
return ;
}

C/C++代码实现(AC):

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <stack>
#include <map>
#include <queue> using namespace std;
long long A[]; void cal_excel()
{
A[] = ;
for(int i = ; i <= ; ++ i)
A[i] = A[i-] + pow(, i-);
} int main()
{
cal_excel();
long long n;
while(~scanf("%lld", &n), n)
{
for(int i = ; i <= ; ++ i)
{
if(A[i] >= n)
{
printf("%d\n", i);
break;
}
}
}
return ;
}
 

最新文章

  1. document.forms用法
  2. Delphi面向对象编程
  3. Leetcode 83 Remove Duplicates from Sorted List 链表
  4. [团队项目]Scrum 项目1.0 (演说视频)NABCD
  5. caffe: test code 执行出问题: Check failed: FLAGS_weights.size() &gt; 0 (0 vs. 0) Need model weights to score.
  6. WPF UI布局之概述
  7. phpmyadmin登陆提示#2002 无法登录 MySQL 服务器和设置自增
  8. asp.net 分页类
  9. APP测试--功能测试
  10. Oracle清除数据库中长时间占用资源的非活动的会话
  11. android动画介绍之 自定义Animation动画实现qq抖一抖效果
  12. JNDI 使用
  13. python开发基础之语法基础
  14. JavaScript 二进制转文件
  15. java OOM还在看log日志,兄弟你错的的很严重,正确方式是分析dump文件
  16. android逆向四则运算
  17. selenium元素定位Xpath,Contains,CssSelector
  18. docker之搭建私有仓库
  19. 不同浏览器的userAgent
  20. NSObject的hash方法

热门文章

  1. 在VS2013下配置BOOST库
  2. Tensorflow从开始到放弃
  3. spark cdh5编译安装[spark-1.0.2 hadoop2.3.0 cdh5.1.0]
  4. 3M隔音耳罩拆分、清洗教程
  5. 百万年薪python之路 -- 数据库初始
  6. 用MATLAB绘制折线图,x轴为字符串,并旋转一定的角度!!!
  7. IIS服务器文件跨域问题(几乎可以解决大多数跨域问题)
  8. Java 在PDF中添加页面跳转按钮
  9. 拨云见日,彻底弄清楚Java日志框架 log4j, logback, slf4j的区别与联系
  10. 2017.12.21 学习vue的新得