617D - Polyline(讨论)

https://codeforces.com/problemset/problem/617/D


#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=10;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct P{
    LL x,y;
}a[maxn];
int main(void){
   cin.tie(0);std::ios::sync_with_stdio(false);
   for(LL i=1;i<=3;i++){
      cin>>a[i].x>>a[i].y;
   }
   if(a[1].x==a[2].x&&a[2].x==a[3].x){ cout<<"1"<<"\n"; }
   else if(a[1].y==a[2].y&&a[2].y==a[3].y){ cout<<"1"<<"\n"; }
   else{
      bool flag=0;
      LL numx=0;LL numy=0;
      for(LL i=1;i<=3;i++){
        for(LL j=i+1;j<=3;j++){
            if(a[i].x==a[j].x){
                flag=1;
                numx++;
            }
            if(a[i].y==a[j].y){
                flag=1;
                numy++;
            }
        }
      }
      if(flag==0){ cout<<"3"<<"\n"; }
      else{
        if(numx&&numy) cout<<"2"<<"\n";
        else{
            if(numx){
                LL pos=0;bool ok=0;
                if(a[1].x==a[2].x) pos=3;
                if(a[1].x==a[3].x) pos=2;
                if(a[2].x==a[3].x) pos=1;
                if(pos==1){
                    if((a[pos].y>a[2].y&&a[pos].y<a[3].y)  ||(a[pos].y>a[3].y&&a[pos].y<a[2].y)){
                        ok=1;
                    }
                }
                if(pos==2){
                    if((a[pos].y>a[1].y&&a[pos].y<a[3].y)  ||(a[pos].y>a[3].y&&a[pos].y<a[1].y)){
                        ok=1;
                    }
                }
                if(pos==3){
                    if((a[pos].y>a[2].y&&a[pos].y<a[1].y)  ||(a[pos].y>a[1].y&&a[pos].y<a[2].y)){
                        ok=1;
                    }
                }
                if(ok) cout<<"3"<<"\n";
                else cout<<"2"<<"\n";
            }
            else if(numy){
                LL pos=0;bool ok=0;
                if(a[1].y==a[2].y) pos=3;
                if(a[1].y==a[3].y) pos=2;
                if(a[2].y==a[3].y) pos=1;
                if(pos==1){
                    if((a[pos].x>a[2].x&&a[pos].x<a[3].x)  ||(a[pos].x>a[3].x&&a[pos].x<a[2].x)){
                        ok=1;
                    }
                }
                if(pos==2){
                    if((a[pos].x>a[1].x&&a[pos].x<a[3].x)  ||(a[pos].x>a[3].x&&a[pos].x<a[1].x)){
                        ok=1;
                    }
                }
                if(pos==3){
                    if((a[pos].x>a[2].x&&a[pos].x<a[1].x)  ||(a[pos].x>a[1].x&&a[pos].x<a[2].x)){
                        ok=1;
                    }
                }
                if(ok) cout<<"3"<<"\n";
                else cout<<"2"<<"\n";
            }
        }
      }
   }
   return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/115347003