zoukankan      html  css  js  c++  java
  • A. Crazy Town

    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 biare 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 x1y1 ( - 106 ≤ x1, y1 ≤ 106) — the coordinates of your home.

    The second line contains two integers separated by a space x2y2 ( - 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 test(s)
    input
    1 1
    -1 -1
    2
    0 1 0
    1 0 0
    
    output
    2
    
    input
    1 1
    -1 -1
    3
    1 0 0
    0 1 0
    1 1 -3
    
    output
    2
    
    Note

    Pictures to the samples are presented below (A is the point representing the house; B is the point representing the university, different blocks are filled with different colors):

    这题想通后很简单,就是看A,B两点间的直线有几条,用零点法看是否一正一负就行。注意一点要分两种情况讨论,不然会爆__int64.

    #include<stdio.h>
    #include<string.h>
    int main()
    {
    __int64 x1,y1,x2,y2,i,j,a,b,c;
    int n,sum;
    while(scanf("%I64d%I64d",&x1,&y1)!=EOF)
    {
    scanf("%I64d%I64d",&x2,&y2);
    scanf("%d",&n);
    sum=0;
    for(i=1;i<=n;i++){
    scanf("%I64d%I64d%I64d",&a,&b,&c);
    if(a*x1+b*y1+c>0 && a*x2+b*y2+c<0){
    sum++;continue;
    }
    if(a*x1+b*y1+c<0 && a*x2+b*y2+c>0){
    sum++;continue;
    }
    }
    printf("%d ",sum);
    }
    }

  • 相关阅读:
    VMware下桥接设置
    oracle 当行函数
    oracle基于scott用户的经典sql 面试题(一)
    java 公平打乱数组顺序 重新排列
    学习.NET3中
    坚持
    分组小计合计报表的SQL
    使用ObjectDataSource注意DeleteMethod、UpdateMethod、Insert等方法中参数的命名约定
    SQL语句like子句中的转义符
    Oracle数据迁移:从存储了中文的但字符集为WE8ISO8859P1数据库导入数据到字符集为ZHS16GBK的数据库
  • 原文地址:https://www.cnblogs.com/herumw/p/9464845.html
Copyright © 2011-2022 走看看