QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#500103#7906. Almost ConvexZGS_WZYWA 845ms4336kbC++141.6kb2024-07-31 22:25:312024-07-31 22:25:32

Judging History

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

  • [2024-07-31 22:25:32]
  • 评测
  • 测评结果:WA
  • 用时:845ms
  • 内存:4336kb
  • [2024-07-31 22:25:31]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define rep2(i,j,k) for(int i=j;i>=k;i--)
using namespace std;
const double eps=1e-6;
int sgn(double x){
	if(x>eps)return 1;
	if(x<-eps)return -1;
	return 0;
}

const int N=2000+10;
struct Vec{
	double xi,yi;
	int pos;
}a[N],b[N];
Vec operator +(Vec a,Vec b){
	return (Vec){a.xi+b.xi,a.yi+b.yi,0};
}
Vec operator -(Vec a,Vec b){
	return (Vec){a.xi-b.xi,a.yi-b.yi,0};
}
double Cross_Product(Vec a,Vec b){
	return a.xi*b.yi-a.yi*b.xi;
}
bool Clockwise(Vec a,Vec b){
	return (sgn(Cross_Product(a,b))==-1);
}

bool cmp1(Vec a,Vec b){
	return a.xi<b.xi;
}
Vec STD;
bool cmp2(Vec a,Vec b){
	return atan2(a.yi-STD.yi,a.xi-STD.xi)<atan2(b.yi-STD.yi,b.xi-STD.xi);
}
int st[N];
bool in[N];
int main(){
	int n;
	scanf("%d",&n);
	rep(i,1,n){
		scanf("%lf%lf",&a[i].xi,&a[i].yi);
		a[i].pos=i;
	}
	sort(a+1,a+n+1,cmp1);
	
	int len=0;
	st[++len]=1;in[a[1].pos]=1;
	rep(i,2,n){
		while(len>1&&!Clockwise(a[st[len]]-a[st[len-1]],a[i]-a[st[len]])){
			in[st[len]]=0;
			len--;
		}
		st[++len]=i;
		in[a[i].pos]=1;
	}
	int tot=len;
	rep2(i,n-1,1){
		if(in[i]&&i!=1)continue;
		while(len>tot&&!Clockwise(a[st[len]]-a[st[len-1]],a[i]-a[st[len]])){
			in[st[len]]=0;
			len--;
		}
		st[++len]=i;
		in[a[i].pos]=1;
	}
	
	int ans=1;
	rep(i,1,n){
		if(in[a[i].pos])continue;
		STD=a[i];
		
		int num=0;
		rep(j,1,i-1)b[++num]=a[j];
		rep(j,i+1,n)b[++num]=a[j];
		sort(b+1,b+num+1,cmp2);
		
		rep(j,1,num-1)ans+=(in[b[j].pos]&&in[b[j+1].pos]);
		ans+=(in[b[num].pos]&&in[b[1].pos]);
	}
	printf("%d\n",ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 4232kb

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

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

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 4300kb

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

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: 845ms
memory: 4336kb

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:

690488

result:

wrong answer 1st numbers differ - expected: '718', found: '690488'