5 条题解
-
0
Guest
-
0
这道题很简单的一道数学问题,but你要是直接写不是太简单了? so我们先用递归函数试试
#include <algorithm> //STL通用算法 #include <bitset>//STL位集容器 #include <cctype> #include <cerrno> #include <iostream> #include <istream>//基本输入流 #include <ostream> //基本输出流 #include <queue>//STL队列容器 #include <set> //STL 集合容器 #include <istream>//基本输入流 #include <ostream> //基本输出流 #include <queue>//STL队列容器 #include <set> //STL 集合容器 #include <sstream>//基于字符串的流 #include <stack> //STL堆栈容器 #include <stdexcept> //标准异常类 #include <streambuf>//底输入/输出支持 #include <string>//字符串类 #include <utility> //STL通用模板类 #include <vector>//STL动态数组容器 #include <cwchar> #include <cwctype> using namespace std; int fucccfalculateTotalPrice(int x) { // 基本情况:如果只有一个小朋友,票价是10元 if (x == 1) { return 10; } // 递归情况:x位小朋友的票价是x-1位小朋友的票价加上一个小朋友的票价 else { return fucccfalculateTotalPrice(x - 1) + 10; } } int main(){ int x; cin>>x;cout<<fucccfalculateTotalPrice(x); return 0; }
- 1
信息
- ID
- 3
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 276
- 已通过
- 172
- 上传者