QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625432 | #7906. Almost Convex | MiniLong | WA | 0ms | 4368kb | C++20 | 4.6kb | 2024-10-09 19:16:54 | 2024-10-09 19:16:55 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 2005;
const double eps = 1e-9;
int n;
bool vis[N];
struct Vector{
double x, y;
int id;
Vector(double _x = 0, double _y = 0){x = _x, y = _y, id = 0;}
Vector operator+(const Vector b)const{return Vector(x + b.x, y + b.y);}
Vector operator-(const Vector b)const{return Vector(x - b.x, y - b.y);}
double operator^(const Vector b)const{return x * b.y - y * b.x;}
double operator|(const Vector b)const{return x * b.x + y * b.y;}
double len(){return sqrtl(x * x + y * y);}
bool operator<(const Vector b)const{
double t = atan2(y, x) - atan2(b.y, b.x);
if(fabsl(t) < eps) return x < b.x;
return t < 0;
}
}a[N], b[N];
int top, st[N];
void init(){
sort(a + 1, a + 1 + n, [](Vector x, Vector y){return x.x == y.x ? x.y < y.y : x.x < y.x;});
vis[st[++top] = 1] = 1;
_rep(i, 2, n){
while(top >= 2 && ((a[st[top]] - a[st[top - 1]]) ^ (a[i] - a[st[top]])) <= 0) vis[st[top--]] = 0;
st[++top] = i, vis[i] = 1;
}
// _rep(i, 1, top) debug("(%.0lf,%.0lf)\n", a[st[i]].x, a[st[i]].y);
// debug("==============\n");
int lst = top;
_req(i, n - 1, 1){
while(top > lst && ((a[st[top]] - a[st[top - 1]]) ^ (a[i] - a[st[top]])) <= 0){
// debug("fuck %d %.0lf (%.0lf,%.0lf)\n", st[top], ((a[st[top]] - a[st[top - 1]]) ^ (a[i] - a[st[top - 1]])), (a[st[top]] - a[st[top - 1]]).x, (a[st[top]] - a[st[top - 1]]).y);
vis[st[top--]] = 0;
}
st[++top] = i, vis[i] = 1;
// debug("i:%d (%.0lf,%.0lf)\n", i, a[i].x, a[i].y);
// _rep(i, 1, top) debug("(%.0lf,%.0lf)\n", a[st[i]].x, a[st[i]].y);
// debug("===========\n");
}
// _rep(i, 1, top) debug("(%.0lf,%.0lf)\n", a[st[i]].x, a[st[i]].y);
}
int main(){
read(n);
_rep(i, 1, n) scanf("%lf%lf", &a[i].x, &a[i].y);
init();
int ans = 1;
_rep(i, 1, n){
if(vis[i]) continue;
int cnt = 0;
_rep(j, 1, n) if(j != i) b[++cnt] = a[j] - a[i], b[cnt].id = j;
sort(b + 1, b + 1 + cnt);
int pos = 0, cur = 0;
_rep(j, 1, cnt) if(vis[b[j].id]){pos = j; break;}
for(int i = pos % cnt + 1; ; i = i % cnt + 1){
if(vis[b[i].id]) ans += !cur, cur = 0;
else cur++;
if(i == pos) break;
}
// debug("(%.0lf,%.0lf) %d\n", a[i].x, a[i].y, ans);
}
writeln(ans);
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4308kb
input:
7 1 4 4 0 2 3 3 1 3 5 0 0 2 4
output:
9
result:
ok 1 number(s): "9"
Test #2:
score: 0
Accepted
time: 0ms
memory: 4368kb
input:
5 4 0 0 0 2 1 3 3 3 1
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 4304kb
input:
6 0 0 3 0 3 2 0 2 1 1 2 1
output:
5
result:
wrong answer 1st numbers differ - expected: '7', found: '5'