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;
}


posted @ 2019-11-07 22:38  miyasaka  阅读(108)  评论(0)    收藏  举报