Quiz(贪心,快速幂乘)
1 second
256 megabytes
standard input
standard output
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this counter increases by 1. If the player answers a question incorrectly, the counter is reset, that is, the number on it reduces to 0. If after an answer the counter reaches the number k, then it is reset, and the player's score is doubled. Note that in this case, first 1 point is added to the player's score, and then the total score is doubled. At the beginning of the game, both the player's score and the counter of consecutive correct answers are set to zero.
Manao remembers that he has answered exactly m questions correctly. But he does not remember the order in which the questions came. He's trying to figure out what his minimum score may be. Help him and compute the remainder of the corresponding number after division by 1000000009 (109 + 9).
The single line contains three space-separated integers n, m and k (2 ≤ k ≤ n ≤ 109; 0 ≤ m ≤ n).
Print a single integer — the remainder from division of Manao's minimum possible score in the quiz by1000000009 (109 + 9).
错误题数为n-m,可以n-m次在连续答对(k-1)道题时使下一道答错,共(n-m) * [(k-1) + 1] = (n-m)* k道题。
假设有x次连续答对k题,则有x * k + (n-m)* k + r = n,这里0 <= r < k,是余下的凑不成k道题目的题目数。得x = n / k - (n - m). 注意这里“/”是C++中向下取整的除法。
AC Code:
#include <iostream>
#include <algorithm>
#include <cstdio> using namespace std; const long long M = ; long long POW(long long y)
{
if(y == ) return ;
long long res = POW(y >> );
res = (res * res) % M;
if(y & ) res = (res << ) % M;
return res;
} int main()
{
long long n, m, k, s;
while(scanf("%I64d %I64d %I64d", &n, &m, &k) != EOF){
long long a = n / k;
long long b = n - m;
if(b >= a){
s = m;
}
else{
//a-b次连续答对k题,b次连续答对题数不足k
long long r = POW(a - b + ) - ;
if(r < ) r += M; //注意这里!
s = (k * r) % M;
s = (s + (m - (a - b) * k) % M) % M;
}
printf("%I64d\n", s);
}
return ;
}
Quiz(贪心,快速幂乘)的更多相关文章
- Codeforces1062C. Banh-mi(贪心+快速幂)
题目链接:传送门 题目: C. Banh-mi time limit per test second memory limit per test megabytes input standard in ...
- 贪心,打表(或者快速幂), UVA - 11636
题目链接: https://cn.vjudge.net/problem/34398/origin 题目比较简单,就是水题,基础贪心,大于所需的即可: AC代码: 打表: #include <cm ...
- Codeforces Round #209 (Div. 2)A贪心 B思路 C思路+快速幂
A. Table time limit per test 1 second memory limit per test 256 megabytes input standard input outpu ...
- 小总结:快速幂+贪心————Bit Mask____UVA 10718 多多去理解去温习哦!
传送门:https://vjudge.net/problem/UVA-10718 Preview: bitstream:a flow of data in binary form. in bit-wi ...
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp,K,二分+排序,L,矩阵快速幂,M,线段树区间更新+Lazy思想,N,超级快速幂+扩展欧里几德,O,BFS】
黑白图像直方图 发布时间: 2017年7月9日 18:30 最后更新: 2017年7月10日 21:08 时间限制: 1000ms 内存限制: 128M 描述 在一个矩形的灰度图像上,每个 ...
- 【BZOJ】2553: [BeiJing2011]禁忌 AC自动机+期望+矩阵快速幂
[题意]给定n个禁忌字符串和字符集大小alphabet,保证所有字符在集合内.一个字符串的禁忌伤害定义为分割能匹配到最多的禁忌字符串数量(一个可以匹配多次),求由字符集构成的长度为Len的字符串的期望 ...
- Codeforces 954 dijsktra 离散化矩阵快速幂DP 前缀和二分check
A B C D 给你一个联通图 给定S,T 要求你加一条边使得ST的最短距离不会减少 问你有多少种方法 因为N<=1000 所以N^2枚举边数 迪杰斯特拉两次 求出Sdis 和 Tdis 如果d ...
- 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)
题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...
- 51nod 算法马拉松18 B 非010串 矩阵快速幂
非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...
- hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)
题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3. ...
随机推荐
- Git 常用的命令总结(欢迎收藏备用)
总结日常开发生产中常用的Git版本控制命令 ------------------------------main-------------------------------- <极客镇楼> ...
- JS获取元素CSS值的各种方法分析
先来看一个实例:如何获取一个没有设置大小的字体? <!DOCTYPE html> <html lang="en"> <head> <met ...
- paip.mysql 批量kill 连接.
paip.mysql 批量kill 连接. 作者Attilax 艾龙, EMAIL:1466519819@qq.com 来源:attilax的专栏 地址:http://blog.csdn.net ...
- Atitit..文件上传组件选型and最佳实践总结(3)----断点续传控件的实现
Atitit..文件上传组件选型and最佳实践总结(3)----断点续传控件的实现 1. 实现思路:::元插件,元设置... 1 2. 实现流程downzip,unzip,exec 1 3. Zip ...
- iOS -iPhone5、iPhone5s、iPhone6、iPhone6Plus 屏幕适配
现在由于苹果公司出了6和6Plus,让写苹果程序的哥们为了做兼容很头疼.用StoryBoard固然方便,但是后期做兼容要花费太多的时间和精力.使用AutoLayout虽然会在不同尺寸的屏幕下自动布局, ...
- Android 学习之显式激活与隐式激活Activity
在res界面里面有两个布局文件activity_main和acivity_two
- js中关于动态添加事件,不能使用循环变量的问题
在编写事件的时候,我们难免会遇到以下这种情况:<!DOCTYPE html><html lang="en"><head> <meta ch ...
- MyEclipse使用总结——设置MyEclipse使用的Tomcat服务器 设置JDK
一.设置使用的Tomcat服务器 如果不想使用MyEclipse自带的tomcat服务器版本,那么可以在MyEclipse中设置我们自己安装好的tomcat服务器 设置步骤如下: Window→Pre ...
- android: 接收和发送短信
8.2 接收和发送短信 收发短信应该是每个手机最基本的功能之一了,即使是许多年前的老手机也都会具备这 项功能,而 Android 作为出色的智能手机操作系统,自然也少不了在这方面的支持.每个 A ...
- NAS服务器局域网内IPad、手机、电视盒子等联网播放
为把各个移动硬盘和不同电脑的数据进行统一管理,入手了一台希捷 Seagate Business 无内置硬盘 商业级 2盘位 云存储网路存储,经过卖家指点和不断摸索,终于能用了,主要步骤如下: 1. 系 ...