Codeforces Round #196 (Div. 2) / 337C Quiz (贪心&快速幂取模)

探讨CodeForces Quiz题目中玩家如何通过合理安排正确答案的顺序来获得最小分数的方法。解析贪心策略的应用,分享代码实现。

C. Quiz
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 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

思路:

用贪心的思想做,把连对放前面。

然后就是自己在纸上画画找规律了。


反思:多找几组数据,不要漏了某些情况。


完整代码:

/*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;
}


内容概要:本文围绕间歇性光伏出力条件下48V直流母线电压的稳定控制与储能系统双向充放电的闭环调控体系展开深入研究,系统探讨了光伏阵列非线性输出特性与锂离子电池储能系统在离网直流微网中的能量均衡建方法及分层控制策略。通过Simulink平台构建完整的光伏储能直流系统仿真型,涵盖PV阵列、Boost DC-DC变换器、负载、双向DC-DC变换器及电池系统等关键组件,实现了最大功率点跟踪(MPPT)与储能系统的协同控制,有效应对光照波动引起的功率供需失衡问题。研究采用双PI闭环控制、型预测控制(MPC)等多种先进控制算法,显著提升了系统的动态响应速度与直流母线电压稳定性,并实现了储能系统在削峰填谷中的优化运行,对于增强离网微网的供电可靠性与能源利用效率具有重要理论价值和工程意义。; 适合人群:具备电力电子、新能源系统或自动控制等相关领域基础知识的研究生、科研人员,以及从事微电网、光伏储能系统开发与设计的工程技术人员。; 使用场景及目标:① 构建适用于离网场景的光伏储能系统Simulink仿真型;② 实现间歇性光照条件下48V直流母线电压的精确稳定控制与储能系统的双向能量管理;③ 研究MPPT控制与储能充放电策略之间的协同机制,提升系统在复杂工况下的运行稳定性与鲁棒性;④ 为微电网能量管理系统的设计、优化与性能验证提供可靠的理论依据和技术支撑。; 阅读建议:建议结合文中所述的Simulink仿真型与控制算法,亲自动手实践建与仿真全过程,重点关注MPPT控制策略的实现、双向DC-DC变换器的设计以及电压外环与电流内环构成的双闭环控制结构的参数整定,并通过设置不同的光照强度变化曲线和负载投切工况,全面测试和评估系统的动态响应能力与控制性能。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值