天天看点

HDU-2042 不容易系列之二代码注解结果

HDU-2042 不容易系列之二代码注解结果
HDU-2042 不容易系列之二代码注解结果

代码

#include <iostream>

using namespace std;

int main() {
	int n;
	cin>>n;
	for(int i=0; i<n; i++) {
		int station;
		cin>>station;
		int ans = 3;
		while(station>=1) {
			ans = (ans-1)*2;
			station--;
		}
		cout<<ans<<endl;
	}
	return 0;
}
           

注解

1、简单的递推关系。

2、正确使用循环结构,终止条件要正确。

结果

HDU-2042 不容易系列之二代码注解结果