P1011 车站

直接上超级无敌

           毫无批注

           超美格式

           AC  代码

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


---------------------------------------------------------------------我是分隔线-------------------------------------------------------------------------------------


题目如下:

题目描述

         火车从始发站(称为第11站)开出,在始发站上车的人数为aa,然后到达第22站,在第22站有人上、下车,但上、下车的  人数相同,因此在第22站开出时(即在到达第33站之前)车上的人数保持为aa人。从第33站起(包括第33站)上、下车的人数有一定规律:上车的人数都是前两站上车人数之和,而下车人数等于上一站上车人数,一直到终点站的前一站(第n-1n−1站),都满足此规律。现给出的条件是:共有NN个车站,始发站上车的人数为aa,最后一站下车的人数是mm(全部下车)。试问xx站开出时车上的人数是多少?

输入格式

          aa(≤20),nn(≤20),mm(≤2000),和xx(≤20),

输出格式

          从xx站开出时车上的人数。

 


真鸡儿帅!!!

别忘了评论鸡你太美哦!!!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值