首页 > 其他分享 >[ABC268C] Chinese Restaurant

[ABC268C] Chinese Restaurant

时间:2023-05-18 22:11:40浏览次数:37  
标签:cnt Chinese Restaurant int ABC268C ++ MaxN ans

[ABC268C] Chinese Restaurant

声明:以下的所有操作都会再做一次 \(\% n+n) \% n\),比如 \(i - 1\) 会变成 \(((i-1)\%n+n)\%n\)

题意

有 \(n\) 个人和 \(n\) 个盘子,每个人如果能拿到 \(i - 1\) 或 \(i\) 或 \(i + 1\) 号盘子那么他会很开心,现在每个人的站位是 \(p_i\),他们的站位位置可以同时 $ + 1$,问最多可以有多少人觉得很开心。

思路

由于是一起动,所以可以用桶记录每个人走了多少步又到了那里,但是这样是 \(O(n^2)\) 的存不下也会超时。我们知道只有他在固定的盘子前才会觉得开心,所以有些桶是没用的,所以只要记录每个人到他想要去的盘子要多远就可以了,时间复杂度和空间复杂度为 \(O(n)\),在记录要走多远的时候,要注意细节。

代码

#include <iostream>

using namespace std;

const int MaxN = 2e5 + 10;

int cnt[MaxN], p[MaxN], n, ans;

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    cnt[n - ((p[i] - (i - 1 + n) % n) + n) % n]++, cnt[n - ((p[i] + n - i) + n) % n]++, cnt[n - ((p[i] + n - (i + 1) % n) + n) % n]++;
  }
  for (int i = 0; i < n; i++) {
    ans = max(ans, cnt[i]);
  }
  cout << ans << endl;
  return 0;
}

标签:cnt,Chinese,Restaurant,int,ABC268C,++,MaxN,ans
From: https://www.cnblogs.com/ybtarr/p/17413443.html

相关文章

  • 【论文解读】(拼音+字形+字三种信息的中文BERT)ChineseBERT: Chinese Pretraining Enhan
    文章目录1.相关信息2.论文内容3.论文模型3.1GlyphEmbedding3.2PinyinEmbedding4.实验与结论5.模型使用方式1.相关信息论文年份:2021论文地址:https://aclanthology.org/2021.acl-long.161.pdf论文代码(官方):https://github.com/ShannonAI/ChineseBertHuggingFace:Shan......
  • 【论文笔记】MacBert:Revisiting Pre-trained Models for Chinese Natural Language Pr
    文章目录相关信息摘要(Abstract)1.介绍(Introduction)2.相关工作(RelatedWork)3.中文预训练模型(ChinesePre-trainedLanguageModels)3.1BERT-wwm&RoBERTa-wwm3.2MacBERT4.实验设置(ExperimentSetups)4.1SetupsforPre-TrainedLanguageModels4.2SetupsforFine-tuningTask......
  • abc268 C - Chinese Restaurant
    C-ChineseRestaurant 算贡献就是在普通思路上交换循环数,或是交换求和符号的2边的个数,来达到优化和解题的目的对于该题,我刚开始的想法是循环旋转次数,再去查看符合要求的菜的个数,这样是O^2的于是我们交换循环数,先去循环每个菜,我们发现每个菜实际上只对3个循环次数有贡献,于是......
  • As a restaurant owner, write a professional email to the supplier to get these p
    Asarestaurantowner,writeaprofessionalemailtothesuppliertogettheseproductseveryweek:Wine(x10)Eggs(x24)Bread(x12)DearSupplier,Ihopethismessagefindsyouwell.Mynameis[YourName],andIamwritingonbehalfofmyrestaurant......
  • Chinese-LLaMA-Alpaca技术报告
    EFFICIENTANDEFFECTIVETEXTENCODINGFORCHINESELLAMAANDALPACAhttps://arxiv.org/pdf/2304.08177v1.pdfhttps://github.com/ymcui/Chinese-LLaMA-AlpacaPart1介绍我们通过在原有的LLaMA词汇中增加20,000个中文符号来提高中文编码和解码的效率,并提高LLaMA的中文理解......
  • HDU 2842 Chinese Rings(矩阵快速幂+递推)
    题目地址:HDU2842这个游戏是一个九连环的游戏。假设当前要卸下前n个环。由于要满足前n-2个都卸下,所以要先把前n-2个卸下,需要f(n-2)次。然后把第n个卸下需要1次,然后这时候要卸下第n-1个,然后此时前n-2个都已经被卸下了。这时候把前n-2个都卸下与都装上所需的次数是一样的,因为卸下与装......
  • UVa 11210 Chinese Mahjong (模拟&枚举&回溯)
    11210-ChineseMahjongTimelimit:3.000secondshttp://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=2151Mahjong()isagameofChineseoriginusuallyplayedbyfourpersonswithtilesresemblingdominoesandbearing......
  • AtCoder ABC286 C - Chinese Restaurant
    AtCoderABC286C-ChineseRestaurant题目描述有\(N\)个人从\(0\)开始编号,按逆时针顺序间隔均匀地坐在转盘周围。在开始时,第\(p_i\)盘菜在第\(i\)个人的前面。现在,你可以进行以下操作\(0\)次或多次。将转盘逆时针旋转\(\dfrac{1}{N}\)圈。也就是说,旋转前......
  • Quick install Chinese input method on Ubuntu
    QuickinstallChineseinputmethodonUbuntu7.04A.ToinstallChineseinputfcitxthroughwebupdate1.Clickapplicationprogramtabandthenclickrootterm......
  • how to become an author of freeCodeCamp in Chinese All In One
    howtobecomeatechnicalauthoroffreeCodeCampinChineseAllInOne如何成为一名freecodecamp的中文技术作者https://www.freecodecamp.org/newshttps://www......