Toyota Programming Contest 2024#1(AtCoder Beginner Contest 337)F. Usual Color Ball Problems(思维题 双指针)

文章描述了一个关于长度为n的球序列放入m个空盒子的问题,通过双指针策略,计算每个操作后不同颜色球在盒子里的总数。关键在于维护第一个不在盒子内的球的位置,以及利用颜色计数快速确定球的放置情况。

题目

长为n(n<=2e5)的球序列,第i个球颜色ci,有m(m<=n)个空盒子,编号1-m

对于r∈[0,n-1]的每个r,打印以下问题的答案:

(一)把序列中最前面的球移动到序列末尾,执行r次

(二)顺序遍历n个球,对于当前队首的球x,记颜色为c[x]

(1)如果存在某一个盒子当前装了[1,k)个颜色为c[x]的球,就把球x放入这个盒子

(2)如果没有这样的盒子:

   ①如果有空盒子,就把球x放入编号最小的空盒子

   ②否则,扔掉这个球,不放进任何一个盒子(注意扔掉的操作不会影响下一个r的询问)

思路来源

官方题解

题解

题意还挺绕的

2400的双指针,难绷,heltion starsilk cuiaoxiang pyy纷纷折戟

主要是没想到双指针,想到双指针了的话可能会好做一些

主要是这个似乎只能双指针,二分似乎都不太行

首先执行r次,意味着,循环询问,对于每个开头的长为n的序列都询问一次,所以序列扩成二倍

然后考虑双指针,双指针维护第一个不在盒子内的球的位置,注意到它是单增的

并且,一旦确定了不在盒子内的球的位置p,

那么前面在盒子内的每种颜色球的个数就是确定的,

这些球占的盒子的个数也是确定的,

位置在p位置之后,但因为和p位置之前放入盒子里的球同色,而能被继续放入的球,

也可以O(1)确定,

即,如果某种颜色总共有all个球,

而当前占了x个盒子,则这种颜色的球总共放了min(x*k,all)个

一旦确定了不在盒子内的球的位置p,前面在盒子里的同色的球的个数也能确定,

记颜色w的球在盒子里的球为now[w]个,则占了now[w]/k(向上取整)个盒子

所以,双指针维护第一个

### AtCoder Beginner Contest 388 Problems and Solutions #### Problem A: Sample Problem Title In this problem, contestants are asked to solve a basic algorithmic challenge that tests fundamental coding skills. The task involves processing input data according to specific rules outlined in the contest guidelines. For instance, consider an example where participants need to determine whether a given string meets certain criteria: ```python def check_string(s): if s.startswith(&#39;A&#39;) and s.endswith(&#39;Z&#39;): return "Yes" else: return "No" print(check_string("ABC")) # Output should be based on provided conditions. ``` The solution approach focuses on understanding the requirements clearly before implementing any logic[^1]. #### Problem B: Another Example Task This section would detail another type of question from ABC 388 which might involve more complex algorithms or data structures compared to Problem A. It could cover topics like sorting arrays, searching within lists, etc., depending upon what was actually featured during the event. An illustrative code snippet demonstrating how one may tackle such issues can look as follows: ```cpp #include <bits/stdc++.h> using namespace std; int main() { vector<int> numbers = { /* Input values */ }; sort(numbers.begin(), numbers.end()); // Further operations with sorted list... } ``` Contestants must carefully read through all instructions while attempting these types of questions. #### General Tips for Participating in Contests Like This One Preparing adequately prior to participating includes practicing similar past papers extensively along with reviewing relevant materials related to common themes encountered frequently across various contests hosted by platforms like AtCoder. Additionally, staying updated about recent changes made either concerning submission formats or evaluation methods ensures smoother participation without unexpected surprises arising midway into solving tasks at hand[^3].
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小衣同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值