Computer Programming Contest Preparation

ToolBox - Source for: naq/naq2022/d.c



/home/toolbox/public_html/solutions/naq/naq2022/d.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 <stdint.h>
    7 #include <math.h>
    8 #include <stdlib.h>
    9 #include <ctype.h>
   10 
   11 #define TRUE  (1 == 1)
   12 #define FALSE (1 != 1)
   13 
   14 #define DEBUG if (FALSE)
   15 
   16 /*
   17  *  Author: Isaac Traxler
   18  *    Date:
   19  * Purpose: fun
   20  * Problem: NAQ - k
   21  */
   22 
   23 /*
   24  * This template reads lines of data at a time until end of file.
   25  */
   26 
   27 #define NUM_ELEMENTS 102
   28 #define NUM_RUNGS 1002
   29 
   30 int table[NUM_RUNGS][NUM_ELEMENTS];
   31 int ans[NUM_ELEMENTS];
   32 int m;
   33 int n;
   34 
   35 void init()
   36 {
   37     /* FUNCTION init */
   38     int i;
   39     int j;
   40 
   41     for (i=0; NUM_ELEMENTS>i; i++)
   42         {
   43             /* for each element */
   44             for (j=0; NUM_RUNGS>j; j++)
   45                 {
   46                     /* for each possible rung */
   47                     table[j][i] = 0;
   48                 } /* for each possible rung */
   49         } /* for each element */
   50 } /* FUNCTION init */
   51 
   52 void dump()
   53 {
   54     /* FUNCTION void */
   55     int i;
   56     int j;
   57 
   58     printf("\n");
   59     for (i=1; m>=i; i++)
   60         {
   61             /* for each rung */
   62             for (j=1; n>=j; j++)
   63                 {
   64                     /* for each element */
   65                     printf("%3d ", table[i][j]);
   66                 } /* for each element */
   67             printf("\n");
   68         } /* for each rung */
   69 } /* FUNCTION void */
   70 
   71 void getInput()
   72 {
   73     /* FUNCTION getInput */
   74     int x;
   75     int r;
   76 
   77     scanf(" %d %d ", &n, &m);
   78     for (r=1; m>=r; r++)
   79         {
   80             /* for each rung */
   81             scanf(" %d ", &x);
   82             table[r][x] = 1;
   83             table[r][x+1] = -1;
   84         } /* for each rung */
   85 } /* FUNCTION getInput */
   86 
   87 void process()
   88 {
   89     /* FUNCTION process */
   90     int i;
   91     int j;
   92     int p;
   93 
   94     for (i=1; n>=i; i++)
   95         {
   96             /* for each element */
   97             p = i;
   98             for (j=1; m>=j; j++)
   99                 {
  100                     /* for each rung */
  101                     DEBUG printf("(i %d) (m %d) (p %d) (j %d) (t[%d][%d] %d)\n", i, m, p, j, j, p, table[j][p]);
  102                     p = p + table[j][p];
  103                 } /* for each rung */
  104             ans[p] = i;
  105         } /* for each element */
  106     for (i=1; n>=i; i++)
  107         {
  108             /* each element */
  109             printf("%d\n", ans[i]);
  110         } /* each element */
  111 
  112 } /* FUNCTION process */
  113 
  114 int main()
  115 {
  116     /* main */
  117 
  118     init();
  119     getInput();
  120     process();
  121 
  122     return EXIT_SUCCESS;
  123 } /* main */
  124