PC110101:The 3n+1 problem
第一道题居然就卡了这么久惭愧惭愧。
过程中出现这么几个问题。
1.关于最终和的数据类型要选择long。
2.循环中途max要初始化为0;
贴出代码。
#include<stdio.h>int main()
{long xl(long m) ;long i,j,k,l;long max=0;long c;while(~scanf("%ld%ld",&i,&j)){max=0;if(i<j){ k=i;l=j;}else{k=j;l=i;}for(;k<=l;k++){c=xl(k);max=c>max?c:max;// if(c>max)// max=c;}printf("%ld %ld %ld\n",i,j,max);}return 0;
}long xl(long m)
{long n=1;while(m>1){if(m%2==1)m=m*3+1;elsem=m/2;n++;}return n;}
PC110101:The 3n+1 problem相关推荐
- 110101_The 3n+1 problem
http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110101&format=html ...
- POJ 1207 The 3n + 1 problem
题目链接:http://poj.org/problem?id=1207 题目大意:给你一个数x,规定一个函数F(x),如果x为1则F(x)==1,否则如果x是偶数,F(x)==F(x/2),x为奇数F ...
- Codeforces 798C:Mike and gcd problem
Codeforces 798C:Mike and gcd problem 题目链接:http://codeforces.com/contest/798/problem/C 题目大意:给出一个大小为$n ...
- 论文解读:On The Alignment Problem In Multi-Head Attention-Based Neural Machine Translation
论文解读:On The Alignment Problem In Multi-Head Attention-Based Neural Machine Translation 机器翻译是自然语言处理 ...
- PC110101(3n+1问题)(3n+1 Problem)
单纯模拟,用一个数组记录下"沿途"的值,避免重复运算. 注意: 1. 中间计算过程会超过int或long型数据所能表示的范围,故需要选择long long型整数. 2. 输入时可能 ...
- PC/UVa 题号: 110101/100 3n+1 Problem
不解释了,暴力,不过需要注意的是 i有可能大于j #include <stdio.h> #include <string.h> #define maxnum 1000001 l ...
- Poj1207 The 3n + 1 problem(水题(数据)+陷阱)
一.Description Problems in Computer Science are often classified as belonging to a certain class of p ...
- 【elasticsearch】elasticsearch--6.8.0报错信息如下: checksum failed (hardware problem?)
界面查不到数据,查看es的heath,看到集群的是red的,然后查看red的分片,手动分配是可以分配的,但是不会自动分配,查看日志报错节点的信息如下: Caused by: org.apache.lu ...
- Python项目:The Ship Rendezvous Problem,利用贪心算法解决船舶交会问题
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 Python利用贪心算法解决船舶交会问题 1 Introduction 2 Python Task Greedy Heuristic ...
最新文章
- 中国 12 个工科世界第一,网友:全是不吃香的|软科 2021 世界一流学科排名
- 出现java.lang.IllegalArgumentException异常
- Ubuntu解压缩zip,tar,tar.gz,tar.bz2
- STM32 电机教程 1 - 用ST Motor Profiler 测量无刷电机参数
- 荣事达空调质量差3天即坏
- 【机器学习】平衡你的数据集的几项技巧
- RocketMQ快速入门之手动创建topic
- mysql修改字段 新增字段
- 强烈推荐:大神总结的超系统的前端提升路径
- 滚动时间选择器recyclerview_Android自定义可循环的滚动选择器CycleWheelView
- BZOJ-4008: [HNOI2015]亚瑟王 (概率期望DP)
- 上位机与西门子PLC通信协议
- 【Python】ID3算法的实现
- 数据仓库系列之总线架构
- Playrix Codescapes Cup (Codeforces Round #413, rated, Div. 1 + Div. 2) F. Beautiful fountains rows
- corutine rust_corutine rust_rust 异步 IO:从 mio 到 coroutine
- Unity2D游戏制作常用方法
- error An unexpected error occurred “httpsregistry.npmjs.orgd3-geo-proje
- 【HCIE-RS】TAC诊断1
- 织梦教程:自定义模型会员无法投稿的解决方法