QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751196 | #7906. Almost Convex | guodong | WA | 0ms | 3800kb | C++17 | 2.1kb | 2024-11-15 17:28:14 | 2024-11-15 17:28:15 |
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;
}
bool cmp2(ben p1,ben p2){
return p1.x != p2.x ? p1.x < p2.x : p1.y < p2.y;
}
int 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<ben> a;
if(Mark[p[i].id]) continue;
for(int j = 1; j <= n; ++j){
if(i == j) continue;
a.push_back(p[j]);
}
sort(a.begin(),a.end(),cmp2);
for(int i = 0;i < (int)a.size(); ++i)
if(Mark[a[i].id] && Mark[a[(i + 1) % a.size()].id]){
ans++;
}
}
cout << ans << '\n';
// printf("%.2lf\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3800kb
input:
7 1 4 4 0 2 3 3 1 3 5 0 0 2 4
output:
10
result:
wrong answer 1st numbers differ - expected: '9', found: '10'