PAT 1005 继续(3n+1)猜想
来源:互联网 发布:java面试项目经历 编辑:程序博客网 时间:2024/06/04 23:22
3n+1不在100以内,开数组要大
#include<iostream>using namespace std;const int n=10000;bool _prev[n],_next[n],exist[n];void setnode(int x){ if((1==x)||_next[x])return; int tmp=( (x%2)? ((3*x+1)/2) : (x/2) ); _prev[tmp]=true; _next[x]=true; setnode(tmp);}void process(){ int k,x;cin>>k; while(k--){ cin>>x; exist[x]=true; setnode(x); } bool flag=true; for(int i=n;i>1;--i) if(exist[i]&&!_prev[i]){ if(flag){cout<<i;flag=false;} else cout<<' '<<i;}}int main(){process();return 0;}
0 0
- pat 1005 继续(3n+1)猜想
- PAT 1005 继续(3n+1)猜想
- PAT 1005 继续(3n+1)猜想
- PAT 1005 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT--继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- pat 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT 1005. 继续(3n+1)猜想
- PAT B1005. 继续(3n+1)猜想
- PAT继续(3n+1)猜想
- PAT basic 1005 : 继续(3n+1)猜想
- 浙江大学PAT---Basic Level---1005----继续(3n+1)猜想
- PAT(BASIC)1005 继续3n+1猜想
- 华为的JAVA面试题及答案(部分)
- MVC里面布局你们具体如何整,求帮
- 关于定时器NSTime与滚动视图一块运用
- Bluetooth LE(低功耗蓝牙) - 第三部分
- struts2HelloWorld
- PAT 1005 继续(3n+1)猜想
- Linux使用PAM锁定多次登陆失败的用户(含重置错误次数)
- android:windowSoftInputMode属性详解
- Nginx 关于 Rewrite 执行顺序详解
- jboss4.2.3更改端口和默认根应用程序
- c#生成不重复的字符串
- CCControlExtension/CCControlButton
- [C++ GUI Programming with Qt 4/5 代码] && [从Qt4过渡至Qt5(The Transition from Qt 4.x to Qt 5)]
- CCControlExtension/CCControl