牛客第二场A-run
链接: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的更多相关文章
- 牛客第二场Dmoney
链接:https://www.nowcoder.com/acm/contest/140/D 来源:牛客网 题目描述 White Cloud has built n stores numbered to ...
- 牛客第二场 J farm
White Rabbit has a rectangular farmland of n*m. In each of the grid there is a kind of plant. The pl ...
- 牛客第二场-J-farm-二维树状数组
二维树状数组真的还挺神奇的,更新也很神奇,比如我要更新一个区域内的和,我们的更新操作是这样的 add(x1,y1,z); add(x2+1,y2+1,z); add(x1,y2+1,-z); add( ...
- 牛客第二场 C.message(计算几何+二分)
题目传送:https://www.nowcoder.com/acm/contest/140/C 题意:有n个云层,每个云层可以表示为y=ax+b.每个飞机的航线可以表示为时间x时,坐标为(x,cx+d ...
- 第k小团(Bitset+bfs)牛客第二场 -- Kth Minimum Clique
题意: 给你n个点的权值和连边的信息,问你第k小团的值是多少. 思路: 用bitset存信息,暴力跑一下就行了,因为满足树形结构,所以bfs+优先队列就ok了,其中记录下最后进入的点(以免重复跑). ...
- 走环概率问题(至今有点迷)--牛客第二场( Eddy Walker)
思路: 概率结论题,好像属于线性递推,现在也不太懂(lll¬ω¬) #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include < ...
- 牛客多校第二场A run(基础DP)
链接:https://www.nowcoder.com/acm/contest/140/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 131072K,其他语言2621 ...
- 巅峰极客第二场CTF部分writeup
word-MISC 微信回答问题+word字体里. sqli-WEB 注册个admin空格即可,长字符截断. 晚上把后续的写出来.现在睡觉
- 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 把题目的矩阵看成无向图的邻接矩阵 这 ...
随机推荐
- python学习之re库
正则表达式库re是非常重要的一个库. 首先正则表达式有两种表示类型,一种是raw string类型(原生字符串类型),也就是我们经常看到的r' '的写法,另一种是不带r的写法,称为string类型. ...
- Newtonsoft.Json 去掉\r\n
itemKindList.ToString(Newtonsoft.Json.Formatting.None)
- SHU oj 422 风力观测 线段树
风力观测 发布时间: 2017年7月9日 18:17 最后更新: 2017年7月9日 21:04 时间限制: 1000ms 内存限制: 128M 描述 小Y正在观测y地区的风力情况,他在一 ...
- springmvc处理过程理解(一)
DispatcherServlet前端控制器:接收request,进行response HandlerMapping处理器映射器:根据url查找Handler.(可以通过xml配置方式,注解方式) H ...
- python发送requests请求时,使用登录的token值,作为下一个接口的请求头信息
背景介绍: 发送搜索请求时,需要用到登录接口返回值中的token值 代码实现: 登录代码: 搜索接口:
- Python + Selenium WebDriver Api 知识回顾
一直再用 Selenium WebDriver 但是用的都比较零散,也没有做过总结,今天借此机会,整理一下,方便大家使用时查阅 webDriver 的属性 ['CONTEXT_CHROME', 'C ...
- nginx+php上传大文件配置
//nginx- //上传文件大小限制,需在nginx.conf中配置 'client_max_body_size' => '500M', //php- //允许上传文件大小的最大值,需在php ...
- 《HTTP 权威指南》笔记:第十三章 摘要认证体制
前言 基本认证存在缺陷,摘要认证为了解决基本认知的一些缺陷,进行了进一步的完善,更加安全. 流程 摘要认证的特点是:永远不会以明文方式在网络上发送密码原理:通过发送一个「指纹」或者「密码的摘要」来验证 ...
- Introduction to dnorm, pnorm, qnorm, and rnorm for new biostatisticians
原文:Introduction todnorm,pnorm,qnorm, andrnormfor new biostatisticians Today I was in Dan’s office ho ...
- 单细胞文章分享:Molecular Diversity of Midbrain Development in Mouse, Human, and Stem Cells
Molecular Diversity of Midbrain Development in Mouse, Human, and Stem Cells 本文作者的官网:Ventral midbrain ...