QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#665761 | #7906. Almost Convex | qzez# | WA | 297ms | 3704kb | C++14 | 1.5kb | 2024-10-22 15:10:11 | 2024-10-22 15:10:17 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using vec=complex<int>;
ll dot(vec a,vec b){
return 1ll*real(a)*real(b)+1ll*imag(a)*imag(b);
}
ll cross(vec a,vec b){
return 1ll*real(a)*imag(b)-1ll*imag(a)*real(b);
}
int find(vec a){
if(imag(a))return imag(a)>0?1:3;
else return real(a)>0?0:2;
}
bool comp(vec a,vec b){
int t=find(a),s=find(b);
if(t!=s)return t<s;
return cross(a,b)>0;
}
const int N=2e3+10;
int n;
vec a[N];
bool cmp(vec a,vec b){
return real(a)!=real(b)?real(a)<real(b):imag(a)<imag(b);
}
int k,id[N],stk[N];
bool chk(vec a,vec b,vec c){
// cerr<<a<<' '<<b<<' '<<c<<endl;
return cross(c-b,a-b)>0;
}
void convex(){
sort(a+2,a+1+n,[&](vec x,vec y){
return comp(x-a[1],y-a[1]);
});
stk[k=1]=1;
for(int i=2;i<=n;i++){
for(;k>1&&!chk(a[stk[k-1]],a[stk[k]],a[i]);k--);
stk[++k]=i;
}
// for(int i=1;i<=n;i++)cerr<<a[i]<<"\n "[i<n];
// cerr<<k<<endl;
for(int i=1;i<=k;i++)id[stk[i]]=i;
}
int main(){
cin>>n;
for(int i=1,x,y;i<=n;i++){
cin>>x>>y,a[i]=vec(x,y);
}
sort(a+1,a+1+n,cmp);
convex();
int ans=1;
for(int i=1;i<=n;i++)if(!id[i]){
static int cur[N];
for(int j=1;j<=n;j++)if(i!=j)cur[j-(j>i)]=j;
sort(cur+1,cur+n,[&](int x,int y){
return comp(a[x]-a[i],a[y]-a[i]);
});
for(int i=1;i<n;i++){
if(id[cur[i]]&&id[cur[i%(n-1)+1]])ans++;
}
}
cout<<ans<<endl;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
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: 3616kb
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: 3704kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
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: 3508kb
input:
4 0 0 0 3 3 0 3 3
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: -100
Wrong Answer
time: 297ms
memory: 3568kb
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...
output:
1912
result:
wrong answer 1st numbers differ - expected: '718', found: '1912'