problem 151
Posted: Thu Apr 18, 2002 5:30 am
[/i][/b][/c]What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
[/i][/b][/c]What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
What will be the output for problem no.151 if I input 98 and 67?
Please inform me soon.
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]
koniloni wrote:[/i][/b][/c]What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
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;
}
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;
}