题解 1095: The 3n + 1 problem 摘要:解题思路:注意事项:还得先比较输入的两个数的大小!!!参考代码#include<stdio.h> int main() { int a,b,m,n,j,temp; int su…… 题解列表 2023年04月03日 0 点赞 0 评论 415 浏览 评分:0.0
LikeWater - 1095: The 3n + 1 problem #####这题挺搞心态的,题目样例全是a小于b结果提交测试里面会有a大于b的情况,然后导致出错,要是有执拗的人不想看题解真要被折磨半天,题目应该提示一下,不然很烦。```cpp#includeusingnamespacestd;intCycle(intn){intcnt=1;while(n!=1){i 题解列表 2023年03月22日 0 点赞 0 评论 694 浏览 评分:0.0
我这个应该是挺好理解的吧 摘要:```cpp #include using namespace std; int main() { int n,m; while(cin>>n>>m)//n…… 题解列表 2023年01月19日 0 点赞 0 评论 592 浏览 评分:0.0
The 3n + 1 problem(水题) ```c#includeintfun(intn){intcnt=0;do{if(n%2==0){n/=2;cnt++;}else{n=n*3+1;cnt++;}}while(n!=1);returncnt+1;}intmain(){inti, 题解列表 2023年01月12日 0 点赞 0 评论 542 浏览 评分:9.9
1095: The 3n + 1 problem ```cpp#include#includeusingnamespacestd;intfun(intnum){intcount=1;while(num!=1){if(num%2!=0){num=num*3+1;count++;}else{num/=2;count++;}}returncount;}in 题解列表 2023年01月12日 0 点赞 0 评论 439 浏览 评分:9.9
1095: The 3n + 1 problem 摘要:解题思路:注意事项:参考代码:#includeint asd(int n){ int a; if (n % 2 == 0) { a = 1; } else { a = 0; } return…… 题解列表 2022年12月23日 0 点赞 0 评论 470 浏览 评分:0.0
耗时18ms,好像有点高了,复杂度更达到了O(n^2).能不能更简单一点 摘要:解题思路:注意事项:参考代码:#include<bits/stdc++.h>using namespace std;int num1(int n,int m){ if(n>m) swap(n,m…… 题解列表 2022年12月10日 0 点赞 1 评论 391 浏览 评分:9.9
20221124The 3n + 1 problem 摘要:解题思路:注意事项:输入&a,&b不确定其大小参考代码:#include <stdio.h>long len(long n){ long c=1; while(n!=1) { if (n%2==0…… 题解列表 2022年11月24日 0 点赞 0 评论 450 浏览 评分:0.0
【如果你也是“答案错误67”】C语言之判断最长周期 :fa-envelope-o:主要需要注意的就是:要比较输入的i,j的大小,可以先输入大的值后输入小的值```c#includelonglongintT_num(intnum){intT_len=0;while(num!=1){T_len++;if(num%2){num=num*3+1;}else{n 题解列表 2022年11月04日 0 点赞 0 评论 411 浏览 评分:0.0
The 3n + 1 problem(c语言代码) - 解决33%的错误 摘要:注意事项:i,j的输入大小顺序不确定因此要比较i,j并交换i,j要提前打印,如果输入时i>j,交换后,i,j的值就交换了,打印时就出错n = n*3+1可能导致溢出,因此直接将i,j,n全设为long…… 题解列表 2022年10月31日 0 点赞 0 评论 430 浏览 评分:0.0