zoukankan      html  css  js  c++  java
  • Codeforces Round #284 (Div. 1) A. Crazy Town 计算几何

    A. Crazy Town

    题目连接:

    http://codeforces.com/contest/498/problem/A

    Description

    Crazy Town is a plane on which there are n infinite line roads. Each road is defined by the equation aix + biy + ci = 0, where ai and bi are not both equal to the zero. The roads divide the plane into connected regions, possibly of infinite space. Let's call each such region a block. We define an intersection as the point where at least two different roads intersect.

    Your home is located in one of the blocks. Today you need to get to the University, also located in some block. In one step you can move from one block to another, if the length of their common border is nonzero (in particular, this means that if the blocks are adjacent to one intersection, but have no shared nonzero boundary segment, then it are not allowed to move from one to another one in one step).

    Determine what is the minimum number of steps you have to perform to get to the block containing the university. It is guaranteed that neither your home nor the university is located on the road.

    Input

    The first line contains two space-separated integers x1, y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.

    The second line contains two integers separated by a space x2, y2 ( - 106 ≤ x2, y2 ≤ 106) — the coordinates of the university you are studying at.

    The third line contains an integer n (1 ≤ n ≤ 300) — the number of roads in the city. The following n lines contain 3 space-separated integers ( - 106 ≤ ai, bi, ci ≤ 106; |ai| + |bi| > 0) — the coefficients of the line aix + biy + ci = 0, defining the i-th road. It is guaranteed that no two roads are the same. In addition, neither your home nor the university lie on the road (i.e. they do not belong to any one of the lines).

    Output

    Output the answer to the problem.

    Sample Input

    1 1
    -1 -1
    2
    0 1 0
    1 0 0

    Sample Output

    2

    Hint

    题意

    给你两个点A,B

    然后给你n条直线,这n条直线会把平面切成几块,然后问你从A走到B至少跨过多少条直线。

    题解:

    对于每一条直线,判断这两个点是否在同侧就好了。

    但是乘法会爆long long。。。

    所以就直接判断符号吧

    代码

    #include<bits/stdc++.h>
    using namespace std;
    
    int main()
    {
        long long x1,x2,y1,y2;
        cin>>x1>>y1;
        cin>>x2>>y2;
        int n;
        scanf("%d",&n);
        int ans = 0;
        for(int i=0;i<n;i++)
        {
            long long a,b,c;
            cin>>a>>b>>c;
            long long tmp1 = a*x1+b*y1+c;
            long long tmp2 = a*x2+b*y2+c;
            if(tmp1>0 != tmp2>0)
                ans++;
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    WinCE NAND flash
    正确选择报表工具的十大标准
    从技术岗位走向管理岗位:机会是留给有准备的人
    创业失败的七个原因及解决之道
    技术人员如何参与产品设计讨论:激活那一潭死水
    基于Android Studio搭建hello world工程
    基于Android Studio搭建Android应用开发环境
    JS数组去重的6种算法实现
    八款前端开发人员更轻松的实用在线工具
    海市蜃楼-嘉兴外蒲岛奇遇
  • 原文地址:https://www.cnblogs.com/qscqesze/p/5927947.html
Copyright © 2011-2022 走看看