首页 > 其他分享 >abc268 C - Chinese Restaurant

abc268 C - Chinese Restaurant

时间:2023-05-04 21:35:07浏览次数:80  
标签:typedef Chinese Restaurant int long 循环 abc268

C - Chinese Restaurant 

算贡献就是在普通思路上交换循环数,或是交换求和符号的2边的个数,来达到优化和解题的目的

对于该题,我刚开始的想法是循环旋转次数,再去查看符合要求的菜的个数,这样是O^2的

于是我们交换循环数,先去循环每个菜,我们发现每个菜实际上只对3个循环次数有贡献,于是时间复杂度就变成了O*3

#include<bits/stdc++.h>

using namespace std;

#define endl '\n'
typedef long long LL;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int>p(n),cnt(n);
    for(int i=0;i<n;i++)cin>>p[i];
    for(int i=0;i<n;i++){
        for(int j=p[i]-1;j<=p[i]+1;j++){
            cnt[(j-i+n)%n]++;
        }        
    }
    int ans=0;
    for(int i=0;i<n;i++)ans=max(ans,cnt[i]);
    cout<<ans<<endl;
    return 0;
}

 

标签:typedef,Chinese,Restaurant,int,long,循环,abc268
From: https://www.cnblogs.com/F-beginner/p/17372571.html

相关文章

  • 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......
  • [LeetCode] 1333. Filter Restaurants by Vegan-Friendly, Price and Distance 餐厅过
    Giventhearray restaurants where restaurants[i]=[idi,ratingi,veganFriendlyi,pricei,distancei].Youhavetofiltertherestaurantsusingthreefilte......
  • [ABC268D] Unique Username 题解
    [ABC268D]UniqueUsernameSolution目录[ABC268D]UniqueUsernameSolution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题面给定$n$各字......
  • [ABC268F] Best Concatenation 题解
    [ABC268F]BestConcatenationSolution目录[ABC268F]BestConcatenationSolution更好的阅读体验戳此进入题面SolutionCodeUPD更好的阅读体验戳此进入题面给定$n$......