Page 3 of 3
Re: 579 - ClockHands
Posted: Sat Mar 12, 2011 2:34 pm
by saiful_islam
ok
Re: 579 - ClockHands
Posted: Sun Mar 13, 2011 6:50 pm
by Dark Lord
Your code is giving these output.
input:
1:59
1:01
your output:
-0.000
-36893488.....something.
But the output should be:
65.500
24.500
Try to use
fabs function from math.h
and visit this page
http://en.wikipedia.org/wiki/Clock_angle_problem
remember angle is always <=180.000
Re: 579 - ClockHands
Posted: Sun Mar 20, 2011 1:55 pm
by saiful_islam
tnx Bro

ACC
Re: 579 - ClockHands(WHY WA??SOS)
Posted: Thu Jan 19, 2012 1:09 pm
by 20112685
I don't know why I get WA though I have check many inputs and outputs.Please help me,thanks in advance!
#include<stdio.h>
#include<math.h>
int main(void)
{
int h,m;
double a;
while(scanf("%i:%i",&h,&m)!=EOF && (h||m))
{
a=fabs(5.5*m-30*h);
if(a-180>1e-9)
a=360-a;
printf("%.3f\n",a);
}
return 0;
}
Re: 579 - ClockHands
Posted: Sun May 27, 2012 10:04 pm
by AT-2012
Plz!! Someone help me out wid this code. I got WA.
579: Code
#include<stdio.h>
#include<math.h>
int main()
{
float h,m,ang,n;
while(scanf("%f:%f",&h,&m)==2)
{
if(h==0 && m==0) break;
ang=((h*60+m)/2-(m*6));
if(ang>180) ang=360-ang;
if(ang<0) ang=fabs(ang);
printf("%.3f\n",ang);
}
return 0;
}
Re: 579 - ClockHands
Posted: Fri Jun 01, 2012 12:40 am
by brianfry713
Use double instead of float.
Re: 579 - ClockHands
Posted: Sat Sep 08, 2012 4:44 pm
by shellexecutor
Float is OK. I use float and got AC.
579 TLE
Posted: Thu Aug 08, 2013 9:02 pm
by moxlotus
The java code is getting TLE, can someone tell me how can this piece of code be optimized ?
The equivalent C code has passed the judge without any problem.
Thanks in advance.
Code: Select all
import java.util.*;
import java.text.DecimalFormat;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class ClockHands
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
String[] arr = line.split("[:\\s]+");
int hr = Integer.parseInt(arr[0]);
int min= Integer.parseInt(arr[1]);
double hrDegree, minDegree, diff;
DecimalFormat df = new DecimalFormat("0.000");
while(hr > 0 || min > 0)
{
if(hr == 12) hr = 0;
hrDegree = ((hr+(min/60.0))/12.0) * 360;
minDegree = (min/60.0) * 360;
diff = hrDegree > minDegree ? hrDegree-minDegree : minDegree-hrDegree;
if(diff > 180) diff = 360 - diff;
System.out.printf("%s\n", df.format(diff));
line = br.readLine();
arr = line.split("[:\\s]+");
hr = Integer.parseInt(arr[0]);
min = Integer.parseInt(arr[1]);
}
}
}
Re: 579 TLE
Posted: Thu Aug 08, 2013 11:06 pm
by brianfry713
Use Class Main. Java is too slow for some problems.
Re: 579 TLE
Posted: Fri Aug 09, 2013 6:31 am
by moxlotus
Actually got a few friends helped me optimized the code.
Apparently the use of StringBuilder and printing it out all at once is much faster than calling System.out.printf.
The performance gain is more than 100%
Re: 579 TLE
Posted: Sat Aug 10, 2013 12:01 am
by brianfry713
You could also try BufferedWriter.
579 - ClockHands
Posted: Fri Nov 01, 2013 2:38 am
by cyberdragon
3rd case in the sample input.
How 8:10 outputs 175, It should be 180 ?
Re: 579 - ClockHands
Posted: Fri Nov 01, 2013 7:57 pm
by brianfry713
The big hand at 10 is 60 degrees to the right of 12.
The small hand at 8:10 is 115 degrees to the left of 12.
Re: 579 - Clock Hands
Posted: Tue Dec 16, 2014 9:31 pm
by This Is ERFAN
Getting WA...plz help me out.
Code: Select all
#include<stdio.h>
int main()
{
float a,b;
char c;
while(scanf("%f %c %f",&a,&c,&b)==3)
{
if(a==0&&b==0) return 0;
float d,d1,d2,d3;
if(b==0)
{
if(a<=6) d=a*5*6;
else
d=(12-a)*5*6;
}
else
{
d1=b/2;
d2=b/5;
if(a==d2) d3=0;
else if(a>d2) d3=(a-d2)*5*6;
else if(a<d2) d3=(d2-a)*5*6;
if(a>d2) d=d3+d1;
else if(a==d2) d=d1;
else d=d3-d1;
if(d>180) d=360-d;
}
printf("%0.3f\n",d);
}
return 0;
}
Re: 579 - Clock Hands
Posted: Tue Dec 16, 2014 9:53 pm
by brianfry713
Try using double instead of float.