QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#739862 | #7906. Almost Convex | xsdgp | WA | 467ms | 3724kb | C++20 | 2.2kb | 2024-11-12 23:33:50 | 2024-11-12 23:33:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n;
struct VECTOR
{
int x,y;
int operator*(const VECTOR &v)const
{
return x*v.x+y*v.y;
}
int operator^(const VECTOR &v)const
{
return x*v.y-y*v.x;
}
};
struct POINT
{
int x,y;
VECTOR operator-(const POINT &p)const
{
return {x-p.x,y-p.y};
}
bool operator<(const POINT &p)const
{
if(x==p.x)return y<p.y;
else return x<p.x;
}
bool operator==(const POINT &p)const
{
return x==p.x&&y==p.y;
}
}p[2005],p1[2005];
vector<POINT> st;
bool cmp1(POINT p1,POINT p2)
{
if(p1.x==p2.x)return p1.y<p2.y;
else return p1.x<p2.x;
}
bool check(POINT p)
{
POINT back1=st.back(),back2=*(st.rbegin()+1);
return ((back1-back2)^(p-back1))<=0;
}
void andrew()
{
sort(p+1,p+n+1,cmp1);
for(int i=1;i<=n;i++)
{
while(st.size()>1&&check(p[i]))st.pop_back();
st.push_back(p[i]);
}
int k=st.size();
for(int i=n-1;i>=1;i--)
{
while(st.size()>k&&check(p[i]))st.pop_back();
st.push_back(p[i]);
}
if(st.size()>1)st.pop_back();
}
POINT o;
int find_zone(POINT p)
{
int x=p.x-o.x,y=p.y-o.y;
if(y<0)return 1;
if(y==0&&x>0)return 2;
if(y==0&&x==0)return 3;
if(y>0)return 4;
if(y==0&&x<0)return 5;
return 0;
}
bool cmp2(POINT p1,POINT p2)
{
int z1=find_zone(p1),z2=find_zone(p2);
if(z1!=z2)return z1<z2;
else
{
VECTOR v1=p1-o,v2=p2-o;
if((v1^v2)==0)return v1*v1>v2*v2;
else return (v1^v2)>0;
}
}
map<POINT,POINT> mp;
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>p[i].x>>p[i].y;
p1[i]=p[i];
}
andrew();
for(int i=0;i<st.size();i++)
mp[st[i]]=st[(i+1)%st.size()];
int add=0;
for(int i=1;i<=n;i++)
{
if(mp.find(p1[i])!=mp.end())continue;
o=p1[i];
int m=0;
for(int j=1;j<=n;j++)
if(j!=i)p[++m]=p1[j];
sort(p+1,p+m+1,cmp2);
POINT last;
for(int j=1;j<n;j++)
{
int pre=j-1;
if(j==1||((p[j]-o)^(p[j-1]-o))!=0)
{
if(j!=1)
{
if(mp.find(last)!=mp.end()&&mp[last]==p[j])
{
add++;
}
}
last=p[j];
}
}
if(mp.find(last)!=mp.end()&&mp[last]==p[1])add++;
}
cout<<add+1<<endl;
}
signed main()
{
ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
solve();
return 0;
}
/*
7
1 4
4 0
2 3
3 1
3 5
0 0
2 4
*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3664kb
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: 1ms
memory: 3592kb
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: 3596kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3596kb
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: 1ms
memory: 3724kb
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: 467ms
memory: 3632kb
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:
449
result:
wrong answer 1st numbers differ - expected: '718', found: '449'