您的位置:首页 > 其它

【打CF,学算法——一星级】CodeForces 617D Polyline(水题)

2016-07-08 19:36 381 查看
【CF简介】

提交链接:CF 617D

题面:

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 -1
1 1
1 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:



题意:

给定三个点的位置,问最少需要几条线段,可以一笔画成。

解题:

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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: