zoukankan      html  css  js  c++  java
  • 牛客2018年第二次多校培训----A-run

    题目描述:

    链接:https://www.nowcoder.com/acm/contest/140/A
    来源:牛客网

    时间限制:C/C++ 1秒,其他语言2秒
    空间限制:C/C++ 131072K,其他语言262144K
    64bit IO Format: %lld

    题目描述

    White Cloud is exercising in the playground.
    White Cloud can walk 1 meters or run k meters per second.
    Since White Cloud is tired,it can't run for two or more continuous seconds.
    White Cloud will move L to R meters. It wants to know how many different ways there are to achieve its goal.
    Two ways are different if and only if they move different meters or spend different seconds or in one second, one of them walks and the other runs.

    输入描述:

    The first line of input contains 2 integers Q and k.Q is the number of queries.(Q<=100000,2<=k<=100000)
    For the next Q lines,each line contains two integers L and R.(1<=L<=R<=100000)

    输出描述:

    For each query,print a line which contains an integer,denoting the answer of the query modulo 1000000007.

    示例1

    输入

    3 3
    3 3
    1 4
    1 5

    输出

    2
    7
    11
    #include <iostream>
    #include <stdio.h>
    #define MOD 1000000007
    using namespace std;
    int main()
    {
        long long a[100005],b[100005];
        int q,k,l,r;
        cin>>q>>k;
        b[0]=0;
        for(int i=1;i<k;i++)
        {
            a[i]=1;
            b[i]=b[i-1]+a[i];
        }
        a[k]=2;b[k]=b[k-1]+a[k];
        a[k+1]=3;b[k+1]=b[k]+a[k+1];
        for(int i=k+2;i<100005;i++)
        {
            a[i]=(a[i-1]+a[i-k-1])%MOD;
            b[i]=(b[i-1]+a[i])%MOD;
        }
        for(int i=0;i<q;i++)
        {
            cin>>l>>r;
            printf("%lld
    ",(MOD+b[r]-b[l-1])%MOD);
        }
        return 0;
    }
  • 相关阅读:
    数据库事务的4种隔离级别
    线程竞争与同步
    flex 1与flex auto
    React环境搭建
    vue与mapbox
    前端-URL到页面显示的全过程
    监听滚动事件
    点击上下箭头,页码发生改变
    鼠标滑过元素,div显示,并根据scrollTop向下移动
    KB/MB/GB。。单位换算
  • 原文地址:https://www.cnblogs.com/ke-yi-/p/10175838.html
Copyright © 2011-2022 走看看