結果
| 問題 |
No.199 星を描こう
|
| コンテスト | |
| ユーザー |
codershifth
|
| 提出日時 | 2016-01-10 22:22:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,050 bytes |
| コンパイル時間 | 1,703 ms |
| コンパイル使用メモリ | 166,644 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-30 03:45:53 |
| 合計ジャッジ時間 | 2,766 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 25 |
ソースコード
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int (i)=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define RANGE(vec) (vec).begin(),(vec).end()
using namespace std;
template<typename T>
struct Pt {
T x, y;
Pt(T x0, T y0) : x(x0), y(y0) {}
Pt() :x(0),y(0) {}
const Pt operator+(const Pt &other) const { return Pt(x+other.x, y+other.y); }
const Pt operator-(const Pt &other) const { return Pt(x-other.x, y-other.y); }
Pt &operator+=(const Pt &other) { x += other.x; y += other.y; return *this; }
Pt &operator-=(const Pt &other) { x -= other.x; y -= other.y; return *this; }
Pt operator*(double r) const { return Pt(x*r, y*r); }
bool operator<(const Pt &other) const { return (x < other.x)? true : ((x==other.x)? (y < other.y) : false); }
bool operator<=(const Pt &other) const { return (*this == other)? true : (*this < other); }
bool operator>(const Pt &other) const { return (other < *this); }
bool operator>=(const Pt &other) const { return (other <= *this); }
bool operator==(const Pt &other) const { return (x==other.x && y==other.y); }
bool operator!=(const Pt &other) const { return !(operator==(other)); }
double norm(void) const { return hypot(x, y); }
// class method
static double cross(const Pt &a, const Pt &b) { return ((double)a.y*b.x - (double)a.x*b.y); }
static double dot(const Pt &a, const Pt &b) { return (double)a.x*b.x+(double)a.y*b.y; }
friend std::ostream &operator<<(std::ostream &os, const Pt &p) {
os <<"("<<p.x<<","<<p.y<<")";
return os;
}
// O(n*log(n))
static std::vector<Pt> convex_hull(std::vector<Pt> &ps) {
std::sort(ps.begin(), ps.end());
int k = 0;
int n = ps.size();
vector<Pt> qs(2*n);
for (int i = 0; i < n; ++i)
{
while (k > 1 && cross(qs[k-1]-qs[k-2], ps[i]-qs[k-1]) <= 0)
--k;
qs[k++] = ps[i];
}
for (int i = n-2, t = k; i >= 0; --i)
{
while (k > t && cross(qs[k-1]-qs[k-2], ps[i]-qs[k-1]) <= 0)
--k;
qs[k++] = ps[i];
}
qs.resize(k-1);
qs.shrink_to_fit();
return std::move(qs);
}
};
template<typename T>
Pt<T> operator*(double r, const Pt<T> &p) { return p*r; }
typedef Pt<double> Ptd;
class WriteStars {
public:
void solve(void) {
vector<Ptd> verts(5);
REP(i,5)
{
int x,y;
cin>>x>>y;
verts[i] = Ptd(x,y);
}
auto pts = Ptd::convex_hull(verts);
if (pts.size() == 5)
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
};
#if 1
int main(int argc, char *argv[])
{
ios::sync_with_stdio(false);
auto obj = new WriteStars();
obj->solve();
delete obj;
return 0;
}
#endif
codershifth