题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2013

题目大意:已知最后一天桃子只有一个,告诉你猴崽子第一天吃掉总桃子数的一半多一个,第二天吃掉剩下总数的一半多一个,给你剩下一个桃子事件是在第 n 天发生的,求桃子总数

解题思路:

很水,想一下就出来了

方法一:for 倒着推

方法二:简单基本递归入门

代码:

方法一:

 #include<iostream>
#include<cmath>
#include<iomanip>
//#include<algorithm>
using namespace std;
int num;
int main()
{
int n;
int sum;
int p;
while(cin >> n)
{
sum = ;
p = ;
for(int i = ; i < n - ; i ++)
{
sum += (p + ) * ;
p = sum;
sum = ;
}
cout << p << endl;
}
}

方法二:

 #include<stdio.h>
int n;
int tao(int cur) {
if(cur == n) return ;
return *(tao(cur+)+);
}
int main() {
while(scanf("%d", &n)!=EOF) {
printf("%d\n", tao());
}
return ;
}

总感觉for 写的蠢蠢的,不知道该怎么修改优化~喵喵喵?

    

****************************更新****************************(优化方法一的 for 写法)

 #include<iostream>
#include<cmath>
#include<iomanip>
//#include<algorithm>
using namespace std;
int num;
int main()
{
int n;
int sum = ;
while(cin >> n)
{
sum = ;
for(int i = ; i < n - ; i ++)
{
sum = (sum + ) << ;
}
cout << sum << endl;
}
}

基本移位操作:“<< n” 乘以 2n   ( 空出地方补 “0”)

“>> n” 除以 2n      (正数空出地方补 “0”     负数补 ”1“ )

HDU 2013 (水)的更多相关文章

  1. 【HDU 2013 猴子吃桃子】 尾递归与迭代

    大一时的一道C语言练习题,可作为递归和尾递归转迭代的范例.HDU 2013 http://acm.hdu.edu.cn/showproblem.php?pid=2013 题意:猴子摘了sum个桃子,从 ...

  2. HDU-1042-N!(Java大法好 &amp;&amp; HDU大数水题)

    N! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Total Subm ...

  3. hdu 4464 水

    http://acm.hdu.edu.cn/showproblem.php?pid=4464 现场赛总会有水题,这就是最水的一道,预计也就是能当高校的上机题,保研用,呵呵~~~ #include &l ...

  4. HDU 5391 水题。

    E - 5 Time Limit:1500MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Statu ...

  5. hdu 1544 水题

    水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...

  6. hdu 3357 水题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...

  7. hdu 2013

    水题 AC代码: #include <iostream> using namespace std; int main() { int i,m,n; while(cin>>n) ...

  8. hdu 5007 水 弦

    http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...

  9. Tickets HDU - 1260 水DP

    HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...

随机推荐

  1. 高级数据结构---红黑树及其插入左旋右旋代码java实现

    前面我们说到的二叉查找树,可以看到根结点是初始化之后就是固定了的,后续插入的数如果都比它大,或者都比它小,那么这个时候它就退化成了链表了,查询的时间复杂度就变成了O(n),而不是理想中O(logn), ...

  2. 深度剖析前端JavaScript中的原型(JS的对象原型)

          这张图片有点劝退了,哈哈哈~    通过原型机制,JavaScript 中的对象从其他对象继承功能特性:这种继承机制与经典的面向对象编程语言的继承机制不同.本文将探讨这些差别,解释原型链如 ...

  3. mysql 使用记录

    修改 mysql 数据库密码 mysqladmin -u username -h host_name password -P <port> "new_password" ...

  4. 机器学习5- 对数几率回归+Python实现

    目录 1. 对数几率回归 1.1 求解 ω 和 b 2. 对数几率回归进行垃圾邮件分类 2.1 垃圾邮件分类 2.2 模型评估 混淆举证 精度 交叉验证精度 准确率召回率 F1 度量 ROC AUC ...

  5. 数值计算方法实验之Newton 多项式插值(MATLAB代码)

    一.实验目的 在己知f(x),x∈[a,b]的表达式,但函数值不便计算或不知f(x),x∈[a,b]而又需要给出其在[a,b]上的值时,按插值原则f(xi)=yi (i=0,1,……, n)求出简单函 ...

  6. pytorch torchversion标准化数据

     新旧标准差的关系

  7. c++动态数组的使用

    在c++中,有的时候会遇到变长的数组(不管是一维的还是二维的),这个时候就需要用到动态数组了,并且要用new和delete两个操作符,这俩操作符一般成对使用. 先说一维的动态数组吧,直接上代码 #in ...

  8. 2019-2020-1 20199326《Linux内核原理与分析》第九周作业

    进程的切换和系统的一般执行过程 中断 中断在本质上都是软件或者硬件发生了某种情形而通知处理器的行为,处理器进而停止正在运行的指令流(当前进程),对这些通知做出相应反应,即转去执行预定义的中断处理程序( ...

  9. 终止过久没有返回的 Windows API 函数 ---- “CancelSynchronousIo”

    Marks pending synchronous I/O operations that are issued by the specified thread as canceled. BOOL W ...

  10. 解决Idea配置文件不显示中文的问题

    1.首先我们的IDEA文件编码一般都修改为utf-8(setting-->file encodings--->Global Encoding 和 Project Encoding 都设置为 ...