C++
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int N;
struct Axis{
int x;
int zero;//1==-,0==+ 저장을 고유값으로 저장할것
bool operator < ( const Axis& axis ) const
{
return x < axis.x;
}
};
using Pt = pair<int,int>;
Pt pts[1000000];
vector<Axis> axis_vec;
int main()
{
/*Axis axis, axis2;
axis.x = 10;
axis2.x = 20;
if ( axis.operator < ( axis2 ) )
{
}
if( axis < axis2 )
{
}
int a;
int &ra = a;
&a == &ra
int *p = &a;
*p = 10;
p = &b;*/
scanf("%d",&N);
int a,b;
int j;
for(j=0;j<N;j++){
scanf("%d %d",&a,&b);
pts[j].first=a;
pts[j].second=b;
}
int minus_;
for(int i=0;i<N;i++){
if(pts[i].second<0){
minus_=i;
break;
}
}
int p1 = minus_, p2;
for(j=0;j<N;j++){
p2 = (p1 + 1) % N;
if(pts[p1].second<0 && pts[p2].second >0){
axis_vec.push_back({pts[p1].first, 0});
}else if(pts[p1].second >0 && pts[p2].second < 0){
if( axis_vec.back().x > pts[p1].first)
{
int x2 = axis_vec.back().x;
axis_vec.back().x = pts[p1].first;
axis_vec.push_back({x2, 1});
}
else
axis_vec.push_back({pts[p1].first, 1});
}
p1 = p2;
}
sort(axis_vec.begin(), axis_vec.end());
int numa=0,numb=0;
int level=0;
auto it = axis_vec.begin();
for(;it!=axis_vec.end();++it){
if(it->zero==0){
if(level==0){
numa++;
}
if((it+1)->zero==1)
numb++;
level++;
}else{
level--;
}
}
printf("%d %d",numa,numb);
return 0;
}
댓글 0
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
|---|---|---|---|---|
| 공지 | 안내사항 | 관리자 | 2019.12.21 | 169 |
| 45 | 2468 | 관리자 | 2019.12.21 | 8 |
| 44 | 2458 | 관리자 | 2020.04.11 | 44 |
| 43 | 2457 | 관리자 | 2020.04.11 | 47 |
| 42 | 2454 | 관리자 | 2020.04.11 | 43 |
| 41 | 2450 | 관리자 | 2020.04.11 | 40 |
| 40 | 2339 | 관리자 | 2020.04.11 | 41 |
| 39 | 2307 | 관리자 | 2019.12.21 | 8 |
| 38 | 2250 | 관리자 | 2019.12.21 | 8 |
| 37 | 2233 | 관리자 | 2019.12.21 | 6 |
| 36 | 2170 | 관리자 | 2019.12.21 | 7 |
| 35 | 2132 | 관리자 | 2019.12.21 | 7 |
| 34 | 2096 | 관리자 | 2019.12.21 | 8 |
| 33 | 2042 | 관리자 | 2020.04.11 | 45 |
| 32 | 2003 | 관리자 | 2020.04.11 | 39 |
| 31 | 1991 | 관리자 | 2019.12.21 | 8 |
| 30 | 1967 | 관리자 | 2019.12.21 | 6 |
| 29 | 1966 | 관리자 | 2020.04.11 | 45 |
| 28 | 1946 | 관리자 | 2020.04.11 | 39 |
| 27 | 1874 | 관리자 | 2020.04.11 | 43 |
| 26 | 1839 | 관리자 | 2020.04.11 | 44 |
| 25 | 17611 | 관리자 | 2019.12.21 | 7 |
| 24 | 1753 | 관리자 | 2019.12.21 | 8 |
| 23 | 1742 | 관리자 | 2020.04.11 | 6 |
| 22 | 1720 | 관리자 | 2020.04.11 | 6 |
| 21 | 16210 | 관리자 | 2020.04.11 | 57 |
| 20 | 16201 | 관리자 | 2020.04.11 | 44 |
| 19 | 15971 | 관리자 | 2019.12.21 | 6 |
| » | 14865 | 관리자 | 2019.12.21 | 8 |
| 17 | 14503 | 관리자 | 2019.12.21 | 7 |
| 16 | 14502 | 관리자 | 2019.12.21 | 6 |