链接:https://www.nowcoder.com/acm/contest/140/A
来源:牛客网 White Cloud is exercising in the playground.
White Cloud can walk 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 integers Q and k.Q is the number of queries.(Q<=,<=k<=)
For the next Q lines,each line contains two integers L and R.(<=L<=R<=)
输出描述:
For each query,print a line which contains an integer,denoting the answer of the query modulo .
示例1
输入
复制 输出
复制

dp。dp[i][j]表示到i这一步是跑的(1)还是走的(0)。

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
long long dp[][];
long long sum[];
int main()
{
long long n,m;
scanf("%lld%lld",&n,&m);
memset(dp,,sizeof dp);
dp[][]=;
for(int i=;i<=;i++)
{
dp[i][]=(dp[i-][]+dp[i-][])%;
if(i>=m)
dp[i][]=dp[i-m][]%;
}
sum[]=;
for(int i=;i<=;i++)
{
sum[i]=sum[i-]+dp[i][]+dp[i][];
sum[i]=sum[i]%;
}
for(int i=;i<n;i++)
{
long long q,w;
scanf("%lld%lld",&q,&w);
cout<<(sum[w]+-sum[q-])%<<endl;
}
return ;
}

牛客第二场A-run的更多相关文章

  1. 牛客第二场Dmoney

    链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to ...

  2. 牛客第二场 J farm

    White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The pl ...

  3. 牛客第二场-J-farm-二维树状数组

    二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add( ...

  4. 牛客第二场 C.message(计算几何+二分)

    题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d ...

  5. 第k小团(Bitset+bfs)牛客第二场 -- Kth Minimum Clique

    题意: 给你n个点的权值和连边的信息,问你第k小团的值是多少. 思路: 用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑). ...

  6. 走环概率问题(至今有点迷)--牛客第二场( Eddy Walker)

    思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include < ...

  7. 牛客多校第二场A run(基础DP)

    链接:https://www.nowcoder.com/acm/contest/140/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言2621 ...

  8. 巅峰极客第二场CTF部分writeup

    word-MISC 微信回答问题+word字体里. sqli-WEB 注册个admin空格即可,长字符截断. 晚上把后续的写出来.现在睡觉

  9. uestc summer training #4 牛客第一场

    A dp[i][j][k]可以n3地做 但是正解是找把问题转化为一个两点不相交路径 最终答案为C(n+m, n)2-C(n+m, m-1)C(n+m,n-1) B 把题目的矩阵看成无向图的邻接矩阵 这 ...

随机推荐

  1. 记时,耗时,Stopwatch

    public static string InvokeStopwatch(Action function) { System.Diagnostics.Stopwatch sw = new System ...

  2. intellij idea 破解教程

    首先呼吁:抵制盗版,抵制盗版,抵制盗版 如果只是个人开发学习用,那么下面的教程可能比较适合你了 有两种方法,第一种:Activate--License server,在License server a ...

  3. 远程连接MongoDB报“Network is unreachable”错误的解决方法

    解决办法:/etc/mongod.conf 里把127.0.0.1 改成 0.0.0.0

  4. header 格式

    headers = { 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,* ...

  5. python类的成员

    一.实例变量:简单的来说就是给对象赋值 class Person: def __init__(self, name, card_no, height, weight, address, laopo): ...

  6. 关于git提示“warning: LF will be replaced by CRLF”终极解答

    一.发现问题 windows平台下使用git add,git deploy 文件时经常出现“warning: LF will be replaced by CRLF” 的提示. 网上很多解决办法提到: ...

  7. ISNULL函数的深入讲解

    1.  标题有点夸张 2. 今天做统计查询员工加班时长的时,因为要将NULL值导入到decimal类型的字段中,但是发现导入之后得字段不属于NULL也不等于0,因此在接下来的运算过程中就很难继续进行, ...

  8. 力扣(LeetCode) 961. 重复 N 次的元素

    在大小为 2N 的数组 A 中有 N+1 个不同的元素,其中有一个元素重复了 N 次. 返回重复了 N 次的那个元素. 示例 1: 输入:[1,2,3,3] 输出:3 示例 2: 输入:[2,1,2, ...

  9. Codeforces 1077 F2 - Pictures with Kittens (hard version)

    F2 - Pictures with Kittens (hard version) 思路: 单调队列优化dp 代码: #pragma GCC optimize(2) #pragma GCC optim ...

  10. datagrid复制

    private void Dgv_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == (char)1) // Ctrl-A ...