QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751744 | #7906. Almost Convex | guodong | WA | 403ms | 4348kb | C++17 | 2.1kb | 2024-11-15 20:25:46 | 2024-11-15 20:25:46 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#include<algorithm>
#include<cstdio>
#include<cmath>
#define For(i,a,b) for(int i = a; i <= b; ++i)
using namespace std;
int n;
struct ben
{
int x,y,id;
}p[10005],s[10005];
double check(ben a1,ben a2,ben b1,ben b2)//检查叉积是否大于0,如果是a就逆时针转到b
{
return (a2.x-a1.x)*(b2.y-b1.y)-(b2.x-b1.x)*(a2.y-a1.y);
}
double d(ben p1,ben p2)//两点间距离。。。
{
return sqrt((p2.y-p1.y)*(p2.y-p1.y)+(p2.x-p1.x)*(p2.x-p1.x));
}
bool cmp(ben p1,ben p2)//排序函数,这个函数别写错了,要不然功亏一篑
{
double tmp=check(p[1],p1,p[1],p2);
if(tmp>0)
return 1;
if(tmp==0&&d(p[0],p1)<d(p[0],p2))
return 1;
return 0;
}
signed main()
{
#ifdef NICEGUODONG
freopen("data.in","r",stdin);
#endif
scanf("%d",&n);
double mid;
for(int i=1;i<=n;i++)
{
scanf("%d%d",&p[i].x,&p[i].y);
p[i].id = i;
if(i!=1&&p[i].y<p[1].y)//这是是去重
{
mid=p[1].y;p[1].y=p[i].y;p[i].y=mid;
mid=p[1].x;p[1].x=p[i].x;p[i].x=mid;
}
}
sort(p+2,p+1+n,cmp);//系统快排
s[1]=p[1];//最低点一定在凸包里
int cnt=1;
for(int i=2;i<=n;i++)
{
while(cnt>1&&check(s[cnt-1],s[cnt],s[cnt],p[i])<=0) //判断前面的会不会被踢走,如果被踢走那么出栈
cnt--;
cnt++;
s[cnt]=p[i];
}
s[cnt+1]=p[1];//最后一个点回到凸包起点
vector<int> Mark(n + 1);
For(i,1,cnt + 1){
Mark[s[i].id] = 1;
}
int ans = 1;
for(int i = 1; i <= n; ++i){
vector<pair<long double,int>> a;
if(Mark[p[i].id]) continue;
for(int j = 1; j <= n; ++j){
if(i == j) continue;
a.push_back(make_pair(atan2(p[j].x - p[i].x,p[j].y - p[i].y),p[j].id));
}
sort(a.begin(),a.end());
for(int i = 0;i < (int)a.size(); ++i)
if(Mark[a[i].second] && Mark[a[(i + 1) % a.size()].second]){
ans++;
}
}
cout << ans << '\n';
// printf("%.2lf\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4256kb
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: 4176kb
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: 3960kb
input:
3 0 0 3 0 0 3
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 4192kb
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: 3748kb
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: 403ms
memory: 4348kb
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:
11729
result:
wrong answer 1st numbers differ - expected: '718', found: '11729'