zoukankan      html  css  js  c++  java
  • Codeforces Round #340 (Div. 2) D. Polyline 水题

    D. Polyline

    题目连接:

    http://www.codeforces.com/contest/617/problem/D

    Descriptionww.co

    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 Input

    -1 -1

    -1 3

    4 3

    Sample Output

    2

    Hint

    题意

    给你3个点,然后问你能够用多少条平行于坐标轴的线段来穿过这三个点

    这些线段是连接在一起的,并且只能在端点处相交

    题解:

    显然答案只会有1 2 3 这三种

    答案为1的,就是这三个点某一维是一样的

    答案为2的,就是这三个点有两个点的某一维是相同的,而另外一个点的另外一维是在这个点之外(画个图就懂了

    剩下的就是答案为3的

    数据:

    1 1
    1 3
    0 2

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    pair<int,int> P[3];
    int check(int x,int y,int z)
    {
        if(x==y)return 0;
        if(y==z)return 0;
        if(x==z)return 0;
    
        if(P[x].first==P[y].first)
        {
            if(P[x].second<P[y].second)
            {
                if(P[z].second<=P[x].second||P[z].second>=P[y].second)
                    return 1;
            }
        }
    
        if(P[x].second==P[y].second)
        {
            if(P[x].first<P[y].first)
            {
                if(P[z].first<=P[x].first||P[z].first>=P[y].first)
                    return 1;
            }
        }
    
        return 0;
    }
    int main()
    {
        for(int i=0;i<3;i++)
            cin>>P[i].first>>P[i].second;
    
        if(P[0].first == P[1].first && P[1].first == P[2].first)
            return puts("1");
        if(P[0].second == P[1].second && P[1].second == P[2].second)
            return puts("1");
    
        for(int i=0;i<3;i++)
            for(int j=0;j<3;j++)
                for(int k=0;k<3;k++)
                    if(check(i,j,k))
                        return puts("2");
    
        return puts("3");
    }
  • 相关阅读:
    C++头文件相互引用,最好一个#include,另一个class C;
    Git 安装配置
    loadrunner字符串赋值
    loadrunner 调用外部dll
    redis启动、清缓存命令
    solr-6.4.1 学习安装与配置 和 Elasticsearch(1.5.2)学习文档
    分页
    JS原型理解
    angular2 依赖注入新坑。
    javascript数组传值与地址。
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5156277.html
Copyright © 2011-2022 走看看