当前位置:网站首页>Pat b-b1005 continue (3n+1) guess (25) [array]
Pat b-b1005 continue (3n+1) guess (25) [array]
2022-07-19 15:40:00 【nekoha_ dexter】
Karaz (Callatz) The conjecture is already in 1001 A description of . In this topic , It's a little more complicated .
When we test karaz's conjecture , To avoid double counting , You can record every number encountered in the recursion process . For example n=3 When it comes to validation , We need to calculate 3、5、8、4、2、1, When we're dealing with n=5、8、4、2 When it comes to validation , Karaz can directly guess whether it is true or not , It doesn't have to be repeated , Because of this 4 The number has been verified 3 When I met , We call 5、8、4、2 Be being 3“ Cover ” Number of numbers . We call a number in a sequence n by “ Key number ”, If n Cannot be covered by other numbers in the sequence .
A given set of numbers is now to be verified , We just need to verify a few of these key numbers , You don't have to double check the rest of the numbers . Your job is to find out these key numbers , And output them in descending order .
Input format :
Each test input contains 1 Test cases , The first 1 The row gives a positive integer K (<100), The first 2 Line is given K Positive integers that are not identical to each other n (1<n≤100) Value , The numbers are separated by spaces .
Output format :
The output of each test case takes up one line , Output key numbers in descending order . Digital inter use 1 Space between , But there is no space after the last number in the line .
sample input :
6
3 5 6 7 8 11
sample output :
7 6#include<iostream>
using namespace std;
// Using arrays to solve , Verification and output require traversal checks
//1、table[] Store the positive integer to be verified , And use idx Record the maximum positive integer ;
//2、 from idx~2 Traverse table[], And start verifying
bool iscal[101], table[101];
int main(){
int k,n, idx = -1; //idx Record the maximum positive integer
cin >> k;
for(int i = 0; i < k; ++i){
cin >> n;
if(idx < n) idx = n;// Record the maximum positive integer
table[n] = true; // Put in table[]
}
for(int i = idx; i >1; --i)
if(table[i]){ //true when , That is, in the table
int t = i;
while(t != 1){// Start validation
if(t & 1) t = (t * 3 + 1)/2; // Odd number
else t /=2;
if(t > 100) continue; // Greater than 100 No operation is necessary
if(iscal[t]) break; // Verified , There is no need to operate and verify
table[t] = false; // Perform table output
iscal[t] = true;// The record has been verified
}
}
while(!table[idx] && idx > 1) idx--; // Find the largest positive integer again
cout << idx;// First bit output
for(int i = idx -1; i >1; --i) // First output spaces and then positive integers
if(table[i]) cout << " " << i;
return 0;
}
边栏推荐
- LVS负载均衡群集
- Argument list too long causes and Solutions
- 使用flex布局实现局部滚动条
- Is it safe for Hengtai securities to open an account online?
- Arkui route jump
- 低代码搭建建筑设计公司数据管理案例分析
- Devops tool chain: open and free to choose the tools most suitable for the needs of the team and business
- 股票账户上买基金安全吗?我要长期买基金
- Work notes | talk about data quality audit
- How should I design my blog? How to build a blog with good experience?
猜你喜欢

OSPF learning notes (III)

浅谈ISP-CCM

06_ Service call feign

OSPF learning notes (V) -- republish

OSPF学习笔记(四)

Discussion on ISP image noise model 2

C# wpf 使用ListBox实现尺子控件
![[advanced C language] - common memory functions](/img/46/962fdaa9c10a096a49bee42ebf51e1.png)
[advanced C language] - common memory functions

The use of "!" in vscode is invalid, and there is no solution to the template problem

SSH uses Socks5 proxy to connect to the remote server
随机推荐
Is online account opening safe? Then choose which securities to open a securities account
Get a list of dates in recent 30 days
Which bank outlet in Chongqing can buy Ritz fund products?
Arkui FAQ summary [Series 2]
Arkui FAQ summary [Series 2]
2036: [蓝桥杯2022初赛] 统计子矩阵(二维前缀和,一维前缀和)
Wechat applet collection
新基民在股票账户上买基金安全吗
可以写进简历的软件测试项目实战经验(包含电商、银行、app等)
ARM未定义指令异常 汇编
OSPF learning notes (V) -- republish
文档型全文检索知识库管理系统源码
Work notes | talk about data quality audit
OSPF学习笔记(五)---重发布
云原生—编排及管理
线性表(顺序存储,链式存储)(带头结点的链表,不带头结点的链表)
Using flex layout to realize local scroll bar
OSPF learning notes (III)
恒泰证券网上开户安全吗?
Reflector uses detailed explanation to convert DLL files into CS file