Codeforces Round #340 (Div. 2)——D

题意:

给你3个点的坐标,然后问你最少用几条折线就可以把这3个点给连接起来,并且同时要满足这几条折线都平行于坐标轴。(具体详见样例)

思路:

直接模拟,要小心。。。

#include<cstdio>
#include<cstring>
#include<map>
#include<set>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
typedef __int64 ll;
typedef unsigned __int64 ULL;
#define inf 99999999
#define maxn 5
struct node{
    ll x,y;
}a[maxn];
bool cmp(node a,node b){
    if(a.x!=b.x) return a.x<b.x;
    else return a.y<b.y;
}
int main(){
    for(int i=0;i<3;i++){
        scanf("%I64d%I64d",&a[i].x,&a[i].y);
    }
    sort(a,a+3,cmp);
    if((a[0].x==a[1].x&&a[1].x==a[2].x)||(a[0].y==a[1].y&&a[1].y==a[2].y)){
        printf("1\n");
    }
    //当有2个点在同一直线上的情况要小心,因为在范围之外的也是可行的!!
    else if((a[0].x==a[1].x&&(a[2].y>=a[1].y||a[2].y<=a[0].y))||
            (a[0].y==a[1].y&&(a[2].x<=a[0].x||a[2].x>=a[1].x))||
            (a[0].y==a[2].y&&(a[1].x<=a[0].x||a[1].x>=a[2].x))||
            (a[1].x==a[2].x&&(a[0].y<=a[1].y||a[0].y>=a[2].y))||
            (a[1].y==a[2].y&&(a[0].x<=a[1].x||a[0].x>=a[2].x))){
                printf("2\n");
    }
    else{
        printf("3\n");
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值