/home/toolbox/public_html/solutions/116/11683/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 <stdint.h>
7 #include <math.h>
8 #include <stdlib.h>
9
10 #define TRUE (1 == 1)
11 #define FALSE (1 != 1)
12
13 #define DEBUG if (FALSE)
14 #define SIZE 10002
15
16 /*
17 * Author: Isaac Traxler
18 * Date: 2014-10-26
19 * Purpose: UVA Hack-a-thon
20 * Problem: 11683 - Laser Sculpture
21 */
22
23 /*
24 * This template reads data until a terminating value is reached.
25 */
26
27 int a;
28 int c;
29 int cnt[SIZE];
30
31 void init()
32 {
33 /* FUNCTION init */
34 int i;
35
36 for(i=0; i<SIZE; i++)
37 {
38 /* for each row */
39 cnt[i] = 0;
40 } /* for each row */
41 } /* FUNCTION init */
42
43 void dump()
44 {
45 /* FUNCTION dump */
46 } /* FUNCTION dump */
47
48 int getInput()
49 {
50 /* FUNCTION getInput */
51 int dataReadFlag;
52
53 scanf(" %d ", &a);
54 if (0 == a)
55 dataReadFlag = FALSE;
56 else
57 {
58 /* something read in */
59 dataReadFlag = TRUE;
60 init();
61 scanf(" %d ", &c);
62 } /* something read in */
63 return (dataReadFlag);
64 } /* FUNCTION getInput */
65
66 void process()
67 {
68 /* FUNCTION process */
69 int i;
70 int h;
71 int x;
72 int prev = a;
73 int tot = 0;
74
75 for (i=0; i<c; i++)
76 {
77 /* for each column */
78 scanf(" %d ", &h);
79 DEBUG printf("height=%d\n", h);
80 if (prev > h)
81 {
82 /* some turned on that were off */
83 for (x=h; x<prev; x++)
84 {
85 /* for each impacted row */
86 cnt[x] = cnt[x] + 1;
87 DEBUG printf("turning on row: %d\n",x);
88 } /* for each impacted row */
89 } /* some turned on that were off */
90 prev = h;
91 } /* for each column */
92
93 /* now some up counts */
94 for (i=0; i<a; i++)
95 {
96 /* for each row */
97 tot = tot + cnt[i];
98 DEBUG printf("cnt[%d] = %d\n", i, cnt[i]);
99 } /* for each row */
100 printf("%d\n", tot);
101 } /* FUNCTION process */
102
103 int main ()
104 {
105 /* main */
106 int moreToDo;
107
108 init();
109 moreToDo = getInput();
110 while (moreToDo)
111 {
112 /* while */
113 process();
114 moreToDo = getInput();
115 } /* while */
116
117 return EXIT_SUCCESS;
118 } /* main */
119