회원가입
로그인
Toggle navigation
문제
문제
전체 문제
문제 출처
단계별로 풀어보기
알고리즘 분류
추가된 문제
문제 순위
문제
푼 사람이 한 명인 문제
아무도 못 푼 문제
최근 제출된 문제
최근 풀린 문제
랜덤
출처
ICPC
Olympiad
한국정보올림피아드
한국정보올림피아드시․도지역본선
전국 대학생 프로그래밍 대회 동아리 연합
대학교 대회
카카오 코드 페스티벌
Coder's High
ICPC
Regionals
World Finals
Korea Regional
Africa and the Middle East Regionals
Europe Regionals
Latin America Regionals
North America Regionals
South Pacific Regionals
문제집
대회
채점 현황
게시판
그룹
더 보기
재채점 기록
블로그
도움말
전체
공지
자유
질문
오타/오역/요청
게시판 공지
홍보
업데이트
solved.ac
글쓰기
질문 도움말
자주묻는 질문
런타임 에러 (Segfault)가 뜹니다
2244번 - 민코프스키 합
guntori31
1년 전
0
코드를 정말 못 짜서 보고 이해하시기 어려우실 수도 있습니다...
#include <bits/stdc++.h> using namespace std; struct poin { long long int x; long long int y; }; poin p[2000010]; poin q[2000010]; poin pp[100001]={}; poin ppp[100001]={}; bool cx1(poin a, poin b) { if(a.x<b.x) return 1; else if(a.x>b.x) return 0; else if(a.y<b.y) return 1; else return 0; } bool cx2(poin a, poin b) { if(a.x<b.x) return 1; else if(a.x>b.x) return 0; else if(a.y>b.y) return 1; else return 0; } long long int f(long int c, long int d, long int e) { return ((p[c].x-p[d].x)*(p[e].y-p[d].y))-((p[c].y-p[d].y)*(p[e].x-p[d].x)); } int nn,mm,ii; stack<int> st; stack<int> ts; stack<int> ct; stack<int> tc; stack<int> ss; stack<long long int> xx; stack<long long int> yy; stack<long long int> xxx; stack<long long int> yyy; int n,k,m,aaaaa=0,bbbbb=0; int main() { scanf("%d %d", &nn, &mm); for(int i=0;i<nn;i++) scanf("\n%lld %lld", &pp[i].x, &pp[i].y); for(int i=0;i<mm;i++) scanf("\n%lld %lld", &ppp[i].x, &ppp[i].y); for(int i=0;i<nn;i++) { for(int j=0;j<mm;j++) { q[i*mm+j].x=pp[i].x+ppp[j].x; q[i*mm+j].y=pp[i].y+ppp[j].y; } } n=nn*mm; sort(q, q+n, cx1); ss.push(0); m=n; for(int i=1;i<n;i++) { if((q[i].x!=q[i-1].x)||(q[i].y!=q[i-1].y)) ss.push(i); else m--; } n=m; for(int i=n-1;i>=0;i--) { if(ss.empty()) break; p[i].x=q[ss.top()].x; p[i].y=q[ss.top()].y; ss.pop(); } ii=0; while(p[ii].x==p[0].x) ii++; if(p[0].x!=p[1].x) aaaaa=1; if(p[n-1].x!=p[n-2].x) bbbbb=1; st.push(ii-1); st.push(ii); ts.push(ii-1); for(int i=ii+1;i<n;i++) { while((k==0)&&(!ts.empty())) { k=1; if(f(st.top(), ts.top(), i)<0) { ts.push(st.top()); st.push(i); } else if(f(st.top(), ts.top(), i)==0) { st.pop(); ts.pop(); ts.push(st.top()); st.push(i); } else { st.pop(); ts.pop(); k=0; } } if(ts.empty()) { ts.push(st.top()); st.push(i); } k=0; } while(!st.empty()) { xx.push(p[st.top()].x); yy.push(p[st.top()].y); st.pop(); } while(!xx.empty()) { xxx.push(xx.top()); yyy.push(yy.top()); xx.pop(); yy.pop(); } sort(p, p+n, cx2); ii=0; while(p[ii].x==p[0].x) ii++; ct.push(ii-1); ct.push(ii); tc.push(ii-1); for(int i=ii+1;i<n;i++) { while((k==0)&&(!tc.empty())) { k=1; if(f(ct.top(), tc.top(), i)>0) { tc.push(ct.top()); ct.push(i); } else if(f(ct.top(), tc.top(), i)==0) { ct.pop(); tc.pop(); tc.push(ct.top()); ct.push(i); } else { ct.pop(); tc.pop(); k=0; } } if(tc.empty()) { tc.push(ct.top()); ct.push(i); } k=0; } if(bbbbb==1) ct.pop(); while(!ct.empty()) { xxx.push(p[ct.top()].x); yyy.push(p[ct.top()].y); ct.pop(); } if(aaaaa==1) printf("%ld\n", xxx.size()-1); else printf("%ld\n", xxx.size()); while(!xxx.empty()) { if(xxx.size()==1) if(aaaaa==1) break; printf("%lld %lld\n", xxx.top(), yyy.top()); xxx.pop(); yyy.pop(); st.pop(); } return 0; }
댓글을 작성하려면
로그인
해야 합니다.
guntori31 1년 전
코드를 정말 못 짜서 보고 이해하시기 어려우실 수도 있습니다...