lightoj1107 How Cow

来源:互联网 发布:gltools优化王者 编辑:程序博客网 时间:2024/06/07 23:44

思路:此题就是简单叉积运用,判断点在规则图形内,比如三角形,平行四边形等。

// #pragma comment(linker, "/STACK:1024000000,1024000000")#include <iostream>#include <algorithm>#include <iomanip>#include <sstream>#include <string>#include <stack>#include <queue>#include <deque>#include <vector>#include <map>#include <set>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <climits>using namespace std;// #define DEBUG#ifdef DEBUG#define debug(...) printf( __VA_ARGS__ )#else#define debug(...)#endif#define CLR(x) memset(x, 0,sizeof x)#define MEM(x,y) memset(x, y,sizeof x)#define pk push_backtemplate<class T> inline T Get_Max(const T&a,const T&b){return a < b?b:a;}template<class T> inline T Get_Min(const T&a,const T&b){return a < b?a:b;}// typedef long long LL;typedef unsigned long long ULL;typedef pair<int,int> ii;const double eps = 1e-10;const int inf = 1 << 30;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;struct Point{double x, y;Point(){}Point(double _x, double _y){x = _x;y = _y;}Point operator + (const Point& rhs)const{return Point(x + rhs.x, y + rhs.y);}Point operator - (const Point& rhs)const{return Point(x - rhs.x, y - rhs.y);}double operator ^ (const Point& rhs)const{return (x * rhs.y - y * rhs.x);}double operator * (const Point& rhs)const{return (x * rhs.x + y * rhs.y);}Point operator * (const double Num)const{return Point(x * Num,y * Num);}friend ostream& operator << (ostream& output,const Point& rhs){output << "(" << rhs.x << "," << rhs.y << ")";return output;}};typedef Point Vector;/*向量的模*/inline double Length(const Vector& A){//Get the length of vector A;return sqrt(A * A);//sqrt(x*x+y*y);}/*向量夹角*/inline double Angle(const Vector& A,const Point& B){return acos(A * B/Length(A)/Length(B));}/*向量A旋转rad弧度*/inline Point Rotate(const Vector& A, double rad){return Vector(A.x*cos(rad) - A.y*sin(rad),A.x*sin(rad) + A.y*cos(rad));}Point LL,LU,RU,RL;double S;bool check(Point O){double x = O^RL;double s1 = fabs((O - LL)^(RL - O)) / 2.0;double s2 = fabs((RL - O)^(RU - O)) / 2.0;double s3 = fabs((RU - O)^(LU - O)) / 2.0;double s4 = fabs((LU - O)^(LL - O)) / 2.0;if (s1 < eps || s2 < eps || s3 < eps || s4 < eps) return false;return (s1 + s2 + s3 + s4 <= S + eps);}int main(){// ios::sync_with_stdio(false);// freopen("in.txt","r",stdin);// freopen("out.txt","w",stdout);int t, icase = 0, n;cin >> t;while(t--){cin >> LL.x >> LL.y >> RU.x >> RU.y;LU = Point(LL.x, RU.y);RL = Point(RU.x, LL.y);S = (RU.x - LL.x) * (RU.y - LL.y);cin >> n;int ans = 0;printf("Case %d:\n", ++icase);while(n--){double x, y;cin >> x >> y;if (check(Point(x,y))) puts("Yes");else puts("No");}}return 0;}


0 0