11152 - Colourful Flowers

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

Moderator: Board moderators

Scottathon
New poster
Posts: 9
Joined: Fri Nov 03, 2006 1:25 am
Location: Canada

Post by Scottathon » Sat Oct 20, 2007 3:15 am

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.

turcse143
Learning poster
Posts: 81
Joined: Wed May 09, 2007 9:59 pm
Location: (CSE,DU) Dhaka,Bangladesh

Post by turcse143 » Wed Dec 19, 2007 5:00 pm

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.

zevrap
New poster
Posts: 1
Joined: Fri Mar 30, 2012 9:14 pm

Re: 11152 - Colorful Flowers

Post by zevrap » Fri Mar 30, 2012 9:25 pm

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 .... :)

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11152 - Colorful Flowers

Post by brianfry713 » Mon Apr 02, 2012 8:55 pm

Use M_PI instead, your PI constant isn't precise enough.
Check input and AC output for thousands of problems on uDebug!

yongwhan
New poster
Posts: 1
Joined: Tue May 01, 2012 2:10 am

Re: 11152 - Colorful Flowers

Post by yongwhan » Tue May 01, 2012 2:12 am

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.

Elsterrier
New poster
Posts: 3
Joined: Fri Jan 11, 2013 2:58 pm

Re: 11152 - Colorful Flowers

Post by Elsterrier » Sun Jan 13, 2013 6:27 am

anything wrong with my code?

Code: Select all

Got AC
Last edited by Elsterrier on Thu Jan 17, 2013 2:09 am, edited 1 time in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11152 - Colorful Flowers

Post by brianfry713 » Sun Jan 13, 2013 9:44 pm

change line 10 to:
p=(a+b+c)/2.0;
Check input and AC output for thousands of problems on uDebug!

Elsterrier
New poster
Posts: 3
Joined: Fri Jan 11, 2013 2:58 pm

Re: 11152 - Colorful Flowers

Post by Elsterrier » Thu Jan 17, 2013 2:09 am

Thanks, got AC now

raj
Learning poster
Posts: 78
Joined: Fri Feb 15, 2013 5:39 pm

Re: 11152 - Colorful Flowers

Post by raj » Tue Mar 26, 2013 5:40 pm

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

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re:

Post by brianfry713 » Wed Mar 27, 2013 1:42 am

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.
Check input and AC output for thousands of problems on uDebug!

B_sayem
New poster
Posts: 7
Joined: Wed Dec 11, 2013 7:57 pm

Re: 11152 - Colorful Flowers

Post by B_sayem » Sat Dec 14, 2013 7:14 pm

Why WA .help me to find error.Thanks yousuf

Code: Select all

Remove after AC.Thanks  :D 
Last edited by B_sayem on Sat Dec 14, 2013 10:09 pm, edited 3 times in total.

Yousuf
New poster
Posts: 13
Joined: Thu Jun 09, 2011 8:22 am

Re: 11152 - Colorful Flowers

Post by Yousuf » Sat Dec 14, 2013 9:25 pm

Use double instead of float. Its better to use double for floating point calculation. double gives much accurate result. Hope you will get AC :D

ehsanulbigboss
New poster
Posts: 32
Joined: Tue Jul 22, 2014 1:17 am

11152 - Colourful Flowers

Post by ehsanulbigboss » Thu Aug 14, 2014 4:23 pm

:( :-? :wink: :) :D
Last edited by ehsanulbigboss on Thu Feb 05, 2015 10:03 pm, edited 2 times in total.

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11152 - Colourful Flowers

Post by brianfry713 » Thu Aug 14, 2014 11:59 pm

Next time post in the existing thread.
Try using M_PI instead of your PI constant.
Check input and AC output for thousands of problems on uDebug!

sejan
New poster
Posts: 6
Joined: Sun Nov 16, 2014 8:32 pm

Re: 11152 - Colourful Flowers

Post by sejan » Tue Nov 25, 2014 9:37 pm

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

Post Reply

Return to “Volume 111 (11100-11199)”