1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
| #pragma GCC optimize(3,"Ofast","inline") #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <vector> #include <string> #define maxn 100005 using namespace std; const double eps = 1e-8; int sgn(double x){ if(fabs(x) < eps) return 0; return x > 0 ? 1 : -1; } struct Point{ double x, y; Point(){} Point(double _x, double _y){ x = _x; y = _y; } Point operator +(const Point &A){ return Point(x + A.x, y + A.y); } Point operator -(const Point &A){ return Point(x - A.x, y - A.y); } double operator *(const Point &A){ return x * A.x + y * A.y; } double operator ^(const Point &A){ return x * A.y - y * A.x; } void print() { printf("[Point] x:%.2lf, y:%.2lf\n", x, y); } }; struct Line{ Point s, e; Line(){} Line(Point _s, Point _e){ s = _s; e = _e; } Point crosspoint(Line v){ double a1 = (v.e - v.s) ^ (s - v.s); double a2 = (v.e - v.s) ^ (e - v.s); return Point((s.x * a2 - e.x * a1) / (a2 - a1), (s.y * a2 - e.y * a1) / (a2 - a1)); } int segcrossseg(Line v) { int d1 = sgn((e - s) ^ (v.s - s)); int d2 = sgn((e - s) ^ (v.e - s)); int d3 = sgn((v.e - v.s) ^ (s - v.s)); int d4 = sgn((v.e - v.s) ^ (e - v.s)); if ((d1 ^ d2) == -2 && (d3 ^ d4) == -2) return 2; return (d1 == 0 && sgn((v.s - s) * (v.s - e)) <= 0) || (d2 == 0 && sgn((v.e - s) * (v.e - e)) <= 0) || (d3 == 0 && sgn((s - v.s) * (s - v.e)) <= 0) || (d4 == 0 && sgn((e - v.s) * (e - v.e)) <= 0); } void print() { printf("[Line] x1:%.2lf, y1:%.2lf x2:%.2lf y2:%.2lf\n", s.x, s.y, e.x, e.y); } }; struct Geometry{ char id; vector<Line> v; }G[maxn]; void Print(char r, vector<char> ID){ if(ID.empty()){ cout << r << " has no intersections\n"; } else if((int)(ID.size()) == 1){ cout << r << " intersects with " << ID[0] << '\n'; } else if((int)(ID.size()) == 2){ cout << r << " intersects with " << ID[0] << " and " << ID[1] << '\n'; } else{ int siz = ID.size(); cout << r << " intersects with "; for(int i = 0; i < siz - 1; i++){ cout << ID[i] << ", "; } cout << "and " << ID[siz - 1] << '\n'; } } void Polygon(vector<Point> &A, vector<Line> &X){ int siz = A.size(); for(int i = 0; i < siz - 1; i++){ X.push_back(Line(A[i], A[i + 1])); } X.push_back(Line(A[siz - 1], A[0])); } void Solve(string str, Geometry &X){ X.id = str[0]; vector<Point> P; int len = str.length(); for(int i = 0; i < len; i++){ if(str[i] == '('){ int nx, ny, pos = i, f = 1, val = 0; while(pos < len && str[pos] < '0' || str[pos] > '9'){ if(str[pos] == '-') f = -1; pos++; } while(pos < len && str[pos] >= '0' && str[pos] <= '9'){ val = val * 10 + (str[pos] - '0'); pos++; } nx = val * f; f = 1, val = 0; while(pos < len && str[pos] < '0' || str[pos] > '9'){ if(str[pos] == '-') f = -1; pos++; } while(pos < len && str[pos] >= '0' && str[pos] <= '9'){ val = val * 10 + (str[pos] - '0'); pos++; } ny = val * f; P.push_back(Point(nx, ny)); } } if(str.find("square") != string::npos){ double cx = P[0].x, cy = P[0].y, tx = P[1].x, ty = P[1].y; double nx1 = (cx + tx + cy - ty) / 2, ny1 = (cy + ty - cx + tx) / 2; double nx2 = (cx + tx - cy + ty) / 2, ny2 = (cy + ty + cx - tx) / 2; P.push_back(Point(nx1, ny1)); P.push_back(Point(nx2, ny2)); swap(P[1], P[2]); Polygon(P, X.v); } else if(str.find("rectangle") != string::npos){ Point D = P[0] + (P[2] - P[1]); P.push_back(D); Polygon(P, X.v); } else{ Polygon(P, X.v); } } bool check(vector<Line> v1, vector<Line> v2){ for(int i = 0; i < v1.size(); i++) for(int j = 0; j < v2.size(); j++){ if(v1[i].segcrossseg(v2[j])){ return true; } } return false; } bool cmp(const Geometry &A, const Geometry &B){ return A.id < B.id; } int main(void) { string str; while(getline(cin, str) && str != "."){ for(int i = 1; i <= 30; i++) G[i].v.clear(); int cnt = 0; do{ Solve(str, G[++cnt]); } while(getline(cin, str) && str != "-"); sort(G + 1, G + cnt + 1, cmp); for(int i = 1; i <= cnt; i++){ vector<char> cpI; for(int j = 1; j <= cnt; j++){ if(i == j) continue; if(check(G[i].v, G[j].v)) cpI.push_back(G[j].id); } Print(G[i].id, cpI); } cout << '\n'; } return 0; }
|