UVA 194-triangle (geometry)

Source: Internet
Author: User

Topic Link: UVA 194-triangle


Note the corner of the two sides, and when the opposite edge of the connection is determined (that is, when solving with the sine theorem, there may be multiple solutions)


#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std; Const DOUBLE PI = 4 * atan (1); const double EPS = 1e-4;double a[6];void cornertocorner () {Double t = 0;for (int i = 1; I & Lt 6; i + = 2) {if (A[i] < 0) continue; t + = a[i];} for (int i = 1; i < 6; i + = 2) if (A[i] < 0) A[i] = pi-t;} Double Getangle (double A, double b, double c) {return ACOs ((A * a + b * b-c * c)/(2 * A * b)); void Edgetocorner () {for (int i = 1; i < 6; i + = 2) {if (A[i] < 0) A[i] = Getangle (a[(i+1)%6], a[(i+3)%6], a[i-1]); }}double Getedge (double x, double y, double c) {//printf ("%lf%lf\n", c, cos (c)); return sqrt (x * x + y * y-2 * x * y * C OS (c));} BOOL Judge () {for (int i = 0; i < 6; i++) if (A[i] < 0) return False;if (Fabs (a[1] + a[3] + a[5]-pi) > EPS) {RET Urn false;} if (A[0] + a[2] <= A[4] | | A[2] + a[4] <= A[0] | | A[0] + a[4] <= a[2]) {return false;} /*for (int i = 0; i < 6; i + = 2) printf ("%lf\n", a[i]/sin (A[i+1])); */for (int i = 0; i < 4; i + = 2) {//if (Fabs (a[i]/sin (a[i+1])-a[i+2]/sin (a[i+3)) > EPs)//printf ("%lf\n", fabs (A[i] * sin (a[i+3)-sin (a[i+1]) * a[i+2])); if (Fabs (a[i] * sin (a[i+3))-sin (a[i+1]) * a[i+2]) > EPS) return false;} return true;}  int main () {int cas;scanf ("%d", &cas), while (cas--) {int S = 0, C = 0, E = 0;bool flag = false;for (int i = 0; i < 6; i++) {scanf ("%lf", &a[i]), if (A[i] > 0) {s++;if (i&1) C++;else e++;}} if (S < 3) {printf ("Invalid input.\n"); continue;} while (S < 6) {int T = s;if (C = = 2) {Cornertocorner (); s++, C = 3;} if (E = = 3) {Edgetocorner (); S + = 3-c, C = 3;}  for (int i = 0; i < 6; i + = 2) {if (A[i] > 0 && a[i+1] > 0) {for (int j = 0; J < 6; J + = 2) {if ((a[j) > 0 && a[j+1] > 0) | | (A[j] < 0 && a[j+1] < 0)) Continue;if (A[j] < 0) {A[j] = a[i]/sin (a[i+1]) * sin (a[j+1]);//printf ("%LF%LF!!!!! \ n ", a[i]/sin (a[i+1]), a[j]/sin (a[j+1])); s++, e++; } else {if (a[i+1]< PI/2 && A[i] < A[j] && A[i] > a[j] * sin (a[i+1)) flag = true;double tmp = sin (a[i+1]) * A[j] /A[I];IF (tmp > 1 | | tmp < 0) continue; A[J+1] = ASIN (SIN (a[i+1]) * A[J]/a[i]); s++, C + +;}}}} if (E = = 2) {for (int i = 0; i < 6; i + = 2) {if (A[i] < 0 && a[i+1] > 0) {a[i] = Getedge (a[(i+2)%6], a[(i +4)%6], A[i + 1]); s++, e++;}}} if (T = = S) break;} printf ("%d\n", S);/*for (int i = 0; i < 6; i++) printf ("%lf%c", a[i], i = = 5? ' \ n ': '), */if (judge ()) {if (flag) printf ("More than one solution.\n"), else {for (int i = 0; i < 6; i++) printf ("%lf%c ", a[i], i = = 5? ' \ n ': ');}} elseprintf ("Invalid input.\n");} return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

UVA 194-triangle (geometry)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.