QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#751742 | #7906. Almost Convex | guodong | Compile Error | / | / | C++17 | 2.1kb | 2024-11-15 20:25:10 | 2024-11-15 20:25:11 |
Judging History
answer
#include<iostream>
#include <bits/stdc++.h>
#define int long long
#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;
}
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<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
cc1plus: error: ‘::main’ must return ‘int’ answer.code: In function ‘int main()’: answer.code:37:13: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 37 | scanf("%d",&n); | ~^ ~~ | | | | | long long int* | int* | %lld answer.code:41:17: warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long long int*’ [-Wformat=] 41 | scanf("%d%d",&p[i].x,&p[i].y); | ~^ ~~~~~~~ | | | | int* long long int* | %lld answer.code:41:19: warning: format ‘%d’ expects argument of type ‘int*’, but argument 3 has type ‘long long int*’ [-Wformat=] 41 | scanf("%d%d",&p[i].x,&p[i].y); | ~^ ~~~~~~~ | | | | int* long long int* | %lld answer.code:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | scanf("%d",&n); | ~~~~~^~~~~~~~~ answer.code:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 41 | scanf("%d%d",&p[i].x,&p[i].y); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~