/home/toolbox/public_html/solutions/3/356/judged.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
15 #define MAX_SIDE 160
16 #define ACTUAL 150
17
18 /*
19 * Author: Isaac traxler
20 * Date: 2005-09-27
21 * Purpose:
22 * Problem: 356
23 */
24
25 /*
26 * This template reads data until a terminating value is reached.
27 */
28
29 int tbl[MAX_SIDE][MAX_SIDE];
30 int num;
31 int firstTime = TRUE;
32
33 int init()
34 {
35 /* FUNCTION init */
36 int row;
37 int col;
38
39 for (row=0; ACTUAL>=row; row++)
40 {
41 /* for each row */
42 for (col=0; ACTUAL>=col; col++)
43 {
44 /* for each column */
45 tbl[row][col] = row*row + col*col;
46 } /* for each column */
47 } /* for each row */
48 } /* FUNCTION init */
49
50 int dump()
51 {
52 /* FUNCTION dump */
53 } /* FUNCTION dump */
54
55 int getInput()
56 {
57 /* FUNCTION getInput */
58 int dataReadFlag;
59
60 dataReadFlag = (0 < scanf(" %d ", &num));
61 return (dataReadFlag);
62 } /* FUNCTION getInput */
63
64 void process()
65 {
66 /* FUNCTION process */
67 int in = 0;
68 int on = 0;
69 int row;
70 int col;
71 /* vertices */
72 double s;
73
74 s = (num - 0.5) * (num -0.5);
75 for (row=0; num>row; row++)
76 {
77 /* for each row */
78 for (col=0; num>col; col++)
79 {
80 /* for each column */
81 if (s >= tbl[row][col])
82 {
83 /* square is on circle or inside */
84 if (s <= tbl[row+1][col+1])
85 {
86 /* on circle */
87 on++;
88 } /* on circle */
89 else
90 {
91 /* inside circle */
92 in++;
93 } /* inside circle */
94 } /* square is on circle or inside */
95 } /* for each column */
96 } /* for each row */
97 if (! firstTime)
98 {
99 printf("\n");
100 }
101 else
102 {
103 firstTime = FALSE;
104 }
105 printf("In the case n = %d, %d cells contain segments of the circle.\n", num, on*4);
106 printf("There are %d cells completely contained in the circle.\n", in*4);
107 } /* FUNCTION process */
108
109 int main ()
110 {
111 /* main */
112 int moreToDo;
113
114 init();
115 moreToDo = getInput();
116 while (moreToDo)
117 {
118 /* while */
119 process();
120 moreToDo = getInput();
121 } /* while */
122
123 return EXIT_SUCCESS;
124 } /* main */
125