Codeforces Round #340 (Div. 2) D. Polyline 计算几何,折线

来源:互联网 发布:淘宝联盟登录不了 编辑:程序博客网 时间:2024/04/29 02:53

D. Polyline
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

There are three points marked on the coordinate plane. The goal is to make a simple polyline, without self-intersections and self-touches, such that it passes through all these points. Also, the polyline must consist of only segments parallel to the coordinate axes. You are to find the minimum number of segments this polyline may consist of.

Input

Each of the three lines of the input contains two integers. The i-th line contains integers xi and yi ( - 109 ≤ xi, yi ≤ 109) — the coordinates of the i-th point. It is guaranteed that all points are distinct.

Output

Print a single number — the minimum possible number of segments of the polyline.

Examples
input
1 -11 11 2
output
1
input
-1 -1-1 34 3
output
2
input
1 12 33 2
output
3
Note

The variant of the polyline in the first sample:The variant of the polyline in the second sample:The variant of the polyline in the third sample:



Source

Codeforces Round #340 (Div. 2)


My Solution

几何,折线

题意 给出3个点的坐标, 用折线把3个点连起来,要求每个线段 parallel to the coordinate axes(平行于坐标轴),然后线段没有交叉 和 self-touches(可能是说不能成环), 求出需要的最小的线段个数

所以, 如果(x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3) 则可以一条线段

                如果 (x1 == x2) || (x2 == x3) || (x1 == x3) || (y1 == y2) || (y2 == y3) || (y1 == y3) 则有2个点的x相等或者y相等, 

        则 如果第三个点如果在外面, 如下

                     point ·            point ·

 point3 ·  ·  ·  ·       ·                     ·     · · · · ·             ······

则 答案为 2, 否则 对于这些第三个点在里面的情况 则答案为 3

                        point ·                                          point ·

 point3                           ·  ·  ·  ·       ·       · ·

               如果是没有2个点的x相等或者y相等, 则 答案为 3


#include <iostream>#include <cstdio>using namespace std;typedef long long LL;const int maxn = 1e6 + 8;int main(){    #ifdef LOCAL    freopen("d.txt", "r", stdin);    //freopen("o.txt", "w", stdout);    int T = 3;    while(T--){    #endif // LOCAL    ios::sync_with_stdio(false); cin.tie(0);    int x1, y1, x2, y2, x3, y3;    cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;    if((x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3)){        cout << 1 << endl;    }    else if((x1 == x2) || (x2 == x3) || (x1 == x3) || (y1 == y2) || (y2 == y3) || (y1 == y3)){        if(x1 == x2){            if(y3 >= max(y1, y2) || y3 <= min(y1, y2)) cout << 2 << endl;            else cout << 3 << endl;        }        else if(x2 == x3){            if(y1 >= max(y3, y2) || y1 <= min(y3, y2)) cout << 2 << endl;            else cout << 3 << endl;        }        else if(x1 == x3){            if(y2 >= max(y1, y3) || y2 <= min(y1, y3)) cout << 2 << endl;            else cout << 3 << endl;        }        else if(y1 == y2){            if(x3 >= max(x1, x2) || x3 <= min(x1, x2)) cout << 2 << endl;            else cout << 3 << endl;        }        else if(y2 == y3){            if(x1 >= max(x3, x2) || x1 <= min(x3, x2)) cout << 2 << endl;            else cout << 3 << endl;        }        else if(y1 == y3){            if(x2 >= max(x1, x3) || x2 <= min(x1, x3)) cout << 2 << endl;            else cout << 3 << endl;        }    }    else{        cout << 3 << endl;    }    #ifdef LOCAL    cout<<endl;    }    #endif // LOCAL    return 0;}

  Thank you!

                                                                                                                                               ------from ProLights

0 0