codeforces 498A crazy town

在平面被无限直线划分的CrazyTown中,确定从家到大学所在区域的最少穿越次数。通过判断直线两侧的区域来计算最短路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

A. Crazy Town
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.


主要就是两个思考地方,要走的步就是有多少线在两点之间,把点带入的值一正一负就行。然后就是就算是long long 一起乘也要爆啊


#include<iostream>
typedef long long LL;
using namespace std;

int main()
{
 LL a,b,c,d;
 LL n;
 cin>>a>>b;
 cin>>c>>d;
 cin>>n;
 LL cross=0;
 LL x,y,z;
 for(LL i=0;i<n;i++)
 {
  cin>>x>>y>>z;
  //if((a*x+b*y+z)*(c*x+d*y+z)<0)cross++;//两个longlong要乘爆啊 
  if((a*x+b*y+z)>0&&(c*x+d*y+z)<0)cross++;
  if((a*x+b*y+z)<0&&(c*x+d*y+z)>0)cross++;
 }
 cout<<cross<<endl;
 return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值