// UVa 477 - Points in Figures: Rectangles and Circles #include <iostream> #include <stdio.h> #include <sstream> #include <cmath> using namespace std; bool rect[11]; double dist(double x1, double y1, double x2, double y2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); } int main() { string l; int n = 0; double x1[11], x2[11], y1[11], y2[11], cx[11], cy[11], cr[11]; while (getline(cin, l) && l[0] != '*') { n++; rect[n] = (l[0] == 'r'); istringstream strm(l.substr(2)); if (rect[n]) { strm >> x1[n] >> y1[n] >> x2[n] >> y2[n]; if (x1[n] > x2[n]) { double tmp = x1[n]; x1[n] = x2[n]; x2[n] = tmp; } if (y1[n] > y2[n]) { double tmp = y1[n]; y1[n] = y2[n]; y2[n] = tmp; } } else strm >> cx[n] >> cy[n] >> cr[n]; } int m = 0; double x, y; while (cin >> x >> y && (x != 9999.9 || y != 9999.9)) { m++; bool outside = true; for (int i = 1; i <= n; i++) if (rect[i] && x1[i] <= x && x <= x2[i] && y1[i] <= y && y <= y2[i]) { printf("Point %d is contained in figure %d\n", m, i); outside = false; } else if (!rect[i] && dist(cx[i], cy[i], x, y) <= cr[i]) { printf("Point %d is contained in figure %d\n", m, i); outside = false; } if (outside) printf("Point %d is not contained in any figure\n", m); } return 0; }
Monday, June 8, 2015
UVa 477 - Points in Figures: Rectangles and Circles
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment