博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1005. 继续(3n+1)猜想 (25)
阅读量:7030 次
发布时间:2019-06-28

本文共 850 字,大约阅读时间需要 2 分钟。

题目来源 

没有深入思考,直接暴力做了,当成是练习语言语法的题目了。如果数的范围不是1 到 100 那就得换种方法了做了。

不排序,或者说是桶排序的方式来。

记录每个数的变化过程中出现的数字,然后比一比就行了。最后用桶排序的方法把结果从大到小输出。

(java 学的烂,代码凑合看吧)

 

import java.util.*;
public class Main{
public static void main(String args[]){
Scanner read = new Scanner(System.in);
int cont = read.nextInt(), i = 0;
int in[] = new int[102];
int res[] = new int[102];
int show[] = new int[10000];
while(i < cont){
int temp = read.nextInt();
in[i++] = temp;
while( temp != 1){
if(temp % 2 == 0){
temp /= 2;
}else{
temp = (temp *3 + 1) / 2;
}
show[temp] = 1;
}
}
int total = 0 ;
for(int j=0; j<cont; ++j){
if(show[in[j]] == 0){
res[in[j]] = 1;
total ++;
}
}
for(int j=100; j>1; --j){
if(res[j] == 1){
System.out.print(j);
if(total > 1){
System.out.print(" ");
}else if(total == 1){
System.out.println();
}
total --;
}
}
}
}

 

转载于:https://www.cnblogs.com/zzusunjs/p/6582669.html

你可能感兴趣的文章
烂泥:centos安装LVM方式
查看>>
写时拷贝(方案一)
查看>>
教程Micropython自制小型家庭气象站(萝卜教育)
查看>>
Redis源码分析系列26:对redis的一点小感触
查看>>
phpstudy 性能调优
查看>>
JDK源码解读(1)ArrayList和LinkedList
查看>>
第22讲: Scala中的闭包实战详解
查看>>
linux信号解释(1)
查看>>
串口DTU设备常见问题处理
查看>>
28.umask值
查看>>
文件操作工具类
查看>>
nginx教程从入门到精通(ttlsa出品)
查看>>
squid日志之access.log格式+内容
查看>>
我的友情链接
查看>>
LVS NAT 模式突然很卡ip_conntrack
查看>>
重拾CCNA,学习笔记持续更新ing......(7)
查看>>
FreeBSD下的开机自启动
查看>>
我的友情链接
查看>>
Linux命令行快捷键
查看>>
python 的实用技巧
查看>>