10110 - Light, more light

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

Moderator: Board moderators

rlatif119
New poster
Posts: 16
Joined: Mon Mar 01, 2004 4:00 pm
Location: Dhaka

10110....WA

Post by rlatif119 » Tue Mar 23, 2004 7:23 am

This is one of the easy problem as far as i know........is it really????.....hmmmmm......but it always gives me wrong answer.......why???[c]

#include<stdio.h>
#include<math.h>
main()
{
long n,s;
while(1)
{
scanf("%ld",&n);
if(n==0)
break;

s = (long)sqrt(n);
if(s*s==n)
printf("yes\n");
else
printf("no\n");

}
}[/c]

[/c]

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

right you are

Post by sohel » Tue Mar 23, 2004 7:49 am

Hello Rlatif,

Here is a quote from the problem statement:
The input will be an integer indicating the n'th bulb in a corridor. Which is less then or equals 2^32-1.
long can not handle inputs more that 2^31-1.

Either use unsigned long or long long.
Otherwise your code seems to be correct.
:wink:

rlatif119
New poster
Posts: 16
Joined: Mon Mar 01, 2004 4:00 pm
Location: Dhaka

Post by rlatif119 » Tue Mar 23, 2004 11:20 am

I've changed my datatype to unsigned long......but its still WA.....anyway thanks for your reply.

Subeen
Experienced poster
Posts: 127
Joined: Tue Nov 06, 2001 2:00 am
Location: Bangladesh
Contact:

Post by Subeen » Wed Mar 24, 2004 10:40 am

rlatif119, I think you are making any mistake in your submission. If you change the datatype into unsigned long then your program gets accepted. You have to use %lu for unsigned data type and do not typecast into long. ( you don't need any typecast here )

rlatif119
New poster
Posts: 16
Joined: Mon Mar 01, 2004 4:00 pm
Location: Dhaka

Post by rlatif119 » Wed Mar 24, 2004 7:54 pm

Thanks a lot Subeen.......Oh i can't imagine i had done a silly mistake like this........i didn't change the format........oh.....i can't imagine......isn't it a silly mistake.

Any way.......Thanks again.

UOB
New poster
Posts: 1
Joined: Wed Jul 14, 2004 11:36 am
Location: Kindom of Bahrain

10110 light more light runtime error

Post by UOB » Sat Aug 07, 2004 8:05 am

hi every body,
i thankful if anybody help me to fix this problem
i submitted my code into the judge amd he gave me a runtime error
please help me
[code]
#include <iostream>

using namespace std;

void Switch( int &state )
{
if ( state == 1 )
state = 0;

else
state = 1;
}




int main()
{ int a[10],i=0,j,size;
int bulb;
char *str[2]={ "no","yes"};
char* out[10];
cin >> a[0];
while(a[i]!=0)
{ i++;
cin>>a[i];}

size=i;
i=0;

while ( i != size ) {
bulb=a[i] ;
int state = 0;


for ( j = 1; j <= bulb; j++ )
if ( bulb % j == 0 ) {
Switch( state );

if ( j * j != bulb )
Switch( state );

}
*(out+i)=*(str+state);



i++;

}



for( i=0;i<size;i++)
cout<<out[i]<<endl;


return 0;
}




another question is that how can i get the compiler that the judge use it
can anyone give me a site i can downloaded??
[/code]

Piers Kennedy
New poster
Posts: 3
Joined: Thu Apr 22, 2004 8:12 pm

Post by Piers Kennedy » Sat Oct 30, 2004 7:39 pm

Actually it isn't quite right.

The input requires integers that are less than or equal to 2^32-1 so you must use unsigned int.

Niaz
Learning poster
Posts: 77
Joined: Fri Dec 17, 2004 11:06 am
Location: East West University, Dhaka, Bangladesh
Contact:

This is my accepted code. Just look... so small and so simpl

Post by Niaz » Sat Dec 18, 2004 8:12 pm

This is my accepted code. Just look... so small and so simple. :)
I hope, it will inspire you to think in a simple way.

Code: Select all

