Suppose the number of stations on the second or lower as \ (K \) ;
Defined function \ (F_1 (X) \) ;
Return \ (f_1 (2) \) when the value without knowing the value of k;
The \ (K \) coefficients \ (cnt ++ \) and returns \ (0 \) ;
Left the following solution \ (k \) use.
Readily available in \ (X \) station, when the number of the car
\ [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;
}