QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#617752 | #7906. Almost Convex | lmz20050701 | WA | 11ms | 9832kb | C++20 | 3.5kb | 2024-10-06 16:54:29 | 2024-10-06 16:54:31 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define Fr(i,l,r) for(int i=l;i<=r;i++)
#define Fr_(i,a) for(auto i:a)
#define Fr_edge(i,x) for(int i=head[x];i!=0;i=edge[i].next)
#define memset(a,b) memset(a,b,sizeof(a));
#define pq priority_queue
#define addedge2(x,y,w) addedge(x,y,w),addedge(y,x,w)
#define new_opt friend bool operator
#define pb push_back
#define fastio ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define pii pair<int,int>
#define fir first
#define sec second
#define pdd pair<double,double>
using namespace std;
const int N=2e6+10;
//const int N2=1e3+100;
int n=0;
pair<double,double> p[N];
int bao[N];
double dis(int x,int y)
{
return sqrt((p[x].fir-p[y].fir)*(p[x].fir-p[y].fir)+(p[x].sec-p[y].sec)*(p[x].sec-p[y].sec));
}
double cc(int a,int b,int c,int d)
{
pair<double,double> A=make_pair(p[a].fir-p[b].fir,p[a].sec-p[b].sec);
pair<double,double> B=make_pair(p[c].fir-p[d].fir,p[c].sec-p[d].sec);
return A.fir*B.sec-A.sec*B.fir;
}
int tubao()
{
n=unique(p+1,p+1+n)-p-1;
sort(p+1,p+1+n);
int ans=0;
Fr(i,1,n)
{
while(ans>=2&&cc(bao[ans],bao[ans-1],i,bao[ans])<0)
{
ans--;
}
bao[++ans]=i;
}
int j=ans;
ans--;
for(int i=n;i>=1;i--)
{
while(ans>=j&&cc(bao[ans],bao[ans-1],i,bao[ans])<0)
{
ans--;
}
bao[++ans]=i;
}
if(n==1) ans--;
return ans;
}
//---------------------------------------------------
vector<pdd> ba;
vector<pdd> fb;
int inbao[N];
struct node
{
pdd pos;
double ang;
};
double ddis(pdd x)
{
return sqrt(x.fir*x.fir+x.sec*x.sec);
}
double getang(pdd a,pdd b,pdd c,pdd e)
{
pdd x={b.fir-a.fir,b.sec-a.sec};
pdd y={e.fir-c.fir,e.sec-c.sec};
return (x.fir*y.fir+x.sec*y.sec)/(ddis(x)*ddis(y));
}
bool cmp(node x,node y)
{
return x.ang>y.ang;
}
int slove(int x,int y)
{
if(fb.size()==0) return 0;
//cout<<p[x].fir<<' '<<p[x].sec<<' '<<p[y].fir<<' '<<p[y].sec<<endl;
int ans=0;
vector<node> v1;
Fr_(i,fb)
{
node t;
t.pos=i;
t.ang=getang(p[x],p[y],p[y],i);
//cout<<t.ang<<' ';
v1.pb(t);
}
//cout<<endl;
sort(v1.begin(),v1.end(),cmp);
vector<node> v2;
Fr_(i,fb)
{
node t;
t.pos=i;
t.ang=getang(p[x],p[y],p[x],i);
//cout<<t.ang<<' ';
v2.pb(t);
}
//cout<<endl;
sort(v2.begin(),v2.end(),cmp);
int j=0;
Fr(i,0,v1.size()-1)
{
if(v1[i].pos==v2[j].pos)
{
ans++;
j++;
}
}
return ans;
}
signed main()
{
cin>>n;
Fr(i,1,n)
{
cin>>p[i].fir>>p[i].sec;
}
int len_b=tubao()-1;
//cout<<"size of bao "<<len_b<<endl;
Fr(j,1,len_b)
{
//cout<<bao[i]<<endl;
int i=j;
inbao[bao[i]]=1;
ba.pb({p[bao[i]].fir,p[bao[i]].sec});
//cout<<"in bao "<<p[bao[i]].fir<<' '<<p[bao[i]].sec<<endl;
}
Fr(i,1,n)
{
if(inbao[i]) continue;
fb.pb({p[i].fir,p[i].sec});
//cout<<"not in bao "<<p[i].fir<<' '<<p[i].sec<<endl;
}
//cout<<"size of fb "<<fb.size()<<endl;
int ans=1;
Fr(j,1,len_b-1)
{
int i=j;
ans+=slove(bao[i],bao[i+1]);
//cout<<"in bao "<<p[bao[i]].fir<<' '<<p[bao[i]].sec<<endl;
}
ans+=slove(bao[len_b],bao[1]);
cout<<ans;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7792kb
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: 7780kb
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: 1ms
memory: 7796kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 7836kb
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: 9832kb
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: 11ms
memory: 8108kb
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:
102
result:
wrong answer 1st numbers differ - expected: '718', found: '102'