日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces 499C、Crazy Town

發布時間:2023/12/20 编程问答 41 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CodeForces 499C、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 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.

Example
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):


題意:給出兩個點,求兩個點之間有多少條直線,給出直線方程ax+by+c

思路:把一個點代入一條直線方程中,有3種結果:大于0,在這條直線上方;小于0,在這條直線下方;等于0 ,在直線上。如果兩個點代入直線,一個大于0一個小于0,說明這條直線在兩個點中間。故求兩點之間有多少直線,只要一一代入直線方程就行

code:

#include<stdio.h> typedef long long ll; int main() {ll x1,x2,y1,y2,a,b,c,n,l1,l2,num;while(~scanf("%lld%lld%lld%lld%lld",&x1,&y1,&x2,&y2,&n)){num=0;while(n--){scanf("%lld%lld%lld",&a,&b,&c);l1=a*x1+b*y1+c;l2=a*x2+b*y2+c;if((l1>0&&l2<0)||(l1<0&&l2>0)) num++;}printf("%lld\n",num);}return 0; }

總結

以上是生活随笔為你收集整理的CodeForces 499C、Crazy Town的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。