UDP广播协议叫吃饭


私信TA

用户名:Mustenaka

访问量:134734

签 名:

个人博客www.mustenaka.cn

等  级
排  名 12
经  验 23712
参赛次数 8
文章发表 196
年  龄 3
在职情况 学生
学  校 Sky_box
专  业 NE

  自我简介:

欢迎光临我的博客www.mustenaka.cn,Python,C#,U3D,C/C++开发合作可以找我

解题思路:
        常规思路,直接写的解嘛。
参考代码:

#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef unsigned long long ull;
int main() {
	hh;
	int n;
	while(cin>>n){
		ull ans=1;
		while(n>1){
			ans=(ans+1)*2;
			n--;
		}
		cout<<ans<<endl;
	} 
	return 0;
}

另一种思路:利用数组。

#include<bits/stdc++.h>
#define hh ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
using namespace std;
typedef unsigned long long ull;
int main(){
	hh;
	ull ans[32]={1},n;
	for(int i=1;i<=32;i++){
		ans[i]=(ans[i-1]+1)*2;
	}
	while(cin>>n)
		cout<<ans[n-1]<<endl;
	return 0;
}

这样更快

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区