牛客第二场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 把题目的矩阵看成无向图的邻接矩阵 这 ...
随机推荐
- 【链接】linuxCentOS权限问题修复(chmod777-R或者chmod755- http://www.cnblogs.com/kofxxf/p/5220836.html
[链接]linuxCentOS权限问题修复(chmod777-R或者chmod755- http://www.cnblogs.com/kofxxf/p/5220836.html
- ASP.NET技术总结
ASP.NET是ASP相关技术的最新版本,它如何工作: (经典)ASP的后缀名是".asp",通常用VB编写:ASP.NET是".aspx"—— ASP.NET ...
- Spring-JDBC依赖
<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</a ...
- codeforces gym 100947 J. Killing everything dp+二分
J. Killing everything time limit per test 4 seconds memory limit per test 64 megabytes input standar ...
- glfw3native.h and glfw3.h
https://www.glfw.org/docs/latest/files.html
- appium 计算器demo
需要修改的是 platformVersion deviceName demo: #coding=utf- from appium import webdriver import time desire ...
- Centos7下安装memcached
1. which memcached //如果已经安装,会有“/usr/bin/memcached”类似的输出 memcached -h //memcache帮助列表 php -m | grep me ...
- linux du
命令参数: -a或-all 显示目录中个别文件的大小. -b或-bytes 显示目录或文件大小时,以byte为单位. -c或--total 除了显示个别目录或文件的大小外,同时也显示所有目录或文 ...
- python + lisp hy的新手注记2 eval, HyModel and python AST
来自我在Stack Overflow上的提问,https://stackoverflow.com/questions/51675355/how-to-eval-a-cond-case-and-retu ...
- Spring Cloud 入门教程(一): 服务注册
1. 什么是Spring Cloud? Spring提供了一系列工具,可以帮助开发人员迅速搭建分布式系统中的公共组件(比如:配置管理,服务发现,断路器,智能路由,微代理,控制总线,一次性令牌,全局锁 ...