151 - Power Crisis

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

koniloni
New poster
Posts: 15
Joined: Thu Apr 18, 2002 5:10 am

problem 151

Post by koniloni » Thu Apr 18, 2002 5:30 am

What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
[/i][/b][/c]

ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi » Thu Apr 18, 2002 9:18 am

the output is:
15
29
But beware! The input shuld terminated by 0!

koniloni
New poster
Posts: 15
Joined: Thu Apr 18, 2002 5:10 am

151 - Power Crisis

Post by koniloni » Thu Apr 18, 2002 1:13 pm

What will be the output for problem no.151 if I input 98 and 67?
Please inform me soon.

ftomi
Learning poster
Posts: 64
Joined: Sun Jan 06, 2002 2:00 am
Location: Hungary
Contact:

Post by ftomi » Thu Apr 18, 2002 8:36 pm

The output is:
113
82
But consider I'll answer only 84 further question! :wink:

koniloni
New poster
Posts: 15
Joined: Thu Apr 18, 2002 5:10 am

Problem 151

Post by koniloni » Fri Apr 19, 2002 6:36 am

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]

Stefan Pochmann
A great helper
Posts: 284
Joined: Thu Feb 28, 2002 2:00 am
Location: Germany
Contact:

Post by Stefan Pochmann » Fri Apr 19, 2002 7:17 am

First of all, you could write all your posts into the same thread instead of opening a new thread for the same problem three times. This will help everybody to keep the overview of what was said about a problem. Plus, it keeps the list of subjects small, which also helps keeping an overview.

zerocool
New poster
Posts: 7
Joined: Wed May 15, 2002 10:30 am
Location: Kaohsiung,Taiwan
Contact:

Post by zerocool » Wed May 15, 2002 5:43 pm

Try this
input : 13
output : 1[/b][/code][/quote]
A mediocrityboy

ricky_bd
New poster
Posts: 3
Joined: Fri May 31, 2002 6:38 am

Re: problem 151

Post by ricky_bd » Fri May 31, 2002 6:55 am

koniloni wrote:
What will be output for problem no.151, if I input 20 and 21?Please inform me soon.
[/i][/b][/c]
:evil: 15 and 21 are the possible output

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

Accepted

Post by manir » Sat Jul 06, 2002 12:03 pm

I got accepted
My inputs:
13
21
20

Outputs:
1
29
15
:D :D
The 2nd laziest person of the world

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

Post by taj79 » Sat Jul 06, 2002 1:46 pm


Can anyone plz explain me the sample order for N=17 and m=5
1,6,11,16,5,12,2,9,17,10,4,15,14,3,8,13,7.

1+5 =6 OK
6+5 = 11 OK
11+5 = 16 OK
but how does 5 come at 5th position.
how does 12 comes at 6th position.
..........

Everything is quite unclear to me.
Plz explain

10153EN
Experienced poster
Posts: 148
Joined: Sun Jan 06, 2002 2:00 am
Location: Hong Kong
Contact:

Post by 10153EN » Sat Jul 06, 2002 2:20 pm

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

taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

Post by taj79 » Sat Jul 06, 2002 5:36 pm

Judge says:
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;
  }







taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

RUN TIME ERROR 151

Post by taj79 » Thu Jul 25, 2002 8:22 pm

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;
  }








taj79
Learning poster
Posts: 74
Joined: Sun Jun 09, 2002 11:56 am
Location: India
Contact:

Post by taj79 » Tue Aug 06, 2002 3:23 pm

plz help me out ......my program is just above it......

scx
New poster
Posts: 4
Joined: Sat Sep 07, 2002 5:13 pm

problem with 151

Post by scx » Sat Sep 07, 2002 5:20 pm

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)

Post Reply

Return to “Volume 1 (100-199)”