Page 3 of 4
Posted: Sat Oct 20, 2007 3:15 am
by Scottathon
Code: Select all
import java.io.*;
import java.util.*;
import java.text.*;
class Main {
public static void main (String args[]) throws IOException {
Scanner in = new Scanner(System.in);
DecimalFormat f = new DecimalFormat();
f.setMaximumFractionDigits(4);
f.setMinimumFractionDigits(4);
while (in.hasNext()) {
double a = in.nextDouble();
double b = in.nextDouble();
double c = in.nextDouble();
double triangleArea = 0.25 * Math.sqrt( (a+(b+c)) * (c-(a-b)) * (c+(a-b)) * (a+(b-c)));
double inCircle = Math.pow((2*triangleArea) / (a+b+c), 2) * Math.acos(-1);
double circumCircleRadius = (a*b*c)/Math.sqrt((a+b+c)*(b+c-a)*(c+a-b)*(a+b-c));
double circumCircle = Math.pow(circumCircleRadius, 2) * Math.acos(-1);
System.out.print(f.format(circumCircle - triangleArea) + " ");
System.out.print(f.format(triangleArea - inCircle) + " ");
System.out.println(f.format(inCircle));
}
}
}
Can anyone see what's wrong with this? My program has been right for the small amount of sample I/O in the topic, but I keep getting wrong answer.
Posted: Wed Dec 19, 2007 5:00 pm
by turcse143
no problem in the the coding format. But check the formula.
You can use this:
area of RED: pi*r*r;
r=sqrt(s*(s-a)*(s-b)*(s-c))/s;
s=(a+b+c)/2;
area of violets: area of triangle-area of RED;
AREA OF BIG CIRCLE: pi*R*R
R=(a*b*c)/4*sqrt((s-a)*(s-b)*(s-c));
then calculate area of yellow by subtracting;
Hope it will work.
Re: 11152 - Colorful Flowers
Posted: Fri Mar 30, 2012 9:25 pm
by zevrap
can't figure out the problem , my code seems to pass the sample io with the problem and also sample ios in this thread ...
Code: Select all
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define PI 3.14159265
double triangle_area(double a,double b,double c)
{
double s=(a+b+c)/2.0;
return sqrt(s*(s-a)*(s-b)*(s-c));
}
int main()
{
double a,b,c,area;
while(scanf("%lf%lf%lf",&a,&b,&c)!=EOF)
{
area=triangle_area(a,b,c);
printf("%.4lf ",PI*(a*b*c/4.0/area)*(a*b*c/4.0/area)-area);
printf("%.4lf ",area-PI*(2.0*area/(a+b+c))*(2.0*area/(a+b+c)));
printf("%.4lf\n",PI*(2.0*area/(a+b+c))*(2.0*area/(a+b+c)));
}
return 0;
}
can anybody help ?
thanks in advance ....

Re: 11152 - Colorful Flowers
Posted: Mon Apr 02, 2012 8:55 pm
by brianfry713
Use M_PI instead, your PI constant isn't precise enough.
Re: 11152 - Colorful Flowers
Posted: Tue May 01, 2012 2:12 am
by yongwhan
make sure the following things:
1. multiple test cases
2. precision for PI -- just use 2*acos(0)
3. output right amount (4) precision after the decimal point.
Re: 11152 - Colorful Flowers
Posted: Sun Jan 13, 2013 6:27 am
by Elsterrier
anything wrong with my code?
Re: 11152 - Colorful Flowers
Posted: Sun Jan 13, 2013 9:44 pm
by brianfry713
change line 10 to:
p=(a+b+c)/2.0;
Re: 11152 - Colorful Flowers
Posted: Thu Jan 17, 2013 2:09 am
by Elsterrier
Thanks, got AC now
Re: 11152 - Colorful Flowers
Posted: Tue Mar 26, 2013 5:40 pm
by raj
help.............

why Wrong Answer...
Code: Select all
import java.io.*;
import java.util.*;
public class Main{
public static void main(String [] args)throws IOException{
BufferedReader k = new BufferedReader(new InputStreamReader(System.in));
PrintWriter z = new PrintWriter(System.out);
String line;
double PI = Math.acos(-1);
while((line = k.readLine())!=null)
{
int a,b,c;
StringTokenizer s = new StringTokenizer(line);
int w = Integer.valueOf(s.nextToken());
int x = Integer.valueOf(s.nextToken());
int y = Integer.valueOf(s.nextToken());
int max = Math.max(w,x);
c = Math.max(max,y);
int min = Math.min(w,x);
a = Math.min(min,y);
if(w!=c && w!=a)
{
b = w;
}
else if(x!=c && x!=a)
{
b = x;
}
else
{
b = y;
}
double roses = PI*(b/4.0)*(b/4.0);
double triangle = 0.5*a*b - roses;
double circle = (PI*(c/2.0)*(c/2.0)) - (0.5*a*b);
String cir = String.format("%.4f",circle);
String tri = String.format("%.4f",triangle);
String ros = String.format("%.4f",roses);
z.println(cir+" "+tri+" "+ros);
}
z.flush();
}
}
Re:
Posted: Wed Mar 27, 2013 1:42 am
by brianfry713
mmonish wrote:ur formula for the area of the circle is not correct.
try this cases
Code: Select all
15 16 17
4 6 8
25 32 41
My AC output
160.2326 44.0084 65.9734
41.9976 6.3830 5.2360
920.8626 190.6515 209.2685
Try to figure out the correct formula for the radious of the circle.
Hope this helps.
Re: 11152 - Colorful Flowers
Posted: Sat Dec 14, 2013 7:14 pm
by B_sayem
Why WA .help me to find error.Thanks yousuf
Re: 11152 - Colorful Flowers
Posted: Sat Dec 14, 2013 9:25 pm
by Yousuf
Use double instead of float. Its better to use double for floating point calculation. double gives much accurate result. Hope you will get AC

11152 - Colourful Flowers
Posted: Thu Aug 14, 2014 4:23 pm
by ehsanulbigboss
Re: 11152 - Colourful Flowers
Posted: Thu Aug 14, 2014 11:59 pm
by brianfry713
Next time post in the existing thread.
Try using M_PI instead of your PI constant.
Re: 11152 - Colourful Flowers
Posted: Tue Nov 25, 2014 9:37 pm
by sejan
why getting WA????
Code: Select all
#include <stdio.h>
#include <math.h>
int main()
{
int a,b,c;
double pi=acos(-1);
while(scanf("%d%d%d",&a,&b,&c)!=EOF)
{
double pm=(a+b+c)/2;
double ta=sqrt(pm*(pm-a)*(pm-b)*(pm-c));
double R=((a*b*c)/4)/ta;
double sfa= (pi*R*R)-ta;
double icr= ta/pm;
double ica= pi*icr*icr;
double va= ta-ica;
printf("%.4lf %.4lf %.4lf\n",sfa,va,ica);
}
return 0;
}