結果
| 問題 |
No.1624 三角形の反射
|
| コンテスト | |
| ユーザー |
startcpp
|
| 提出日時 | 2021-07-23 22:06:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 228 ms / 2,000 ms |
| コード長 | 3,007 bytes |
| コンパイル時間 | 964 ms |
| コンパイル使用メモリ | 99,392 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-18 17:50:31 |
| 合計ジャッジ時間 | 2,572 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
ソースコード
#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++) {
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;
}
startcpp