/home/toolbox/public_html/solutions/114/11480/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
15 /*
16 * Author: Isaac Traxler
17 * Date: 2020-03-05
18 * Purpose: fun
19 * Problem: 11480 - Jimmy's Balls
20 */
21
22 /*
23 * This template reads data until a terminating value is reached.
24 */
25
26 /* n is total number of balls
27 * r is red
28 * g is green
29 * b is blue
30 * n = r + g + b
31 * n - 3r = r-r + g-r + b-r
32 * n - 3r = g-r (x) + b-r(y)
33 * n - 3r = x + y and x>y>0
34 * n - 3r >= x + x + 1
35 * n - 3r >= 2x + 1
36 * n - 3r - 1 >= 2x
37 * (n - 3r - 1) / 2 >= x and x > 0
38 */
39
40 /*
41 * cnt r b g g-b
42 * 6 1 2 3 1 1
43 * 7 1 2 4 2 1
44 * 8 1 2 5 3 2
45 * 1 3 4 1
46 * 9 1 2 6 4 3
47 * 1 3 5 2
48 * 2 3 4 1
49 * 10 1 2 7 5 4
50 * 1 3 6 3
51 * 1 4 5 1
52 * 2 3 5 2
53 * 11 1 2 8 6 5
54 * 1 3 7 4
55 * 1 4 6 2
56 * 2 3 6 3
57 * 2 4 5 1
58 * 12 1 2 9 7 7
59 * 1 3 8 5
60 * 1 4 7 3
61 * 1 5 6 1
62 * 2 3 7 4
63 * 2 4 6 2
64 * 3 4 5 1
65 */
66
67 int n; /* number of balls */
68 int cs = 0;
69
70 void init()
71 {
72 /* FUNCTION init */
73 } /* FUNCTION init */
74
75 void dump()
76 {
77 /* FUNCTION dump */
78 } /* FUNCTION dump */
79
80 int getInput()
81 {
82 /* FUNCTION getInput */
83 int dataReadFlag;
84
85 scanf(" %d ", &n);
86 cs++;
87 dataReadFlag = 0 != n;
88 return (dataReadFlag);
89 } /* FUNCTION getInput */
90
91 void process()
92 {
93 /* FUNCTION process */
94 int r;
95 int tmp;
96 long int total = 0;
97
98 /* (n - 3r - 1) / 2 >= x and x > 0 */
99 tmp = (n - 3) / 3;
100 for (r = 1; r<=tmp; r++)
101 {
102 /* each value r may have */
103 total = total + (n - 3*r - 1) / 2;
104 DEBUG printf("(r=%d) (total=%d) (n=%d}\n", r, total, n);
105 } /* each value r may have */
106 printf("Case %d: %ld\n", cs, total);
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