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.
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.
Print a single number — the minimum possible number of segments of the polyline.
1 -1 1 1 1 2
1
-1 -1 -1 3 4 3
2
1 1 2 3 3 2
3
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;
}