主打一个枚举找规律...
站台 | 1 | 2 | 3 | 4 | 5 | 6 | ... |
上车 | a | b | a+b | a+2b | 2a+3b | 3a+5b | |
下车 | b | b | a+b | a+2b | 2a+3b | ||
人数 | a | a | 2a | 2a+b | 3a+2b | 4a+4b |
上车这一行: 观察a的系数(假设是dx[i])可知: dx[i] = dx[i-1] + dx[i-2]
b的系数(假设是dy[i])可知: dy[i] = dy[i-1] + dy[i-2]
人数: (假设为p[i])p[i] = (dx[i] + 1) * a + (dy[i] -1)* b
import java.util.Scanner;
/**
* @Author YuLing
* @Date 2023-12-17 18:09
* @Description: 车站
* @Version 1.0
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();//已知
int n = scanner.nextInt();//已知 则需要找到n-1
int m = scanner.nextInt();//已知
int x = scanner.nextInt();
//destination: 从x站开出车上的人数
int[] dx = new int[n + 1];//a的系数
int[] dy = new int[n + 1];//b的系数
dx[1] = 1;
dx[2] = 0;
for (int i = 3; i < n; i++) {
dx[i] = dx[i - 1] + dx[i - 2];
}
dy[1] = 0;
dy[2] = 1;
for (int i = 3; i < n; i++) {
dy[i] = dy[i - 1] + dy[i - 2];
}
//(dx[n-1]+1)*a+(dy[n-1]-1)*b=m
int b = (m - (dx[n - 1] + 1) * a) / (dy[n - 1] - 1);
// System.out.println("b = " + b);
//从x站开出时车上的人数
int px = (dx[x] + 1) * a + (dy[x] - 1) * b;
System.out.println(px);
}
}