-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRound1AP1.java
More file actions
273 lines (238 loc) · 6.37 KB
/
Copy pathRound1AP1.java
File metadata and controls
273 lines (238 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
package gcj1A;
/**
*
* @author RasPat
*This is a skeleton for basic read write operations
*Make this template threaded
*/
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Arrays;
public class Round1AP1 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
String pathRoot = "C:\\Users\\RasPat\\Dev\\GCodeJam\\2014_1A\\";
String relRoot = "test.in";
String in = pathRoot + relRoot;
//Length of the file extension
int extLength = 2;
String out = in.substring(0, in.length() - extLength) + "out";
String test = pathRoot + "test.in";
String testo = pathRoot + "test.out1";
BufferedReader r = null;
BufferedWriter w = null;
BufferedWriter answers = null;
BufferedWriter samples = null;
int times = 120;
//Generate a bunch of these permutation guys;
samples = new BufferedWriter(new FileWriter(test));
answers = new BufferedWriter(new FileWriter(testo));
samples.write("120");
samples.newLine();
for (int i = 0; i < times; i++) {
samples.write("1000");
samples.newLine();
answers.write("Case #" + String.valueOf(i + 1) + ": ");
int[] vals = new int[1000];
int who = (int)(Math.random() * 2);
if (who >= 1) {
vals = good();
show(vals, samples);
answers.write("GOOD");
} else {
vals = bad();
show(vals, samples);
answers.write("BAD");
}
answers.newLine();
}
answers.close();
samples.close();
w = new BufferedWriter(new FileWriter(out));
String line;
int caseCount = 0;
r = new BufferedReader(new FileReader(in));
int testCases = Integer.parseInt(r.readLine()); // number of test cases
// int[] sols = new int[testCases];
while((line = r.readLine()) != null) {
line = r.readLine();
int[] vals = new int[1000];
String[] inS = line.split(" ");
for (int i = 0; i < 1000; i++) {
vals[i] = Integer.parseInt(inS[i]);
}
w.write("Case #" + String.valueOf(caseCount + 1) + ": ");
String outcome = "";
int score = diffCalc2(vals);
if (score < (472 + 500) / 2) {
outcome = "BAD";
// sols[caseCount] = 0;
} else {
outcome = "GOOD";
// sols[caseCount] = 1;
}
w.write(outcome);
w.newLine();
caseCount++;
}
r.close();
if(w != null) {
w.flush();
w.close();
}
}
public static int diffCalc(int[] vals) {
int sum = 0;
int len = vals.length;
int halfLen = len / 2;
for(int i = 0; i < len; i++) {
int diff = i - vals[i];
if (diff > halfLen) {
diff = len - diff;
} else if (diff < (-1 * halfLen)) {
diff = len + diff;
diff = diff * -1;
}
sum += diff;
}
return sum;
}
public static int diffCalc2(int[] vals) {
int score = 0;
for(int i = 0; i < vals.length; i++) {
if (vals[i] <= i) {
score++;
}
}
return score;
}
/*
* Take the magnitude of the distance form teh averages
* take the average of that
* on the good the average distance from the averages should be what??
* Run a test on some good lists and see what happens
*
* On teh bad the distance will eb whatever
*
* When given a test set Find the magnitude of difference form teh average
* Then find teh distance of the magnitude of diff from teh bad averages
*
* The average difference of the average difference third central moment?
*
* I guess we can do this chcek the mean(hint itll be 500), stdev, 3rd moment for the good and bad distributions
*
* Then when we get a new set check the vars and see fi they are closer to the good or bad?
*
*
*/
// public static int diffCalc2(int[] vals) {
// for (int i = 0; i < vals.length; i++) {
//
// }
//
//
// return null;
// }
public static double getStdev(int[] vals, double[] means) {
double stdev = 0;
int len = vals.length;
for (int i = 0; i < len; i++) {
stdev += Math.pow((vals[i] - means[i]), 2);
}
stdev = Math.sqrt(stdev / len);
return stdev;
}
public static double stdev2(int[] vals) {
double stdev = 0;
int len = vals.length;
for (int i = 0; i < len; i++) {
stdev = Math.pow((vals[i] - 500), 2) / len;
}
return stdev;
}
/*
* Create a bad algo n times and see what the average
* values at each index are. In teh good they should be 500.
* Used to determine how far any index actually shifts from the bias
*/
public static double[] getMeans(int times, boolean useGood) {
long[] avgArray = new long[1000];
double[] diffArray = new double[1000];
int[] vals = new int[1000];
Arrays.fill(avgArray, 0L);
for(int i = 0; i < times; i++) {
if (useGood) {
vals = good();
} else {
vals = bad();
}
for (int j = 0; j < vals.length; j++) {
avgArray[j] += vals[j];
}
}
for(int i = 0; i < avgArray.length; i++) {
diffArray[i] = (avgArray[i] / times);
}
return diffArray;
// System.out.println(Arrays.toString(diffArray));
}
public static int[] genList(BufferedWriter w1) throws IOException {
int who = (int)(Math.random() * 2);
int[] vals = new int[1000];
if (who >= 1) {
vals = good();
w1.write("GOOD");
} else {
vals = bad();
w1.write("BAD");
}
w1.newLine();
return vals;
}
public static int[] good() {
int[] vals = new int[1000];
for (int k = 0; k < 1000; k++) {
vals[k] = k;
}
for (int k = 0; k < 1000; k++) {
int p = k + (int)(Math.random() * (1000-k));
int tmp = vals[k];
vals[k] = vals[p];
vals[p] = tmp;
}
return vals;
}
public static int[] bad() {
int[] vals = new int[1000];
for (int k = 0; k < 1000; k++) {
vals[k] = k;
}
for (int k = 0; k < 1000; k++) {
int p = (int)(Math.random() * 1000);
int tmp = vals[k];
vals[k] = vals[p];
vals[p] = tmp;
}
return vals; }
public static int[] rand() {
int[] r = new int[1000];
for (int i = 0; i < r.length; i++) {
r[i] = (int)(Math.random() * r.length);
}
return r;
}
public static void show(int[] vals, BufferedWriter w) throws IOException {
String v = Arrays.toString(vals);
v = v.replace(",", "");
v = v.replace("[", "");
v = v.replace("]", "");
w.write(v);
w.newLine();
}
}