Codeforces 617D Polyline 【枚举】

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.

Sample test(s)
input
1 -1
1 1
1 2
output
1
input
-1 -1
-1 3
4 3
output
2
input
1 1
2 3
3 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:



题意:给你三个点,问你最少用几条平行于坐标轴的线段把它们连起来,要求线不能相交,不能成环。


枚举所有情况。


AC代码:


#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#include <string>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define MAXN (1000+10)
#define MAXM (200000+10)
#define Ri(a) scanf("%d", &a)
#define Rl(a) scanf("%lld", &a)
#define Rf(a) scanf("%lf", &a)
#define Rs(a) scanf("%s", a)
#define Pi(a) printf("%d\n", (a))
#define Pf(a) printf("%.2lf\n", (a))
#define Pl(a) printf("%lld\n", (a))
#define Ps(a) printf("%s\n", (a))
#define W(a) while((a)--)
#define CLR(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define LL long long
#define lson o<<1, l, mid
#define rson o<<1|1, mid+1, r
#define ll o<<1
#define rr o<<1|1
#define PI acos(-1.0)
using namespace std;
int x[3], y[3];
int solve1(int a, int b, int c)
{
    int cnt = 3;
    if(x[a] == x[b])
    {
        if(x[a] == x[c])
            cnt = 1;
        else
        {
            if(min(y[a], y[b]) < y[c] && y[c] < max(y[a], y[b]))
                cnt = 3;
            else
                cnt = 2;
        }
    }
    return cnt;
}
int solve2(int a, int b, int c)
{
    int cnt = 3;
    if(y[a] == y[b])
    {
        if(y[a] == y[c])
            cnt = 1;
        else
        {
            if(min(x[a], x[b]) < x[c] && x[c] < max(x[a], x[b]))
                cnt = 3;
            else
                cnt = 2;
        }
    }
    return cnt;
}
int main()
{
    for(int i = 0; i < 3; i++)
        Ri(x[i]), Ri(y[i]);
    int ans = INF;
    for(int i = 0; i < 3; i++)
    {
        for(int j = 0; j < 3; j++)
        {
            if(i == j) continue;
            for(int k = 0; k < 3; k++)
            {
                if(k == i || k == j) continue;
                ans = min(ans, solve1(i, j, k));
                ans = min(ans, solve2(i, j, k));
            }
        }
    }
    Pi(ans);
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值