1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| #include <stdio.h> #include <math.h>
#define MAX (20) int nN; struct Point { char szLabel[5]; int x; int y; }; Point points[MAX];
bool IsOneLine(int nOne, int nTwo, int nThree) { int nA = points[nTwo].x - points[nOne].x; int nB = points[nTwo].y - points[nOne].y; int nC = points[nThree].x - points[nOne].x; int nD = points[nThree].y - points[nOne].y;
return (nA * nD == nB * nC); }
bool IsSameSide(int nBeg, int nEnd, int nOne, int nTwo) { int nA = points[nBeg].x - points[nEnd].x; int nB = points[nBeg].y - points[nEnd].y;
int nRes = (nB * (points[nOne].x - points[nBeg].x) - nA * (points[nOne].y - points[nBeg].y)) * (nB * (points[nTwo].x - points[nBeg].x) - nA * (points[nTwo].y - points[nBeg].y));
if (nRes > 0) { } return nRes > 0; }
bool PointOutTriangle(int nOne, int nTwo, int nThree, int nPoint) { if (IsOneLine(nOne, nTwo, nPoint)) { if ((points[nOne].x - points[nPoint].x) * (points[nTwo].x - points[nPoint].x) <= 0) { return false; } } else if (IsOneLine(nOne, nThree, nPoint)) { if ((points[nOne].x - points[nPoint].x) * (points[nThree].x - points[nPoint].x) <= 0) { return false; } } else if (IsOneLine(nTwo, nThree, nPoint)) { if ((points[nTwo].x - points[nPoint].x) * (points[nThree].x - points[nPoint].x) <= 0) { return false; } }
return !(IsSameSide(nOne, nTwo, nThree, nPoint) IsSameSide(nOne, nThree, nTwo, nPoint) IsSameSide(nTwo, nThree, nOne, nPoint)); }
bool IsValid(int nOne, int nTwo, int nThree) { if (IsOneLine(nOne, nTwo, nThree)) { return false; }
for (int i = 0; i < nN; ++i) { if (i == nOne || i == nTwo || i == nThree) { continue; }
if (!PointOutTriangle(nOne, nTwo, nThree, i)) { return false; } }
return true; }
double GetArea(int nOne, int nTwo, int nThree) { return 0.5 * fabs((points[nThree].y - points[nOne].y) * (points[nTwo].x - points[nOne].x) - (points[nTwo].y - points[nOne].y) * (points[nThree].x - points[nOne].x)); }
int main() { while (scanf("%d", &nN), nN) { for (int i = 0; i < nN; ++i) { scanf("%s%d%d", points[i].szLabel, &points[i].x, &points[i].y); }
double fMaxArea = 0.0; int nI = -1, nJ = -1, nK = -1; for (int i = 0; i < nN - 2; ++i) { for (int j = i + 1; j < nN - 1; ++j) { for (int k = j + 1; k < nN; ++k) { if (IsValid(i, j, k)) { double fArea = GetArea(i, j, k); if (fArea > fMaxArea) { nI = i; nJ = j; nK = k; fMaxArea = fArea; } } } } } printf("%s%s%s\n", points[nI].szLabel, points[nJ].szLabel, points[nK].szLabel); }
return 0; }
|