#include #include #include #include #include #include #include // 内部定数 #define D_POINT_CNT 5 // 座標数 #define D_ROUND_POS 7 // 四捨五入位置 // 内部構造体 - 座標情報 typedef struct Point { double mdX, mdY; // 座標 double mdR; // 角度 } Point; // 内部変数 static FILE *szpFpI; // 入力 static Point sz1Point[D_POINT_CNT + 5]; // 座標 // 内部変数 - テスト用 #ifdef D_TEST static int siRes; static FILE *szpFpA; static int siTNo; #endif // ソート関数 - 角度昇順 int fSortFnc( const void *pzpVal1 // 値1 , const void *pzpVal2 // 値2 ) { Point *lzpVal1 = (Point *)pzpVal1; Point *lzpVal2 = (Point *)pzpVal2; // 角度昇順 if (lzpVal1->mdR > lzpVal2->mdR) { return 1; } else if (lzpVal1->mdR < lzpVal2->mdR) { return -1; } return 0; } // double値の四捨五入(double) double fRoundD( double pdVal // 四捨五入する値 , int piPos // 四捨五入する位置 1~ ) { // 乗算値 double ldRate = pow(10.0, (double)(piPos - 1)); // 乗算 pdVal *= ldRate; // 整数部分 int liVal = (int)pdVal; pdVal -= liVal; // 四捨五入 if (pdVal > 0.0) { pdVal += 0.5; } else if (pdVal < 0.0) { pdVal -= 0.5; } liVal += (int)pdVal; // 除算 return (double)liVal / ldRate; } // 実行メイン int fMain( ) { int i; char lc1Buf[1024]; // 座標 - 取得 for (i = 0; i < D_POINT_CNT; i++) { fgets(lc1Buf, sizeof(lc1Buf), szpFpI); sscanf(lc1Buf, "%lf%lf", &sz1Point[i].mdX, &sz1Point[i].mdY); } // 中心座標 - 取得 double ldCx = 0.0; double ldCy = 0.0; for (i = 0; i < D_POINT_CNT; i++) { ldCx += sz1Point[i].mdX; ldCy += sz1Point[i].mdY; } ldCx /= 5.0; ldCy /= 5.0; // 中心座標 - 原点へ for (i = 0; i < D_POINT_CNT; i++) { sz1Point[i].mdX -= ldCx; sz1Point[i].mdY -= ldCy; } // 角度 - 取得 for (i = 0; i < D_POINT_CNT; i++) { sz1Point[i].mdR = atan2((double)sz1Point[i].mdY, (double)sz1Point[i].mdX); } // 座標 - ソート qsort(sz1Point, D_POINT_CNT, sizeof(Point), fSortFnc); // 2座標 - コピー memcpy(&sz1Point[D_POINT_CNT], &sz1Point[0], sizeof(Point)); memcpy(&sz1Point[D_POINT_CNT + 1], &sz1Point[1], sizeof(Point)); // 中心座標からの距離 - 判定 for (i = 1; i <= D_POINT_CNT; i++) { // 3辺の長さ double ldLen1 = sqrt(sz1Point[i - 1].mdX * sz1Point[i - 1].mdX + sz1Point[i - 1].mdY * sz1Point[i - 1].mdY); double ldLen2 = sqrt(sz1Point[i + 1].mdX * sz1Point[i + 1].mdX + sz1Point[i + 1].mdY * sz1Point[i + 1].mdY); double ldX = sz1Point[i + 1].mdX - sz1Point[i - 1].mdX; double ldY = sz1Point[i + 1].mdY - sz1Point[i - 1].mdY; double ldLen3 = sqrt(ldX * ldX + ldY * ldY); // 面積 double ldS = (ldLen1 + ldLen2 + ldLen3) / 2.0; double ldArea = sqrt(ldS * (ldS - ldLen1) * (ldS - ldLen2) * (ldS - ldLen3)); // 中心座標と各線分の距離 double ldLenL = ldArea * 2.0 / ldLen3; ldLenL = fRoundD(ldLenL, D_ROUND_POS); // 中心座標と各座標の距離 double ldLenP = sqrt(sz1Point[i].mdX * sz1Point[i].mdX + sz1Point[i].mdY * sz1Point[i].mdY); ldLenP = fRoundD(ldLenP, D_ROUND_POS); if (ldLenP <= ldLenL) { return -1; } } return 0; } // 1回実行 int fOne( ) { char lc1Buf[1024], lc1Out[1024]; // 入力 - セット #ifdef D_TEST sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo); szpFpI = fopen(lc1Buf, "r"); sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo); szpFpA = fopen(lc1Buf, "r"); siRes = 0; #else szpFpI = stdin; #endif // 実行メイン int liRet = fMain(); // 結果 - セット if (liRet == 0) { sprintf(lc1Out, "YES\n"); } else { sprintf(lc1Out, "NO\n"); } // 結果 - 表示 #ifdef D_TEST fgets(lc1Buf, sizeof(lc1Buf), szpFpA); if (strcmp(lc1Buf, lc1Out)) { siRes = -1; } #else printf("%s", lc1Out); #endif // 残データ有無 #ifdef D_TEST lc1Buf[0] = '\0'; fgets(lc1Buf, sizeof(lc1Buf), szpFpA); if (strcmp(lc1Buf, "")) { siRes = -1; } #endif // テストファイルクローズ #ifdef D_TEST fclose(szpFpI); fclose(szpFpA); #endif // テスト結果 #ifdef D_TEST if (siRes == 0) { printf("OK %d\n", siTNo); } else { printf("NG %d\n", siTNo); } #endif return 0; } // プログラム開始 int main() { #ifdef D_TEST int i; for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) { siTNo = i; fOne(); } #else fOne(0); #endif return 0; }