• CSU1007: 矩形着色


    Description

    Danni想为屏幕上的一个矩形着色,但是她想到了一个问题。当点击鼠标以后电脑是如何判断填充的区域呢?

    现在给你一个平面直角坐标系,其中有一个矩形和一个点,矩形的四条边均是平行于x轴或y轴的。请你判断这个点相对于矩形的位置,即在矩形内,在矩形上,还是在矩形外?

    Input

    第一行只有一个整数T,(T < 150),代表共有T种情况。

    接下对于每种情况,均有两行数据:

    第一行有两个整数Px Py,以空格分隔,代表点的坐标(Px,Py).

    第二行有四个整数Ax Ay Bx By,以空格分隔,代表矩形左下角的坐标(Ax,Ay)和右上角的坐标(Bx,By).

    所有的坐标均为区间[0,100]内的整数,且Ax<Bx,Ay<By

    Output

    对于每种情况仅输出一行:

    1. 如果点在矩形外部,请输出”Outside”
    2. 如果点正好在矩形的边上,请输出”On”
    3. 如果点在矩形内部,请输出”Inside” 所有输出都不包含引号。

    Sample Input

    3
    38 7
    30 7 52 66
    55 1
    9 13 54 84
    74 67
    73 66 76 68
    

    Sample Output

    On
    Outside
    Inside

    题意:水题,分组判断就好。
    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <algorithm>
    using namespace std;
    int T;
    int px,py;
    int ax,ay,bx,by;
    int main()
    {
        scanf("%d",&T);
        while(T--)
        {
            scanf("%d %d",&px,&py);
            scanf("%d %d %d %d",&ax,&ay,&bx,&by);
            if(px==ax&&py<=by&&py>=ay)
                printf("On
    ");
            else if(px==bx&&py<=by&&py>=ay)
                printf("On
    ");
            else if(py==ay&&px>=ax&&px<=bx)
                printf("On
    ");
            else if(py==by&&px>=ax&&px<=bx)
                printf("On
    ");
            else if(px>ax&&px<bx&&py>ay&&py<by)
                printf("Inside
    ");
            else
                printf("Outside
    ");
        }
        return 0;
    }
    
    /**********************************************************************
    	Problem: 1007
    	User: therang
    	Language: C++
    	Result: AC
    	Time:0 ms
    	Memory:0 kb
    **********************************************************************/
    

      

  • 相关阅读:
    linux 命令——48 watch (转)
    linux 命令——47 iostat (转)
    linux 命令——46 vmstat(转)
    linux 命令——45 free(转)
    linux 命令——44 top (转)
    linux 命令——43 killall(转)
    linux 命令——42 kill (转)
    linux 命令——41 ps(转)
    linux 命令——40 wc (转)
    Java for LeetCode 068 Text Justification
  • 原文地址:https://www.cnblogs.com/jkzr/p/9956649.html
Copyright © 2020-2023  润新知