hdu 2085 暴力打表

来源:互联网 发布:sql server findinset 编辑:程序博客网 时间:2024/05/29 03:44

Problem Description
某核反应堆有两类事件发生:
高能质点碰击核子时,质点被吸收,放出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 <bits/stdc++.h>using namespace std;typedef long long LL;pair<LL,LL> a[34];void init(){   a[0].first=1;   a[0].second=0;   for(int i=1;i<=33;i++)   {       a[i].first=a[i-1].first*3+a[i-1].second*2;       a[i].second=a[i-1].first+a[i-1].second;   }}int main(){    int n;    init();    while(cin>>n)    {        if(n==-1) break;        cout<<a[n].first<<", "<<a[n].second<<endl;    }    return 0;}
原创粉丝点击