QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625467 | #7906. Almost Convex | MiniLong | TL | 0ms | 4376kb | C++17 | 4.1kb | 2024-10-09 19:26:47 | 2024-10-09 19:26:48 |
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;
}
int lst = top;
_req(i, n - 1, 1){
if(vis[i]) continue;
while(top > lst && ((a[st[top]] - a[st[top - 1]]) ^ (a[i] - a[st[top]])) <= 0){
vis[st[top--]] = 0;
}
st[++top] = i, vis[i] = 1;
}
}
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: 4272kb
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: 4376kb
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: 4008kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4372kb
input:
6 0 0 3 0 3 2 0 2 1 1 2 1
output:
7
result:
ok 1 number(s): "7"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3952kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Time Limit Exceeded
input:
2000 86166 617851 383354 -277127 844986 386868 -577988 453392 -341125 -386775 -543914 -210860 -429613 606701 -343534 893727 841399 339305 446761 -327040 -218558 -907983 787284 361823 950395 287044 -351577 -843823 -198755 138512 -306560 -483261 -487474 -857400 885637 -240518 -297576 603522 -748283 33...