LGOJ P1011 [ステーション]

第二に局の数を考えるか、などの低級\(K \)

定義された関数\(F_1(X)\)

リターン\(F_1(2)\)場合、kの値を知らなくても値。

\(K \)係数\(CNT ++ \)とリターン(\ 0 \)

次のソリューション左\(K \)を使用します。

で容易に入手可能な\(X \)ステーション、車の数
\ [PeopleNUM = A +(F 1)+ F(2)+ ... + F(X-2)\]

// P1011.cpp: 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
using namespace std;
int a, n, m, x;
double k;
int cnt = 0;
int f1(int x)
{
    if (x == 1)return a;
    if (x == 2)
    {
        cnt++;
        return 0;
    }
    return f1(x - 1) + f1(x - 2);
}
int f(int x)
{
    if (x == 1)return a;
    if (x == 2)return k;
    return f(x - 1) + f(x - 2);
}
int main()
{
    cin >> a >> n >> m >> x;
    int s = a;
    for (int i = 1; i <= n - 3; i++)
        s += f1(i);//n-1站剩余人数=m可解方程.
    //解k
    k = (m - s) / cnt;
    //cout << k << endl;
    int sum = a;
    for (int i = 1; i <= x - 2; i++)
        sum += f(i);//车上剩余人数
    if (x == 1)
        cout << a;
    else
    cout << sum;
    return 0;
}

おすすめ

転載: www.cnblogs.com/kion/p/11816240.html