codeforces 337C Quiz(贪心)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud
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 by 1000000009 (109 + 9).
5 3 2
3
5 4 2
6
Sample 1. Manao answered 3 questions out of 5, and his score would double for each two consecutive correct answers. If Manao had answered the first, third and fifth questions, he would have scored as much as 3 points.
Sample 2. Now Manao answered 4 questions. The minimum possible score is obtained when the only wrong answer is to the question 4.
Also note that you are asked to minimize the score and not the remainder of the score modulo 1000000009. For example, if Manao could obtain either 2000000000 or 2000000020 points, the answer is 2000000000 mod 1000000009, even though2000000020 mod 1000000009 is a smaller number.
题意:
有n道题目,要求在答对m道题目的情况下所得到的最小的分数。每答对一道题目 加一分,并且在连续答对k道题目的时候当前分数翻倍,然后开始重新计数连续答对的题数。当然中间若有答错,也开始重新计数。
分析:
首先可以考虑到在不翻倍的情况下,最少要错的题目为n/k,即每次在连续k-1题的时候答错。
如果n-m>=n/k,那么一定不需要翻倍,直接输出m就行。
在要发生翻倍的情况下,我们可以发现,在最前面几轮的时候翻倍是最好的。
所以我们可以将整个过程划分为两段,第一段是连续若干轮答对,然后翻倍。
第二段是每到连续答对k-1题的时候答错,一直到最后一题。
//#####################
//Author:fraud
//Blog: http://www.cnblogs.com/fraud/
//#####################
#include <iostream>
#include <sstream>
#include <ios>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <cctype>
using namespace std;
#define XINF INT_MAX
#define INF 0x3FFFFFFF
#define MP(X,Y) make_pair(X,Y)
#define PB(X) push_back(X)
#define REP(X,N) for(int X=0;X<N;X++)
#define REP2(X,L,R) for(int X=L;X<=R;X++)
#define DEP(X,R,L) for(int X=R;X>=L;X--)
#define CLR(A,X) memset(A,X,sizeof(A))
#define IT iterator
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<PII> VII;
typedef vector<int> VI;
const ll MOD=;
ll fast_pow(ll n,ll m){
ll ret=;
while(m){
if(m&)ret=ret*n%MOD;
n=n*n%MOD;
m>>=;
}
return ret;
}
int main()
{
ios::sync_with_stdio(false);
ll n,m,k;
cin>>n>>m>>k;
ll wa=n-m;
ll min_wa=n/k;
ll ans=;
if(wa>=min_wa){
ans=m;
}else{
ll tmp=fast_pow(,min_wa-wa+)-;
tmp=(tmp+MOD)%MOD;
tmp=tmp*k%MOD;
ans=tmp+(m-(min_wa-wa)*k);
ans%=MOD;
}
cout<<ans<<endl; return ;
}
codeforces 337C Quiz(贪心)的更多相关文章
- CodeForces - 158B.Taxi (贪心)
CodeForces - 158B.Taxi (贪心) 题意分析 首先对1234的个数分别统计,4人组的直接加上即可.然后让1和3成对处理,只有2种情况,第一种是1多,就让剩下的1和2组队处理,另外一 ...
- codeforces 724D(贪心)
题目链接:http://codeforces.com/contest/724/problem/D 题意:给定一个字符串和一个数字m,选取一个一个子序列s,使得对于字符串中任意长度为m的子序列都至少含有 ...
- Codeforces 626G Raffles(贪心+线段树)
G. Raffles time limit per test:5 seconds memory limit per test:256 megabytes input:standard input ou ...
- Cut 'em all! CodeForces - 982C(贪心dfs)
K - Cut 'em all! CodeForces - 982C 给一棵树 求最多能切几条边使剩下的子树都有偶数个节点 如果n是奇数 那么奇数=偶数+奇数 不管怎么切 都会有奇数 直接打印-1 贪 ...
- CodeForces - 940E - Cashback +贪心+DP
传送门:CodeForces - 940E - Cashback 题意:在一个长度为n的数组中,可以分出长度为 k 连续的多个数组b(每个数组 b 的 k 可不相同),然后,可以对每个数组 b 进行删 ...
- Codeforces 515C 题解(贪心+数论)(思维题)
题面 传送门:http://codeforces.com/problemset/problem/515/C Drazil is playing a math game with Varda. Let’ ...
- CodeForces 485C Bits[贪心 二进制]
C. Bits time limit per test1 second memory limit per test256 megabytes inputstandard input outputsta ...
- codeforces 732E(贪心)
题目链接:http://codeforces.com/contest/732/problem/E 题意:有n台计算机,m个插座,每台计算机有一个值a[i],每个插座有一个值b[i],每个插座最多只能对 ...
- Codeforces 732D [二分 ][贪心]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: n天进行m科考试,每科考试需要a的复习时间,n天每天最多可以考一科.并且指定哪天考哪科. 注意考试那天不能复习. 问最少需要多少天可全部通过考试. ...
随机推荐
- C++中string类的基本用法
#include <iostream> #include <set> using namespace std; int main() { string line; getlin ...
- JAVA $ JSP
1. java中数据类型分为两种 基本数据类型:数值型,字符型,布尔型 引用数据类型:类,接口,数组 基本数据类型所占空间固定,有别与C++,java中没有无符号数byte:1字节short: ...
- Oracle11g R2学习系列 之十 解决EM不能用
不知道是什么原因https://localhost:1158/em,今天突然就不能用了.做了好多搜索也没有解决.现象是在services.msc中,不能重启OracleDBConsole服务,提示: ...
- Oracle11g R2学习系列 之七安全性
其实,对于目前我使用的Oracle的水平来看,还达不到使用安全管理的高度,只是作为一个学习来看一下. 关于Oracle的安全管理,一般使用OEM来操作完成好了,入口是:OEM的“服务器”属性页中,选择 ...
- VMware网络配置 实现与物理机互访
虚拟机和物理主机互访,两台机器可以互访并可以被局域网内其他机器访问,可以ping通并可以访问网站. 这几天正好有空搞个虚拟机,并装了不同系统,以备不同部署环境需要.明明是搞编程的,却不得不学各种知识, ...
- silverlight中使用Json读取数据
假定按照 如何:对基于 HTTP 的服务发出请求中描述的方法向基于 HTTP 的 Web 服务发出请求后,在 Stream 类型的 responseStream 对象中返回了下列 JSON. {&qu ...
- Codeforces Round #281 (Div. 2) 解题报告
题目地址:http://codeforces.com/contest/493 A题 写完后就交了,然后WA了,又读了一遍题,没找出错误后就开始搞B题了,后来回头重做的时候才发现,球员被红牌罚下场后还可 ...
- 剖析C语言中a=a+++++a的无聊问题
同僚们闲聊,突然就聊到了a+++++a的问题.这种纯属C语言 “二” 级的问题应该是从a+++a引申出来的吧.于是乎兄弟姐妹们开始讨论它的运算结果,以及改如何理解.更有人写出(a++)+(++a) a ...
- BZOJ 1036 [ZJOI2008]树的统计Count(动态树)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1036 题意:一棵树,每个节点有一个权值.三种操作:(1)修改某个节点的权值:(2)输出某两 ...
- tp28xx port pin (open-drain )and (push-pull) 和open collector)
具有开漏(OD)输出的器件是指内部输出和地之间有个N沟道的MOSFET(T1),这些器件可以用于电平转换的应用.输出电压由Vcc'决定.Vcc'可以大于输入高电平电压VCC(up-translate) ...