I solved this problem easily.
But, judge server judged Wrong Answer.
I can't find my mistake...ToT
Give me correct input and output set.
Help me......ToT~~~~
[cpp]
#include <stdio.h>
typedef struct _POINT {
int x;
int y;
bool hidden;
} POINT;
typedef struct _RECT {
int left;
int top;
int right;
int bottom;
} RECT;
void remove_hidden_icon(RECT *prect, int rects, POINT *picon, int icons);
bool find_rect(RECT *prect, int rects, POINT click);
void find_icon(POINT *picon, int icons, POINT click);
bool inner_rect(RECT rect, POINT point);
int square(int a);
int main()
{
POINT mouse, icon[50];
RECT rect[25];
int icon_count = 0, rect_count = 0;
char line[255];
bool start_click = false;
while (gets(line) != NULL) {
if (line[0] == '#') { // end condition
icon_count = rect_count = 0;
start_click = false;
} else if (line[0] == 'I') { // Icon input
sscanf(&line[1], "%d %d", &icon[icon_count].x, &icon[icon_count].y);
icon[icon_count].hidden = false;
icon_count++;
} else if (line[0] == 'R') { // Rect input
sscanf(&line[1], "%d %d %d %d", &rect[rect_count].left, &rect[rect_count].top,
&rect[rect_count].right, &rect[rect_count].bottom);
rect_count++;
} else if (line[0] == 'M') { // Mouse input
if (start_click == false) {
remove_hidden_icon(rect, rect_count, icon, icon_count);
start_click = true;
}
sscanf(&line[1], "%d %d", &mouse.x, &mouse.y);
if (!find_rect(rect, rect_count, mouse))
find_icon(icon, icon_count, mouse);
}
}
return 0;
}
void remove_hidden_icon(RECT *prect, int rects, POINT *picon, int icons)
{
for (int i = 0; i < icons; i++)
for (int j = 0; j < rects; j++) {
if (inner_rect(prect[j], picon
)) {
picon.hidden = true;
break;
}
}
}
// find clicked rectangle
bool find_rect(RECT *prect, int rects, POINT click)
{
for (int i = rects - 1; i >= 0; i--)
if (inner_rect(prect, click)) {
printf("%c\n", (char)(i + 65));
return true;
}
return false;
}
// find the closest icon that clicked
void find_icon(POINT *picon, int icons, POINT click)
{
int closest = 250000;
int length[50], i;
for (i = 0; i < icons; i++)
if (picon.hidden == false) {
length = square(picon.x - click.x) + square(picon.y - click.y);
if (closest > length)
closest = length;
} else
length = -1;
for (i = 0; i < icons; i++)
if (closest == length[i])
printf("%3c", (char)(i + 49));
printf("\n");
}
bool inner_rect(RECT rect, POINT point)
{
if (rect.left <= point.x && rect.right >= point.x &&
rect.top <= point.y && rect.bottom >= point.y)
return true;
return false;
}
int square(int a)
{
return a * a;
}[/cpp]