C - Urban Design

A new town is being planned, and the designers have some very specific ideas about how things should be laid out. First, they lay out the streets. Each street is perfectly straight and passes completely from one end of the town to the other. These streets divide the town into regions, and each region is to be designated either"residential"or"commercial".The town planners require that any two regions directly across the street from one another must have different designations. On this one particular day, all of the streets have been planned, but none of the regions have been designated. One town planner wishes to purchase two properties, and it is important to him that the properties eventually have different designations. For this problem, the streets can be modeled by lines in the plane that extend forever in both directions and have no width, and properties may be modeled by points. Given the lines and two points, can you decide whether or not they must get different designations,“commercial"or"residential”?

C.jpg\[20pt]

​​\normalsize \textbf{Input}Input

Input begins with an integer SS on a single line, giving the number of streets (1≤S≤10000)(1≤S≤10000). The next SS lines of input each contain four integers x_1x
1

, y_1y
1

, x_2x
2

, and y_2y
2

, specifying the coordinates of two distinct points (x_1,y_1)(x
1

,y
1

) and (x_2,y_2)(x
2

,y
2

). The unique line through these two points gives one of the streets. Each coordinate is in the range [0,10000][0,10000], and no two lines will be identical. That is, the town will have SS distinct streets. The next line contains an integer TT, the number of pairs of properties to test (1≤T≤1000)(1≤T≤1000). This is followed by TT lines of input, each containing four integers x_3x
3

, y_3y
3

, x_4x
4

, and y_4y
4

, representing two distinct points (x3,y3)(x3,y3) and (x4,y4)(x4,y4), where each point lies within one of the two properties to test. None of these points will lie on any of the streets, nor will both points lie within the same property. Again, each coordinate is in the range [0,10000][0,10000].

\[20pt]
\normalsize \textbf{Output}Output

For each of the TT pairs of properties to be tested, output either"same"if the properties are guaranteed to receive the same designation or"different"if they are guaranteed to receive different designations.

输出时每行末尾的多余空格,不影响答案正确性

样例输入1复制
2
1 1 2 1
1 1 1 2
3
2 0 2 2
2 0 0 3
0 0 2 2
样例输出1复制
different
same
same
样例输入2复制
4
1 3 2 4
1 3 2 5
1 3 3 4
7 9 8 8
2
14 7 10 13
1 4 2 3
样例输出2复制
same
different

题意,直线划分区域。

如图所示,记下来要求任意两点是否同时在0或1区域。
我们经过观察寻找规律可以发现,点存在的区域是否相同取决于其左边(或者右边)线的数量。同奇或同偶数则在相同区域,反之不同。

#include <cstdio>
using namespace std;
int line;
int q;
const int maxn = 10009;
struct shit{
    int x1,y1;
    int x2,y2;
}street[10009],house[1009];//存线和存点
bool check(int x1,int y1,int x2,int y2,int a,int b){//判断在左边还有右边
    int t = (b-y1)*(x2-x1) - (y2-y1)*(a-x1);
    if(t > 0) return true;
    else return false;
}
int main(void){
    scanf("%d",&line);
    for(int i = 1; i <= line; i++)
        scanf("%d %d %d %d", &street[i].x1,&street[i].y1,&street[i].x2,&street[i].y2);
    scanf("%d", &q);
    for(int i = 1; i <= q; i++)
        scanf("%d %d %d %d", &house[i].x1,&house[i].y1,&house[i].x2,&house[i].y2);
    for(int i = 1; i <= q; i++){
        int a1=0;
        int a2=0;
        for(int j = 1; j <= line; j++){
            if(check(street[j].x1,street[j].y1,street[j].x2,street[j].y2,house[i].x1,house[i].y1))
                a1++;//计算线的个数
            if(check(street[j].x1,street[j].y1,street[j].x2,street[j].y2,house[i].x2,house[i].y2))
                a2++;//计算线的个数
        }
        a1%=2;//取余,得奇偶性
        a2%=2;//取余,得奇偶性
        if(a1==a2)printf("same\n");
        else printf("different\n");
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值