## 10991 - Region

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

Moderator: Board moderators

sclo
Guru
Posts: 519
Joined: Mon Jan 23, 2006 10:45 pm
Location: Vancouver, BC, Canada
Contact:
you'll need to somehow use cosine theorem for this problem.

solon_aguiar
New poster
Posts: 7
Joined: Mon Jun 08, 2009 11:16 pm

### Re: 10991 - Region

Hello guys. I've read all posts and done exclaty what I think you said, but I still can't figure out what's wrong with my code. I'd be glad you someone could help me (variable names are in Porguese, but I still think you guys can figure out what I'm doing. Sorry for that).

Code: Select all

``````import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.Locale;

public class Region {

public static void main(String[] args) throws IOException {

BufferedReader entradas = new BufferedReader(new InputStreamReader(
System.in));
StringBuilder saida = new StringBuilder();
DecimalFormat formato = new DecimalFormat("0.000000");

formato.setDecimalFormatSymbols(new DecimalFormatSymbols(Locale.US));

int casos = Integer.parseInt(entradas.readLine().trim());

for (int i = 0; i < casos; i++) {

String[] valores = entradas.readLine().trim().split("\\s+");

double raioUm = Double.parseDouble(valores[0]);
double raioDois = Double.parseDouble(valores[1]);
double raioTres = Double.parseDouble(valores[2]);

double ladoUm = raioUm + raioDois;
double ladoDois = raioTres + raioDois;
double ladoTres = raioUm + raioTres;

double semiPerimetro = (ladoUm + ladoDois + ladoTres)/2;

double areaTriangulo = Math.sqrt((semiPerimetro
* (semiPerimetro - ladoUm) * (semiPerimetro - ladoDois)
* (semiPerimetro - ladoTres)));

double cosA = Math.cos((Math.pow(ladoTres, 2) + Math.pow(ladoUm, 2)
- Math.pow(ladoDois, 2)) / (2 * ladoTres * ladoUm));

double cosB = Math.cos((Math.pow(ladoDois, 2) + Math.pow(ladoUm, 2)
- Math.pow(ladoTres, 2)) / (2 * ladoDois * ladoUm));

double cosC = Math.cos((Math.pow(ladoDois, 2) + Math.pow(ladoTres, 2)
- Math.pow(ladoUm, 2)) / (2 * ladoDois * ladoTres));

double a = Math.acos(cosA);
double b = Math.acos(cosB);
double c = Math.acos(cosC);

double areaSetorUm = 0.5 * a * Math.pow(raioUm, 2);
double areaSetorDois = 0.5 * b * Math.pow(raioDois, 2);
double areaSetorTres = 0.5 * c * Math.pow(raioTres, 2);

double areaSetores = areaSetorUm + areaSetorDois + areaSetorTres;

System.out.println(formato.format(areaTriangulo - areaSetores));
}
}
}
``````

Thanks in advance

DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

### Re: 10991 - Region

I don't think this problem asks too much on precision since I got A.C. without any checking. Just try to apply those formulas and implement it directly.
Have you ever...
• Wanted to work at best companies?
• Struggled with interview problems that could be solved in 15 minutes?
• Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.