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

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



题意:

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


解题:

     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;
}


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值