点击查看代码
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int n,a[10010],b[10][1010];
bool vis[10][1010];
int judge(int x)
{
for(int i=1;i<=n;i++)
{
int book=0;
while(a[i]-f>=minn)
{
a[i]-=f;
book++;
if(bok<book)bok=book;
}
b[a[i]][book]=1;
}
}
int main()
{
int minn=100010,maxx=-1;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
if(a[i]>maxx)maxx=a[i];
if(a[i]<minn)minn=a[i];
}
int f=(maxx-minn)/5;
for(int i=1;i<=n;i++)
{
int id=judge(a[i],f,minn);
b[id][a[i]-(minn+f*(id-1))]=a[i];
vis[id][a[i]-(minn+f*(id-1))]=1;
}
for(int i=1;i<=5;i++)
{
sort(b[i]+1,b[i]+f+1);
}
for(int i=0;i<=4;i++)
{
for(int j=minn+f*(i-1);j<=minn+f*i;j++)
{
if(vis[i][j]==1)
printf("%d ",b[i][j]);
}
}
return 0;
}
//20
//20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1
点击查看修正
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string.h>
using namespace std;
int n,a[10010],b[1010][10],bok;
void judge(int f,int minn)
{
for(int i=1;i<=n;i++)
{
int book=0;
while(a[i]-f>=minn)
{
a[i]-=f;
book++;
if(bok<book)bok=book;
}
b[a[i]][book]=1;
}
}
int main()
{
int minn=100010,maxx=-1;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
for(int i=1;i<=n;i++)
{
if(a[i]>maxx)maxx=a[i];
if(a[i]<minn)minn=a[i];
}
int f=(maxx-minn)/5+1;
judge(f,minn);
for(int i=0;i<=f;i++)
{
for(int j=1;j<=bok;j++)
{
if(b[i][j]==1)cout<<j+i*f<<' ';
}
}
return 0;
}