[/i][/b][/c]What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
151 - Power Crisis
Moderator: Board moderators
problem 151
151 - Power Crisis
What will be the output for problem no.151 if I input 98 and 67?
Please inform me soon.
Problem 151
Sir,
I solved my problem & it shows the output for 98- 113 and 67- 82.But when I send it Judge's response is-"wrong answer & it ran during 0.00 seconds".So,what I will do now? Please inform me soon.
[/c]
-
- A great helper
- Posts: 284
- Joined: Thu Feb 28, 2002 2:00 am
- Location: Germany
- Contact:
Re: problem 151
koniloni wrote:[/i][/b][/c]What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
![:evil:](./images/smilies/icon_evil.gif)
There are initially 17 people namely
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(^ means current position) with m = 5,
firstly 1 is eliminated, so it becomes:
^2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
counting 2 3 4 5 and eliminate 6, so it becomes
2 3 4 5 ^7 8 9 10 11 12 13 14 15 16 17
counting 7 8 9 10 and eliminate 11, so it becomes
2 3 4 5 7 8 9 10 ^12 13 14 15 16 17
counting 12 13 14 15 and eliminate 16, so it becomes
2 3 4 5 7 8 9 10 12 13 14 15 ^17
counting 17 2 3 4 and elimiate 5, so it becomes
2 3 4 ^7 8 9 10 12 13 14 15 17
counting 7 8 9 10 and elimiate 12, so it becomes
2 3 4 7 8 9 10 ^13 14 15 17
.....
Hope can help![:D](./images/smilies/icon_biggrin.gif)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
(^ means current position) with m = 5,
firstly 1 is eliminated, so it becomes:
^2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
counting 2 3 4 5 and eliminate 6, so it becomes
2 3 4 5 ^7 8 9 10 11 12 13 14 15 16 17
counting 7 8 9 10 and eliminate 11, so it becomes
2 3 4 5 7 8 9 10 ^12 13 14 15 16 17
counting 12 13 14 15 and eliminate 16, so it becomes
2 3 4 5 7 8 9 10 12 13 14 15 ^17
counting 17 2 3 4 and elimiate 5, so it becomes
2 3 4 ^7 8 9 10 12 13 14 15 17
counting 7 8 9 10 and elimiate 12, so it becomes
2 3 4 7 8 9 10 ^13 14 15 17
.....
Hope can help
![:D](./images/smilies/icon_biggrin.gif)
Judge says:
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Before crash, it ran during 0.000 seconds.
Plz help
Your program has died with signal 11 (SIGSEGV). Meaning:
Invalid memory reference
Before crash, it ran during 0.000 seconds.
Plz help
Code: Select all
#include<stdio.h>
#include<stdlib.h>
void func(int N);
main()
{int N;
do{
scanf("%d",&N);
if(N == 0)
exit(1);
if(N==13)
{ printf("1\n");
continue;
}
func(N);
}while(N != 0);
}
void func(int N)
{int m;
int check(int m,int N);
for(m=1;m<=N;m++)
if( check(m,N) == 1)
{ printf("%d\n",m);
return;
}
}
int check(int m,int N)
{ int A[N],j,i,t;
void shiftleft(int A[],int pos,int n);
int n = N;/* n = number of elements at any moment in the array */
for(i=1;i<=N;i++)
A[i] = i;
j=1;
shiftleft(A,j,n);
n -= 1;
do
{ if( (j + m-1)>n )
{t = n-j;
j = m-1-t;
}
if(n>1 && A[j] == 13)
return(0);
shiftleft(A,j,n);
n -= 1;
}while(n>1);
if( n==1 && A[1]== 13)
return(1);
return(0);
}
void shiftleft(int A[],int pos,int n)
{int j;
for(j=pos;j<n;j++)
A[j] = A[j+1];
return;
}
RUN TIME ERROR 151
Code: Select all
#include<stdio.h>
#include<stdlib.h>
void func(int N);
main()
{int N;
do{
scanf("%d",&N);
if(N == 0)
exit(1);
if(N==13)
{ printf("1\n");
continue;
}
/* printf("N = %d\n",N); */
func(N);
}while(N != 0);
}
void func(int N)
{int m;
int check(int m,int N);
for(m=1;m<=N;m++)
if( check(m,N) == 1)
{ printf("%d\n",m);
return;
}
}
int check(int m,int N)
{ int A[N],j,i,t,n;
void shiftleft(int A[],int pos,int n);
n = N;/* n = number of elements at any moment in the array */
for(i=1;i<=N;i++)
A[i] = i;
j=1;
shiftleft(A,j,n);
n -= 1;
do
{ if( (j + m-1)>n )
{t = n-j;
j = m-1-t;
}
if(n>1 && A[j] == 13)
return(0);
shiftleft(A,j,n);
n -= 1;
}while(n>1);
if( n==1 && A[1]== 13)
return(1);
return(0);
}
void shiftleft(int A[],int pos,int n)
{int j;
for(j=pos;j<n;j++)
A[j] = A[j+1];
return;
}
problem with 151
I'm newbie to acm.uva.es and this is my first program I wrote in acm.uva.es
my program is working properly on my computer
but when i send it to Online Judge I get
Runntime error
And I don't know why
Could someone help me and tell me what is wrong in most cases ? (I can paste source code if someone needs it)
my program is working properly on my computer
but when i send it to Online Judge I get
Runntime error
And I don't know why
Could someone help me and tell me what is wrong in most cases ? (I can paste source code if someone needs it)