Codeforces Round #340 (Div. 2) 617D Polyline(暴力)

本文探讨了一个关于在坐标平面上通过三个不重复的点构造最短Polyline的问题。该Polyline由平行于坐标轴的线段组成且不允许自我相交。文章提供了具体的输入输出示例并分享了AC代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 "algorithm"
#include "queue"
#include "stack"
#include "cmath"
#include "utility"
#include "map"
#include "set"
#include "vector"
#include "list"
#include "string"
#include "cstdlib"
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
int x11, y11, x2, y2, x3, y3, flag1, flag2, flag3, flag4, flag5, flag6;
int main(int argc, char const *argv[])
{
	cin >> x11 >> y11 >> x2 >> y2 >> x3 >> y3;
	if(x11 == x2) flag1++;
	if(x11 == x3) flag2++;
	if(x2 == x3) flag3++;
	if(y11 == y2) flag4++;
	if(y11 == y3) flag5++;
	if(y2 == y3) flag6++;
	if((flag1 && flag2 && flag3) || (flag4 && flag5 && flag6)) cout << 1 << endl;
	else if((flag1 && (y3 <= min(y11, y2) || y3 >= max(y11, y2))) || 
		(flag2 && (y2 <= min(y11, y3) || y2 >= max(y11, y3))) ||
		(flag3 && (y11 <= min(y2, y3) || y11 >= max(y2, y3))) || 
		(flag4 && (x3 <= min(x11, x2) || x3 >= max(x11, x2))) || 
		(flag5 && (x2 <= min(x11, x3) || x2 >= max(x11, x3))) || 
		(flag6 && (x11 <= min(x2, x3) || x11 >= max(x2, x3)))) cout << 2 << endl;
	else cout << 3 << endl;
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值