QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322697#7906. Almost ConvexposviiTL 1ms3832kbC++143.0kb2024-02-07 15:57:422024-02-07 15:57:43

Judging History

你现在查看的是最新测评结果

  • [2024-02-07 15:57:43]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3832kb
  • [2024-02-07 15:57:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
template<typename G> inline void read(G &x) {x=0;G f=1;char ch=getchar();while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();if(ch=='-') f=-1,ch=getchar();while(ch>='0'&&ch<='9') {x=x*10+(ch^48);ch=getchar();}if(ch=='.') ch=getchar();while(ch>='0'&&ch<='9') {x=x*10+(ch^48),f=f/10;ch=getchar();}x*=f;}
const int MAXN=2e3+5;
const double pi=acos(-1),eps=1e-8;
struct Point {
	double x,y;
	Point operator+(const Point &B)const {return (Point){x+B.x,y+B.y};}
	Point operator-(const Point &B)const {return (Point){x-B.x,y-B.y};}
	Point operator*(const double &B)const {return (Point){x*B,y*B};}
	Point operator/(const double &B)const {return (Point){x/B,y/B};}
	double operator|(const Point &B)const {return x*B.x+y*B.y;}
	double operator^(const Point &B)const {return x*B.y-y*B.x;}
	bool operator<(const Point &B)const {return fabs(x-B.x)<eps?y+eps<B.y:x+eps<B.x;}
}p[MAXN];
int sign(double x) {return x>eps?1:(x<-eps?-1:0);}
struct Line {
	Point a,b;
	double slope() {if(a.x==b.x) return 1e9;return (a.y-b.y)/(a.x-b.x);}
	friend bool operator<(Line L1,Line L2) {
		return (L1.b-L1.a)<(L2.b-L2.a);
	}
}L[MAXN];int num;
bool onl(Point A,Line L) {
	if(A.x==1e9) return 0;
  	return (min(L.a.x,L.b.x)<=A.x&&A.x<=max(L.a.x,L.b.x));
}
Point inter(Line a,Line b) {
	if(a.slope()==b.slope()) return {1e9,0};
	Point res=a.a+(a.b-a.a)*(((b.b-b.a)^(b.a-a.a))/((b.b-b.a)^(a.b-a.a)));
	if(a.a.x==a.b.x) {
		if(a.a.y<a.b.y) {
			if(res.y>a.a.y) return res;
		}
		else {
			if(res.y<a.a.y) return res;
		}
	}
	else {
		if(a.a.x<a.b.x) {
			if(res.x>a.a.x) return res;
		}
		else {
			if(res.x<a.a.x) return res;
		}
	}return {1e9,0};
}
double dis(Point A,Point B) {return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));}
bool f(Point A,Point B,Point C) {return ((A-B)^(C-B))>eps;}
int n,s[MAXN],tot;
bool vis[MAXN],imp[MAXN];
Line li[MAXN];int cnt;
double ans;
signed main() {
	read(n);
	for(int i=1;i<=n;++i) read(p[i].x),read(p[i].y);
	sort(p+1,p+1+n);
	for(int i=1;i<=n;++i) {
		while(tot>=2&&!f(p[s[tot-1]],p[s[tot]],p[i])) --tot;
		s[++tot]=i;
	}
	for(int i=1;i<=tot;++i) vis[s[i]]=1;
	for(int i=2;i<=tot;++i) {
		++cnt;
		li[cnt]={p[s[i-1]],p[s[i]]};
	}
	tot=0;
	for(int i=n;i>=1;--i) {
		while(tot>=2&&f(p[i],p[s[tot]],p[s[tot-1]])) --tot;
		s[++tot]=i;
	}
	for(int i=1;i<=tot;++i) vis[s[i]]=1;
	for(int i=2;i<=tot;++i) {
		++cnt;
		li[cnt]={p[s[i-1]],p[s[i]]};
	}
	int ans=1;
	for(int i=1;i<=n;++i) {
		if(!vis[i]) {
			num=0;
			for(int j=1;j<=n;++j) {
				if(!vis[j]&&j!=i) {
					L[++num]={p[i],p[j]};
				}
			}
			sort(L+1,L+num+1);
			int now=-1;ans+=cnt;
			for(int j=1;j<=cnt;++j) {
				imp[j]=0;
				if(onl(inter(L[1],li[j]),li[j])) now=j;
			}
			for(int j=1;j<=num;++j) {
				bool flag=0;
				for(int k=1;k<=cnt;++k) {
					if(onl(inter(L[j],li[k]),li[k])) {
						flag=1;
						break;
					}
				}
				assert(flag);
				while(!onl(inter(L[j],li[now]),li[now])) now=now%cnt+1;
				if(!imp[now]) imp[now]=1,--ans;
			}
		}
	}
	printf("%d",ans);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3832kb

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: 3748kb

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: 3800kb

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3816kb

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: 3828kb

input:

4
0 0
0 3
3 0
3 3

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: -100
Time Limit Exceeded

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:

718

result: