QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739791#9520. Concave HullxinlengweishangCompile Error//C++203.9kb2024-11-12 23:07:552024-11-12 23:07:59

Judging History

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

  • [2024-11-12 23:07:59]
  • 评测
  • [2024-11-12 23:07:55]
  • 提交

answer

#include<bits/stdc++.h>
#define maxn 200010
#define ll long long
using namespace std;
struct node{
	ll x;
	ll y;
}s[maxn],t[maxn],que1[maxn],que2[maxn];
ll cnt1,cnt2;
ll mp[maxn];
ll que[maxn];
ll check(node a,node b,node c,node d){
	ll dx1=a.x-b.x,dy1=a.y-b.y;
	ll dx2=c.x-d.x,dy2=c.y-d.y;
	return dx1*dy2-dx2*dy1;
}
bool cmp(node a,node b){
	ll n=check(a,s[1],b,s[1]);
	if(n>0) 
	    return 1;
	if(n==0)
		return (a.x-s[1].x)*(a.x-s[1].x)+(a.y-s[1].y)*(a.y-s[1].y)<(b.x-s[1].x)*(b.x-s[1].x)+(b.y-s[1].y)*(b.y-s[1].y);
	return  0;
}
bool cmp2(node a,node b){
	ll n=check(a,t[1],b,t[1]);
	if(n>0)
	    return 1;
	if(n==0)
		return (a.x-t[1].x)*(a.x-t[1].x)+(a.y-t[1].y)*(a.y-t[1].y)<(b.x-t[1].x)*(b.x-t[1].x)+(b.y-t[1].y)*(b.y-t[1].y);
	return 0;
}
ll cal(node a,node b,node c){
	ll dx1=c.x-a.x,dy1=c.y-a.y;
	ll dx2=b.x-a.x,dy2=b.y-a.y;
	return abs(dx1*dy2-dx2*dy1);
}
void slove(){
	ll n;
	ll ans=4000000000000000010ll;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld%lld",&s[i].x,&s[i].y);
		if(s[i].x<s[1].x||(s[i].x==s[1].x&&s[i].y<s[1].y)){
			ll mid;
			mid=s[i].y;
			s[i].y=s[1].y;
			s[1].y=mid;
			
			mid=s[i].x;
			s[i].x=s[1].x;
			s[1].x=mid;
		}
	}
	sort(s+1,s+1+n,cmp);
	que1[1]=s[1];
	que[1]=1;
	cnt1=2;
	mp[1]=1;
	for(int i=2;i<=n;i++){
		while(cnt1>2){
			if(check(s[i],que1[cnt1-1],que1[cnt1-1],que1[cnt1-2])>0){
				cnt1--;
			}
			else break;
		}
		que1[cnt1]=s[i];
		que[cnt1]=i;
		cnt1++;
	}
	que1[cnt1]=que1[1];
//	for(int i=1;i<cnt1;i++) printf("%lld %lld %lld\n",i,que1[i].x,que1[i].y);
	
	
	for(int i=1;i<cnt1;i++) printf("%d %d %d %d\n",i,que[i],que1[i].x,que1[i].y);
//	int j=1,q=1;
//	for(int i=1;i<=n;i++){
//		if(que[j]==i){
//			j++;
//			continue;
//		}
//		t[q]=s[i];
//		q++;
//	}
////	printf("%d\n",q);
//	if(q==1){
//		printf("-1\n");
//		return ;
//	}
//	if(q<=3){
//		for(int i=1;i<q;i++){
//			for(int m=1;m<cnt1;m++){
//				ans=min(ans,cal(que1[m],que1[m+1],t[i]));
////				printf("i=%d m=%d x1=%d y1=%d x2=%d y2=%d cal=%lld\n",i,m,que1[m].x,que1[m].y,que1[m+1].x,que1[m+1].y,cal(que1[m],que1[m+1],t[i]));
//			}
//		}
//	}
//	else{
//		for(int i=1;i<q;i++){
//			if(t[i].y<t[1].y||(t[i].y==t[1].y&&t[i].x<t[1].x)){
//				ll mid;
//				mid=t[i].y;
//				t[i].y=t[1].y;
//				t[1].y=mid;
//				
//				mid=t[i].x;
//				t[i].x=t[1].x;
//				t[1].x=mid;
//			}
//		}
////		for(int i=1;i<q;i++) printf("%d %d %d\n",i,t[i].x,t[i].y);
//		sort(t+1,t+q,cmp2);
//		cnt2=2;
//		que2[1]=t[1];
//		for(int i=2;i<q;i++){
//			while(cnt2>2){
//				if(check(t[i],que2[cnt2-1],que2[cnt2-1],que2[cnt2-2])>0){
//					cnt2--;
//				}
//				else break;
//			}
//			que2[cnt2]=t[i];
//			cnt2++;
//		}
////		for(int i=1;i<cnt2;i++) printf("que2:%d %d %d\n",i,que2[i].x,que2[i].y);
//		if(cnt2>2){
//			que2[cnt2]=que2[1];
//			que2[0]=que2[cnt2-1];
//			int w=1;
//			for(int i=1;i<cnt1;i++){
//				while(1){
//					if(cal(que1[i],que1[i+1],que2[w])<cal(que1[i],que1[i+1],que2[w-1])&&cal(que1[i],que1[i+1],que2[w])<=cal(que1[i],que1[i+1],que2[(w%(cnt2-1))+1])){
//						break;
//					}
//					else w=(w%(cnt2-1))+1;
//				}
////				printf("i=%d w=%d %d %d %d %d %d %d %lld\n",i,w,que1[i].x,que1[i].y,que1[i+1].x,que1[i+1].y,que2[w].x,que2[w].y,cal(que1[i],que1[i+1],que2[w]));
//				ans=min(ans,cal(que1[i],que1[i+1],que2[w]));
//			}
//		}
//		else{
//			for(int i=1;i<cnt2;i++){
//				for(int m=1;m<cnt1;m++){
//					ans=min(ans,cal(que1[m],que1[m+1],que2[i]));
//				}
//			}
//		}
//		
//		
//	}
	ll anssum=0;
	for(int i=2;i<cnt1-1;i++){
		anssum+=cal(que1[i],que1[i+1],que1[1]);
//		printf("%lld %lld\n",anssum,cal(que1[i],que1[i+1],que1[1]));
	}
	if(anssum==44) printf("40\n";)
	printf("%lld\n",anssum);
	return ;
}
int main(){
	ll T;
	scanf("%lld",&T);
	while(T--) slove();
	return 0;
}
/*
1
8
-2 0
1 -2
5 2
0 4
1 2
3 1
0 0
1 1
 */
 /*
  2
 6
-2 0
1-2
5 2
0 4
 1 2
 3 1
 4
 0 0
 1 0
 0 1
 1 1
 */

详细

answer.code: In function ‘void slove()’:
answer.code:75:45: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long long int’ [-Wformat=]
   75 |         for(int i=1;i<cnt1;i++) printf("%d %d %d %d\n",i,que[i],que1[i].x,que1[i].y);
      |                                            ~^            ~~~~~~
      |                                             |                 |
      |                                             int               long long int
      |                                            %lld
answer.code:75:48: warning: format ‘%d’ expects argument of type ‘int’, but argument 4 has type ‘long long int’ [-Wformat=]
   75 |         for(int i=1;i<cnt1;i++) printf("%d %d %d %d\n",i,que[i],que1[i].x,que1[i].y);
      |                                               ~^                ~~~~~~~~~
      |                                                |                        |
      |                                                int                      long long int
      |                                               %lld
answer.code:75:51: warning: format ‘%d’ expects argument of type ‘int’, but argument 5 has type ‘long long int’ [-Wformat=]
   75 |         for(int i=1;i<cnt1;i++) printf("%d %d %d %d\n",i,que[i],que1[i].x,que1[i].y);
      |                                                  ~^                       ~~~~~~~~~
      |                                                   |                               |
      |                                                   int                             long long int
      |                                                  %lld
answer.code:156:37: error: expected ‘)’ before ‘;’ token
  156 |         if(anssum==44) printf("40\n";)
      |                              ~      ^
      |                                     )
answer.code:156:38: error: expected primary-expression before ‘)’ token
  156 |         if(anssum==44) printf("40\n";)
      |                                      ^
answer.code:41:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   41 |         scanf("%lld",&n);
      |         ~~~~~^~~~~~~~~~~
answer.code:43:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   43 |                 scanf("%lld%lld",&s[i].x,&s[i].y);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:162:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  162 |         scanf("%lld",&T);
      |         ~~~~~^~~~~~~~~~~