hdoj:2085

核反应堆

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15706    Accepted Submission(s): 7036

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 <iostream>
#include <string>
#include <vector>

using namespace std;

#define limit 34

void f(long long x, long long &a, long  long &b)
{
    a += 3 * x;
    b += x;
}
void g(long long x, long long &a, long long &b)
{
    a += 2 * x;
    b += x;
}
long long a[limit];
long long b[limit];
int main()
{
    int n;
    a[0] = 1;
    b[0] = 0;

    for (int i = 1; i < limit; i++)
    {
        f(a[i - 1], a[i], b[i]);
        g(b[i-1], a[i], b[i]);
    }
    while (true)
    {
        cin >> n;
        if (n == -1)
            break;

        cout << a[n] <<", "<<b[n]<< endl;
    }
    return 0;
}
时间: 2024-12-24 23:22:26

hdoj:2085的相关文章

hdoj:2086

A1 = ? Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 7535    Accepted Submission(s): 4675 Problem Description 有如下方程:Ai = (Ai-1 + Ai+1)/2 - Ci (i = 1, 2, 3, .... n).若给出A0, An+1, 和 C1, C2, .....

hdoj:2084

数塔 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 39043    Accepted Submission(s): 23246 Problem Description 在讲述DP算法的时候,一个经典的例子就是数塔问题,它是这样描述的: 有如下所示的数塔,要求从顶层走到底层,若每一步只能走到相邻的结点,则经过的结点的数字之和最大是多少?

hdoj:2046

#include <iostream> using namespace std; long long fib(int n) { if (n == 1) return 1; if (n == 2) return 2; long long f1 = 1; long long f2 = 2; while (n >= 3) { long long f3 = f1 + f2; f1 = f2; f2 = f3; n--; } return f2; } int main() { int n; whi

hdoj:2045

#include <iostream> using namespace std; long long a[51]; int main() { int n; a[1] = 3; a[2] = 6; a[3] = 6; for (int i = 4; i <= 50; i++) { a[i] = a[i - 1] + 2 * a[i - 2]; } while (cin >> n) { cout << a[n] << endl; } }

hdoj:2042

#include <iostream> using namespace std; int main() { int n,a; while (cin >> n) { while (n--) { cin >> a; long num = pow(2, a) + 2; cout << num << endl; } } } a(n) = 2*a(n-1) -2 a(n) -2 = 2*{a(n-1) -2} a(n) = 2^n + 2

hdoj:2040

#include <iostream> #include <vector> using namespace std; vector<long> yueShu(long a) { vector<long> vec; vec.push_back(1); for (int i = 2; i < a; i++) { if (a%i == 0) { vec.push_back(i); //cout << i << " "

hdoj:2043

#include <iostream> #include <string> using namespace std; bool judgeSize(string str) { int size = str.size(); if (size < 8 || size>16) return false; return true; } int isA(string str) { for (auto &c : str) { if (c >= 'A' &&am

hdoj:2027

#include <iostream> #include <string> #include <vector> using namespace std; int main() { int n; cin >> n; string t; getline(cin, t); while (n >= 1) { string s; int a = 0, e = 0, i = 0, o = 0,u=0; getline(cin, s); for (char &

hdoj:2070

Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 22530    Accepted Submission(s): 10375 Problem Description Your objective for this question is to develop a program which will g