2016-04-23 Problem Solving►UVa UVa 477 - Points in Figures: Rectangles and Circles Contents 1. Problem2. Solution3. Code Problem題目網址中文網址 Solution一個一個判斷即可。 CodeUVa 477UVa 477 - Points in Figures: Rectangles and Circles123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657#include<cstdio>#define N 10struct Shape{ char type; double x1, y1, x2, y2, r;}shape[N];int main(){ char c; int count = 0; while ((c = getchar()) != '*') { shape[count].type = c; if (c == 'r') scanf("%lf%lf%lf%lf", &shape[count].x1, &shape[count].y1, &shape[count].x2, &shape[count].y2); else scanf("%lf%lf%lf", &shape[count].x1, &shape[count].y1, &shape[count].r); count++; getchar(); } bool in; int i = 0; double x, y; while (scanf("%lf%lf", &x, &y) && x != 9999.9&&y != 9999.9) { in = false; i++; for (int j = 0; j<count; j++) { if (shape[j].type == 'r') { if (x > shape[j].x1&&x < shape[j].x2&&y<shape[j].y1&&y > shape[j].y2) { printf("Point %d is contained in figure %d\n", i, j+1); in = true; } } else { double dis2 = (x - shape[j].x1)*(x - shape[j].x1) + (y - shape[j].y1)*(y - shape[j].y1); if (dis2 < shape[j].r*shape[j].r) { printf("Point %d is contained in figure %d\n", i, j+1); in = true; } } } if (!in) printf("Point %d is not contained in any figure\n", i); } return 0;} Newer UVa 10986 - Sending Email Older UVa 10245 - The Closest Pair Problem