题目链接:点击打开链接
给出三个点的坐标, 问几条平行于坐标轴的线可以连接这三个点, 不能像十字路口一样连接方式.
暴力枚举即可, 特判十字路口的连接方式.
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;
}