151 - Power Crisis
Moderator: Board moderators
may be you should paste you code.
Don`t worry this site is full of broken code. If you paste it someone may find the error.
By the way WA could also be a result of "array" problems. For example on my computer I write on MS Visual C and as a result it treats these two codes identical:
[cpp]int a[5];
...
a[0]=...; <=> a[5]=..;[/cpp]
Good luck.
By the way WA could also be a result of "array" problems. For example on my computer I write on MS Visual C and as a result it treats these two codes identical:
[cpp]int a[5];
...
a[0]=...; <=> a[5]=..;[/cpp]
Good luck.

I simple can't understand problem 151
Someone could explain me why it isn't 1 always the right answer in problem 151?
-
- Learning poster
- Posts: 82
- Joined: Thu Oct 10, 2002 1:15 pm
- Location: St. Johns, Canada
- Contact:
151 - there is some problem in judge end.
Can any one tell me what is the difference between the following codes :
Code A
Code: Select all
#include<stdio.h>
#define MAX 150
/** Implementatiom of circular queue **/
int queue[MAX];
int e,f,r;
/** _f is front; _r is rear & _e is element number **/
void push(int i)
{
r++;
e++;
if(r>=MAX)
r=1;
queue[r] = i;
}
int pop(void)
{
e--;
int i=queue[f];
f++;
if(f>=MAX)
f = 1;
return i;
}
/** End of circular queue **/
/** A general joshusf function **/
/** This function start removing element from first element */
/** and return the sirviver **/
int joshups(int n,int v)
{ register int i;
e=n;
for(i=1;i<=n;i++)
queue[i] = i;
f = 1; // 0 for serviving first element.
r = n; // n+1 for serviving first element.
i = 0;
if(n > 1)
pop();
while(e!=1)
{
if(i!=v)
{
i++;
push(pop());
}
else
{
if((pop())==13) /** this if statement and its body (not the pop) is out ofgeneral code **/
return -1;
i = 0;
}
}
return queue[f];
}
/** end of jouishof functionb **/
main(void)
{
int i,m;
scanf("%d",&i);
while(i)
{ m=1;
while((joshups(i,m++)) != 13 );
printf("%d",m);
putchar('\n');
scanf("%d",&i);
}
return 0;
}
Code: Select all
#include<stdio.h>
int count(int *region,int N)
{
int i,t=0;
for(i=0;i<N;i++)
if(!region[i])
{
t++;
if(t>1)
return t;
}
return 1;
}
void main()
{
int N,i,m,j,inc,tag;
int region[100];
while(scanf("%d",&N)==1)
{
if(!N)break;
tag=0;
m=1;
while(!tag)
{
j=0;
for(i=0;i<100;i++)region[i]=0;
region[j]=1;
j++;
while(count(region,N)!=1)
{
inc=m;
for(i=0;i<inc;)
{
if(j==N){j=0;continue;}
if(!region[j])i++;
if(j<N)j++;
}
j--;
region[j]=1;
}
for(i=0;i<N;i++)
if(!region[i])
break;
if(i==12)
{
printf("%d\n",m);
tag=1;
break;
}
m++;
}
}
}
[/b]
How to do 151?
Is there any overall formula for Josephus problem according to the problem 151. Please let me know it in detail.
In my Concrete Math (Knuth) there Josephus problem written for cuting Head one man after another and cutting start from the 1st person. So everything become so complex for me. Plsease help me.
In my Concrete Math (Knuth) there Josephus problem written for cuting Head one man after another and cutting start from the 1st person. So everything become so complex for me. Plsease help me.
-
- Experienced poster
- Posts: 131
- Joined: Thu Apr 17, 2003 8:39 am
- Location: Baku, Azerbaijan
Two answers
If I'm not mistaken, there are at least to possible answers for N=13, which are 1 and 7.
I think the wording should say something like "If there's more than one solution, print the lowest possible m."
I think the wording should say something like "If there's more than one solution, print the lowest possible m."