当前位置:网站首页>Pat grade b-b1005 continue (3n+1) guess score (25) [map solve]
Pat grade b-b1005 continue (3n+1) guess score (25) [map solve]
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>
#include<map>
using namespace std;
// utilize map Automatic sorting and find() Characteristics , Completely eliminate elements and output from large to small
//1、 use map Store positive integers to be verified (1<n<=100),map It can be sorted from large to small
//2、 Traverse map Take out a number , Start validation , use iscal[] Whether the record has been verified .
//2.1、 It may be greater than 100, for example (99*3+1)/2 >100, At this time, it is impossible to map in
//2.2、 utilize iscal[], If it has been verified, it is not necessary to eliminate it , Such as verification 3 when ,
//5、8、4、2、1 Again iscal[] The middle is true, There is no need to eliminate
//2.3、 You can use map.find() and map.erase() To operate
//3、 because map Sort from large to small , Output directly after traversal verification
bool iscal[101];// Record whether it has been calculated
//map Sort from large to small , Store the positive integer to be verified
map<int, bool, greater<int>> table;
int main(){
int k,n;
cin >> k;
for(int i = 0; i < k;++i){
cin >> n;
table[n] = true;// Put in map
}
for(auto it = table.begin(); it != table.end(); ++it){
int t = it->first;
while(t /2 != 1){
if(t & 1) t = (3 * t + 1)/2; // If it's an odd number
else t /=2;
if(t > 100) continue; // Greater than 100 There is no need to eliminate and record
if(iscal[t]) break; //false when , Indicates that it has not been verified , You can find and eliminate
iscal[t] = true;
map<int,bool> :: iterator pt = table.find(t); // Find and cull
if(pt != table.end()) table.erase(pt);
}
}
auto it = table.begin();
cout << it->first;// Output the first element , And there is at least one output
it++;
while(it != table.end()){// Subsequent elements, if any , Then output the space first and then the element
cout << " " << it->first;
it++;
}
return 0;
}边栏推荐
- 云原生—编排及管理
- OSPF learning notes (III)
- 【动态内存管理】
- 232. 用栈实现队列
- 【codeforces Round#801 Div2 D题 Tree Queries】树形贪心结论
- Radiotap
- Est - il sûr d'ouvrir un compte en ligne pour acheter des fonds? Je viens de toucher le Fonds, je ne sais pas comment demander des conseils.
- Several reasons for postman calling interface to return 404
- emoji 为什么叫 emoji
- Code compliance: five reasons why developers use helix QAC
猜你喜欢

CloudBees CI使用Velero进行灾备(DR)概念验证

Cloudbees CI uses velero for disaster recovery (DR) proof of concept
通过群晖套件搭建内网邮件服务

LVS负载均衡群集

OSPF学习笔记(五)---重发布

Notepad++实用功能分享(正则行尾行首替换常用方法、文本比对功能等)

SSH uses Socks5 proxy to connect to the remote server

I'm new here, so please take care of me. (actually, it's not new here ^ ^, hello CSDN, I'm here.)

C# wpf 使用ListBox实现尺子控件

Identity Server 4使用OpenID Connect添加用户身份验证(三)
随机推荐
云原生—编排及管理
ArkUI路由跳转
LVS负载均衡群集
Several scenarios of technical "brick house" solving problems
用对工具,CI事半功倍
With the right tools, CI achieves twice the result with half the effort
E. Split Into Two Sets(种类并查集+染色法判二分图)
【C语言进阶】---常见内存函数
Several reasons for postman calling interface to return 404
开户有需要特别要注意什么?请问手机开户股票开户安全吗?
影响分析:RubyGems未授权访问漏洞(CVE-2022-29176)
06_ Service call feign
PostgreSQL在Linux和Windows安裝和入門基礎教程
C # minimize the WinForm software to the system tray, and start up automatically
Reflector uses detailed explanation to convert DLL files into CS file
我应该怎么设计我的博客?如何搭建一个体验好的博客?
Arkui FAQ summary [Series 2]
Stack和Queue容器的系列操作( 详解 )
2022-7-17
Is it safe to buy funds in a stock account? I want to buy funds for a long time