zoukankan      html  css  js  c++  java
  • 牛客网暑期ACM多校训练营(第二场)A .run

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

    题目描述

    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
    

    思路:

    1. dp[i][0]表示到达走着到达i   dp[i][1]表示跑着到达i

    ACcode:
     

    #include <algorithm>
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    
    using namespace std;
    
    const int maxn = 1e5+5;
    const int mod = 1000000007;
    
    int dp[maxn][2];
    
    int main(){
    
        int K,Q;
        while(cin>>Q>>K)
        {
            memset(dp,0,sizeof(dp));
            for (int i = 1;i<maxn;i++){
                if ( i<K ) {
                    dp[i][0] = dp[i-1][0] + 1;
                } else {
                    dp[i][0] = (dp[i-1][0] + dp[i-1][1] + 1) % mod;
                    dp[i][1] = (dp[i-K][0] + 1) % mod;
                }
            }
            int l,r;
            while(Q--){
                scanf("%d %d",&l,&r);
                printf("%d
    ",((dp[r][0] + dp[r][1]) % mod - (dp[l-1][0] + dp[l-1][1]) % mod + mod) % mod);
            }
        }
        return 0;
    }
    
  • 相关阅读:
    source insight快捷键及使用技巧
    HTTP 状态码
    select poll epoll三者之间的比较
    服务器程序后台化以及守护进程的编写规范
    Linux 信号表
    Linux下有线无线网络配置------命令模式
    浅谈 qmake 之 pro、pri、prf、prl文件
    Python VUE 基础知识
    VUE 实现tab切换页面效果
    爬虫框架:scrapy
  • 原文地址:https://www.cnblogs.com/Nlifea/p/11745984.html
Copyright © 2011-2022 走看看