链接: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. [UVA-11100] The Trip

    题目大意 大箱子能装小箱子,求在满足最少箱子的情况下,最小化每个箱子中最大的箱子个数. 解析 想到二分枚举箱子数,然后贪心的选择放进箱子的位置. 最优策略一定是将最大的 \(m\) 个先找出来,然后把 ...

  2. python + eclipse +pydev

    本文重点介绍使用Eclipse+pydev插件来写Python代码,  以及在Mac上配置Eclipse+Pydev 和Windows配置Eclipse+Pydev 编辑器:Python 自带的 ID ...

  3. 详解JS中DOM 元素的 attribute 和 property 属性

    一.'表亲戚':attribute和property 为什么称attribute和property为'表亲戚'呢?因为他们既有共同处,也有不同点. attribute 是 dom 元素在文档中作为 h ...

  4. P2016 战略游戏

    传送门 思路: 前置知识——普通树D: ▲普通的树形 DP : 设 f [ i ][ 0 ] 表示这个点不取,则它的所有子节点都要取:f [ i ][ 1 ] 表示这个点取,则它的子节点取与不取对之前 ...

  5. Spring boot Value注入 未整理 待完善

    Springboot 热部署Springboot为开发者提供了一个名叫 spring-boot-devtools来使Springboot应用支持热部署,提供开发者的开发效率,无需手动重启Spring ...

  6. Qt532.QString_填充字符

    1.代码: void MainWindow::on_pushButton_clicked() { QString str = "; QString str01 = str.leftJusti ...

  7. img 下方的4px像素问题

    问题:在一个div块里面放了一个图片,图片下面有内容,可以不管怎么调试,在火狐浏览器,IE6下.图片img底部多出了4个像素 解决:img样式中   vertical-align: top/middl ...

  8. arcgis10.3 python2.7 开发环境配置

    如题: 首先安装arcgis desktop 和 自带的python版本,本楼的是2.7.8,安装地址在E:\PYTHON2.7,安装完成后即可开始安装pythonwin2.7,下载地址为:http: ...

  9. 力扣(LeetCode) 771. 宝石与石头

    给定字符串J 代表石头中宝石的类型,和字符串 S代表你拥有的石头. S 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石. J 中的字母不重复,J 和 S中的所有字符都是字母 ...

  10. 力扣(LeetCode) 104. 二叉树的最大深度

    给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例: 给定二叉树 [3,9,20,null,null,15,7], ...