codeforces 337C Quiz(贪心)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud

Quiz

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).

Input

The single line contains three space-separated integers nm and k (2 ≤ k ≤ n ≤ 109; 0 ≤ m ≤ n).

Output

Print a single integer — the remainder from division of Manao‘s minimum possible score in the quiz by 1000000009 (109 + 9).

Sample test(s)

input

5 3 2

output

3

input

5 4 2

output

6

Note

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题的时候答错,一直到最后一题。

 1 //#####################
 2 //Author:fraud
 3 //Blog: http://www.cnblogs.com/fraud/
 4 //#####################
 5 #include <iostream>
 6 #include <sstream>
 7 #include <ios>
 8 #include <iomanip>
 9 #include <functional>
10 #include <algorithm>
11 #include <vector>
12 #include <string>
13 #include <list>
14 #include <queue>
15 #include <deque>
16 #include <stack>
17 #include <set>
18 #include <map>
19 #include <cstdio>
20 #include <cstdlib>
21 #include <cmath>
22 #include <cstring>
23 #include <climits>
24 #include <cctype>
25 using namespace std;
26 #define XINF INT_MAX
27 #define INF 0x3FFFFFFF
28 #define MP(X,Y) make_pair(X,Y)
29 #define PB(X) push_back(X)
30 #define REP(X,N) for(int X=0;X<N;X++)
31 #define REP2(X,L,R) for(int X=L;X<=R;X++)
32 #define DEP(X,R,L) for(int X=R;X>=L;X--)
33 #define CLR(A,X) memset(A,X,sizeof(A))
34 #define IT iterator
35 typedef long long ll;
36 typedef pair<int,int> PII;
37 typedef vector<PII> VII;
38 typedef vector<int> VI;
39 const ll MOD=1000000009;
40 ll fast_pow(ll n,ll m){
41     ll ret=1;
42     while(m){
43         if(m&1)ret=ret*n%MOD;
44         n=n*n%MOD;
45         m>>=1;
46     }
47     return ret;
48 }
49 int main()
50 {
51     ios::sync_with_stdio(false);
52     ll n,m,k;
53     cin>>n>>m>>k;
54     ll wa=n-m;
55     ll min_wa=n/k;
56     ll ans=0;
57     if(wa>=min_wa){
58         ans=m;
59     }else{
60         ll tmp=fast_pow(2,min_wa-wa+1)-2;
61         tmp=(tmp+MOD)%MOD;
62         tmp=tmp*k%MOD;
63         ans=tmp+(m-(min_wa-wa)*k);
64         ans%=MOD;
65     }
66     cout<<ans<<endl;
67
68
69     return 0;
70 }

时间: 2024-10-12 17:40:29

codeforces 337C Quiz(贪心)的相关文章

Codeforces 413C Jeopardy!(贪心)

题目链接:Codeforces 413C Jeopardy! 题目大意:给出n个关卡,每个关卡闯关成功会得到相应的分数,有m个关卡闯关成功之后,可以选择不加上该关卡的分,而是将已有的分数翻倍,现在有一位选手已经有能力闯过所有的关卡,问说他能得到的最大分数是多少. 解题思路:贪心,将可以翻倍的关卡放在后面比,不能翻倍的关卡放在前面比,然后在按照关卡分数大的先比,如果该关卡分数可以翻倍,就判断是当前关卡的分数高还是已有的分数高. #include <cstdio> #include <cst

UvaLive 6441 Horrible Quiz 贪心

链接:http://vjudge.net/problem/viewProblem.action?id=47588 题意:刚开始有15000的积分,有N道题,对于每道题,有Ci%的概率答对,有Wi%的概率答错,(100-Ci-Wi)%的概率会选择提供的答案,可以提供的答案中最多可以提供M个错的答案,剩下的都必须是对的,答错的时候,积分*-1,答对的时候积分不变,问可以选择的M题,使可以得到的分数最低的期望是多少. 思路:公式中Ci,Wi分别表示正确和错误的概率(Ci+Wi=1) 对于提供错误答案和

CodeForces - 95B(搜索+贪心)

题目链接:http://codeforces.com/problemset/problem/95/B 题意:给一个正整数n(1-100000位),求出不小于n的最小幸运.幸运数的概念是:由数量相等的4和7组成的数. 思路: 大体分三种情况: 1.n的位数len为奇数,最简单就是增加一位变成len+1偶数个,前一半为4,后一半为7 2.n的位数len为偶数,但找不到有len位数的幸运数比n大,那么就要增加两位len+2,前一半为4,后一半为7(可以和情况1放在一起) 3.n的位数len为偶数,可以

CodeForces 767E(贪心)

CodeForces 767E 题意:有100元的纸币和1元的硬币,某同学有无限多的纸币和 m 个硬币,并决定接下来的 n 天去食堂每天花费 c[i] 元.已知食堂大叔在第 i 天找零 x 元的话,不满意度会增加 w[i],问最小不满意度. 题解:按顺序先直接使用手上有的硬币,当手上硬币剩余为负数的时候,说明前面一定会出现有一天需要多使用一张纸币,取的策略就是取前面的代价 w[i]*(100-a[i]%100) 最少的一次,然后手里剩余硬币 +100.用优先队列维护即可. (代码略挫) 1 #i

Codeforces 452D [模拟][贪心]

题意: 给你k件衣服处理,告诉你洗衣机烘干机折叠机的数量,和它们处理一件衣服的时间,要求一件衣服在洗完之后必须立刻烘干,烘干之后必须立刻折叠,问所需的最小时间. 思路: 1.按照时间模拟 2.若洗完的衣服或者烘干的衣服较多来不及进行下一个步骤,则从一开始就顺延洗衣服的时间,贪心的思想也是体现在这里. 3.关键在于烘干衣服的顺延如何处理,因为需要调整洗衣服的起始时间,其实我们只要对烘干衣服的时间进行顺延处理就可以了,因为即使没有调整洗衣服的起始时间,那么下次到了烘干衣服的时间的时候因为烘干衣服的数

CodeForces 651A Joysticks 贪心

A. Joysticks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Friends are going to play console. They have two joysticks and only one charger for them. Initially first joystick is charged at

Codeforces 484A Bits(贪心)

题目链接:Codeforces 484A Bits 题目大意:给定区间l,r,找到一个数x,保证x在区间上,并且要求x的bitcount尽量大的前提下数值尽量小. 解题思路:默认x为全1的二进制数,每次从最高为判断,看最高位的1变为0后大于r,就将该为变成0:落在区间上则即 为要照的答案:小于l则表示该为不能为0. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm&g

CodeForces #100 C 贪心+STL

题目链接:CodeForces #100  C 题意:现在给出n个snowball的半径,3个半径严格递增或递减的snowball,可以组成1个snowmen.问最多能组成多少个snowmen.并且按照半径递减的顺序输出每个snowmen的组成. 思路:嗯...每次都从前三个个数最多的snowball里选择,最后组成的snowmen最多... ...可以用优先队列写..但是感觉set+map写的太优雅了...map当然不等于数组了...哼. #include <stdio.h> #includ

codeforces 335A Banana(贪心)

转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud    Banana Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a