#include<stdio.h>
#include<math.h>
int main()
{
	long double num,b;
	long a;
	while(1)
	{
		scanf("%Lf",&num);
		if(num==0)
			break;

           a= some_function(num); 
                       //calling a commonly used 
                       //builtin C function.
           b= some_function(num);
                       // same function again.
		
           if(a==b)
			printf("yes\n");
           else
			printf("no\n");
	}
	return 0;
}
Please join The ACM Solver Group at Yahoo
http://groups.yahoo.com/group/acm_solver/

Mohammad Mahmudur Rahman
Experienced poster
Posts: 154
Joined: Sat Apr 17, 2004 9:34 am
Location: EEE, BUET

Post by Mohammad Mahmudur Rahman » Sat Dec 18, 2004 9:00 pm

Also you can try to work out for the first few numbers to find out which of them leads to an on bulb. I think u'll need no more than 15-20 cases to get the idea.
You should never take more than you give in the circle of life.

User avatar
Rocky
Experienced poster
Posts: 124
Joined: Thu Oct 14, 2004 9:05 am
Contact:

Post by Rocky » Mon Dec 20, 2004 12:06 pm

GOOD Reply NIAZ

I think that is the best solution for the problem.\

BY the Way
GOOD LUCK

CodeJerk
New poster
Posts: 4
Joined: Sun May 29, 2005 1:08 am
Location: India

10110 Presentation Error

Post by CodeJerk » Sun May 29, 2005 1:13 am

Hi
I get a PE with this program. Its driving me crazy now. Could some1 plz tell me why i m getting it. Thanks in advance.

Code: Select all

#include <iostream.h>
#include <math.h>

int main()
{

int flag = 1;
unsigned long i;

while (flag)
{
  cin >> i;
   if (i != 0) 
  
 {
   double value = i;
   double sqrtvalue = sqrt(value);
 
 if (floor(sqrtvalue) - sqrtvalue == 0.00) //perfect square
 cout<<"yes\n";
 
 else cout<<"no\n";
 }
 else flag=0;
 }
 return (0);
}

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Ah....

Post by sohel » Sun May 29, 2005 7:19 am

Well, that's odd..
.. I just submitted your code and got AC without presentation error. :o

CodeJerk
New poster
Posts: 4
Joined: Sun May 29, 2005 1:08 am
Location: India

Doesnt even Compile!!!

Post by CodeJerk » Sun May 29, 2005 8:40 am

Actually I was trying my code at the Programming Challenges website, where I was repeatedly getting a PE.
After seeing that the code was getting accepted at the online-judge, I did try mailing it. I mailed the following :-

Code: Select all

/* @JUDGE_ID:  62454TK  10110  C++ */

/* @BEGIN_OF_SOURCE_CODE */

#include <iostream.h> 
#include <math.h> 

int main() 
{ 

int flag = 1; 
unsigned long i; 

while (flag) 
{ 
  cin >> i; 
   if (i != 0) 
  
 { 
   double value = i; 
   double sqrtvalue = sqrt(value); 
  
 if (floor(sqrtvalue) - sqrtvalue == 0.00) //perfect square 
 cout<<"yes\n"; 
  
 else cout<<"no\n"; 
 } 
 else flag=0; 
 } 
 return (0); 
}

/* @END_OF_SOURCE_CODE */
And the program doesn't even compile now!!!!
What has gone wrong? This is the first time I am using the online-judge, so maybe I am doing something that is downright stupid. Could you please point it out, and help me out of this mess.
Thanks

neno_uci
Experienced poster
Posts: 104
Joined: Sat Jan 17, 2004 12:26 pm
Location: Cuba

Post by neno_uci » Sun May 29, 2005 10:53 am

After trying a lot of changes to your program, all the solutions I sent were PE too, so don't worry, your algorithm is correct and my AC code here got PE there too..., best regards,

Yandry. :D

eyeabhi
New poster
Posts: 11
Joined: Fri Apr 28, 2006 4:16 pm
Location: Bangladesh
Contact:

10110

Post by eyeabhi » Mon May 15, 2006 11:05 am

I think if the number of bulbs is a perfect square, then answer is yes, otherwise no. Is my guess incorrect?

Code: Select all

deleted
I get WA every time. Plz anyone tell me whts wrong here?

I have solved the problem.
Abhishek Roy
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.

Post Reply

Return to “Volume 101 (10100-10199)”