CodeForce 508C Anya and Ghosts (贪心+模拟)

本文介绍了一种使用优先队列解决蜡烛点亮问题的方法。在特定时间需要保持一定数量的蜡烛亮着,每根蜡烛维持时间为t秒,点一根蜡烛需要1秒。通过维护一个优先队列来跟踪蜡烛的点亮和熄灭时间,确保每个时间点都有足够数量的蜡烛亮着。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目大意:有m个时刻,在第i时刻即wi秒的时候需要保持有r根蜡烛亮着,每根蜡烛维持的时间为t秒,点一根蜡烛需要1秒。

注意:一根蜡烛亮的时间为下一秒开始。并且一开始是可以事先准备蜡烛的。

想法:利用了优先队列,维护r根蜡烛,每次wi秒,它需要开始点蜡烛的最晚时间为wi-t,如果不够这个时间,那么在最晚结束点蜡烛的时间wi-1开始补上。

感谢阿扎夫人提供的思维题。

AC代码:

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<queue>
#include<functional>
#include<vector>
#include<cstdio>
using namespace std;
priority_queue<int, vector<int>, greater<int> > q;
int main()
{
	int m, t, r;
	int w[333];
	while (cin >> m >> t >> r)
	{
		for (int i = 1; i <= m; i++)
			scanf("%d", &w[i]);
		while (!q.empty())
			q.pop();
		if (t < r)
		{
			cout << "-1" << endl;
			continue;
		}
		int start, end;
		int sum = 0;
		int mid;
		while (sum < r)
		{
			q.push(-500);
			sum++;
		}
		sum = 0;
		for (int i = 1; i <= m; i++)
		{
			start = w[i]-t;
			end = w[i] - 1;
			while (!q.empty() && q.top() < start)
			{
				q.push(end);
				q.pop();
				end--;
				sum++;
			}
		}
		cout << sum << endl;
	}
}


### Codeforces Problem or Contest 998 Information For the specific details on Codeforces problem or contest numbered 998, direct references were not provided within the available citations. However, based on similar structures observed in other contests such as those described where configurations often include constraints like `n` representing numbers of elements with defined ranges[^1], it can be inferred that contest or problem 998 would follow a comparable format. Typically, each Codeforces contest includes several problems labeled from A to F or beyond depending on the round size. Each problem comes with its own set of rules, input/output formats, and constraint descriptions. For instance, some problems specify conditions involving integer inputs for calculations or logical deductions, while others might involve more complex algorithms or data processing tasks[^3]. To find detailed information regarding contest or problem 998 specifically: - Visit the official Codeforces website. - Navigate through past contests until reaching contest 998. - Review individual problem statements under this contest for precise requirements and examples. Additionally, competitive programming platforms usually provide comprehensive documentation alongside community discussions which serve valuable resources when exploring particular challenges or learning algorithmic solutions[^2]. ```cpp // Example C++ code snippet demonstrating how contestants interact with input/output during competitions #include <iostream> using namespace std; int main() { int n; cin >> n; // Process according to problem statement specifics } ```
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值