本文主要是介绍CF#284 (Div. 2) C.(几何规律),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目链接:http://codeforces.com/contest/499/problem/C
解题思路:
把两个点的坐标分别带入方程组,如果最后两个值相乘为负,即异号,计数器++。其中有一个有趣的现象,从A到B的最短步数,可以变化为求A和B之间夹了多少条直线,那么最后只要求出直线数,即可求出最小步数。
如果一条直线夹在A和B中间,那么把A和B的坐标带入后,所得值相乘一定为负。数据很大,中间还涉及乘法,所以开成__int64.
完整代码:
#include <functional>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <numeric>
#include <cstring>
#include <climits>
#include <cassert>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef __int64 LL;
typedef double DB;
typedef unsigned uint;
typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const DB EPS = 1e-9;
const DB OO = 1e20;
const DB PI = acos(-1.0); //M_PI;const int maxn = 1000001;
struct node
{LL a , b , c;
}k[maxn];int f(LL a , LL b , LL c , LL d , LL e)
{if(a * b + c * d + e > 0)return 1;elsereturn -1;
}int main()
{#ifdef DoubleQfreopen("in.txt","r",stdin);#endifstd::ios::sync_with_stdio(false);std::cin.tie(0);LL x1 , y1 , x2, y2;while(cin >> x1 >> y1 >> x2 >> y2){int n;cin >> n;for(int i = 0 ; i < n ; i ++){cin >> k[i].a >> k[i].b >> k[i].c ;}int cnt = 0;for(int i = 0 ; i < n ; i ++){int k1 = f(x1 , k[i].a , y1 , k[i].b , k[i].c);int k2 = f(x2 , k[i].a , y2 , k[i].b , k[i].c);if(k1 * k2 == -1)cnt ++;}cout << cnt << endl;}
}
这篇关于CF#284 (Div. 2) C.(几何规律)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!