题解 | #xxx定律#

xxx定律

https://www.nowcoder.com/practice/75c189249d6145cfa33cd53edae6afc8

#include<cstdio>
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int n;
	int count=0;
//	cin>>n;
	int t=n;
	while(cin>>n){
		while(n!=1){
			if(n%2==0)
			{
				n=n/2;
			}
			else
			n=(3*n+1)/2;
			
			count++;
		}
		cout<<count<<endl;
		
	}
//	if(n%2!=0)
//	{
//		while(true){
//		if(t==1)
//		{
//			cout<<count<<endl;
//			break;
//		}
//	    	t=t+t+t+1;
//		    t=t/2;
//			count++;
//		
//		}
//	}
//		else{
//			while(true){
//			if(t==1)
//			{
//				cout<<count<<endl;
//				break;
//			}
//			t=t/2;
//			count++;
//		}
//		}
//		
//		
//
//	
}

注解的代码会超时,不懂为什么?

全部评论

相关推荐

青春运维少年不会梦到...:实习大王
点赞 评论 收藏
分享
10-13 16:58
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务