博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【codeforces 499C】Crazy Town
阅读量:4654 次
发布时间:2019-06-09

本文共 1337 字,大约阅读时间需要 4 分钟。

【题目链接】:

【题意】

一个平面,被n条直线分成若干个块;
你在其中的某一块,然后你想要要到的终点在另外一个块;
给出起点坐标(x0,y0),终点坐标(x1,y1);
每次你能从一个块移动到相邻的块;
问你最少需要穿过多少条直线,才能到达终点所在的块;

【题解】

枚举每一条直线;
如果这两个点在这条直线的两边;(即不在一边);
那么肯定最后是需要穿过这条直线的(才能走在一起);
所以答案递增;
代入一般式,看看符号是不是不同即可;
因为有说不在线上,所以不用考虑为0的情况;
【Number Of WA
0
【完整代码】

#include 
using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define LL long long#define rep1(i,a,b) for (int i = a;i <= b;i++)#define rep2(i,a,b) for (int i = a;i >= b;i--)#define mp make_pair#define pb push_back#define fi first#define se second#define ms(x,y) memset(x,y,sizeof x)#define Open() freopen("F:\\rush.txt","r",stdin)#define Close() ios::sync_with_stdio(0),cin.tie(0)typedef pair
pii;typedef pair
pll;const int dx[9] = {
0,1,-1,0,0,-1,-1,1,1};const int dy[9] = {
0,0,0,-1,1,-1,1,-1,1};const double pi = acos(-1.0);const int N = 110;LL x1,y1,x2,y2,a,b,c;int n,ans = 0;int main(){ //Open(); Close();//scanf,puts,printf not use //init?????? cin >> x1 >> y1; cin >> x2 >> y2; cin >> n; rep1(i,1,n) { cin >> a >> b >> c; LL temp1 = a*x1+b*y1+c; LL temp2 = a*x2+b*y2+c; if ( (temp1<0 && temp2>0) || (temp1>0 && temp2<0)) ans++; } cout << ans << endl; return 0;}

转载于:https://www.cnblogs.com/AWCXV/p/7626302.html

你可能感兴趣的文章