結果

問題 No.55 正方形を描くだけの簡単なお仕事です。
ユーザー HiroakiSoftware
提出日時 2014-11-03 01:51:03
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 2,481 bytes
コンパイル時間 506 ms
コンパイル使用メモリ 23,168 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-30 16:44:05
合計ジャッジ時間 1,290 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 18 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:18:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |         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(Ver2)
※このコードだとケースによってひし形になる可能性がある
作成者:ヒロソフ
*/

#include <stdio.h>

struct  Point {
	double X;
	double Y;
};


int main(void) {
	Point inPoint[3];

	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];
	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);

	if (Length[0] == Length[1]) {
		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);

		if (Length[0] == Length[1]) {
			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);

			if (Length[0] == Length[1]) {
				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");
			}
		}
	}

	return 0;
}
0