#include
#include
#include
Int main ()
{
Int n, m, I;
int *p;
Int num, j, k;
While (the scanf (" % d ", & amp; N)!=(EOF)
{
The scanf (" % d ", & amp; M);
N * (p=(int *) malloc sizeof (int));
Memset (p, 1, sizeof (p));
Num=1; i=0;
J=n;
for(k=0; J> 1; K++)
{
If (p [I]!=0)
{
If (num==m)
{p [I]=0; j--;
Num=1;
}
The else
{
num++;
}
If (I==n - 1)
{I=0; }
The else
{i++; }
}
The else
{if (I==n - 1)
{I=0; }
The else
{i++; }
}
}
for(i=0; i
{
Printf (" % d \ n ", I);
break;
}
}
}
return 0;
}
CodePudding user response:
Modified memset (p, 1, n * sizeof (int));According to clew simulation algorithm, the complexity of O (m * n), m * n<1 e7 not timeout
CodePudding user response:
First you memset usage, there are two mistakes:Memset (p, 1, sizeof (p));
1, the third parameter on the writing should be n * sizeof (int);
Even if the correct one, there is still a mistake:
2, memset can't use the integer 1 filling arrays,