C - “简单”的循环

某核反应堆有两类事件发生:
高能质点碰击核子时,质点被吸收,放出3个高能质点和1个低能质点;
低能质点碰击核子时,质点被吸收,放出2个高能质点和1个低能质点。
假定开始的时候(0微秒)只有一个高能质点射入核反应堆,每一微秒引起一个事件发生(对于一个事件,当前存在的所有质点都会撞击核子),试确定n微秒时高能质点和低能质点的数目。

Input

输入含有一些整数n(0≤n≤33),以微秒为单位,若n为-1表示处理结束。

Output

分别输出n微秒时刻高能质点和低能质点的数量,高能质点与低能质点数量之间以逗号空格分隔。每个输出占一行。

Sample Input

5 2
-1

Sample Output

571, 209
11, 4

提示

可以使用long long int对付GNU C++,使用__int64对付VC6

代码:

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define ll long long
#define mes(x,y) memset(x,y,sizeof(x))
using namespace std;
int main(){
	long long max=-1,n;
	vector<long long>a,b,c;
		while(n!=-1){
			cin>>n;
			if(max<n)max=n;
			c.push_back(n);
		}
		a.push_back(1);
		b.push_back(0);
		for(int i=0;i<=max;i++){
			a.push_back(a[i]*3+b[i]*2);
			b.push_back(a[i]+b[i]);
		}
		for(int i=0;i<c.size()-1;i++){
			cout<<a[c[i]]<<", "<<b[c[i]]<<endl;
		}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_44417851/article/details/89059413