题目链接:
https://www.luogu.org/problemnew/show/P1011
题意理解
显然,我们看到数据量那么小,可以来个模拟。直接暴力枚举一波即可。
我的代码
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static final int maxn = 30;
static int a, n, m, x;
static int[] nums = new int[maxn];
static int[] getOn = new int[maxn];
static int[] getOff = new int[maxn];
public static void main(String[] args) {
FastScanner fs = new FastScanner();
a = fs.nextInt();
n = fs.nextInt();
m = fs.nextInt();
x = fs.nextInt();
for(int i = 0; i <= 20; i++) {
getOn[1] = a;
getOff[1] = 0;
nums[1] = a;
getOn[2] = i;
getOff[2] = i;
nums[2] = a;
for(int j = 3; j <= n - 1; j++) {
getOn[j] = getOn[j-1] + getOn[j-2];
getOff[j] = getOn[j-1];
nums[j] = nums[j-1] + getOn[j] - getOff[j];
}
if(nums[n - 1] == m) {
System.out.println(nums[x]);
return;
}
}
}
public static class FastScanner {
StringTokenizer st;
BufferedReader br;
public void eat(String s) {
st = new StringTokenizer(s);
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
eat("");
}
public String nextLine() {
try {
return br.readLine();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
public boolean hasNext() {
while(!st.hasMoreTokens()) {
String s = nextLine();
if(s == null) {
return false;
}
eat(s);
}
return true;
}
public String nextToken() {
hasNext();
return st.nextToken();
}
public int nextInt() {
return Integer.valueOf(nextToken());
}
}
}