結果

問題 No.1624 三角形の反射
ユーザー startcppstartcpp
提出日時 2021-07-23 22:03:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,018 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 98,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 22:07:06
合計ジャッジ時間 2,950 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 35 ms
4,380 KB
testcase_04 WA -
testcase_05 AC 9 ms
4,384 KB
testcase_06 AC 4 ms
4,384 KB
testcase_07 AC 89 ms
4,380 KB
testcase_08 AC 18 ms
4,380 KB
testcase_09 AC 30 ms
4,380 KB
testcase_10 WA -
testcase_11 AC 90 ms
4,384 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 26 ms
4,380 KB
testcase_14 AC 5 ms
4,380 KB
testcase_15 AC 17 ms
4,380 KB
testcase_16 AC 22 ms
4,380 KB
testcase_17 AC 5 ms
4,380 KB
testcase_18 AC 18 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 10 ms
4,380 KB
testcase_24 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <tuple>
#include <complex>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;
typedef complex<double> P;

namespace std {
  bool operator < (const P& a, const P& b) {
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
  P operator + (const P&a, const P & b) {
	  return P(a.real() + b.real(), a.imag() + b.imag());
  }
}

const double EPS = 1e-9;

struct L : public vector<P> {
  L() {}
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}

double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
         ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l[1] - l[0], m[1] - m[0]);
  double B = cross(l[1] - l[0], l[1] - m[0]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

void resize(P &p) {
	double length = 4;
	p /= abs(p);
	p *= length;
}

signed main() {
	double a;
	cin >> a;

	P now = P(0, 0);
	P dir = P(1, a);
	resize(dir);
	//cout << "dir = [" << dir.real() / 4 << ", " << dir.imag() / 4 << "]" << endl;

	P ps[3] = {P(0, 0), P(1, 0), P(0, 1)};
	L ls[3];
	L ab = L(P(0, 0), P(1, 0));
	L bc = L(P(1, 0), P(0, 1));
	L ca = L(P(0, 1), P(0, 0));
	ls[0] = ab; ls[1] = bc; ls[2] = ca;

	string pointName[3] = {"A", "B", "C"};

	int i, j;
	int ngId = 0;
	for (i = 0; i < 1000000; i++) {
		L l = L(now, now + dir);
		for (j = 0; j < 3; j++) {
			if (i == 0 && j != 1) continue;
			if (j == ngId) continue;
			if (intersectSS(l, ls[j])) {
				break;
			}
		}
		assert(j < 3);
		ngId = j;	//次はj番目の辺を見ない
		P cp = crosspoint(l, ls[j]);
		//cout << "i = " << i << ", j = " << j << ", cp = [" << cp.real() << ", " << cp.imag() << "]" << endl;

		for (j = 0; j < 3; j++) {
			if (abs(cp - ps[j]) < EPS) {
				break;
			}
		}
		if (j < 3) {
			cout << pointName[j] << " " << i << endl;
			return 0;
		}

		P ndir;
		if (ngId == 0) {
			ndir = P(dir.real(), -dir.imag());
		}
		else if (ngId == 2) {
			ndir = P(-dir.real(), dir.imag());
		}
		else {
			ndir = P(-dir.imag(), -dir.real());
		}
		now = cp;
		dir = ndir;
		//cout << "ndir = [" << ndir.real() / 4 << ", " << ndir.imag() / 4 << "]" << endl;
	}

	cout << -1 << endl;
	return 0;
}
0