結果

問題 No.306 さいたま2008
ユーザー berlysiaberlysia
提出日時 2015-12-01 19:24:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,633 bytes
コンパイル時間 1,193 ms
コンパイル使用メモリ 146,516 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 06:33:50
合計ジャッジ時間 2,091 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<n;++i)
#define Rep(i,n) for(int i=1;i<=n;++i)
#define rrep(i,n) for(int i=n-1;0<=i;--i)
#define rRep(i,n) for(int i=n;0<i;--i)
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define EPS 1e-8
#define INF 1e8

typedef double Real;
typedef int Int;
typedef vector<Int> vi;
typedef vector<vector<Int> > vvi;
typedef pair<Int,Int> pii;

class Point{
public:
  Real x, y;

  Point() : x(0), y(0) {}
  Point(Real _x, Real _y) : x(_x), y(_y) {}
  Point(const Point &p) : x(p.x), y(p.y) {}
  Point operator+ (const Point &p) const{return Point(x + p.x, y + p.y);}
  Point operator- (const Point &p) const{return Point(x - p.x, y - p.y);}
  Point operator* (Real r) const{return Point(x * r, y * r); }
  bool operator< (const Point &p) const{return x != p.x ? x < p.x : y < p.y;}
  bool operator== (const Point &p) const{return x == p.x && y == p.y;}
  Real norm() const{return x * x + y * y; }
  Real abs() const{return sqrt(norm()); }
  Real dot(const Point &p) const{return x * p.x + y * p.y;}
  Real cross(const Point &p) const{return x * p.y - y * p.x;}
};

typedef Point Vector;

class Segment{
public:
  Point p1, p2;
  Segment() : p1(), p2(){}
  Segment(const Point &_p1, const Point &_p2) : p1(_p1), p2(_p2) {}
  Segment(const Segment &s) : p1(s.p1), p2(s.p2) {}
};

typedef Segment Line;

Point project(const Segment &s, const Point &p){
  Vector base = s.p2 - s.p1;
  Real r = (p-s.p1).dot(base) / base.norm();
  return s.p1 + base * r;
}

Point reflect(const Segment &s, const Point &p){
  return p + (project(s, p) - p) * 2.0;
}

Point getCrossPoint(const Segment &s1, const Segment &s2) {
  Vector base = s2.p2 - s2.p1;
  Real d1 = abs(base.cross(s1.p1 - s2.p1));
  Real d2 = abs(base.cross(s1.p2 - s2.p1));
  Real t = d1 / (d1 + d2);
  return s1.p1 + (s1.p2 - s1.p1) * t;
}

const vi dy = {-1, 0, 1, 0}, dx = {0, -1, 0, 1};

template <typename K, typename V> ostream& operator<< (ostream& out, const pair<K, V>& p) {
  out << '(' << p.first << ", " << p.second << ')';
  return out;
}

template <typename T> ostream& operator<< (ostream& out, const vector<T>& v) {
  out << '[';
  rep(i, v.size()) out << v[i] << ",";
  out << "\b], " << v.size();
  return out;
}

void solve(){
  Real ax,ay,bx,by;
  cin >> ax >> ay >> bx >> by;

  Point a(ax, ay), b(bx, by);

  cout << getCrossPoint(Segment(a,b), Segment(Point(), Point(0.0, 1024.0))).y << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(9);

  solve();

  return 0;
}
0