TJU训练赛—C

来源:互联网 发布:剪空镜用什么软件 编辑:程序博客网 时间:2024/05/17 03:27
C.   find the princessIII

Time Limit: 1.0 Seconds   Memory Limit: 65536K



It is a pity that the Dsir cost much time in "find the princess II". The devil has dropped a bomb beside the princess.This is the scope of bomb is a circle. The radius of the circle is R. The bomb can be regarded as a point. The coordinates of cirle is (cx, cy). For this problem,we can assume that the princess was tied to a stick. The coordinates of stick two endpoints is (x1, y1), (x2,y2). Dsir want to know whether the princess would be Fried.

Input

First line of input T(the number of cases), each line of input cx, cy, R, x1, y1, x2, y2.
-100≤cx≤100,-100≤cy≤100,-100≤x1≤100, -100≤y1≤100, -100≤x2≤100, -100≤y2≤100, -100≤R≤100

Output

For each case, output "All in"(the princess completely within the circle) OR "Part in"(the princess parts within the circle) OR "All out"(the princess not in the circle).

Hint:

If stick with only one point on the circle, is considered to be the princess is not in the circle!

Sample Input

3

0 0 1 0 0 0 1

0 0 1 0 0 1 1

0 0 1 1 0 1 1

Sample Output

All in

Part in

All out


【分析】

几何模板题....考虑几种情况

1.两点都在圆内是"All in"

2.一点在园内一点在圆外是“Part in”

3.两点都在圆外,考虑圆心点线段的距离,若距离<R是"Part in"否则“All out”

浙大模板....

【代码】

