QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439552#7906. Almost ConvexDjangle162857WA 365ms6656kbC++202.1kb2024-06-12 10:15:532024-06-12 10:15:53

Judging History

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

  • [2024-06-12 10:15:53]
  • 评测
  • 测评结果:WA
  • 用时:365ms
  • 内存:6656kb
  • [2024-06-12 10:15:53]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
typedef double T;
const int N=100005; 
using namespace std;
int n,ans=1;
struct point{
	T x,y;
	bool operator<(const point &a)const {if(y==a.y) return x<a.x;return y<a.y;}
	bool operator==(const point &a)const {return x==a.x&&y==a.y;}
	point operator+(const point &a) const {return {x+a.x,y+a.y};}
	point operator-(const point &a) const {return {x-a.x,y-a.y};}
	point operator-() const {return {-x,-y};}
	point operator*(const T k) const {return {k*x,k*y};}
	point operator/(const T k) const {return {x/k,y/k};}
	T operator*(const point &a) const {return x*a.x+y*a.y;} // 点积
	T operator^(const point &a) const {return x*a.y-y*a.x;}
	
	double dis(const point &a) const {
		return sqrt((a-(*this))*(a-(*this)));
	}
}p[N],mn,ctr;
bool out[N];
int stk[N],tot;
bool cmp(point A,point B) {
	if(A==B) return 0;
	if(((A-mn)^(B-mn))==0) return mn.dis(A)<mn.dis(B);
	return ((A-mn)^(B-mn))>0;
}
int q[N];
bool cmp1(int a,int b) {
	point A=p[a],B=p[b];
	if(A==B) return 0;
	if(A==ctr) return 1;
	if(B==ctr) return 0;
	if(A==mn) return 1;
	if(B==mn) return 0;
	if(((mn-ctr)^(A-ctr))>0&&((mn-ctr)^(B-ctr))<0) return 1;
	if(((A-ctr)^(B-ctr))==0){
		//cout<<ctr.x<<" "<<ctr.y<<endl;
		//cout<<a<<" "<<b<<" "<<111<<endl; 
		return ctr.dis(A)<ctr.dis(B);
	}
	return ((A-ctr)^(B-ctr))>0;
}
//vector<int> ot
signed main() {
	//T u;cout<<sizeof(u)<<endl;
	cin>>n;
	for(int i=1;i<=n;i++) 
		scanf("%lf%lf",&p[i].x,&p[i].y);
	for(int i=1;i<=n;i++) {
		if(p[i]<p[1]) swap(p[1],p[i]);
	}
	mn=p[1];
	sort(p+2,p+n+1,cmp);
	stk[++tot]=1;stk[++tot]=2;
	for(int i=1;i<=n;i++) {
		while(tot>=2&&((p[stk[tot]]-p[stk[tot-1]])^(p[i]-p[stk[tot]]))<0)
			tot--;
		stk[++tot]=i;
	}
	for(int i=1;i<=tot;i++) out[stk[i]]=1;
	/*for(int i=1;i<=n;i++) {
		cout<<p[i].x<<" "<<p[i].y<<" "<<out[i]<<endl;
	}*/
	for(int i=1;i<=n;i++) q[i]=i;
	for(int i=1;i<=n;i++) {
		if(!out[i]) {
			ctr=p[i];
			sort(q+1,q+n+1,cmp1);
			for(int j=2;j<=n;j++) {
				if(out[q[j]]&&out[q[j-1]])
					ans++;
			}
			ans+=out[q[n]];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 1ms
memory: 5940kb

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

input:

3
0 0
3 0
0 3

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

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: 1ms
memory: 5864kb

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: 365ms
memory: 6656kb

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:

5147

result:

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