牛客小白月赛64 C-Karashi的生日蛋糕(思维)
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;
}
本文作者:Vijurria
本文链接:https://www.cnblogs.com/Vivian-0918/p/17035220.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步