結果

問題 No.94 圏外です。(EASY)
ユーザー asugen0402asugen0402
提出日時 2019-01-28 10:52:27
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 3,335 bytes
コンパイル時間 271 ms
コンパイル使用メモリ 34,560 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 05:57:37
合計ジャッジ時間 1,245 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_POINT_MAX		1000									// 最大中継局数
#define D_POINT_LEN2	100										// 通信距離の2乗

// 内部構造体 - 中継局情報
typedef struct Point {
	int miX, miY;												// 位置
	int miGNo;													// グループ番号 0~
} Point;

// 内部変数
static FILE *szpFpI;											// 入力
static Point sz1Point[D_POINT_MAX];								// 中継局
static int siPCnt;												// 中継局数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// グループ番号 - 取得
int
fGetGNo(
	int piPNo					// <I> 中継局 0~
)
{
	// 自分が代表
	if (sz1Point[piPNo].miGNo == piPNo) {
		return piPNo;
	}

	// 下位へ
	sz1Point[piPNo].miGNo = fGetGNo(sz1Point[piPNo].miGNo);

	return sz1Point[piPNo].miGNo;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1~
)
{
	int i, j;
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 中継局数 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &siPCnt);

	// 中継局 - 取得
	for (i = 0; i < siPCnt; i++) {
		fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
		sscanf(lc1Buf, "%d%d", &sz1Point[i].miX, &sz1Point[i].miY);

		// グループ番号 - セット
		sz1Point[i].miGNo = i;
		for (j = 0; j < i; j++) {

			// 距離の2乗
			int liX = sz1Point[i].miX - sz1Point[j].miX;
			int liY = sz1Point[i].miY - sz1Point[j].miY;
			int liLen2 = liX * liX + liY * liY;
			if (liLen2 > D_POINT_LEN2) {
				continue;
			}

			// グループ番号 - 更新
			sz1Point[i].miGNo = j;
			break;
		}
	}

	// 最大通信距離 - 取得
	double ldMax = -1.0;
	for (i = 0; i < siPCnt; i++) {
		int liGNo1 = fGetGNo(i);

		for (j = i + 1; j < siPCnt; j++) {
			int liGNo2 = fGetGNo(j);

			// 同一グループのみ
			if (liGNo1 != liGNo2) {
				continue;
			}

			// 距離
			double ldX = sz1Point[i].miX - sz1Point[j].miX;
			double ldY = sz1Point[i].miY - sz1Point[j].miY;
			double ldLen = sqrt(ldX * ldX + ldY * ldY);

			// 最大通信距離 - 更新
			if (ldMax < ldLen) {
				ldMax = ldLen;
			}
		}
	}

	// 無線機での距離
	if (ldMax < 0.0) {
		if (siPCnt < 1) {
			ldMax = 1.0;
		}
		else {
			ldMax = 2.0;
		}
	}
	else {
		ldMax += 2.0;
	}

	// 結果 - セット
	sprintf(lc1Out, "%.7lf\n", ldMax);

	// 結果 - 表示
#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", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}

0