QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#622867 | #7906. Almost Convex | wpoem | WA | 0ms | 3828kb | C++20 | 5.1kb | 2024-10-09 08:03:29 | 2024-10-09 08:03:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define qmx(a, b) a < b ? b : a
#define qmn(a, b) a > b ? b : a
#define ll long long
#define i64 long long
#define fr first
#define se second
template <class T, class G>
struct BaseVector2 {
T x, y;
constexpr BaseVector2()
: BaseVector2(T {}, T {})
{
}
constexpr BaseVector2(T x, T y)
: x { x }
, y { y }
{
}
// 运算
constexpr BaseVector2 operator+(BaseVector2 a) const
{
return BaseVector2(x + a.x, y + a.y);
}
constexpr BaseVector2 operator-(BaseVector2 a) const
{
return BaseVector2(x - a.x, y - a.y);
}
constexpr BaseVector2 operator-() const
{
return BaseVector2(-x, -y);
}
constexpr G operator*(BaseVector2 a) const
{
return G(x) * a.x + G(y) * a.y;
}
constexpr G operator%(BaseVector2 a) const
{
return G(x) * a.y - G(y) * a.x;
}
constexpr BaseVector2 rotate() const
{
return BaseVector2(-y, x);
}
template <class Float>
constexpr BaseVector2 rotate(Float theta) const
{
BaseVector2 b(cosl(theta), sinl(theta));
return BaseVector2(x * b.x - y * b.y,
x * b.y + y * b.x);
}
constexpr friend BaseVector2 operator*(const T& a, BaseVector2 b)
{
return BaseVector2(a * b.x, a * b.y);
}
// 比较
constexpr bool operator<(BaseVector2 a) const
{
if (x == a.x) {
return y < a.y;
}
return x < a.x;
}
constexpr bool operator>(BaseVector2 a) const
{
if (x == a.x) {
return y > a.y;
}
return x > a.x;
}
constexpr bool operator<=(BaseVector2 a) const
{
if (x == a.x) {
return y <= a.y;
}
return x <= a.x;
}
constexpr bool operator>=(BaseVector2 a) const
{
if (x == a.x) {
return y >= a.y;
}
return x >= a.x;
}
constexpr bool operator==(BaseVector2 a) const
{
return x == a.x and y == a.y;
}
constexpr bool operator!=(BaseVector2 a) const
{
return x != a.x or y != a.y;
}
// 输入输出
friend std::istream& operator>>(std::istream& in, BaseVector2& p)
{
return in >> p.x >> p.y;
}
friend std::ostream& operator<<(std::ostream& ot, BaseVector2 p)
{
return ot << '(' << p.x << ", " << p.y << ')';
}
};
template <class T, class G>
G dis2(BaseVector2<T, G> a, BaseVector2<T, G> b = BaseVector2<T, G>(0, 0))
{
BaseVector2<T, G> p = a - b;
return p * p;
}
template <class T, class G>
auto dis(BaseVector2<T, G> a, BaseVector2<T, G> b = BaseVector2<T, G>(0, 0))
{
return sqrtl(dis2(a, b));
}
template <class T, class G>
int sgn(BaseVector2<T, G> p)
{
if (p.x < 0 or p.x == 0 and p.y > 0) {
return 1;
} else
return 0;
// 以41象限为先
}
template <class Vector>
bool polarCmp(Vector p, Vector q)
{
if (sgn(p) == sgn(q)) {
if (p % q == 0) {
return dis2(p) < dis2(q);
} else {
return p % q > 0;
}
} else {
return sgn(p) < sgn(q);
}
}
using Point = BaseVector2<int, int>;
using Vector = Point;
using PS = std::vector<Point>;
PS convex(PS ps)
{
std::sort(ps.begin(), ps.end());
ps.erase(std::unique(ps.begin(), ps.end()), ps.end());
const int n = ps.size();
if (n <= 1) {
return ps;
}
PS hull(n + 1);
int k = -1;
for (int i = 0; i < n; i++) {
while (k >= 1 and (hull[k] - hull[k - 1]) % (ps[i] - hull[k]) <= 0) {
k -= 1;
}
hull[++k] = ps[i];
}
for (int i = n - 2, m = k + 1; i >= 0; i--) {
while (k >= m and (hull[k] - hull[k - 1]) % (ps[i] - hull[k]) <= 0) {
k -= 1;
}
hull[++k] = ps[i];
}
assert(k >= 2);
return hull.resize(k), hull;
}
inline bool belong(Point x, PS& st)
{
for (auto pt : st) {
if (pt == x)
return true;
}
return false;
}
inline PS calculate(PS& st, Point o)
{
PS res;
for (auto pt : st) {
if (pt != o) {
res.push_back(pt - o);
}
}
return res;
}
int n, ans;
PS p, convex_p, dcp;
int main()
{
cin >> n;
p.resize(n);
for (int i = 0; i < n; i++)
cin >> p[i];
convex_p = convex(p);
ans = 1;
for (int i = 0; i < n; i++) {
// if(!belong(p[i], convex_p)){
dcp = calculate(p, p[i]);
sort(dcp.begin(), dcp.end(), polarCmp<Point>);
for (int j = 1; j < dcp.size(); j++) {
if (belong(dcp[j] + p[i], convex_p) && belong(dcp[j - 1] + p[i], convex_p)) {
ans++;
}
}
if (belong(dcp[dcp.size() - 1] + p[i], convex_p) && belong(dcp[0] + p[i], convex_p)) {
ans++;
}
} //
cout << ans;
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3828kb
input:
7 1 4 4 0 2 3 3 1 3 5 0 0 2 4
output:
13
result:
wrong answer 1st numbers differ - expected: '9', found: '13'