Codeforces Round #196 (Div. 2) / 337C Quiz (贪心&快速幂取模)
2013-08-17 13:18
363 查看
C. Quiz
http://codeforces.com/problemset/problem/337/C
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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).
Input
The single line contains three space-separated integers n, m 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
output
input
output
思路:
用贪心的思想做,把连对放前面。
然后就是自己在纸上画画找规律了。
反思:多找几组数据,不要漏了某些情况。
完整代码:
http://codeforces.com/problemset/problem/337/C
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
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).
Input
The single line contains three space-separated integers n, m 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
思路:
用贪心的思想做,把连对放前面。
然后就是自己在纸上画画找规律了。
反思:多找几组数据,不要漏了某些情况。
完整代码:
/*30ms,0KB*/ #include<cstdio> const int mod = 1000000009; __int64 pow(__int64 a, __int64 b)///a^b % mod { __int64 r = 1, base = a; while (b) { if (b & 1) r = r * base % mod; base = base * base % mod; b >>= 1; } return r; } int main() { __int64 n, m, k, temp, ans; scanf("%I64d%I64d%I64d", &n, &m, &k); if (n < k * (n - m + 1)) printf("%I64d", m); else { temp = n / k - n + m; ans = ((k * (pow(2, temp + 1) - 2 - temp)) % mod + m + mod) % mod; printf("%I64d", ans); } return 0; }
相关文章推荐
- Codeforces Round #459 (Div. 2) C.The Monster【贪心&括号匹配】
- Codeforces Round #196 (Div. 2)(c快速幂)
- Codeforces Round #177 (Div. 1) C. Polo the Penguin and XOR operation(贪心)
- 【Codeforces Round 331 (Div 2)B】【水题 贪心】Wilbur and Array 修改对p位置后的所有位置生效 最少修改次数使得数列变成b
- Codeforces Round #375 (Div. 2) A B C 水 模拟 贪心
- 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
- Educational Codeforces Round 36 (Rated for Div. 2)C. Permute Digits(贪心)
- 【Codeforces Round 329 (Div 2) B】【映射 排序 贪心】Anton and Lines 查看所有直线pair在[x1,x2]范围内是否有交点
- Codeforces Round #253 (Div. 2) D. Andrey and Problem (贪心+数学概率)
- Codeforces Round #383 (Div. 2) A. Arpa’s hard exam and Mehrdad’s naive cheat(快速幂水题)
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心
- Codeforces Round #194 (Div. 1) / 333B Chips(贪心+代码优化)
- Codeforces Round #437 (Div. 2 C. Ordering Pizza 贪心 only two types of pizza
- Codeforces Round #331 (Div. 2)-Wilbur and Array(贪心模拟)
- cf/Codeforces Round #373 div1-C/div2-E Sasha and Array 线段树 + 维护矩阵快速幂
- Codeforces Round #378 (Div. 2) D. Kostya the Sculptor【贪心】
- 【Codeforces Round 345 (Div 2) B】【贪心 STL-set】Beautiful Paintings 安排顺序使得a[i]大于a[i-1]的i尽可能多
- Codeforces Round #193 (Div. 2) - C. Students' Revenge(贪心)
- Codeforces Round #434 (Div. 2, )-字典树&好题&板子-Polycarp's phone book
- 【Codeforces Round 274 (Div 2)B】【贪心】Towers 若干次移数后使得最大差值尽可能小