母牛的故事_推导表达式 解题思路:采用递归的做法,我么需要考虑每一年母牛的数量和前面几年之间的关系,写出递推公式,就能轻松写出代码。我们以f(n)表示第n年母牛的数量。第一年:f(1)=1,只有一只母牛。第二年:f(2)=f(1)+f(1),可以这样考虑,第二年就是第一年母牛的数量加上第一年母牛的数量, 题解列表 2024年11月03日 4 点赞 0 评论 887 浏览 评分:10.0
明明的随机数 ```cppincludeincludeincludeincludeusingnamespacestd;constintN=110;intn;intq[N];intmain(){scanf(“%d”,&n);for(inti=0;i 题解列表 2024年11月03日 1 点赞 0 评论 586 浏览 评分:9.9 没有上司的晚会 树形dp #includeusingnamespacestd;inth[6005],v[6005],f[6005][2],n,x,y,root;/*h数组存储每个节点的权重。v数组存储每个节点的父亲节点数量,在树中应该是0或1n是树中节点的数量。x和y是临时变量,用于存储输入的边的两个节点。 题解列表 2024年11月02日 0 点赞 0 评论 519 浏览 评分:9.9 3005: 糖果游戏题解 解题思路:可以把这个问题看作是一个循环分配的过程,由于是圆桌,1号和5号小朋友也是相邻的。可以利用数组来模拟每个小朋友手中的糖果数量,通过计算每个小朋友分配后的糖果情况,更新数组中的值。通过模运算对索引进行处理后,代码可以应对不同数量的小朋友,只需调整v.resize()的参数即可。 题解列表 2024年11月01日 1 点赞 0 评论 645 浏览 评分:0.0 2757: 浮点数向零舍入题解 摘要:解题思路:注意事项:参考代码:#include <iostream> #include <cmath> using namespace std; double round(double r) …… 题解列表 2024年11月01日 0 点赞 0 评论 663 浏览 评分:0.0 包会,不会你来锤我 ####贪心策略:优先选择先结束的活动,保证每个选择子结构的最佳结果```cpp#include#includeusingnamespacestd;//创建结构体,结构体成员begin,end分别为每一个活动的开始与结束时间structa{intbegin, 题解列表 2024年10月31日 3 点赞 3 评论 903 浏览 评分:10.0 与7无关的数 摘要:解题思路:注意事项:参考代码:#include <iostream>#include <cmath>using namespace std;int main(){ int n; cin >…… 题解列表 2024年10月31日 0 点赞 0 评论 496 浏览 评分:7.3 最易懂的代码 摘要:解题思路:注意事项:参考代码:#include<bits/stdc++.h>using namespace std;int n,r;int arr[30];void func(int x,int st…… 题解列表 2024年10月31日 0 点赞 0 评论 651 浏览 评分:6.0 杀到这九天十地无人敢称尊,直到身边再无一人能陪我征战,叶天帝不过如此 #不用抽象标题没人看俺题解此题模板题就不多说了直接看看代码######ACCode:```cpp#include#include#include#include#defineintlonglongusingnamespacestd;constintN=1e5+10;intc[N];intn, 题解列表 2024年10月30日 1 点赞 1 评论 514 浏览 评分:10.0 1762: printf基础练习题解 摘要:解题思路:注意事项:参考代码:#include <iostream> using namespace std; int main() { int a = 123456789; …… 题解列表 2024年10月30日 1 点赞 0 评论 1196 浏览 评分:0.0 « 12...123124125126127128129...16491650 »
没有上司的晚会 树形dp #includeusingnamespacestd;inth[6005],v[6005],f[6005][2],n,x,y,root;/*h数组存储每个节点的权重。v数组存储每个节点的父亲节点数量,在树中应该是0或1n是树中节点的数量。x和y是临时变量,用于存储输入的边的两个节点。 题解列表 2024年11月02日 0 点赞 0 评论 519 浏览 评分:9.9
3005: 糖果游戏题解 解题思路:可以把这个问题看作是一个循环分配的过程,由于是圆桌,1号和5号小朋友也是相邻的。可以利用数组来模拟每个小朋友手中的糖果数量,通过计算每个小朋友分配后的糖果情况,更新数组中的值。通过模运算对索引进行处理后,代码可以应对不同数量的小朋友,只需调整v.resize()的参数即可。 题解列表 2024年11月01日 1 点赞 0 评论 645 浏览 评分:0.0
2757: 浮点数向零舍入题解 摘要:解题思路:注意事项:参考代码:#include <iostream> #include <cmath> using namespace std; double round(double r) …… 题解列表 2024年11月01日 0 点赞 0 评论 663 浏览 评分:0.0
包会,不会你来锤我 ####贪心策略:优先选择先结束的活动,保证每个选择子结构的最佳结果```cpp#include#includeusingnamespacestd;//创建结构体,结构体成员begin,end分别为每一个活动的开始与结束时间structa{intbegin, 题解列表 2024年10月31日 3 点赞 3 评论 903 浏览 评分:10.0
与7无关的数 摘要:解题思路:注意事项:参考代码:#include <iostream>#include <cmath>using namespace std;int main(){ int n; cin >…… 题解列表 2024年10月31日 0 点赞 0 评论 496 浏览 评分:7.3
最易懂的代码 摘要:解题思路:注意事项:参考代码:#include<bits/stdc++.h>using namespace std;int n,r;int arr[30];void func(int x,int st…… 题解列表 2024年10月31日 0 点赞 0 评论 651 浏览 评分:6.0
杀到这九天十地无人敢称尊,直到身边再无一人能陪我征战,叶天帝不过如此 #不用抽象标题没人看俺题解此题模板题就不多说了直接看看代码######ACCode:```cpp#include#include#include#include#defineintlonglongusingnamespacestd;constintN=1e5+10;intc[N];intn, 题解列表 2024年10月30日 1 点赞 1 评论 514 浏览 评分:10.0
1762: printf基础练习题解 摘要:解题思路:注意事项:参考代码:#include <iostream> using namespace std; int main() { int a = 123456789; …… 题解列表 2024年10月30日 1 点赞 0 评论 1196 浏览 评分:0.0