提交链接:CF 617D
题面:
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:
题意:
给定三个点的位置,问最少需要几条线段,可以一笔画成。
解题:
1.三点一线,1条线段。
2.两点共线,另外一点在两点之间,2条线段。
3.两点共线,另外一点在两点之外,3条线段。
4.其他情况,3条线段。
#include <iostream>
#include <string>
#include <cstdio>
#define cal1(a,b,c) x[a]==x[b]&&(y[c]<min(y[a],y[b])||y[c]>max(y[a],y[b]))
#define cal2(a,b,c) y[a]==y[b]&&(x[c]<min(x[a],x[b])||x[c]>max(x[a],x[b]))
using namespace std;
int main()
{
int x[3],y[3],a=0,b=0,ans;
for(int i=0;i<3;i++)
scanf("%d%d",&x[i],&y[i]);
for(int i=0;i<2;i++)
for(int j=i+1;j<3;j++)
{
if(x[i]==x[j])
a++;
if(y[i]==y[j])
b++;
}
if(a==3||b==3)
ans=1;
else if(a==1&&b==1)
ans=2;
else if(a==1)
{
if(cal1(0,1,2)||cal1(0,2,1)||cal1(1,2,0))
ans=2;
else
ans=3;
}
else if(b==1)
{
if(cal2(0,1,2)||cal2(1,2,0)||cal2(0,2,1))
ans=2;
else
ans=3;
}
else
ans=3;
printf("%d\n",ans);
return 0;
}