You shouldn't worry about printing a blank line here:
for this test case does not select anything at all since it does not select the only region in this test case and the only icon the mouse click can select is not visible.
Can someone help me please? I am getting WA. Some test cases will be very helpful.
Is it a multiple input problem or will there be only one test input?
Please someone reply. Thanks in advance.
struct Icon icon[50];
struct Area area[25];
struct Mouse mouse[100000];
int main()
{
int i = 0, j = 0, k = 0;
char str[100];
gets(str);
while (str[0] != '#')
{
if (str[0] == 'I')
{
CreateIcon(i, str);
i++;
}
else if (str[0] == 'R')
{
CreateArea(j, str);
j++;
}
else if (str[0] == 'M')
{
CreateMouse(k, str);
k++;
}
gets(str);
}
int p;
for (p=0;p<i;p++)
{
IconInArea(p, j);
}
for (p=0;p<k;p++)
{
if (!MouseInArea(p, j))
{
MouseInIcon(p, i);
}
}
return 0;
}
void IconInArea(int index, int area_size)
{
int i;
for (i=0;i<area_size;i++)
{
if ((area.x1 <= icon[index].x && area.x2 >= icon[index].x) && (area.y1 <= icon[index].y && area.y2 >= icon[index].y))
{
icon[index].visible = 0;
break;
}
}
}
int MouseInArea(int index, int area_size)
{
int i;
for (i=area_size-1;i>=0;i--)
{
if ((area.x1 <= mouse[index].x && area.x2 >= mouse[index].x) && (area.y1 <= mouse[index].y && area.y2 >= mouse[index].y))
{
printf("%c\n", i+65);
return 1;
}
}
return 0;
}
void MouseInIcon(int index, int icon_size)
{
int i;
int click[50];
int min = 10000000, sum = 0;
for (i=0;i<icon_size;i++)
{
if (icon.visible == 1)
{
sum = pow((icon.x - mouse[index].x), 2) + pow((icon[i].y - mouse[index].y), 2);
if (sum < min)
min = sum;
click[i] = sum;
}
}
for (i=0;i<icon_size;i++)
{
if (click[i] == min)
printf("%3d", i+1);
}
printf("\n");
}
void CreateIcon(int i, char *str)
{
int j = 1, k = 0;
int x;
int temp[2];
int tag;
while (str[j] == ' ' && str[j] != '\0')
{
x = 0;
tag = 0;
j++;
while (str[j] != ' ' && str[j] != '\0')
{
tag = 1;
x = x*10 + (str[j] - '0');
j++;
}
if (tag)
{
temp[k] = x;
k++;
}
}
icon[i].x = temp[0];
icon[i].y = temp[1];
icon[i].visible = 1;
}
void CreateArea(int i, char *str)
{
int j = 1, k = 0;
int x;
int temp[4];
int tag;
while (str[j] == ' ' && str[j] != '\0')
{
x = 0;
tag = 0;
j++;
while (str[j] != ' ' && str[j] != '\0')
{
tag = 1;
x = x*10 + (str[j] - '0');
j++;
}
if (tag)
{
temp[k] = x;
k++;
}
}
area[i].x1 = temp[0];
area[i].y1 = temp[1];
area[i].x2 = temp[2];
area[i].y2 = temp[3];
}
void CreateMouse(int i, char *str)
{
int j = 1, k = 0;
int x;
int temp[2];
int tag;
while (str[j] == ' ' && str[j] != '\0')
{
x = 0;
tag = 0;
j++;
while (str[j] != ' ' && str[j] != '\0')
{
tag = 1;
x = x*10 + (str[j] - '0');
j++;
}
if (tag)
{
temp[k] = x;
k++;
}
}
mouse[i].x = temp[0];
mouse[i].y = temp[1];
}
I 216 28
R 22 19 170 102
I 40 150
I 96 138
I 36 193
R 305 13 425 103
I 191 184
I 387 200
R 266 63 370 140
I 419 134
I 170 102
M 50 50
M 236 30
M 403 167
M 330 83
#
I 383 386
I 277 415
I 293 335
I 386 492
I 149 421
I 362 27
I 190 59
I 263 426
I 40 426
I 172 236
I 211 368
I 67 429
I 282 30
I 362 123
I 67 135
I 429 302
I 22 58
I 69 167
I 393 456
I 11 42
I 229 373
I 421 419
I 284 37
I 198 324
I 315 370
I 413 26
I 91 480
I 456 373
I 362 170
I 496 281
I 305 425
I 84 327
I 336 5
I 346 229
I 313 357
I 124 395
I 82 45
I 314 367
I 434 364
I 43 250
I 87 308
I 276 178
I 288 84
I 403 151
I 254 399
I 432 60
I 176 368
I 239 12
I 226 86
I 94 39
R 295 70 344 368
R 467 101 493 247
R 317 492 483 496
R 301 280 327 401
R 365 189 429 404
R 440 229 491 287
R 97 271 485 285
R 209 427 230 454
R 497 353 497 451
R 306 183 481 471
R 28 371 120 379
R 3 19 370 362
R 208 215 480 239
R 296 223 358 306
R 346 451 441 493
R 379 488 464 496
R 341 350 480 450
R 34 264 250 362
R 487 356 494 383
R 227 365 335 426
R 432 51 441 165
R 275 407 449 408
R 358 395 477 462
R 235 293 453 313
R 143 11 434 299
M 276 404
M 443 263
M 113 38
M 106 340
M 404 318
M 128 188
M 369 417
M 417 496
M 324 243
M 470 183
M 490 499
M 272 225
M 144 90
M 5 139
M 454 286
M 169 82
M 42 464
M 197 7
M 355 304
M 348 111
M 122 328
M 299 343
M 246 68
M 340 422
M 311 310
M 105 301
M 161 230
M 378 305
M 320 236
M 444 126
M 22 465
M 208 416
M 282 258
M 424 137
M 62 124
M 100 36
M 452 399
M 379 50
M 468 71
M 473 131
M 381 430
M 433 394
M 160 163
M 199 481
M 399 496
M 459 273
M 313 168
M 190 95
M 426 466
M 84 340
M 90 184
M 376 42
M 436 107
M 445 256
M 179 418
M 387 412
M 348 172
M 159 9
M 336 210
M 342 87
M 206 301
M 213 372
M 321 255
M 319 99
M 221 404
M 439 311
M 440 167
M 205 228
M 127 150
M 484 158
M 420 224
M 422 269
M 396 81
M 130 84
M 292 472
M 172 350
M 125 385
M 222 299
M 140 42
M 398 213
M 298 190
M 24 90
M 209 81
M 319 336
M 232 155
M 494 4
M 379 269
M 273 276
M 350 255
M 360 142
M 79 384
M 493 205
M 121 67
M 4 113
M 461 254
M 326 259
M 444 202
M 202 6
M 284 21
M 342 368
#
T
J
L
R
J
L
W
P
Y
J
30
Y
Y
L
J
Y
9
33
X
Y
R
L
Y
J
X
R
Y
X
Y
33
9
11
Y
Y
L
L
W
Y
33
B
W
Q
Y
5
P
J
Y
Y
O
R
L
Y
U
J
5
W
Y
33
Y
Y
R
11
Y
Y
11
X
30
Y
L
B
Y
Y
Y
L
11
R
36
Y
L
Y
Y
L
Y
L
Y
33
Y
Y
Y
Y
36
B
L
L
J
Y
J
33
Y
Q
Check input and AC output for thousands of problems on uDebug!
The problem statement says: Coordinates will be given as pairs of integers in the range 0..499 and you can assume that all icons and regions lie wholly within the screen.
But the tests above contain bigger integers like 560. is judge contain such numbers?
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman
I got acc. The statement really ambiguous. It must be clearly stated that if icon comes later and lies on existing region -> it will be invisible or obscured.
Judge don't contain integers greater 0..499.
A person who sees the good in things has good thoughts. And he who has good thoughts receives pleasure from life... Bediuzzaman