結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー HiroakiSoftwareHiroakiSoftware
提出日時 2014-11-03 02:08:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 5,000 ms
コード長 3,179 bytes
コンパイル時間 305 ms
コンパイル使用メモリ 23,424 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-26 22:04:54
合計ジャッジ時間 1,011 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 0 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 0 ms
5,376 KB
testcase_04 AC 0 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 0 ms
5,376 KB
testcase_07 AC 0 ms
5,376 KB
testcase_08 AC 0 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 0 ms
5,376 KB
testcase_11 AC 0 ms
5,376 KB
testcase_12 AC 0 ms
5,376 KB
testcase_13 AC 0 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 0 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 0 ms
5,376 KB
testcase_21 AC 0 ms
5,376 KB
testcase_22 AC 1 ms
5,376 KB
testcase_23 AC 0 ms
5,376 KB
testcase_24 AC 0 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void yukicoder55()’:
main.cpp:23:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   23 |         scanf("%lf %lf %lf %lf %lf %lf", &inPoint[0].X, &inPoint[0].Y, &inPoint[1].X, &inPoint[1].Y, &inPoint[2].X, &inPoint[2].Y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

/*
yukicoder No.55(Ver3)
作成者:ヒロソフ
*/

#include <stdio.h>

struct  Point {
	double X;
	double Y;
};

void yukicoder55(void);

int main(void) {
	yukicoder55();
	return 0;
}

void yukicoder55(void) {
	Point inPoint[3];
	bool bPossible;
	scanf("%lf %lf %lf %lf %lf %lf", &inPoint[0].X, &inPoint[0].Y, &inPoint[1].X, &inPoint[1].Y, &inPoint[2].X, &inPoint[2].Y);
	
	//1点目を中点と仮定する
	double Length[2] , hypLength;
	Point pt_Center;

	Length[0] = (inPoint[1].X - inPoint[0].X) * (inPoint[1].X - inPoint[0].X) + (inPoint[1].Y - inPoint[0].Y) * (inPoint[1].Y - inPoint[0].Y);
	Length[1] = (inPoint[2].X - inPoint[0].X) * (inPoint[2].X - inPoint[0].X) + (inPoint[2].Y - inPoint[0].Y) * (inPoint[2].Y - inPoint[0].Y);
	hypLength =  (inPoint[2].X - inPoint[1].X) * (inPoint[2].X - inPoint[1].X) + (inPoint[2].Y - inPoint[1].Y) * (inPoint[2].Y - inPoint[1].Y);

	bPossible = (Length[0] == Length[1]);
	bPossible &= ((Length[0] + Length[1]) == hypLength);
	if (bPossible) {
		pt_Center.X = (inPoint[1].X + inPoint[2].X) / 2;
		pt_Center.Y = (inPoint[1].Y + inPoint[2].Y) / 2;

		Point diff;
		diff.X = pt_Center.X - inPoint[0].X;
		diff.Y = pt_Center.Y - inPoint[0].Y;

		printf("%d %d\n", (int)(inPoint[0].X + 2 * diff.X), (int)(inPoint[0].Y + 2 * diff.Y));

	} else {
		//2点目を中心と仮定する
		Length[0] = (inPoint[0].X - inPoint[1].X) * (inPoint[0].X - inPoint[1].X) + (inPoint[0].Y - inPoint[1].Y) * (inPoint[0].Y - inPoint[1].Y);
		Length[1] = (inPoint[2].X - inPoint[1].X) * (inPoint[2].X - inPoint[1].X) + (inPoint[2].Y - inPoint[1].Y) * (inPoint[2].Y - inPoint[1].Y);

		hypLength = (inPoint[2].X - inPoint[0].X) * (inPoint[2].X - inPoint[0].X) + (inPoint[2].Y - inPoint[0].Y) * (inPoint[2].Y - inPoint[0].Y);
		bPossible = (Length[0] == Length[1]);
		bPossible &= ((Length[0] + Length[1]) == hypLength);
		if (bPossible) {
			pt_Center.X = (inPoint[0].X + inPoint[2].X) / 2;
			pt_Center.Y = (inPoint[0].Y + inPoint[2].Y) / 2;

			Point diff;
			diff.X = pt_Center.X - inPoint[1].X;
			diff.Y = pt_Center.Y - inPoint[1].Y;

			printf("%d %d\n", (int)(inPoint[1].X + 2 * diff.X), (int)(inPoint[1].Y + 2 * diff.Y));
		} else {

			//3点目を中心と仮定する
			Length[0] = (inPoint[0].X - inPoint[2].X) * (inPoint[0].X - inPoint[2].X) + (inPoint[0].Y - inPoint[2].Y) * (inPoint[0].Y - inPoint[2].Y);
			Length[1] = (inPoint[1].X - inPoint[2].X) * (inPoint[1].X - inPoint[2].X) + (inPoint[1].Y - inPoint[2].Y) * (inPoint[1].Y - inPoint[2].Y);
	
			hypLength = (inPoint[1].X - inPoint[0].X) * (inPoint[1].X - inPoint[0].X) + (inPoint[1].Y - inPoint[0].Y) * (inPoint[1].Y - inPoint[0].Y);
			bPossible = (Length[0] == Length[1]);
			bPossible &= ((Length[0] + Length[1]) == hypLength);

			if (bPossible) {
				pt_Center.X = (inPoint[0].X + inPoint[1].X) / 2;
				pt_Center.Y = (inPoint[0].Y + inPoint[1].Y) / 2;

				Point diff;
				diff.X = pt_Center.X - inPoint[2].X;
				diff.Y = pt_Center.Y - inPoint[2].Y;

				printf("%d %d\n", (int)(inPoint[2].X + 2 * diff.X), (int)(inPoint[2].Y + 2 * diff.Y));
			} else {
				printf("-1\n");
			}
		}
	}
}
0