比赛 |
20120807 |
评测结果 |
WTTTTTTTTT |
题目名称 |
宁采臣的书架 |
最终得分 |
0 |
用户昵称 |
Truth.Cirno |
运行时间 |
28.562 s |
代码语言 |
C++ |
内存使用 |
0.29 MiB |
提交时间 |
2012-08-07 11:57:42 |
显示代码纯文本
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(void)
{
freopen("arrangement.in","r",stdin);
freopen("arrangement.out","w",stdout);
int i,j,kk,n,k,a[101],aa[101],min,temp,x,y,c;
scanf("%d%d",&n,&k);
while (n!=0&&k!=0)
{
for (i=1;i<=n;i++)
scanf("%d",&a[i]);
min=100;
for (i=1;i<=1000000;i++)
{
for (j=1;j<=n;j++)
aa[j]=a[j];
for (j=1;j<=k;j++)
{
x=rand()%n+1;
y=rand()%n+1;
temp=x;
if (x<=y)
{
for (kk=x;kk<y;kk++)
aa[kk]=aa[kk+1];
aa[y]=temp;
}
else
{
for (kk=x;kk>y;kk--)
aa[kk]=aa[kk-1];
aa[y]=temp;
}
}
c=0;
for (j=1;j<=n;j+=kk)
{
temp=aa[j];
for (kk=1;;kk++)
if (aa[j+kk]!=temp)
break;
c++;
}
if (c<min)
min=c;
}
printf("%d\n",min);
scanf("%d%d",&n,&k);
}
return(0);
}