QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#313818#7730. Convex CheckerHqwqWA 1ms3812kbC++141.8kb2024-01-25 00:08:222024-01-25 00:08:22

Judging History

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

  • [2024-07-04 19:27:17]
  • hack成功,自动添加数据
  • (/hack/727)
  • [2024-07-04 19:17:30]
  • hack成功,自动添加数据
  • (/hack/726)
  • [2024-01-25 00:08:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3812kb
  • [2024-01-25 00:08:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

int n,cnt;
struct point{
    int x,y;
}p[200010],v[200010],q[200010];

bool cmp(point x,point y){
    if (x.x!=y.x) return x.x<y.x;
    return x.y<y.y;
}

bool check(point x,point y,point z){
    point l1,l2;
    l1.x=y.x-x.x;
    l1.y=y.y-x.y;
    l2.x=z.x-y.x;
    l2.y=z.y-y.y;
    if (l1.x*l2.y-l2.x*l1.y>0) return 1;
    return 0;
}

void tb(){
    point p1,p2;
    v[++cnt]=p[1];
    v[++cnt]=p[2];
    for (int i=3;i<=n;i++){
        p1=v[cnt-1];
        p2=v[cnt];
        while(!check(p1,p2,p[i]) && cnt>1){
            cnt--;
            p1=v[cnt-1];
            p2=v[cnt];
        }
        v[++cnt]=p[i];
    }
    int temp=cnt;
    v[++cnt]=p[n-1];
    for (int i=n-2;i>=1;i--){
        p1=v[cnt-1];
        p2=v[cnt];
        while(!check(p1,p2,p[i]) && cnt>temp){
            cnt--;
            p1=v[cnt-1];
            p2=v[cnt];
        }
        v[++cnt]=p[i];
    }
    cnt--; 
}

int main(){
    scanf("%d",&n);
    int m=0;
    for (int i=1;i<=n;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        if (p[m].x!=x || p[m].y!=y){
        	m++;
			p[m].x=x;
        	p[m].y=y;
        	q[m]=p[m];
		}
    }
    sort(p+1,p+1+n,cmp);
    tb();
    int pp=1;
    if (cnt!=n) pp=0;
    else {
    	int i=1,j;
	    for (i=1;i<=n;i++) if (q[1].x==v[i].x && q[1].y==v[i].y) break;
	    int p1=1,p2=1;
	    j=1;
	    while(j<=n){
	    	if (v[i].x!=p[j].x || v[i].y!=p[j].y){
	    		p1=0;
	    		break;
			}
	    	i=i%n+1;
			j=j%n+1;
		}
		j=n;
		while(j>=1){
			if (v[i].x!=p[j].x || v[i].y!=p[j].y){
	    		p2=0;
	    		break;
			}
	    	i=i%n+1;
			j=j%n-1;
		}
		pp=p1|p2;
	}
    if (pp) printf("Yes\n");
    else printf("No\n");
}

詳細信息

Test #1:

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

input:

3
0 0
1 0
0 1

output:

Yes

result:

ok answer is YES

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3812kb

input:

4
0 0
0 1
1 1
1 0

output:

No

result:

wrong answer expected YES, found NO