結果
| 問題 |
No.306 さいたま2008
|
| コンテスト | |
| ユーザー |
berlysia
|
| 提出日時 | 2015-12-01 19:24:24 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,633 bytes |
| コンパイル時間 | 1,507 ms |
| コンパイル使用メモリ | 159,324 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2025-02-14 12:11:18 |
| 合計ジャッジ時間 | 2,342 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 26 |
ソースコード
#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;
}
berlysia