HDU 2013 (水)
题目链接: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 (水)的更多相关文章
- 【HDU 2013 猴子吃桃子】 尾递归与迭代
大一时的一道C语言练习题,可作为递归和尾递归转迭代的范例.HDU 2013 http://acm.hdu.edu.cn/showproblem.php?pid=2013 题意:猴子摘了sum个桃子,从 ...
- HDU-1042-N!(Java大法好 && HDU大数水题)
N! Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) Total Subm ...
- hdu 4464 水
http://acm.hdu.edu.cn/showproblem.php?pid=4464 现场赛总会有水题,这就是最水的一道,预计也就是能当高校的上机题,保研用,呵呵~~~ #include &l ...
- HDU 5391 水题。
E - 5 Time Limit:1500MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Submit Statu ...
- hdu 1544 水题
水题 /* * Author : ben */ #include <cstdio> #include <cstdlib> #include <cstring> #i ...
- hdu 3357 水题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3357 #include <cstdio> #include <cmath> # ...
- hdu 2013
水题 AC代码: #include <iostream> using namespace std; int main() { int i,m,n; while(cin>>n) ...
- hdu 5007 水 弦
http://acm.hdu.edu.cn/showproblem.php?pid=5007 纯粹的联系String的substr 什么时候substr拦截比写短话 string te; int n; ...
- Tickets HDU - 1260 水DP
HDU - 1260 现在有n个人要买电影票,如果知道每个人单独买票花费的时间, 还有和前一个人一起买花费的时间,问最少花多长时间可以全部买完票. 直接dp就行,注意下输出和初始化 每次从dp[i-1 ...
随机推荐
- [GitHub] 75+的 C# 数据结构和算法实现
C#中标准数据结构和算法的即插即用类库项目 GitHub:https://github.com/aalhour/C-Sharp-Algorithms Watch: 307 Star: 3.4k For ...
- 适合新手练习的Python项目有哪些?Python爬虫用什么框架比较好?
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. Python爬虫一般用什么框架比较好?一般来讲,只有在遇到比较大型的需求时 ...
- JAVA的synchronized写法
使用关键字synchronized的写法比较多,常用的有如下几种,代码如下: public class MyService { synchronized public static void test ...
- fasttext 和pysparnn的安装
- pytorch torchversion自带的数据集
from torchvision.datasets import MNIST # import torchvision # torchvision.datasets. #准备数据集 mnist = M ...
- pytorch实现手动线性回归
import torch import matplotlib.pyplot as plt learning_rate = 0.1 #准备数据 #y = 3x +0.8 x = torch.randn( ...
- TensorFlow keras中一些著名的神经网络
- js判断一个元素是否在数组内
1.indexOf()返回给定元素在数组内的索引值,如果不存在则返回-1 var arr=[0,1,2,3,4,5] console.log(arr.indexOf(1)) console.log(a ...
- JS在线代码编辑器多种方案monaco-editor,vue-monaco-editor
前言 JavaScript在线代码编辑器. 需要代码提示,关键字高亮,能够格式化代码.(不需要在线运行) 简简单单的需求. 方案一: Monaco-editor 简介:微软的开源项目,开源中国上面的在 ...
- 微信小程序入门(持续更新)
微信小程序的主要文件介绍: . js:脚本文件 .json:配置文件 .wxss:样式表文件 .wxml:页面 微信小程序差不多也是和mvc模式差不多的,采用数据和页面分离的模式,在js上写的数据可以 ...