首页 > 其他分享 >牛客小白月赛64 C-Karashi的生日蛋糕(思维)

牛客小白月赛64 C-Karashi的生日蛋糕(思维)

时间:2023-01-08 20:14:16浏览次数:55  
标签:map cout int LL cin Karashi 牛客 64

https://ac.nowcoder.com/acm/contest/49244/C

题目大意:
 
Karashi决定将水果摆放成n圈,第i圈必须有i个水果。 一共k个人,Karashi需要把蛋糕沿半径均分成k块,任意两块蛋糕包含的水果总个数相差不得超过1 。
 
写出满足上述条件的一种摆放方案。
输入 
5 5
输出 
0 0 1 1 1
0 0 1 1 1
1 0 1 0 1
0 1 0 1 1
0 1 0 1 1

友情提醒:这unordered_map带cin cout会被卡时间
常数大,实际速度和map相差不大

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> PII;
const LL MAXN=1e18;
const LL N=1000200,M=2002;
//vector<LL> v[N];
//priority_queue<LL> pq;
//priority_queue<LL,vector<LL>,greater<LL>> pq2;
LL n,m;
unordered_map<LL,LL> a[N];
int main()
{
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
    LL T=1;
    //cin>>T;
    while(T--)
    {
        //cin>>m>>n;
        scanf("%ld %ld",&m,&n);
        LL head=0;
        LL num=1;
        for(int j=0;j<m;j++)
        {
            for(int i=head,idx=1;idx<=(j+1)-(num-1)*n;i++,idx++)
            {
                a[i%n][j]=num;
                head=(i%n+1)%n;
            }
            LL flag=0;
            for(int i=0;i<n;i++)
            {
                if(a[i][j]!=num)
                {
                    a[i][j]=num-1;
                    flag++;
                }
            }
            if(flag==0) num++;
        }
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                //cout<<a[i][j]<<" ";
                printf("%ld ",a[i][j]);
            }
            //cout<<endl;
            printf("\n");
        }
    }
    return 0;
}

标签:map,cout,int,LL,cin,Karashi,牛客,64
From: https://www.cnblogs.com/Vivian-0918/p/17035220.html

相关文章

  • leetcode-643-easy
    MaximumAverageSubarrayIYouaregivenanintegerarraynumsconsistingofnelements,andanintegerk.Findacontiguoussubarraywhoselengthisequalto......
  • 牛客进阶题目13:时钟分频(偶数)
    用计数器来翻转即可`timescale1ns/1nsmoduleeven_div(inputwirerst,inputwireclk_in,outputwireclk_out2,outputwir......
  • 牛客小白月赛65 D-牛牛取石子(博弈论)
    https://ac.nowcoder.com/acm/contest/49888/D题目大意:一共有两堆石子,第一堆a个,第二堆b个,牛牛(先手)和牛妹轮流取石子:2种方案种挑一种1.第一堆取1个,第二堆取2个2......
  • 4645. 选数异或
    4645.选数异或给定一个长度为n的数列A1,A2,⋅⋅⋅,An和一个非负整数x,给定m次查询,每次询问能否从某个区间[l,r]中选择两个下标不同的数使得他们的异或等于x。......
  • 牛客进阶题目12:重叠序列检测
    注意看波形,flag相对于data的输入延迟两拍。也就是在输入1011后,第一拍进行检测,第二拍拉高flag。`timescale1ns/1nsmodulesequence_test2( inputwireclk, inputw......
  • 牛客2022跨年场
    B.分赃首先统计只有一个的数字个数,如果是偶数就平均分给两个人,然后把剩下的数字全部分给任意一个人。如果是奇数个,就看时候有数字的数量大于三,如果有,就把这个数字的其中......
  • anydesk arm64
    sudodpkg--add-architecturearmhfsudoaptupdatesudoaptinstalllibpolkit-gobject-1-0:armhflibraspberrypi0:armhflibraspberrypi-dev:armhflibraspberrypi-b......
  • 牛客进阶题目11:非重叠的序列检测
    可以用状态机也可用移位寄存器注意题目给rst的命名不带n后缀,但其实还是下降沿触发`timescale1ns/1nsmodulesequence_test1( inputwireclk, inputwirerst,......
  • 牛客进阶刷题10:整数倍数据位宽转换8to16
    比非整数倍简单`timescale1ns/1nsmodulewidth_8to16( input clk , input rst_n , input valid_in , input [7:0] data_in ,......
  • 牛客进阶刷题9:非整数倍数据位宽转换8to12
    输入位宽8bit,输出位宽12bit,也就是说每三个输入数据可以生成两个完整输出。注意给出的波形是data_lock而不是data_in,这是陷阱。data_lock是data_in打了一拍的结果。用一......