#include <cstdio>#include <iostream>#include <algorithm>#include <string>#include <cstring>#include <cmath>#include <cstdlib>#include <vector>#include <list>#include <queue>#include <bitset>#include <complex>#include <deque>#include <climits>#include <cassert>#include <stack>#include <set>#include <map>#include <utility>#include <cctype>#include <fstream>#include <sstream>#include <iomanip>#include <numeric>using namespace std;#define fi first#define se second#define clr(a, b) memset(a, b, sizeof(a))typedef long long ll;typedef double db;typedef pair<int, int> Pii;typedef pair<double, double> Pdd;const db PI = acos(-1.0);const int inf = 0x3f3f3f3f;const int mod = 1e9 + 7;const int maxn = 100+ 10;int T;const double EPS = 1e-8;struct Point {double x, y;};struct Line {Point a, b;};inline bool zero(double x) {return ((x > 0 ? x : -x) < EPS);}inline double xmult(const Point & p1, const Point & p2, const Point & p0) {return (p1.x - p0.x) * (p2.y - p0.y) - (p2.x - p0.x) * (p1.y - p0.y);}inline double xmult(double x1, double y1, double x2, double y2, double x0, double y0) {return (x1 - x0) * (y2 - y0) - (x2 - x0) * (y1 - y0);}inline double dmult(const Point & p1, const Point & p2, const Point & p0) {return (p1.x - p0.x) * (p2.x - p0.x) + (p1.y - p0.y) * (p2.y - p0.y);}inline double dmult(double x1, double y1, double x2, double y2, double x0, double y0) {return (x1 - x0) * (x2 - x0) + (y1 - y0) * (y2 - y0);}inline double dis(const Point & p1, const Point & p2) {return sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y));}inline double dis(double x1, double y1, double x2, double y2) {return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));}bool dotsInline(const Point & p1, const Point & p2, const Point & p3) {return zero(xmult(p1, p2, p3));}bool dotsInline(double x1, double y1, double x2, double y2, double x3, double y3) {return zero(xmult(x1, y1, x2, y2, x3, y3));}bool dotOnlineIn(const Point & p, const Line & l) {return zero(xmult(p, l.a, l.b)) && (l.a.x - p.x) * (l.b.x - p.x) < EPS && (l.a.y - p.y) * (l.b.y - p.y) < EPS;}bool dotOnlineIn(const Point & p, const Point & l1, const Point & l2) {return zero(xmult(p, l1, l2)) && (l1.x - p.x) * (l2.x - p.x) < EPS && (l1.y - p.y) * (l2.y - p.y) < EPS;}bool dotOnlineIn(double x, double y, double x1, double y1, double x2, double y2) {return zero(xmult(x, y, x1, y1, x2, y2)) && (x1 - x) * (x2 - x) < EPS && (y1 - y) * (y2 - y) < EPS;}bool dotOnlineEx(const Point & p, const Line & l) {return dotOnlineIn(p, l) && (!zero(p.x - l.a.x) || !zero(p.y - l.a.y)) && (!zero(p.x - l.b.x) || !zero(p.y - l.b.y));}bool dotOnlineEx(const Point & p, const Point & l1, const Point & l2) {return dotOnlineIn(p, l1, l2) && (!zero(p.x - l1.x) || !zero(p.y - l1.y)) && (!zero(p.x - l2.x) || !zero(p.y - l2.y));}bool dotOnlineEx(double x, double y, double x1, double y1, double x2, double y2) {return dotOnlineIn(x, y, x1, y1, x2, y2) && (!zero(x - x1) || !zero(y - y1)) && (!zero(x - x2) || !zero(y - y2));}bool sameSide(const Point & p1, const Point & p2, const Line & l) {return xmult(l.a, p1, l.b) * xmult(l.a, p2, l.b) > EPS;}bool sameSide(const Point & p1, const Point & p2, const Point & l1, const Point & l2) {return xmult(l1, p1, l2) * xmult(l1, p2, l2) > EPS;}bool oppositeSide(const Point & p1, const Point & p2, const Line & l) {return xmult(l.a, p1, l.b) * xmult(l.a, p2, l.b) < -EPS;}bool oppositeSide(const Point & p1, const Point & p2, const Point & l1, const Point & l2) {return xmult(l1, p1, l2) * xmult(l1, p2, l2) < -EPS;}bool parallel(const Line & u, const Line & v) {return zero((u.a.x - u.b.x) * (v.a.y - v.b.y) - (v.a.x - v.b.x) * (u.a.y - u.b.y));}bool parallel(const Point & u1, const Point & u2, const Point & v1, const Point & v2) {return zero((u1.x - u2.x) * (v1.y - v2.y) - (v1.x - v2.x) * (u1.y - u2.y));}bool perpendicular(const Line & u, const Line & v) {return zero((u.a.x - u.b.x) * (v.a.x - v.b.x) + (u.a.y - u.b.y) * (v.a.y - v.b.y));}bool perpendicular(const Point & u1, const Point & u2, const Point & v1, const Point & v2) {return zero((u1.x - u2.x) * (v1.x - v2.x) + (u1.y - u2.y) * (v1.y - v2.y));}bool intersectIn(const Line & u, const Line & v) {if (!dotsInline(u.a, u.b, v.a) || !dotsInline(u.a, u.b, v.b)) {return !sameSide(u.a, u.b, v) && !sameSide(v.a, v.b, u);} else {return dotOnlineIn(u.a, v) || dotOnlineIn(u.b, v) || dotOnlineIn(v.a, u) || dotOnlineIn(v.b, u);}}bool intersectIn(const Point & u1, const Point & u2, const Point & v1, const Point & v2) {if (!dotsInline(u1, u2, v1) || !dotsInline(u1, u2, v2)) {return !sameSide(u1, u2, v1, v2) && !sameSide(v1, v2, u1, u2);} else {return dotOnlineIn(u1, v1, v2) || dotOnlineIn(u2, v1, v2) || dotOnlineIn(v1, u1, u2) || dotOnlineIn(v2, u1, u2);}}bool intersectEx(const Line & u, const Line & v) {return oppositeSide(u.a, u.b, v) && oppositeSide(v.a, v.b, u);}bool intersectEx(const Point & u1, const Point & u2, const Point & v1, const Point & v2) {return oppositeSide(u1, u2, v1, v2) && oppositeSide(v1, v2, u1, u2);}Point intersection(const Line & u, const Line & v) {Point ret = u.a;double t = ((u.a.x - v.a.x) * (v.a.y - v.b.y) - (u.a.y - v.a.y) * (v.a.x - v.b.x)) / ((u.a.x - u.b.x) * (v.a.y - v.b.y) - (u.a.y - u.b.y) * (v.a.x - v.b.x));ret.x += (u.b.x - u.a.x) * t;ret.y += (u.b.y - u.a.y) * t;return ret;}Point intersection(const Point & u1, const Point & u2, const Point & v1, const Point & v2) {Point ret = u1;double t = ((u1.x - v1.x) * (v1.y - v2.y) - (u1.y - v1.y) * (v1.x - v2.x)) / ((u1.x - u2.x) * (v1.y - v2.y) - (u1.y - u2.y) * (v1.x - v2.x));ret.x += (u2.x - u1.x) * t;ret.y += (u2.y - u1.y) * t;return ret;}Point ptoline(const Point & p, const Line & l) {Point t = p;t.x += l.a.y - l.b.y;t.y += l.b.x - l.a.x;return intersection(p, t, l.a, l.b);}Point ptoline(const Point & p, const Point & l1, const Point & l2) {Point t = p;t.x += l1.y - l2.y;t.y += l2.x - l1.x;return intersection(p, t, l1, l2);}double disptoline(const Point & p, const Line & l) {return fabs(xmult(p, l.a, l.b)) / dis(l.a, l.b);}double disptoline(const Point & p, const Point & l1, const Point & l2) {return fabs(xmult(p, l1, l2)) / dis(l1, l2);}double disptoline(double x, double y, double x1, double y1, double x2, double y2) {return fabs(xmult(x, y, x1, y1, x2, y2)) / dis(x1, y1, x2, y2);}Point ptoseg(const Point & p, const Line & l) {Point t = p;t.x += l.a.y - l.b.y;t.y += l.b.x - l.a.x;if (xmult(l.a, t, p) * xmult(l.b, t, p) > EPS) {return dis(p, l.a) < dis(p, l.b) ? l.a : l.b;} else {return intersection(p, t, l.a, l.b);}}Point ptoseg(const Point & p, const Point & l1, const Point & l2) {Point t = p;t.x += l1.y - l2.y;t.y += l2.x - l1.x;if (xmult(l1, t, p) * xmult(l2, t, p) > EPS) {return dis(p, l1) < dis(p, l2) ? l1 : l2;} else {return intersection(p, t, l1, l2);}}double disptoseg(const Point & p, const Line & l) {Point t = p;t.x += l.a.y - l.b.y;t.y += l.b.x - l.a.x;if (xmult(l.a, t, p) * xmult(l.b, t, p) > EPS) {return dis(p, l.a) < dis(p, l.b) ? dis(p, l.a) : dis(p, l.b);} else {return fabs(xmult(p, l.a, l.b))/dis(l.a, l.b);}}double disptoseg(const Point & p, const Point & l1, const Point & l2) {Point t = p;t.x += l1.y - l2.y;t.y += l2.x - l1.x;if (xmult(l1, t, p) * xmult(l2, t, p) > EPS) {return dis(p, l1) < dis(p, l2) ? dis(p, l1) : dis(p, l2);} else {return fabs(xmult(p, l1, l2))/dis(l1, l2);}}Point rotate(Point v, Point p, double angle, double scale) {Point ret = p;v.x -= p.x;v.y -= p.y;p.x = scale * cos(angle);p.y = scale * sin(angle);ret.x += v.x * p.x - v.y * p.y;ret.y += v.x * p.y + v.y * p.x;return ret;}int main() {int pp;scanf("%d", &pp);double R;Point c, x1, x2;while(pp--) {scanf("%lf%lf%lf%lf%lf%lf%lf",&c.x,&c.y,&R,&x1.x,&x1.y,&x2.x,&x2.y);double dis1=disptoseg(c,x1,x2);double dis2=dis(c,x1);double dis3=dis(c,x2);if(R<=dis1) printf("All out\n");else if(R>=max(dis2,dis3)) printf("All in\n");else printf("Part in\n");}return 0;}


原创粉丝点击