結果
| 問題 |
No.199 星を描こう
|
| コンテスト | |
| ユーザー |
asugen0402
|
| 提出日時 | 2019-03-13 13:56:42 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,507 bytes |
| コンパイル時間 | 452 ms |
| コンパイル使用メモリ | 32,896 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-23 15:59:41 |
| 合計ジャッジ時間 | 1,264 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 WA * 10 |
ソースコード
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// 内部定数
#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 // <I> 値1
, const void *pzpVal2 // <I> 値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 // <I> 四捨五入する値
, int piPos // <I> 四捨五入する位置 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;
}
asugen0402