Computer Programming Contest Preparation

ToolBox - Source for: 127/12748/a.c



/home/toolbox/public_html/solutions/127/12748/a.c
    1 #include <stdio.h>
    2 #include <string.h>
    3 #include <sys/types.h>
    4 #include <sys/stat.h>
    5 #include <fcntl.h>
    6 #include <stdlib.h>
    7 #include <math.h>
    8 #include <stdint.h>
    9 
   10 #define TRUE  (1 == 1)
   11 #define FALSE (1 != 1)
   12 
   13 #define DEBUG if (FALSE)
   14 
   15 /* fprintf(stderr, "functionName: message", varslist); */
   16 
   17 /*
   18  *  Author: Isaac Traxler
   19  *    Date: 2015-09-30
   20  * Purpose: fun
   21  * Problem: 12748
   22  */
   23 
   24 /*
   25  * This template reads data a specified number of times.
   26  */
   27 
   28 #define MAX_ROUTERS 101
   29 #define MAX_LOCATIONS 11
   30 
   31 typedef struct ROUTER_STRUCT
   32 {
   33     /* struct ROUTER_STRUCT */
   34     int  x;
   35     int  y;
   36     int  r;
   37 } /* struct ROUTER_STRUCT */
   38 ROUTER_STRUCT;
   39 
   40 
   41 int numberOfTimes;
   42 ROUTER_STRUCT routers[MAX_ROUTERS];
   43 int routerCount;
   44 int X[MAX_LOCATIONS];
   45 int Y[MAX_LOCATIONS];
   46 int locationCount;
   47 
   48 void init()
   49 {
   50     /* FUNCTION init */
   51     scanf("%d ", &numberOfTimes);
   52 } /* FUNCTION init */
   53 
   54 void dump()
   55 {
   56     /* FUNCTION dump */
   57 } /* FUNCTION dump */
   58 
   59 void getInput()
   60 {
   61     /* FUNCTION getInput */
   62     int i;
   63 
   64     scanf(" %d %d ", &routerCount, &locationCount);
   65     for (i=0; i<routerCount; i++)
   66         {
   67             /* load each router */
   68             scanf(" %d %d %d ", &routers[i].x, &routers[i].y, &routers[i].r);
   69             /* distance formula is sqrt(dx*dy + dy*dy). By squaring coverage
   70                radius I can skip taking square root of distance later */
   71             routers[i].r = routers[i].r * routers[i].r;
   72         } /* load each router */
   73     for (i=0; i<locationCount; i++)
   74         {
   75             /* load each location */
   76             scanf(" %d %d ", &X[i], &Y[i]);
   77         } /* load each location */
   78 } /* FUNCTION getInput */
   79 
   80 int covered(int x, int y)
   81 {
   82     /* FUNCTION covered */
   83     int i;
   84     int cvrd = FALSE;
   85 
   86     for (i=0; (!cvrd) && (i<routerCount); i++)
   87         {
   88             /* check each router */
   89             cvrd = routers[i].r >= ((x - routers[i].x) * (x - routers[i].x) +
   90                                     (y - routers[i].y) * (y - routers[i].y));
   91         } /* check each router */
   92     return cvrd;
   93 } /* FUNCTION covered */
   94 
   95 void process()
   96 {
   97     /* FUNCTION process */
   98     int i;
   99 
  100     for (i=0; i<locationCount; i++)
  101         {
  102             /* for each location */
  103             if (covered(X[i], Y[i]))
  104                 {
  105                     printf("Yes\n");
  106                 }
  107             else
  108                 {
  109                     printf("No\n");
  110                 }
  111         } /* for each location */
  112 } /* FUNCTION process */
  113 
  114 int main()
  115 {
  116     /* main */
  117     int i;
  118 
  119     init();
  120     for (i=1; i<=numberOfTimes; i++)
  121         {
  122             /* while */
  123             printf("Case %d:\n", i);
  124             getInput();
  125             process();
  126         } /* while */
  127 
  128     return EXIT_SUCCESS;
  129 } /* main */
  130 
  131