f1
stringlengths 6
6
| f2
stringlengths 6
6
| content_f1
stringlengths 66
8.69k
| content_f2
stringlengths 48
42.7k
| flag
int64 0
1
| __index_level_0__
int64 0
1.19M
|
---|---|---|---|---|---|
A11759 | A10498 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} |
package B;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class B {
public static void main(String[] args) throws IOException {
PrintStream out = new PrintStream(new File("/output.txt"));
Scanner in = new Scanner(new File("/B-small-attempt0.in"));
int testCase = Integer.parseInt(in.next());
for (int n = 0; n < testCase; n++) {
int count = 0;
int googlers = Integer.parseInt(in.next());
int surprising = Integer.parseInt(in.next());
int wantScores = Integer.parseInt(in.next());
for (int g = 0; g < googlers; g++) {
int scores = Integer.parseInt(in.next());
if (scores - (wantScores * 3) >= -2) {
count++;
} else if ((surprising > 0) && (((scores - (wantScores * 3) == -4)&&scores>=2) || ((scores - (wantScores * 3) == -3)&&scores>=3))) {
surprising--;
count++;
}
}
out.println("Case #" + (n + 1) + ": " + count);
System.out.println("Case #" + (n + 1) + ": " + count);
}
in.close();
out.close();
}
}
| 0 | 1,189,300 |
A11759 | A11993 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
import java.io.*;
public class A
{
private Scanner reader;
private PrintWriter writer;
public A(String inFile, String outFile)
{
try {
reader = new Scanner(new File(inFile));
writer = new PrintWriter(new File(outFile));
init();
}
catch (Exception ex ) {
ex.printStackTrace();
}
}
private void init() {
int T = reader.nextInt();
for (int i=1; i<=T; i++) {
int N = reader.nextInt();
int S = reader.nextInt();
int p = reader.nextInt();
int med = p*3;
int vlow = med - 2;
if (vlow < p)
vlow = p;
int slow = med - 4;
if (slow < p)
slow = p;
int res = 0;
for (int j=0; j<N; j++) {
int k = reader.nextInt();
if (k >= vlow) {
res ++;
}
else if ( k >= slow && S > 0) {
res++;
S--;
}
}
String out = "Case #"+i+": " + res +"\n";
writer.write(out);
writer.flush();
}
writer.close();
}
public static void main(String[] args)
{
new A("/Users/prabhaks/work/workspace/Test/src/in.txt", "/Users/prabhaks/work/workspace/Test/src/out.txt");
}
} | 0 | 1,189,301 |
A11759 | A12275 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class DancingWithTheGooglers {
private static final boolean DEBUG = false;
private static final String FILENAME = "dancing";
public static void main(String[] args) throws IOException {
long startTime = System.nanoTime();
if(DEBUG) {
System.setIn(new BufferedInputStream(new FileInputStream(FILENAME + "_example.in")));
} else {
System.setIn(new BufferedInputStream(new FileInputStream(FILENAME + ".in")));
System.setOut(new PrintStream(FILENAME + ".out"));
}
Scanner sc = new Scanner(System.in);
int numTestCases = sc.nextInt();
for(int caseNum = 1; caseNum <= numTestCases; caseNum++) {
int numGooglers = sc.nextInt();
int numSurprising = sc.nextInt();
int scoreMaxLowerBound = sc.nextInt();
int numGooglersWithBetter = 0;
for(int i = 0; i < numGooglers; i++) {
int totalScore = sc.nextInt();
if(totalScore <= 1) {
if(totalScore >= scoreMaxLowerBound) {
numGooglersWithBetter++;
}
} else {
int maxScore;
if(totalScore % 3 == 0) {
maxScore = totalScore / 3;
} else {
maxScore = totalScore / 3 + 1;
}
if(maxScore >= scoreMaxLowerBound) {
numGooglersWithBetter++;
} else if(numSurprising > 0) {
maxScore++;
if(maxScore >= scoreMaxLowerBound) {
numGooglersWithBetter++;
numSurprising--;
}
}
}
}
System.out.println("Case #" + caseNum + ": " + numGooglersWithBetter);
}
if(DEBUG) System.out.println("Total time: " + ((System.nanoTime() - startTime) / 1000.0 / 1000.0 / 1000.0) + "s");
}
} | 0 | 1,189,302 |
A11759 | A11218 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Dancing {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader ("data/input"));
PrintWriter pw = new PrintWriter(new FileWriter("data/output"));
int lines = Integer.parseInt(br.readLine());
for(int j = 0; j < lines; j++){
String sol = "Case #" + (j+1) + ": ";
StringTokenizer st = new StringTokenizer(br.readLine());
int googlers = Integer.parseInt(st.nextToken());
int surprising = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
int googlerOK = 0;
while(st.hasMoreElements()){
int score = Integer.parseInt(st.nextToken());
int value = score/3;
int mod = score%3;
if(score == 0){
if(p==0){
googlerOK++;
}
}else if(value >= p || (mod > 0 && value+1>=p)){
googlerOK++;
}else if(mod == 2 && value+2 >= p && surprising > 0){
surprising--;
googlerOK++;
}else if(mod < 2 && value+1 >= p && surprising > 0){
surprising--;
googlerOK++;
}
}
pw.println(sol + ""+ googlerOK);
}
pw.close();
}
}
| 0 | 1,189,303 |
A11759 | A12945 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /**
* Copyright Carma Systems, Inc. All rights reserved.
*/
package com.jessehutton.codejam.util;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
/**
* @author Jesse Hutton <jesse.hutton@carmasys.com>
*/
public abstract class IOHandler {
protected BufferedReader reader;
protected PrintStream writer;
public IOHandler(String inputFile) throws FileNotFoundException {
this(new String[] {inputFile});
}
public IOHandler(String[] args) throws FileNotFoundException {
reader = new BufferedReader(new FileReader(args[0]));
if (args.length > 1 && args[1] != null) {
writer = new PrintStream(new FileOutputStream(args[1]));
} else {
writer = System.out;
}
}
public abstract String formatCase(int caseNum, Object result);
public String line() throws IOException {
return reader.readLine();
}
public void recordCase(int caseNum, Object result) {
writer.println(formatCase(caseNum, result));
}
public void finish() {
try {
reader.close();
} catch (IOException e) {
System.err.println("closing reader failed.");
e.printStackTrace();
}
writer.close();
}
}
| 0 | 1,189,304 |
A11759 | A10199 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
import static java.lang.Math.*;
public class BB {
public static void main(String[] args){
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for(int zz = 1; zz <= T;zz++){
int N = in.nextInt();
int S = in.nextInt();
int p = in.nextInt();
int res = 0;
for(int i = 0; i < N;i++){
int t = in.nextInt();
if(p==0){
res++; continue;
}
if(t>=p && t>=(p*3-2)){
res++;
}
else if(S>0 && t>=p && (t>=(p*3-4))){
S--;
res++;
}
}
System.out.format("Case #%d: %d\n", zz, res);
}
}
}
| 0 | 1,189,305 |
A11759 | A11180 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dancinggooglers;
import java.io.*;
/**
*
* @author Oscar
*/
public class DancingGooglers {
public static String resolver(String[] parametros) {
int num = Integer.parseInt(parametros[0]);
int especial = Integer.parseInt(parametros[1]);
int objetivo = Integer.parseInt(parametros[2]);
if(objetivo == 0)
return Integer.toString(num);
int min_1 = objetivo * 3 - 2;
int min_2 = objetivo * 3 - 4;
if(objetivo == 1)
min_2 = 1;
int encontrados = 0;
for(int i = 0; i < num; i++) {
int actual = Integer.parseInt(parametros[3 + i]);
if(actual >= min_1) {
encontrados++;
continue;
}
if(actual >= min_2 && especial > 0) {
especial--;
encontrados++;
}
}
return Integer.toString(encontrados);
}
public static void main(String[] args) throws Exception {
System.out.println("?");
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String tipo = lector.readLine().trim();
BufferedReader entrada = new BufferedReader(new InputStreamReader(new FileInputStream(tipo + ".in")));
BufferedWriter salida = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(tipo + ".out")));
int casos = Integer.parseInt(entrada.readLine());
int contador = 1;
while(casos > 0) {
String[] parametros = entrada.readLine().split(" ");
salida.write("Case #" + contador + ": " + resolver(parametros) + "\n");
contador++;
casos--;
}
salida.close();
System.out.println("Fin");
}
}
| 0 | 1,189,306 |
A11759 | A13188 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.abuhijleh.googlejam;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class GoogleJam {
static final String code = "yhesocvxduiglbkrztnwjpfmaq";
public static void main(String[] args) {
File input = new File("inputFile");
String[] result;
Scanner scan;
try {
scan = new Scanner(input);
result = new String[scan.nextInt()];
scan.nextLine();
for (int i = 0; i < result.length; i++) {
int N, S, P;
int[] val;
N = scan.nextInt();
S = scan.nextInt();
P = scan.nextInt();
val = new int[N];
for (int j = 0; j < val.length; j++)
val[j] = scan.nextInt();
scan.nextLine();
result[i] = "Case #" + (i + 1) + ": " + solve(S, P, val);
}
System.out.println("Output");
for (int i = 0; i < result.length; i++)
System.out.println(result[i]);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static int solve(int s, int p, int[] val) {
int count = 0;
for (int i = 0; i < val.length; i++) {
if ((val[i] - p) >= 0)
if (((val[i] - p) / 2) < (p - 1)) {
if (s > 0 && (((val[i] - p) / 2)+2) >= p) {
s--;
count++;
}
} else
count++;
}
return count;
}
}
| 0 | 1,189,307 |
A11759 | A11192 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {
private static Map<Character,Character> mapa;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(Thread.currentThread().getContextClassLoader().getResourceAsStream("B-small-attempt0.in"));
BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\Users\\Erich\\Desktop\\B-small-attempt0.out"));
int qtd = sc.nextInt();
for(int j=0;j<qtd;j++){
int googlers=sc.nextInt();
int surprising = sc.nextInt();
int limite = sc.nextInt();
int total=0;
for(int i=0;i<googlers;i++){
int tripla = sc.nextInt();
int divisao = tripla/3;
if(divisao>=limite){
total++;
}else{
switch(tripla%3){
case 1:
if(divisao+1>=limite){
total++;
}
break;
case 2:
if(divisao+1>=limite){
total++;
}else{
if(surprising>0 && divisao+2>=limite){
surprising--;total++;
}
}
break;
case 0:
if(divisao+1>=limite && surprising>0 && tripla>0){
surprising--;total++;
}
break;
}
}
}
String saida = "Case #"+(j+1)+": "+total+"\n";
bw.write(saida);
}
bw.flush();
bw.close();
}
}
| 0 | 1,189,308 |
A11759 | A12870 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
public class GCJ2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
GCJ2 g = new GCJ2();
// int i1 = g.calculate(3, 1, 3, 6, 6, 3);
// System.out.println(i1);
// int i1 = g.calculate(3, 1, 5, 15, 13, 11);
// int i2 = g.calculate(3, 0, 8, 23, 22, 21);
// int i3 = g.calculate(2, 1, 1, 8, 0);
// int i4 = g.calculate(6, 2, 8, 29, 20, 8, 18, 18, 21);
//
// System.out.println(i1);
// System.out.println(i2);
// System.out.println(i3);
// System.out.println(i4);
try {
// Open the file that is the first
// command line parameter
FileInputStream fstream = new FileInputStream(
"C:/PROG/java/work/tc/src/gcj2.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// Read File Line By Line
int lineNum = 1;
br.readLine();
while ((strLine = br.readLine()) != null) {
// Print the content on the console
// System.out.print(strLine+"\t");
String[] val = strLine.split("\\s");
int[] valI = new int[val.length-3];
for (int i = 3; i < val.length; i++) {
valI[i-3] = Integer.valueOf(val[i]);
// System.out.print(val[i]+"_"+valI[i]);
}
System.out.print("Case #" + lineNum + ": ");
System.out
.println(g.calculate(Integer.valueOf(val[0]),
Integer.valueOf(val[1]),
Integer.valueOf(val[2]), valI));
// System.out.println();
// System.out.println(strLine.charAt(0));
lineNum++;
}
// Close the input stream
in.close();
} catch (Exception e) {// Catch exception if any
e.printStackTrace();
}
}
public int calculate(int n, int surprises, int p, int... tArray) {
int counterGreaterThanP = 0;
int surpriseRemaining = surprises;
for (int t : tArray) {
int d = t / 3;
int r = t % 3;
int max = 0;
int maxS = 0;
if (t == 0) {
max = 0;
maxS = 0;
} else if (t == 30) {
max = 10;
maxS = 10;
} else if (t == 1) {
max = 1;
maxS = 1;
} else if (t == 2) {
max = 1;
maxS = 2;
} else {
if (r == 0) {
max = d;
maxS = d + 1;
} else if (r == 1) {
max = d + 1;
maxS = d + 1;
} else if (r == 2) {
max = d + 1;
maxS = d + 2;
}
}
if (max >= p) {
counterGreaterThanP++;
} else if (maxS >= p && surpriseRemaining > 0) {
counterGreaterThanP++;
surpriseRemaining--;
}
}
return counterGreaterThanP;
}
}
| 0 | 1,189,309 |
A11759 | A12056 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package qr1;
import org.junit.Test;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import static junit.framework.Assert.assertEquals;
/**
* Created with IntelliJ IDEA.
* User: shtratos
* Date: 14/04/12
* Time: 04:28
*/
public class DancingGooglers {
public static void main(String[] args) {
DancingGooglers dg = new DancingGooglers();
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
int numOfTests = Integer.valueOf(br.readLine());
for (int i = 0; i < numOfTests; i++) {
System.out.println("Case #" + (i + 1) + ": " + dg.parseAndCalc(br.readLine()));
}
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
@Test
public void testExamples() {
DancingGooglers dg = new DancingGooglers();
assertEquals(3, dg.parseAndCalc("3 1 5 15 13 11"));
assertEquals(2, dg.parseAndCalc("3 0 8 23 22 21"));
assertEquals(1, dg.parseAndCalc("2 1 1 8 0"));
assertEquals(1, dg.parseAndCalc("2 1 2 8 1"));
assertEquals(2, dg.parseAndCalc("2 1 2 8 2"));
assertEquals(1, dg.parseAndCalc("2 0 2 8 2"));
assertEquals(1, dg.parseAndCalc("1 0 0 26"));
assertEquals(0, dg.parseAndCalc("1 0 10 26"));
assertEquals(0, dg.parseAndCalc("2 0 5 5 11"));
assertEquals(0, dg.parseAndCalc("3 3 8 17 13 4"));
assertEquals(1, dg.parseAndCalc("2 0 9 7 27"));
assertEquals(2, dg.parseAndCalc("2 0 0 30 30"));
assertEquals(2, dg.parseAndCalc("2 1 10 30 30"));
assertEquals(1, dg.parseAndCalc("1 1 6 27"));
assertEquals(1, dg.parseAndCalc("1 0 10 30"));
assertEquals(0, dg.parseAndCalc("3 0 9 24 24 21"));
assertEquals(1, dg.parseAndCalc("3 1 9 24 24 21"));
assertEquals(2, dg.parseAndCalc("3 2 9 24 24 21"));
assertEquals(1, dg.parseAndCalc("1 1 10 27"));
assertEquals(0, dg.parseAndCalc("1 1 9 6"));
assertEquals(0, dg.parseAndCalc("3 0 9 17 23 23"));
assertEquals(1, dg.parseAndCalc("3 1 9 17 23 23"));
assertEquals(0, dg.parseAndCalc("2 0 7 18 16"));
assertEquals(1, dg.parseAndCalc("1 1 10 26"));
assertEquals(0, dg.parseAndCalc("1 0 10 26"));
assertEquals(3, dg.parseAndCalc("6 2 8 29 20 8 18 18 21"));
}
private int parseAndCalc(String s) {
potentialCounter = 0;
guaranteedCounter = 0;
String[] parts = s.split(" ", 4);
int numOfGooglers = Integer.parseInt(parts[0]);
int numOfSurprises = Integer.parseInt(parts[1]);
int maxScore = Integer.parseInt(parts[2]);
String[] totalScores = parts[3].split(" ");
for (int i = 0; i < numOfGooglers; i++) {
try {
assessGoogler(Integer.valueOf(totalScores[i]), maxScore);
} catch (Exception e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
}
return guaranteedCounter + Math.min(numOfSurprises, potentialCounter);
}
private int potentialCounter = 0;
private int guaranteedCounter = 0;
private void assessGoogler(int totalScore, int maxScore) throws Exception {
if (totalScore > 30 || totalScore < 0) throw new Exception();
if (maxScore > 10 || maxScore < 0) throw new Exception();
int base = totalScore / 3;
if (base > 10 || base < 0) throw new Exception();
int remain = totalScore % 3;
if (remain > 2 || remain < 0) throw new Exception();
if (remain == 0) {
int best = base;
if ((best-maxScore) >= 0) {
if (best > 10 || best < 0) throw new Exception();
if (best < maxScore) throw new Exception();
guaranteedCounter++;
} else if ((best-maxScore) == -1 && totalScore >= 3 ){// && best <= 9) {
if (base+1 > 10 || base+1 < 0) throw new Exception();
if (base-1 > 10 || base-1 < 0) throw new Exception();
if (base+1 != maxScore) throw new Exception();
potentialCounter++;
}
} else if (remain == 1) {
int best = base + 1;
if ((best-maxScore) >= 0) {
if (best > 10 || best < 0) throw new Exception();
if (best < maxScore) throw new Exception();
guaranteedCounter++;
}/* else if ((best-maxScore) == -1 && totalScore >= 4 && best <= 9) {
if (base+1 > 10 || base+1 < 0) throw new Exception();
if (base-1 > 10 || base-1 < 0) throw new Exception();
if (base+1 != maxScore) throw new Exception();
potentialCounter++;
} */
} else if (remain == 2) {
int best = base + 1;
if ((best-maxScore) >= 0) {
if (best > 10 || best < 0) throw new Exception();
if (best < maxScore) throw new Exception();
guaranteedCounter++;
} else if ((best-maxScore) == -1){// && best <= 9) {
if (base+1 > 10 || base+1 < 0) throw new Exception();
if (base+2 > 10 || base+2 < 0) throw new Exception();
if (base+2 != maxScore) throw new Exception();
potentialCounter++;
}
}
}
}
| 0 | 1,189,310 |
A11759 | A10490 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class GCIFileReader {
public GCIFileReader(File file) throws FileNotFoundException {
mBufferedReader = new BufferedReader(new FileReader(file));
mFile = file;
}
public String getLine() {
try {
String s = mBufferedReader.readLine();
if (s == null)
{
mBufferedReader.close();
}
return s;
} catch (IOException e) {
return null;
}
}
public void reset () throws IOException
{
mBufferedReader.close();
mBufferedReader = new BufferedReader(new FileReader(mFile));
}
private BufferedReader mBufferedReader;
private File mFile;
} | 0 | 1,189,311 |
A11759 | A10858 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
public class letDance {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
StringBuffer output = new StringBuffer();
try{
FileInputStream fstream = new FileInputStream("/Users/iToR/Documents/workspace/CodeJam2/src/B-small-attempt2.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
strLine = br.readLine();
int line = (new Integer(strLine)).intValue();
int i = 1;
while ((strLine = br.readLine()) != null) {
output.append("Case #"+i+": ");
String[] temp;
/* delimiter */
String delimiter = " ";
/* given string will be split by the argument delimiter provided. */
temp = strLine.split(delimiter);
int compet = (new Integer(temp[0])).intValue();
int surprise = (new Integer(temp[1])).intValue();
int max = (new Integer(temp[2])).intValue();
int count = 0;
for(int j = 3;j<temp.length;j++){
int dif = (new Integer(temp[j])).intValue()-(3*max);
if(max==0){
count++;
}
else if((new Integer(temp[j])).intValue()==0){
}
else if(dif>=0||dif==-1||dif==-2){
count++;
}
else if(dif==-3||dif==-4){
if(surprise>0){
count++;
surprise--;
}
}
}
output.append(count);
if(i<line){
output.append("\n");
}
i++;
}
//Close the input stream
in.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
//write output
try{
FileWriter fstream = new FileWriter("result.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.append(output);
out.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
| 0 | 1,189,312 |
A11759 | A12087 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class B {
/**
* @param args
*/
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
in.nextLine();
for (int i = 1; i <= T; i++) {
int numDancers = in.nextInt();
int numSurprisingTriplets = in.nextInt();
int p = in.nextInt();
int triplet, div, mod;
int res = 0;
for (int j = 0; j < numDancers; j++) {
triplet = in.nextInt();
div = triplet / 3;
mod = triplet % 3;
if (triplet != 0) {
if (div >= p)
res++;
else {
if (mod != 0) {
div++;
if (div >= p)
res++;
else {
mod--;
if (mod != 0) {
div++;
if (div >= p && numSurprisingTriplets > 0) {
res++;
numSurprisingTriplets--;
}
}
}
} else {
div++;
if (div >= p && numSurprisingTriplets > 0) {
res++;
numSurprisingTriplets--;
}
}
}
}
else
if (p == 0)
res++;
}
System.out.println("Case #" + i + ": " + res);
}
}
}
| 0 | 1,189,313 |
A11759 | A11733 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package de.johanneslauber.codejam.model.impl;
import de.johanneslauber.codejam.model.ICase;
/**
*
* @author Johannes Lauber - joh.lauber@googlemail.com
*
*/
public class DancingGooglersCase implements ICase {
private final int numberOfAttributes = 1;
private int numberOfGooglers;
private int numberOfTriplets;
private int minLimitOfPoints;
private int[] maxPointsOfGooglers;
@Override
public void setLine(int lineNumber, String lineValue) {
if (lineNumber == 1) {
String[] splittedLine = lineValue.split(" ");
numberOfGooglers = Integer.parseInt(splittedLine[0]);
numberOfTriplets = Integer.parseInt(splittedLine[1]);
minLimitOfPoints = Integer.parseInt(splittedLine[2]);
maxPointsOfGooglers = new int[splittedLine.length - 3];
for (int i = 3; i < splittedLine.length; i++) {
maxPointsOfGooglers[i - 3] = Integer.parseInt(splittedLine[i]);
}
} else {
System.out.println("Linenumber is out of range");
}
}
// Setter & Getter
@Override
public int getNumberOfAttributes() {
return numberOfAttributes;
}
public int getNumberOfGooglers() {
return numberOfGooglers;
}
public void setNumberOfGooglers(int numberOfGooglers) {
this.numberOfGooglers = numberOfGooglers;
}
public int getNumberOfTriplets() {
return numberOfTriplets;
}
public void setNumberOfTriplets(int numberOfTriplets) {
this.numberOfTriplets = numberOfTriplets;
}
public int getMinLimitOfPoints() {
return minLimitOfPoints;
}
public void setMinLimitOfPoints(int minLimitOfPoints) {
this.minLimitOfPoints = minLimitOfPoints;
}
public int[] getMaxPointsOfGooglers() {
return maxPointsOfGooglers;
}
public void setMaxPointsOfGooglers(int[] maxPointsOfGooglers) {
this.maxPointsOfGooglers = maxPointsOfGooglers;
}
}
| 0 | 1,189,314 |
A11759 | A13045 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package dancing;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
public class DanceAllNight {
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new FileReader(new File("test.txt")));
BufferedWriter wr = new BufferedWriter(new FileWriter(new File("output.txt")));
int count = Integer.parseInt(br.readLine());
int yes,surprising,p,numsurprising,current,div3,output;
String[] buffer;
int[] values;
for(int i=1; i<=count; i++)
{
String line = br.readLine();
buffer = line.split(" ");
values = new int[buffer.length];
for(int j=0; j<buffer.length; j++)
{
values[j] = Integer.parseInt(buffer[j]);
}
yes = 0;
surprising =0;
p = values[2];
numsurprising = values[1];
for(int k=3; k<values.length; k++)
{
current = values[k];
div3 = current/3;
if(current % 3 == 0)
{
if(div3 >= p)
{
yes++;
}
else if(div3 == p-1 && current >= p)
{
surprising++;
}
}
else if(current %3 == 1)
{
if(div3 >= p-1 && current >= p)
{
yes++;
}
}
else
{
if(div3 >= p-1 && current >= p)
{
yes++;
}
else if(div3 == p-2 && current >= p)
{
surprising++;
}
}
}
output = Math.min(yes+surprising, yes+numsurprising);
//make sure that its not more than the total # of contestants
//output = Math.min(output, values[0]);
wr.write("Case #"+i+": "+output);
wr.newLine();
}
wr.close();
}
}
| 0 | 1,189,315 |
A11759 | A10695 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.text.MessageFormat;
import java.util.Map;
import java.util.Scanner;
public class QualQ2 {
private final Scanner inputScanner = new Scanner(System.in);
private Scanner testCaseScanner;
private int answer;
int[] scores;
int N;
int p;
int S;
/**
* @param args
*/
public static void main(String[] args) {
QualQ2.init();
QualQ2 speaking = new QualQ2();
speaking.solve();
}
private static void init() {
try {
System.setIn(new FileInputStream("in.txt"));
System.setOut(new PrintStream("out.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
private void solve() {
// Number of test cases
int T = inputScanner.nextInt();
inputScanner.nextLine();
for (int i = 1; i <= T; i++) {
initTestCase();
readTestCase();
solveTestCase();
printTestCase(i);
}
}
private void initTestCase() {
answer = 0;
}
private void readTestCase() {
testCaseScanner = new Scanner(inputScanner.nextLine());
N = testCaseScanner.nextInt();
S = testCaseScanner.nextInt();
p = testCaseScanner.nextInt();
scores = new int[N];
for (int i=0;i<N;i++)
scores[i] = testCaseScanner.nextInt();
}
private void solveTestCase() {
if (p==0) {
answer = N;
return;
}
for (int i=0;i<N;i++) {
int high = (int)(Math.ceil(((float) scores[i] / 3.0f)));
if (high >= p) {
answer++;
continue;
}
if (high == p-1 && S>0 && high !=0) {
int mod = scores[i] % 3;
if (mod == 0 || mod == 2) {
answer++;
S--;
}
}
}
}
private final MessageFormat printFormat = new MessageFormat("Case #{0}: ");
private void printTestCase(int num) {
System.out.print(printFormat.format(new Object[] { num }));
System.out.println(answer);
}
}
| 0 | 1,189,316 |
A11759 | A11773 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class B implements Runnable {
private MyScanner in;
private PrintWriter out;
private void solve() {
int n = in.nextInt();
int surprise = in.nextInt();
int score = in.nextInt();
int[] total = new int[n];
for (int i = 0; i < n; ++i) {
total[i] = in.nextInt();
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (total[i] >= 3 * score - 2) {
++ans;
} else if (score > 1 && surprise > 0 && total[i] >= 3 * score - 4) {
++ans;
--surprise;
}
}
out.println(ans);
}
@Override
public void run() {
in = new MyScanner();
try {
out = new PrintWriter(new File("B-small-attempt0.out"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int tests = in.nextInt();
for (int i = 0; i < tests; ++i) {
out.print("Case #" + (i + 1) + ": ");
solve();
}
in.close();
out.close();
}
public static void main(String[] args) {
new B().run();
}
class MyScanner {
private BufferedReader br;
private StringTokenizer st;
public MyScanner() {
try {
br = new BufferedReader(new FileReader("B-small-attempt0.in"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public void close() {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean hasNext() {
while (st == null || !st.hasMoreTokens()) {
try {
String s = br.readLine();
if (s == null) {
return false;
}
st = new StringTokenizer(s);
} catch (IOException e) {
e.printStackTrace();
return false;
}
}
return st != null && st.hasMoreTokens();
}
private String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String s = br.readLine();
if (s == null) {
return null;
}
st = new StringTokenizer(s);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
return st.nextToken();
}
public String nextLine() {
try {
st = null;
return br.readLine();
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
} | 0 | 1,189,317 |
A11759 | A12440 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
public class CodeJamSolverDancing {
public static HashMap<Integer,ArrayList<Integer>> valueToIndexMap=new HashMap<Integer,ArrayList<Integer>>();
public static void main(String[] args) {
int numTestCases=0;
int numLinePerTestCase=1;
int currentCase=0;
String inputFileName="B-small-attempt1.in";
//String inputFileName="input.in";
BufferedReader br=null;
StringBuilder solutionString=new StringBuilder();
int lineCount=0;
try{
String line;
br=new BufferedReader(new FileReader(inputFileName));
while((line=br.readLine())!=null){
lineCount++;
if(lineCount==1){
numTestCases=Integer.parseInt(line);
continue;
}
int[] splittedLine=getIntArrayFromStringLine(line);
int numGoogler=splittedLine[0];
int numSurprises=splittedLine[1];
int bestResult=splittedLine[2];
ArrayList<Integer> scoresList=new ArrayList<Integer>();
for(int i=3;i<splittedLine.length;i++){
scoresList.add(splittedLine[i]);
}
String solution=getSolution(numGoogler,numSurprises,bestResult,scoresList);
//System.out.println(solution);
currentCase++;
solutionString.append("Case #"+currentCase+": "+solution+"\n");
}
br.close();
writeTextToFile(inputFileName.replace(".in", ".out"), solutionString.toString().trim());
}
catch(IOException ex){
System.out.println("Unable to read from file!");
ex.printStackTrace();
}
}
private static String getSolution(int numGoogler, int numSurprises,
int bestResult, ArrayList<Integer> scoresList) {
int tentativeScoreWOS=0;
int tentativeScoreWS=0;
int tentativeScoreWS2=0;
if(bestResult==0){
tentativeScoreWOS=0;
tentativeScoreWS=0;
tentativeScoreWS2=0;
}
else if(bestResult==1){
tentativeScoreWOS=1;
tentativeScoreWS=1;
tentativeScoreWS2=1;
}
else{
tentativeScoreWOS=bestResult+bestResult-1+bestResult-1;
tentativeScoreWS=bestResult+bestResult-2+bestResult-2;
tentativeScoreWS2=bestResult+bestResult-1+bestResult-2;
}
int maxGooglers=0;
for(int eachScore:scoresList){
if(eachScore<bestResult)
continue;
if(tentativeScoreWOS<=eachScore){
maxGooglers++;
continue;
}
//int thirdScore=eachScore-bestResult-bestResult-2;
else if(eachScore>=tentativeScoreWS && tentativeScoreWS>1 && numSurprises>0){
maxGooglers++;
numSurprises--;
continue;
}
else if(eachScore>=tentativeScoreWS2 && tentativeScoreWS2>1 && numSurprises>0){
maxGooglers++;
numSurprises--;
continue;
}
}
return maxGooglers+"";
}
private static int[] getIntArrayFromStringLine(String line) {
String[] stringArray=line.split("\\s+");
int length=stringArray.length;
int intArray[]=new int[length];
valueToIndexMap=new HashMap<Integer,ArrayList<Integer>>();
for(int i=0;i<length;i++){
intArray[i]=Integer.parseInt(stringArray[i]);
ArrayList<Integer> indicesList=new ArrayList<Integer>();
if(valueToIndexMap.containsKey(intArray[i])){
indicesList=valueToIndexMap.get(intArray[i]);
}
indicesList.add(i);
valueToIndexMap.put(intArray[i], indicesList);
}
return intArray;
}
public static void writeTextToFile(String fileName, String textToWrite){
try{
BufferedWriter bw= new BufferedWriter(
new FileWriter(fileName));
bw.write(textToWrite);
bw.close();
}
catch(IOException ex){
System.out.println("Unable to write to file!");
ex.printStackTrace();
}
}
}
| 0 | 1,189,318 |
A11759 | A11191 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
import java.io.*;
public class B {
public static void main(String[]args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int T = Integer.parseInt(in.readLine());
for(int x=1;x<T+1;x++) {
StringTokenizer st = new StringTokenizer(in.readLine());
int n = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
int[] scores = new int[n];
for(int i=0;i<n;i++)
scores[i]=Integer.parseInt(st.nextToken());
int cases = 0;
for(int score : scores) {
int base = score/3;
switch(score%3) {
case 0:
if(base>=p) {
cases++;
}
else
if (s > 0 && base > 0 && base + 1 >= p) {
cases++;
s--;
}
break;
case 1:
if(base+1>=p) {
cases++;
}
else
if (s > 0 && base + 1 >= p) {
cases++;
s--;
}
break;
case 2:
if(base+1>=p) {
cases++;
}
else
if (s > 0 && base + 2 >= p) {
cases++;
s--;
}
break;
}
}
System.out.println("Case #"+x+": "+cases);
}
}
} | 0 | 1,189,319 |
A11759 | A11955 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.codejam2012.qualificationround;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class B {
public static int nTest;
public static int nGoogler;
public static int nSurprise;
public static int threshold;
public static int[] scores;
public static int nHaveHighScore;
public static int maxScore;
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(new File("input.txt"));
FileWriter writer = new FileWriter(new File("output.txt"));
nTest = scanner.nextInt();
for (int i=1;i<=nTest;++i) {
nHaveHighScore = 0;
nGoogler = scanner.nextInt();
nSurprise = scanner.nextInt();
threshold = scanner.nextInt();
scores = new int[nGoogler];
for (int j=0;j<nGoogler;++j) {
scores[j] = scanner.nextInt();
if (scores[j] % 3 == 0) {
maxScore = scores[j] / 3;
if (maxScore >= threshold) {
nHaveHighScore++;
}
else if (nSurprise > 0 && maxScore+1 >= threshold && maxScore-1 >= 0) {
nHaveHighScore++;
nSurprise--;
}
}
else if (scores[j] % 3 == 1) {
maxScore = scores[j] / 3 + 1;
if (maxScore >= threshold) {
nHaveHighScore++;
}
}
else if (scores[j] % 3 == 2) {
maxScore = scores[j] / 3 + 1;
if (maxScore >= threshold) {
nHaveHighScore++;
}
else if (nSurprise > 0 && maxScore+1 >= threshold && maxScore-1 >= 0) {
nHaveHighScore++;
nSurprise--;
}
}
}
writer.write("Case #" + i + ": " + nHaveHighScore);
if (i < nTest) {
writer.write("\n");
}
writer.flush();
}
writer.close();
}
}
| 0 | 1,189,320 |
A11759 | A12772 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;
public class Test {
static BufferedReader reader;
static StringTokenizer tokenizer;
static PrintWriter writer;
static int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
static long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
static double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
static String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
public static void main(String[] args) throws IOException {
reader = new BufferedReader(new InputStreamReader(new FileInputStream("b.in")));
tokenizer = null;
writer = new PrintWriter("b.out");
solve();
reader.close();
writer.close();
}
private static void test() throws IOException
{
int n = nextInt();
int s = nextInt();
int p = nextInt();
int[] sum = new int[n];
for(int i=0;i<n;i++)
{
sum[i]=nextInt();
}
int res=0;
for(int i=0;i<n;i++)
{
if(sum[i]==0)
{
if(p==0)
res++;
continue;
}
if(sum[i]==1)
{
if(p<=1)
res++;
continue;
}
if((sum[i]+2)/3>=p)
{
res++;
continue;
}
if(s>0)
{
if((sum[i]+4)/3>=p)
{
s--;
res++;
}
}
}
writer.print(res);
}
private static void solve() throws IOException {
int t = nextInt();
for(int i=1;i<=t;i++)
{
writer.print("Case #"+i+": ");
test();
writer.println();
}
}
}
| 0 | 1,189,321 |
A11759 | A10853 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package jam2012.qround;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
public class PB {
public static void main(String args[])
{
int line = 0;
try{
BufferedReader br = new BufferedReader(new FileReader("B-small-attempt0.in"));
BufferedWriter bw = new BufferedWriter(new FileWriter("B-small-attempt0.out"));
String str;
String[] strIn;
Integer.parseInt(br.readLine());
while ((str = br.readLine()) != null){
strIn = str.split(" ");
int i=0;
int N = Integer.parseInt(strIn[i++]);
int S = Integer.parseInt(strIn[i++]);
float p = Integer.parseInt(strIn[i++]);
int cases = 0;
while(N>0){
float score = Integer.parseInt(strIn[i++]);
N--;
if (score >= (3*p-2))
cases++;
else
if (score >= (3*p-4) && S>0 && score >=2){
cases++;
S--;
}
}
line++;
bw.write("Case #"+line+": "+cases);
bw.newLine();
}
br.close();
bw.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
| 0 | 1,189,322 |
A11759 | A10374 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
public class BQ {
public static void main(String[] args) {
BufferedReader reader = null;
BufferedWriter writer = null;
int T = 0, k, j, N, S, p, i, ti, tis, mod, G = 0;
String line = null, caseSolution;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream(args[0])));
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(args[1])));
T = Integer.parseInt(reader.readLine());
for (k = 1; k <= T; k++) {
line = reader.readLine();
N = Integer.parseInt(line.substring(0, j = line.indexOf((int)' ', 0)));
S = Integer.parseInt(line.substring(++j, j = line.indexOf((int)' ', j)));
p = Integer.parseInt(line.substring(++j, j = line.indexOf((int)' ', j)));
for (i = 0; i < N; i++) {
if (i != N - 1) {
ti = Integer.parseInt(line.substring(++j, j = line.indexOf((int)' ', j)));
}
else {
ti = Integer.parseInt(line.substring(++j));
}
tis = ti/3;
mod = ti%3;
if (tis >= p || (tis + 1 >= p && mod > 0)) {
G++;
}
else {
if (((tis + 1 >= p && mod == 0 && tis > 0) || (tis + 2 >= p && mod == 2)) && S > 0) {
G++;
S--;
}
}
}
writer.write("Case #" + k + ": " + G + "\n");
G = 0;
}
}
catch (IOException ex) {
ex.printStackTrace();
}
try {
if (reader != null) {
reader.close();
}
if (writer != null) {
writer.close();
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
} | 0 | 1,189,323 |
A11759 | A11744 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class googleDancers {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Integer> lstInt = new ArrayList<Integer>();
boolean error_ni = false;
try{
FileReader fr=new FileReader("B-small-attempt11.in");
BufferedReader br = new BufferedReader (fr);
int numCases = Integer.parseInt(br.readLine());
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("solution.txt")));
int i;
for(i=1; i<=numCases; i++ ){
String linea = new String(br.readLine());
StringTokenizer palabraSeparation = new StringTokenizer(linea);
lstInt.clear();
int N = Integer.parseInt(palabraSeparation.nextToken());
int S = Integer.parseInt(palabraSeparation.nextToken());
int p = Integer.parseInt(palabraSeparation.nextToken());
int solution = 0;
int surprising = 0;
while(palabraSeparation.hasMoreTokens() != false){
int num_i = Integer.parseInt(palabraSeparation.nextToken());
lstInt.add(num_i);
/*if (num_i > 30)
error_ni = true;*/
}
if ((S>=0 && S <= N) && (p>= 0 && p <= 10) && error_ni == false){
if (p==0){
solution = lstInt.size();
}
else
for (int j=0; j<lstInt.size(); j++){
if (p == 1 ){
if (lstInt.get(j)>0) solution++;
}
else if (p*3 <= lstInt.get(j) && lstInt.get(j)!=0 ){
solution++;
}
else if(p*3-2 <= lstInt.get(j) && p>=1 && lstInt.get(j)!=0 ){
solution++;
}
else if(p*3-4 <= lstInt.get(j) && lstInt.get(j) >= 2 && lstInt.get(j)<=28){
surprising++;
}
}
if(S >= surprising)
solution +=surprising;
else if(S < surprising )
solution +=S;
}
//System.out.println("Case #" + i+": "+solution);
bw.write("Case #" + i+": "+solution);
bw.newLine();
}
bw.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
| 0 | 1,189,324 |
A11759 | A10528 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class ProbB {
static int[][] SurprisingCombinations = {{0,0,2},{0,1,2},{0,2,2}};
static int[][] notSurprisingCombinations = {{0,0,0},{0,0,1},{0,1,1}};
public static void main(String[] args) {
PrintWriter out;
try {
out = new PrintWriter(new FileWriter("d:\\codejam2012\\outputfile.txt"));
Scanner scanner = new Scanner(new File("d:\\codejam2012\\B-small-attempt1.in"));
int cases = scanner.nextInt();
scanner.nextLine();
for (int i = 1; i <= cases; i++) {
int n = scanner.nextInt(), s = scanner.nextInt(), p = scanner.nextInt();
int[] dancers = new int[n];
for (int j = 0; j < dancers.length; j++) {
dancers[j] = scanner.nextInt();
}
int sol = solve(dancers, n, s, p);
out.println("Case #"+i+": " +sol);
}
out.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private static int solve(int[] dancers, int n, int s, int p) {
int ret = 0;
for (int i = 0; i < dancers.length; i++) {
if(isDoneWithCombinations(notSurprisingCombinations,dancers[i], p)){
//here not surprising sequence and can get atleast p
ret++;
}else if(isDoneWithCombinations(SurprisingCombinations,dancers[i], p) && s > 0){
//here surprising sequence and can get atleast p
ret++;
s--;
}
}
return ret;
}
private static boolean isDoneWithCombinations(int[][] combinations, int seq, int p) {
boolean sol = false;
for (int i = 0; i < combinations.length; i++) {
int sub = 0;
for (int j = 0; j < combinations[i].length; j++) {
sub += combinations[i][j];
}
if((seq - sub) >= 0 && (seq - sub)% 3 == 0 && ((seq - sub) / 3) + combinations[i][2] >= p){
sol = true;
}
}
return sol;
}
}
| 0 | 1,189,325 |
A11759 | A11449 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package de.hg.codejam.tasks.dance.controller;
import de.hg.codejam.tasks.dance.domain.Case;
import de.hg.codejam.tasks.dance.help.Converter;
import de.hg.codejam.tasks.dance.service.Calculator;
import de.hg.codejam.tasks.io.Reader;
import de.hg.codejam.tasks.io.Writer;
public class Test {
public static void main(String[] args) {
String inputPath = "file/B-small-attempt0.in";
String outputPath = Writer.generateOutputPath(inputPath);
System.out.println("=== READ FILE: " + inputPath + " ===");
String[] input = Reader.readFile(inputPath);
Writer.print(input);
System.out.println("=== CASES ===");
Case[] cases = new Case[input.length];
for (int i = 0; i < input.length; i++) {
cases[i] = Case.parse(input[i]);
System.out.println(cases[i]);
}
System.out.println("=== CALCULATION: Start ===");
int[] results = Calculator.calculate(cases);
System.out.println("=== CALCULATION: End ===");
System.out.println("=== RESULTS ===");
String[] resultStrings = Converter.convert(results);
Writer.write(resultStrings);
System.out.println("=== WRITE TO FILE: " + outputPath + " ===");
Writer.write(resultStrings, outputPath);
System.out.println("=== FILE WRITTEN ===");
}
}
| 0 | 1,189,326 |
A11759 | A10022 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.ArrayList;
public class SpeakingInToungues {
private static String inputFile = "C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Input.txt";
private static String outputFile = "C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Output.txt";
public static void main(String[] args) {
InputReader ir = new InputReader(inputFile);
OutputWriter ow = new OutputWriter(outputFile);
ArrayList<String> lines = ir.loadLines();
//Given examples cover 25 chars and the one left out is q which is ideally mapped to the unused char z.
String normalText = "aozq our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up";
String googlereseText = "yeqz ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv";
StringBuffer sb = null;
for(int i=1;i<lines.size();i++){
sb = new StringBuffer();
char[] charArray = lines.get(i).toCharArray();
for(int j=0;j<charArray.length;j++){
sb.append(normalText.charAt(googlereseText.indexOf(charArray[j])));
}
ow.writeCaseLine(sb.toString());
}
ow.flushAndClose();
}
}
| 0 | 1,189,327 |
A11759 | A10672 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class ProblemBDancingWithTheGooglers {
private static int lines;
private static Scanner input;
private static String [] outputs;
public static void main(String[] args) {
try {
input = new Scanner(new FileReader(args[0]));
} catch (FileNotFoundException e) {
e.printStackTrace();
System.exit(-1);
}
lines = Integer.parseInt(input.nextLine());
outputs = new String [lines];
for(int i = 1; i<=lines; i++)
{
int maxVal;
int num;
int supriseCase;
int iAns = 0;
String ans = "Case #" + i + ": ";
StringTokenizer str = new StringTokenizer(input.nextLine());
num = Integer.parseInt(str.nextToken());
supriseCase = Integer.parseInt(str.nextToken());
maxVal = Integer.parseInt(str.nextToken());
for(int j = 0; j<num; j++)
{
Triplet t = new Triplet(Integer.parseInt(str.nextToken()));
if(t.highest()>=maxVal)
{
iAns++;
}
else if(supriseCase>0 && (t.highest() + 1)>= maxVal && t.highest() != t.sum && t.canBeSuprise())
{
supriseCase--;
iAns++;
}
}
ans += iAns;
outputs[i-1] = ans;
}
try{
File file =new File("outputB.txt");
//if file doesnt exists, then create it
if(!file.exists()){
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getName());
BufferedWriter bw = new BufferedWriter(fw);
for(int k = 0; k<outputs.length; k++)
{
bw.write(outputs[k]);
bw.newLine();
}
bw.close();
}catch(IOException e){
e.printStackTrace();
}
}
public static class Triplet {
public static int sum, x, y, z;
public Triplet(int i)
{
sum = i;
x = (int) Math.round(((double)sum)/3.0);
y = (int) Math.round(((double)sum)/3.0);
z = sum - x - y;
}
public static boolean canBeSuprise()
{
return ((x==y && x==z) || x>z);
}
public static boolean allEqual()
{
return (x==y && x==z);
}
public static int highest()
{
if(x>=y)
{
if (x>=z)
{
return x;
}
else
{
return z;
}
}
else
{
if(y>=z)
{
return y;
}
else
{
return z;
}
}
}
}
}
| 0 | 1,189,328 |
A11759 | A11753 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class problemB {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner cin = new Scanner(System.in);
int t = cin.nextInt();
int k = 0, n, s, p, i, ans;
int[] a;
while (t > 0) {
t--;
k++;
n = cin.nextInt();
s = cin.nextInt();
p = cin.nextInt();
a = new int[n];
for (i = 0; i < n; i++)
a[i] = cin.nextInt();
ans = 0;
for (i = 0; i < n; i++) {
if(a[i]>=p+Math.max(p-1, 0)*2){
ans++;
}else
if(a[i]>=p+Math.max(p-2, 0)*2 && s>0){
ans++;
s--;
}
}
System.out.println("Case #"+k+": "+ans);
}
}
}
| 0 | 1,189,329 |
A11759 | A10217 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gcj.base;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.regex.Pattern;
/**
*
* @author jalves
*/
public class Console {
static final String defaultDelimiters = "\\s+";
static final int intRadix = 10;
private BufferedReader in = null;
private PrintWriter out = null;
private String delimiters = defaultDelimiters;
private Pattern splitter = null;
private String line = null;
private String[] tokens = null;
private int tokenIdx = 0;
public Console(String inputName, String outputName, boolean overwrite) {
File f;
InputStreamReader isr;
OutputStreamWriter osw;
if ((inputName == null) || inputName.equals("-")) {
isr = new InputStreamReader(System.in/*, charset*/);
} else {
f = new File(inputName);
if (f.canRead()) {
try {
isr = new FileReader(f);
} catch (FileNotFoundException ex) {
throw new IllegalArgumentException("Error accessing input file '" + inputName + "': Exiting...", ex);
}
} else {
throw new IllegalArgumentException("Error accessing input file '" + inputName + "': Exiting...");
}
}
if ((outputName == null) || outputName.equals("-")) {
osw = new OutputStreamWriter(System.out/*, charset*/);
} else {
f = new File(outputName);
try {
if (f.createNewFile()) {
// new file was created
osw = new FileWriter(f);
} else {
// file already exists
if (overwrite && f.canWrite()) {
osw = new FileWriter(f);
} else {
throw new IllegalArgumentException("Output file '" + outputName + "' already exists: Exiting...");
}
}
} catch (IOException e) {
throw new IllegalArgumentException("Error accessing output file '" + outputName + "': Exiting...", e);
}
}
in = new BufferedReader( isr );
out = new PrintWriter( osw , true);
delimiters = defaultDelimiters;
splitter = Pattern.compile(delimiters);
}
/*************************************************
* Read from input
*************************************************/
protected String readLine() throws IOException {
line = in.readLine();
tokenIdx = 0;
tokens = null;
return line;
}
public boolean newLine() throws IOException {
if (readLine() != null) {
return true;
} else {
return false;
}
}
public void changeDelimiters(String newDelims) {
if (newDelims == null) {
delimiters = defaultDelimiters;
} else {
delimiters = newDelims;
}
splitter = Pattern.compile(delimiters);
}
private String[] getTokens() throws IOException {
if (line == null) {
if ( ! newLine()) {
return null;
}
}
tokens = splitter.split(line);
return tokens;
}
public String[] getStrings() throws IOException {
return getTokens();
}
private long toLong(String s) {
return Long.parseLong(s, intRadix);
}
public long[] getLongs() throws IOException {
long[] result = null;
if (getTokens() != null) {
result = new long[tokens.length];
for (int i = 0; i < tokens.length; i++) {
result[i] = toLong(tokens[i]);
}
}
return result;
}
private double toDouble(String s) {
return Double.parseDouble(s);
}
public double[] getDoubles() throws IOException {
double[] result = null;
if (getTokens() != null) {
result = new double[tokens.length];
for (int i = 0; i < tokens.length; i++) {
result[i] = toDouble(tokens[i]);
}
}
return result;
}
public String getString() throws IOException {
if (tokens == null) {
getTokens(); // no check to wether it returns null
}
if (tokenIdx >= tokens.length) {
newLine(); // no check to wether it returns false
getTokens(); // no check to wether it returns null
}
return tokens[tokenIdx++];
}
public long getLong() throws IOException {
if (tokens == null) {
getTokens(); // no check to wether it returns null
}
if (tokenIdx >= tokens.length) {
newLine(); // no check to wether it returns false
getTokens(); // no check to wether it returns null
}
return toLong(tokens[tokenIdx++]);
}
public double getDouble() throws IOException {
if (tokens == null) {
getTokens(); // no check to wether it returns null
}
if (tokenIdx >= tokens.length) {
newLine(); // no check to wether it returns false
getTokens(); // no check to wether it returns null
}
return toDouble(tokens[tokenIdx++]);
}
public void cleanup() {
try {
in.close();
} catch (IOException ex) {
// do nothing
}
out.close();
}
/*************************************************
* Write to output
*************************************************/
public void print(String s) {
out.print(s);
}
public void println(String s) {
out.println(s);
}
/*************************************************
* Log to console
*************************************************/
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
private Date now = new Date();
public void logt(String s) {
now.setTime(System.currentTimeMillis());
System.err.println(sdf.format(now) + ": " + s);
System.err.flush();
}
public void log(String s) {
System.err.print(s);
System.err.flush();
}
}
| 0 | 1,189,330 |
A11759 | A11413 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class pro2 {
private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
public static void main ( String [] args ) throws IOException
{
int N = Integer.parseInt(br.readLine());
for(int i = 0;i < N; i++)
System.out.println("Case #" + (i+1) + ": " + cal());
}
private static String cal() throws IOException {
String[] buffer = br.readLine().split("\\s");
int p=Integer.parseInt(buffer[2]);
int winner=0;
int s=Integer.parseInt(buffer[1]);
int tempS=0;
for(int i=0;i<Integer.parseInt(buffer[0]);i++){
int score=Integer.parseInt(buffer[i+3]);
if(score%3==0){
if(p<=(score/3))
winner++;
else if(p<=(score/3)+1 && tempS<s && (score/3)-1>=0){
winner++;
tempS++;
}
}
if(score%3==1)
if(p<=(score/3)+1)
winner++;
if(score%3==2){
if(p<=(score/3)+1)
winner++;
else if(p<=(score/3)+2 && tempS<s){
winner++;
tempS++;}
}
}
return Integer.toString(winner);
}
} | 0 | 1,189,331 |
A11759 | A10894 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package utils;
/**
*
* @author Fabien Renaud
*/
public class StopWatch {
private long startTime = -1;
private long stopTime = -1;
private boolean running = false;
public StopWatch start() {
startTime = System.currentTimeMillis();
running = true;
return this;
}
public StopWatch stop() {
stopTime = System.currentTimeMillis();
running = false;
return this;
}
public long getElapsedTime() {
if (startTime == -1) {
return 0;
}
if (running) {
return System.currentTimeMillis() - startTime;
} else {
return stopTime - startTime;
}
}
public String getElapsedSeconds() {
return String.format("%1$.4f", getElapsedTime() / 1000.0f);
}
public StopWatch reset() {
startTime = -1;
stopTime = -1;
running = false;
return this;
}
}
| 0 | 1,189,332 |
A11759 | A12326 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package gcj.main;
import gcj.cases.competition.qualification_round_2012.CaseB;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class Main {
public static final void main (String[] args) throws Exception{
// doTask("taskTeszt0", "/home/dev/Letöltések/0-teszt-practice.in", "/home/dev/Letöltések/0-teszt-practice.out", new Case0());
// doTask("taskSmall0", "/home/dev/Letöltések/A-small-attempt0.in", "/home/dev/Letöltések/A-small-attempt0.out", new Case0());
// doTask("taskTesztB", "/home/dev/Letöltések/B-teszt-practice.in", "/home/dev/Letöltések/B-teszt-practice.out", new CaseB());
doTask("taskSmallB", "/home/dev/Letöltések/B-small-attempt0.in", "/home/dev/Letöltések/B-small-attempt0.out", new CaseB());
// doTask("taskLargeB", "/home/dev/Letöltések/B-large-practice.in", "/home/dev/Letöltések/B-large-practice.out", new CaseB());
// doTask("taskTesztC", "/home/dev/Letöltések/C-teszt-practice.in", "/home/dev/Letöltések/C-teszt-practice.out", new CaseC());
// doTask("taskSmallC", "/home/dev/Letöltések/C-small-attempt0.in", "/home/dev/Letöltések/C-small-attempt0.out", new CaseC());
// doTask("taskLargeC", "/home/dev/Letöltések/C-large.in", "/home/dev/Letöltések/C-large.out", new CaseC());
doTask(null, null, null, null); //because i hate the 'never used locally' warning...
}
private static final void doTask(String taskID, String inpFilePath, String outFilePath, Case c) throws Exception {
if(taskID == null) return;
BufferedReader br = null;
BufferedWriter bw = null;
String strLine;
int caseNum = 0;
System.out.println(taskID + " strated...");
try{
{
//open files
br = new BufferedReader(new FileReader(new File(inpFilePath)));
bw = new BufferedWriter(new FileWriter(new File(outFilePath)));
}
{
//read caseNum value
if ((strLine = br.readLine()) != null){
caseNum = Integer.parseInt(strLine);
}
System.out.println("CaseNum: "+caseNum);
}
for(int i=0; i<caseNum; i++){
System.out.println("\tprocessing Case #: "+(i+1));
//load case
c.init(i+1, br);
//processing case
c.solve();
//write to file
c.generateOutput(bw, i<caseNum-1);
}
}catch(Exception e){
System.out.println(taskID + " failed!");
e.printStackTrace();
}finally{
//end
if(br!=null) br.close();
if(bw!=null) bw.close();
System.out.println(taskID + " finished.");
}
}
}
| 0 | 1,189,333 |
A11759 | A10050 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
public class GooglerIdol {
/**
* @param args
*/
public static void main(String[] args) {
File sample = new File(
"D:/Feng/Workspace/googlecodejam2012/problemB/in/sample.in");
File in = new File(
"D:/Feng/Workspace/googlecodejam2012/problemB/in/B-small-attempt1.in");
try {
BufferedWriter out = new BufferedWriter(new FileWriter(
"D:/Feng/Workspace/googlecodejam2012/problemB/out/out-attempt1.txt"));
StringBuilder s;
String line = "";
int googlers, surprises, p = 0;
int[] totalScores;
int idols, chances = 0;
int count = 1;
Scanner scanner = new Scanner(in);
// Ignore the first line showing total count
scanner.nextLine();
while (scanner.hasNextLine()) {
s = new StringBuilder("Case #");
s.append(count);
s.append(": ");
line = scanner.nextLine();
String[] tokens = line.split(" ");
googlers = Integer.parseInt(tokens[0]);
surprises = Integer.parseInt(tokens[1]);
p = Integer.parseInt(tokens[2]);
totalScores = new int[googlers];
for (int i = 3; i < tokens.length; i++) {
totalScores[i - 3] = Integer.parseInt(tokens[i]);
}
Arrays.sort(totalScores);
idols = 0;
chances = surprises;
for (int j = googlers - 1; j >= 0; j--) {
if (pass(p, totalScores[j], false)) {
idols++;
}
else if (chances > 0 && pass(p, totalScores[j], true)) {
idols++;
chances--;
}
}
s.append(idols);
/*
s.append("\ngooglers:");
s.append(googlers);
s.append(" surprises:");
s.append(surprises);
s.append(" p:");
s.append(p);
s.append("\nTotal Scores");
s.append(Arrays.toString(totalScores));
*/
System.out.println(s);
out.write(s.toString());
out.newLine();
count++;
}
scanner.close();
out.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static boolean pass(int p, int totalScore, boolean surprise) {
if (p == 0)
return true;
if (totalScore == 0)
return false;
int avg = totalScore / 3;
if (avg >= p)
return true;
int diff = totalScore - (3 * avg);
if (p - avg == 1 && diff > 0) {
return true;
}
if (surprise && p - avg == 1 && diff == 0) {
return true;
}
if (surprise && p - avg == 2 && diff > 1) {
return true;
}
return false;
}
}
| 0 | 1,189,334 |
A11759 | A13013 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package gcj2012Q;
import java.io.*;
import java.util.*;
public class B {
public static void main(String[] args) {
new B().run(new Scanner(System.in));
}
void run(Scanner sc) {
int n = sc.nextInt();
for(int i = 1; n-- > 0; i++)
solve(sc, i);
}
void solve(Scanner sc, int case_num) {
int n = sc.nextInt();
int s = sc.nextInt();
int p = sc.nextInt();
int count = 0, surprising = 0;
for(int i = 0; i < n; i++) {
int t = sc.nextInt();
if(t < p) continue;
if(t / 3 >= p || (t / 3 == p - 1 && t % 3 > 0)) count++;
else if(t / 3 == p - 1 && t % 3 == 0) surprising++;
else if(t / 3 == p - 2 && t % 3 == 2) surprising++;
}
// System.out.println(count+" "+surprising);
int res = count + Math.min(surprising, s);
System.out.printf("Case #%d: %d\n", case_num, res);
}
}
| 0 | 1,189,335 |
A11759 | A10268 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class B {
static ArrayList<Triplet> surprising = new ArrayList<Triplet>();
static ArrayList<Triplet> nonSurprising = new ArrayList<Triplet>();
public static boolean isValid(int a, int b, int c) {
if (Math.abs(a - b) > 2 || Math.abs(a - c) > 2 || Math.abs(b - c) > 2)
return false;
return true;
}
static public void generate(int a, int b, int c, int i) {
int j = 0;
if (i == 1)
j = a;
else if (i == 2)
j = b;
for (; j <= 10; j++) {
if (i == 0)
generate(j, b, c, 1);
else if (i == 1)
generate(a, j, c, 2);
else if (i == 2)
if (isValid(a, b, j)) {
Triplet tmp = new Triplet(a, b, j);
if (tmp.isSurprising())
surprising.add(tmp);
else
nonSurprising.add(tmp);
}
}
}
static private int getMax(ArrayList<Triplet> currTriplets, int n,
ArrayList<Integer> googlers, int p) {
int removed = 0;
label:for (int i = 0; i < n; i++) {
int maxNo = -1, maxI = -1;
for (int j = 0; j < currTriplets.size(); j++) {
Triplet tr = currTriplets.get(j);
if (tr.a == tr.b && tr.a == 6)
System.out.print("");
int tmp = 0;
for (int j2 = 0; j2 < googlers.size(); j2++)
if (tr.sum == googlers.get(j2) && tr.best >= p)
tmp++;
if (tmp > maxNo) {
maxNo = tmp;
maxI = j;
}
}
if (maxNo == 0)
break;
Triplet chosen = currTriplets.get(maxI);
for (int j = 0; j < googlers.size(); j++)
if (chosen.sum == googlers.get(j) && chosen.best >= p) {
googlers.remove(j);
removed++;
if (removed == n)
break label;
j--;
}
}
return removed;
}
public static void main(String[] args) throws IOException {
Scanner in = new Scanner(new FileInputStream("B-small-attempt0.in"));
FileWriter out = new FileWriter(new File("B-small-attempt0.out"));
generate(0, 0, 0, 0);
int t = in.nextInt(), cnt = 1, n, s, p, res;
ArrayList<Integer> googlers = new ArrayList<Integer>();
while (t-- > 0) {
n = in.nextInt();
s = in.nextInt();
p = in.nextInt();
for (int i = 0; i < n; i++)
googlers.add(in.nextInt());
res = getMax(nonSurprising, n - s, googlers, p);
res += getMax(surprising, s, googlers, p);
out.write("Case #" + cnt++ + ": " + res + "\n");
googlers.clear();
}
out.close();
in.close();
}
static class Triplet {
private int a, b, c, sum, best;
public Triplet(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
sum = a + b + c;
best = Math.max(a, Math.max(b, c));
}
public boolean isSurprising() {
if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2
|| Math.abs(b - c) == 2)
return true;
return false;
}
public int sum() {
return sum;
}
public String toString() {
return "[" + a + " " + b + " " + c + "]";
}
public int getBest() {
return best;
}
}
}
| 0 | 1,189,336 |
A11759 | A10657 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
class Dancing
{
public static void main(String... args)
{
Scanner sc = new Scanner(System.in);
int tests = sc.nextInt();
for (int test = 1; test <= tests; test++)
{
int n = sc.nextInt();
int s = sc.nextInt();
int p = sc.nextInt();
List<Integer> scores = new ArrayList<Integer>(n);
for (int i = 0; i < n; i++)
{
scores.add(sc.nextInt());
}
int result = solve(n, s, p, scores);
System.out.println("Case #" + test + ": " + result);
}
}
public static int solve(int n, int s, int p, List<Integer> scores)
{
java.util.Collections.sort(scores);
java.util.Collections.reverse(scores);
int result = 0;
for (Integer score : scores)
{
int avg = score / 3;
if (avg >= p)
{
result++;
continue;
}
if (score - (avg * 3) > 0 && avg + 1 >= p)
{
result++;
continue;
}
// need a surprising result
if (score < 2 || score > 28)
{
// suprising results impossible here
continue;
}
if (score - (avg * 3) == 2 && avg + 2 >= p && s > 0)
{
result++;
s--;
continue;
}
if (score - (avg * 3) == 0 && avg + 1 >= p && s > 0)
{
result++;
s--;
continue;
}
}
return result;
}
}
| 0 | 1,189,337 |
A11759 | A10652 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
class Problems
{
public static void main (String [] args) throws Exception
{
BufferedReader f = new BufferedReader(new FileReader("input.java"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.java")));
StringTokenizer st = new StringTokenizer(f.readLine());
int T=Integer.parseInt(st.nextToken());
for(int t=0;t<T;t++) {
st=new StringTokenizer(f.readLine());
int N=Integer.parseInt(st.nextToken());
int S=Integer.parseInt(st.nextToken());
int p=Integer.parseInt(st.nextToken());
int[] scores=new int[N];
for(int i=0;i<N;i++) {
scores[i]=Integer.parseInt(st.nextToken());
}
int res=0;
int minScoreWithSurprise=p+2*(p-2);
int minScoreWithoutSurprise=p+2*(p-1);
for(int i=0;i<N;i++) {
if(scores[i]==0) {
if(p==0) res++;
} else if(scores[i]==1) {
if(p==1||p==2) res++;
}
else if(minScoreWithoutSurprise<=scores[i]) res++;
else if(minScoreWithSurprise<=scores[i]&&S>0) {
res++;
S--;
}
}
out.println("Case #"+(t+1)+": "+res);
}
out.close();
System.exit(0);
}
}
| 0 | 1,189,338 |
A11759 | A10790 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
class JamB
{
public static void main(String args[])throws Exception
{
FileReader fr = new FileReader("B-small-attempt0.in");
BufferedReader br = new BufferedReader(fr);
FileWriter fw= new FileWriter("out.txt");
BufferedWriter bw=new BufferedWriter(fw);
PrintWriter pw= new PrintWriter(bw);
int t=Integer.parseInt(br.readLine());
int n=0,s=0,p=0,ans=0,scount=0;String str="";
for(int i=0;i<t;i++)
{
n=0;s=0;p=0;ans=0;scount=0;
str=br.readLine();
StringTokenizer st=new StringTokenizer(str);
n=Integer.parseInt(st.nextToken());
s=Integer.parseInt(st.nextToken());
p=Integer.parseInt(st.nextToken());
for(int j=0;j<n;j++)
{
int a=Integer.parseInt(st.nextToken());
if(a!=0)
{
if(a>(p-1)*3)ans++;
else if(a>=(p-1)*3-1&&scount<s){scount++;ans++;}
}
else if(p==0)
ans++;
}
pw.println("Case #"+(i+1)+": "+ans);
}
pw.close();
bw.close();
fw.close();
}
} | 0 | 1,189,339 |
A11759 | A10003 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package qualification.b;
import java.util.Scanner;
public class DancingWith {
/**
* OK, I think the algorithm is this:
* for each googler's score:
* -could this have a highest value > N when it's unsurprising? If so, count it.
* If not,
* -- do we have a surprising score left?
* --can we get above N by making it surprising?
* If so, use up a 'surprising' point and make it so.
* you don't have to backtrack. there are at most 100 googlers
* so performance should be easy?
*/
public static void main(final String[] args) {
new DancingWith().start();
}
private void start() {
final Scanner s = new Scanner(System.in);
final int numTests = s.nextInt();
for (int i = 0; i < numTests; i++) {
// deb("Case " + (i + 1) + "---------");
final int numGooglers = s.nextInt(); //<= 100
final int numSurprises = s.nextInt();
final int scoreRequired = s.nextInt();
//output and calculation variables
int surprisesLeft = numSurprises;
int matchesFound = 0;
for (int g = 0; g < numGooglers; g++) { //for each googler
final int score = s.nextInt();
if (highEnough(score, scoreRequired, false)) {
matchesFound++;
} else if (surprisesLeft > 0 && highEnough(score, scoreRequired, true)) {
surprisesLeft--;
matchesFound++;
}
}
System.out.println("Case #" + (i+1) + ": " + matchesFound);
}
}
//we have the sum of three scores, at most 1 apart.
//[todo] There are only 30 possible scores so we could precalc or cache these.
//this code keeps the value of the middle score as low as possible.
private boolean highEnough(final int score, final int scoreRequired, final boolean surprising) {
final int range = surprising ? 2 : 1;
int one = score; //only decreases
int two = 0; //only increases
int three = 0; //only increases
while (one - three > range) {
//three can't increase above two - keep the order.
if (three < two) {
one--;
three++;
} else {
one--;
two++;
}
}
// deb(three + " " + two + " " + one + (one >= scoreRequired ? "*" : "") + (surprising ? " S" : ""));
return (one >= scoreRequired);
}
// private void deb(final String value) {
// System.out.println(value.toString());
// }
}
| 0 | 1,189,340 |
A11759 | A10367 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dancing.gogglers;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import speaking.tongues.WordMap;
/**
*
* @author Raveesh
*/
public class Googlers {
private static int inputSurpriseCount = 0;
private static int inputPointLimit = 0;
private static int inputGooglerCount = 0;
private static int surpriseCount = 0;
private static int outputCount = 0;
private static HashMap playerMap = new HashMap();
private static void printMap() {
Iterator iter = playerMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry e = (Map.Entry) iter.next();
Integer player = (Integer) e.getKey();
List comboList = (ArrayList) e.getValue();
Iterator listIter = comboList.iterator();
System.out.println("Player combo :: " + player);
while (listIter.hasNext()) {
StringBuffer str = (StringBuffer) listIter.next();
System.out.println("Str : " + str.toString());
}
}
}
private static ArrayList getInputList(BufferedReader stdin) throws IOException {
ArrayList stringList = new ArrayList<String>();
String line;
int inputLineCount = 0;
Integer testCaseCount = 0;
while ((line = stdin.readLine()) != null && line.length() != 0 && inputLineCount <= testCaseCount.intValue()) {
// System.out.println("line :: " + line);
if (inputLineCount == 0) {
try {
testCaseCount = Integer.valueOf(line);
} catch (NumberFormatException pe) {
System.out.println("Invalid input for # of test cases");
System.exit(0);
}
inputLineCount++;
continue;
}
stringList.add(line);
inputLineCount++;
if (inputLineCount == testCaseCount + 1) {
break;
}
}
return stringList;
}
public static void main(String[] args) throws FileNotFoundException, IOException {
String filePath = "C:\\Users\\Raveesh\\Downloads\\B-small-attempt1.in";
String filePathOutput = filePath + "_out";
BufferedReader stdin = new BufferedReader(new FileReader(new File(filePath)));
FileWriter fileWriter = new FileWriter(filePathOutput);
ArrayList stringList = Googlers.getInputList(stdin);
inputSurpriseCount = 1;
inputPointLimit = 1;
int count = 1;
Iterator iter = stringList.iterator();
while (iter.hasNext()) {
String inputStr = (String) iter.next();
System.out.println("Str :: " + inputStr);
String[] inputStrArr = inputStr.split("\\ ");
inputGooglerCount = Integer.valueOf(inputStrArr[0]);
inputSurpriseCount = Integer.valueOf(inputStrArr[1]);
inputPointLimit = Integer.valueOf(inputStrArr[2]);
surpriseCount = 0;
outputCount = 0;
playerMap = new HashMap();
System.out.println("c : " + inputGooglerCount + "c : " + inputSurpriseCount
+ "c : " + inputPointLimit);
for (int i = 0; i < inputGooglerCount; i++) {
System.out.println("Doing for :: " + (inputStrArr[i + 3]));
List comboListA = Googlers.getCombibations(Integer.valueOf(inputStrArr[i + 3]));
playerMap.put(i, comboListA);
}
Googlers.printMap();
/** String[] atrArr = new String[inputGooglerCount];
for (int i = 0;i < inputGooglerCount ; i++) {
atrArr[i] = "0";
}
String a= Integer.toBinaryString(000000);
String b= Integer.toBinaryString(000001);
System.out.println("Sum " + Integer.toBinaryString(10+ 1));
int counter = inputGooglerCount-1;
for (int i = 0;i < atrArr.length ; i++) {
String index = atrArr[i];
String str = new String();
for (int j = 0;j < inputGooglerCount ; j++) {
StringBuffer sb = (StringBuffer)
((ArrayList)playerMap.get(j)).get(Integer.parseInt(atrArr[j]));
str = str + sb.toString();
if (j == counter) {
atrArr[counter] = "1";
counter--;
}
}
System.out.println("Str :: " + str);
}
**/
int maxCount = 0;
List li1 = (ArrayList) playerMap.get(0);
for (int i = 0; i < li1.size(); i++) {
StringBuffer str = (StringBuffer) li1.get(i);
String newStr = new String();
List li2 = (ArrayList) playerMap.get(1);
if (inputGooglerCount > 1) {
for (int k = 0; k < li2.size(); k++) {
StringBuffer str1 = (StringBuffer) li2.get(k);
if (inputGooglerCount > 2) {
List li3 = (ArrayList) playerMap.get(2);
for (int m = 0; m < li3.size(); m++) {
StringBuffer str2 = (StringBuffer) li3.get(m);
newStr = str.toString() + "," +str1 + "," + str2;
String[] arr = newStr.split(",");
System.out.println(":: " + newStr);
int sur = 0;
int out = 0;
for ( int p = 0 ; p < arr.length ;p=p+4) {
int a = Integer.parseInt(arr[p]);
int b = Integer.parseInt(arr[p+1]);
int c = Integer.parseInt(arr[p+2]);
if (arr[p+3].equalsIgnoreCase("Y")) {
sur++;
}
if (Googlers.checkLimit(a, b, c)) {
out++;
}
}
if(sur == inputSurpriseCount && maxCount < out) {
maxCount = out;
}
}
} else {
newStr = str.toString() + "," + str1;
String[] arr = newStr.split(",");
System.out.println(":: " + newStr);
int sur = 0;
int out = 0;
for ( int p = 0 ; p < arr.length ;p=p+4) {
int a = Integer.parseInt(arr[p]);
int b = Integer.parseInt(arr[p+1]);
int c = Integer.parseInt(arr[p+2]);
if (arr[p+3].equalsIgnoreCase("Y")) {
sur++;
}
if (Googlers.checkLimit(a, b, c)) {
out++;
}
}
if(sur == inputSurpriseCount && maxCount < out) {
maxCount = out;
}
System.out.println(":: " + newStr);
}
}
}
else {
newStr = str.toString();
String[] arr = newStr.split(",");
System.out.println(":: " + newStr);
int sur = 0;
int out = 0;
for ( int p = 0 ; p < arr.length ;p=p+4) {
int a = Integer.parseInt(arr[p]);
int b = Integer.parseInt(arr[p+1]);
int c = Integer.parseInt(arr[p+2]);
if (arr[p+3].equalsIgnoreCase("Y")) {
sur++;
}
if (Googlers.checkLimit(a, b, c)) {
out++;
}
}
if(sur == inputSurpriseCount && maxCount < out) {
maxCount = out;
}
System.out.println(":: " + newStr);
}
}
outputCount = maxCount;
/*while (iter2.hasNext()) {
Map.Entry e2 = (Map.Entry)iter2.next();
Iterator iter3 = ((ArrayList)e2.getValue()).iterator();
boolean found = false;
boolean mul = false;
int remove = 0;
while (iter3.hasNext()) {
StringBuffer str = (StringBuffer)iter3.next();
String[] strArr = str.toString().split(",");
if(Googlers.checkLimit(Integer.valueOf(strArr[0]), Integer.valueOf(strArr[1])
, Integer.valueOf(strArr[2]))) {
if (mul) {
remove ++;
}
mul = true;
outputCount++;
if (strArr[3].equalsIgnoreCase("Y") && !found) {
surpriseCount++;
found = true;
}
else if (strArr[3].equalsIgnoreCase("Y") && found) {
outputCount--;
}
}
outputCount = outputCount - remove;
}
}
/**HashMap toBeComparedMap = (HashMap) playerMap.clone();
Set toBeCamparedSet = toBeComparedMap.keySet();
while (iter1.hasNext()) {
Map.Entry e = (Map.Entry) iter1.next();
Integer player = (Integer) e.getKey();
toBeCamparedSet.remove(player);
List comboList = (ArrayList) e.getValue();
Iterator listIter = comboList.iterator();
while (listIter.hasNext()) {
StringBuffer str = (StringBuffer) listIter.next();
Iterator comparedIter = toBeCamparedSet.iterator();
while(comparedIter.hasNext()) {
Integer comparedPlayer = (Integer)comparedIter.next();
List comStr = (List)toBeComparedMap.get(comparedPlayer);
Iterator comStrListIter = comStr.iterator();
while(comStrListIter.hasNext()) {
str.append(":");
str.append((StringBuffer)comStrListIter.next());
comStrListIter.remove();
continue;
}
System.out.println("str ::" + str.toString());
}
}
}
**/
String out = "Case #" + count + ": " + outputCount;
fileWriter.write(out);
fileWriter.write("\n");
count++;
}
fileWriter.close();
// Googlers.printMap();
System.out.println("outputCount : " + outputCount);
}
private static boolean checkLimit(int a, int b, int c) {
if (a >= inputPointLimit || b >= inputPointLimit || c >= inputPointLimit) {
// outputCount++;
return true;
}
return false;
}
private static List getCombibations(int num) {
int n = num / 3;
int a;
int b;
int c;
int offset = 0;
List listStr = new ArrayList();
StringBuffer str = null;
if (num % 3 == 0) {
offset = 0;
str = new StringBuffer();
a = b = c = n;
if (a >= 0 && b >= 0 && c >= 0) {
str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N");
listStr.add(str);
}
a = n + 1;
b = n;
c = n - 1;
str = new StringBuffer();
if (a >= 0 && b >= 0 && c >= 0) {
str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N");
listStr.add(str);
}
} else if (num % 3 == 1) {
offset = 1;
a = n;
b = n;
c = n + 1;
str = new StringBuffer();
if (a >= 0 && b >= 0 && c >= 0) {
str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N");
listStr.add(str);
}
a = n - 1;
b = n + 1;
c = n + 1;
str = new StringBuffer();
if (a >= 0 && b >= 0 && c >= 0) {
str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N");
listStr.add(str);
}
} else if (num % 3 == 2) {
offset = 2;
a = n;
b = n + 1;
c = n + 1;
str = new StringBuffer();
if (a >= 0 && b >= 0 && c >= 0) {
str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N");
listStr.add(str);
}
a = n;
b = n;
c = n + 2;
str = new StringBuffer();
if (a >= 0 && b >= 0 && c >= 0) {
str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N");
listStr.add(str);
}
}
return listStr;
}
private static boolean checkSurprise(int a, int b, int c) {
boolean flag = false;
if ((a - b) >= 2 || (b - a) >= 2) {
flag = true;
} else if ((b - c) >= 2 || (c - b) >= 2) {
flag = true;
} else if ((c - a) >= 2 || (a - c) >= 2) {
flag = true;
}
return flag;
}
}
| 0 | 1,189,341 |
A11759 | A11505 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package World2012_01;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Scanner;
public class B {
public static final String in = "/Users/vickcy/Downloads/B-small-attempt1.in.txt";
public static final String out = "outB.txt";
public static void main(String[] args) throws Exception {
Writer writer = new OutputStreamWriter(new FileOutputStream(out));
Scanner sc = new Scanner(new File(in));
int T = sc.nextInt();
for (int i = 1; i <= T; i++) {
int N = sc.nextInt();
int S = sc.nextInt();
int p = sc.nextInt();
int result = 0;
if (p == 0) {
result = N;
while (N-- > 0) sc.nextInt();
} else {
while (N-- > 0) {
int ti = sc.nextInt();
if (ti >= p * 3 - 2) {
++result;
} else if (p == 1) {
result += ti > 0 ? 1 : 0;
} else if (ti >= p * 3 - 4) {
if (S > 0) {
--S;
++result;
}
}
}
}
writer.write("Case #" + i + ": " + result + "\n");
}
writer.close();
}
}
| 0 | 1,189,342 |
A11759 | A11464 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package it.simone.google.code.jam2012;
public interface GoogleCodeExercise {
public String execute(String line);
public void initialize();
}
| 0 | 1,189,343 |
A11759 | A12195 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package test;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.FileWriter;
import java.io.IOException;
import java.math.*;
public class case2 {
public static void main(String[] args){
try {
FileReader is_reader= new FileReader("C:\\Users\\Paul\\Downloads\\B-small-attempt0.in");
BufferedReader reader = new BufferedReader(is_reader);
FileWriter out_writer = new FileWriter("c:\\output.txt");
int T = common.readInt(reader);
int result;
String sResult = "";
for (int i=0;i<T;i++){
int input[] = common.readInt(reader, " ");
int N = input[0];
int S = input[1];
int p = input[2];
int L1 = 3*p-2;
int L2 = Math.max(1, 3*p-4);
result = 0;
for(int j=0;j<N;j++){
if (input[j+3]>=L1)
result++;
else if (input[j+3]<L1&&input[j+3]>=L2&&S>0){
result++;
S--;
}
}
sResult+="Case #" + (i+1)+": "+result+"\n";
}
System.out.print(sResult);
out_writer.write(sResult);
out_writer.flush();
}
catch (Exception e){
}
}
}
| 0 | 1,189,344 |
A11759 | A10254 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
public class DancingGooglers {
private String[] m_testInput;
private String[] m_testOutput;
private int[] m_bestNormal = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
private int[] m_bestSurprising = {0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10};
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("CodeJam #1: Speaking In Tongues!");
DancingGooglers dg = new DancingGooglers();
//actual test cases:
dg.m_testInput = dg.readInputTestCases("./testcases/input2.in");
//length: System.out.println(sit.m_testInputGooglerese.length);
int noOfTestCases = Integer.parseInt(dg.m_testInput[0]);
System.out.println("Number of test cases: " + noOfTestCases);
//for(int i : dg.m_bestNormal)
//System.out.println(dg.m_bestNormal[i]);
System.out.println(dg.m_bestNormal.length);
System.out.println(dg.m_bestSurprising.length);
String outputLine = null;
dg.m_testOutput = new String[noOfTestCases];
for(int i=1; i <= noOfTestCases; i++) {
// translate each single testcase, write to output
//dg.computeMaxResult(i);
outputLine = "Case #" + i + ": " + dg.computeMaxResult(i); // + sit.mapUnknownString(sit.m_testInputGooglerese[i]);
dg.m_testOutput[i-1] = outputLine;
}
for(String s : dg.m_testOutput)
System.out.println(s);
//write to output file
dg.writeOutputTestResults("./testcases/output2.out");
}
public DancingGooglers() {
/* for int(i=1; i < 10; i++) {
m_bestNormal[i] =
}*/
}
public int computeMaxResult(int _testCaseNo) {
int res = 0;
int curNormValue = -1;
int curSurpriseValue = -1;
int curSurprises = 0;
String input = this.m_testInput[_testCaseNo];
System.out.println(input);
String[] inStrings = input.split(" ");
Integer[] integers = new Integer[inStrings.length];
for(int i = 0; i < inStrings.length; i++) {
integers[i] = Integer.valueOf(inStrings[i]);
}
int _noGooglers = integers[0];
int _noSurprising = integers[1];
int _bestResult = integers[2];
//System.out.println(_noGooglers);
for(int i=0; i < _noGooglers; i++) {
curNormValue = m_bestNormal[integers[i+3]];
curSurpriseValue = m_bestSurprising[integers[i+3]];
System.out.println(curNormValue + " " + curSurpriseValue);
System.out.println();
if(curNormValue >= _bestResult)
res++;
else if(curSurprises < _noSurprising) {
if(curSurpriseValue >= _bestResult) {
res++;
curSurprises++;
}
}
}
System.out.println("Result: " + res);
return res;
}
public String[] readInputTestCases(String _filename) {
try {
BufferedReader in = new BufferedReader(new FileReader(_filename));
String line = null;
List<String> lines = new ArrayList<String>();
while ((line = in.readLine()) != null) {
//process(str);
//System.out.println(line);
lines.add(line);
}
in.close();
return lines.toArray(new String[lines.size()]);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public void writeOutputTestResults(String _outputFilename) {
//String[] array = ... // wherever you get this from;
try {
File file = new File(_outputFilename);
PrintWriter out = new PrintWriter(new FileWriter(file));
// Write each string in the array on a separate line
for (String s : this.m_testOutput) {
out.println(s);
}
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| 0 | 1,189,345 |
A11759 | A11109 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Joel
*/
import java.io.*;
import java.util.*;
public class GoogleDance
{
public static void main(String[] args)
{
try
{
FileWriter output = new FileWriter("C:\\Users\\Joel\\Documents\\CSCI 221\\Netbeans Projects\\Google CodeJam\\src\\B-small-attempt1.out");
BufferedWriter out = new BufferedWriter(output);
FileReader reader = new FileReader("C:\\Users\\Joel\\Documents\\CSCI 221\\Netbeans Projects\\Google CodeJam\\src\\B-small-attempt1.in");
BufferedReader in = new BufferedReader(reader);
ArrayList<Integer> scores = new ArrayList<Integer>();
int count = 0;
int t = Integer.parseInt(in.readLine());
for (int i = 0; i < t; i++)
{
StringBuilder nums = new StringBuilder(in.readLine());
int n = Integer.parseInt(nums.substring(0, nums.indexOf(" ")));
nums.delete(0, (nums.indexOf(" ") + 1));
int s = Integer.parseInt(nums.substring(0, nums.indexOf(" ")));
nums.delete(0, (nums.indexOf(" ") + 1));
int p = Integer.parseInt(nums.substring(0, nums.indexOf(" ")));
nums.delete(0, (nums.indexOf(" ") + 1));
for (int j = 0; j < (n - 1); j++)
{
scores.add(Integer.parseInt(nums.substring(0, nums.indexOf(" "))));
nums.delete(0, (nums.indexOf(" ") + 1));
}
scores.add(Integer.parseInt(nums.substring(0)));
Collections.sort(scores);
int next = 0;
if (p == 0)
count = scores.size();
else if (p == 1)
{
for (int k : scores)
if (k != 0)
count++;
}
else
{
while (s > 0 && (next != scores.size()))
{
if (scores.get(next) >= (p + (2 * (p - 2))))
{
count++;
next++;
s--;
}
else
next++;
}
while (next != (scores.size()))
{
if (scores.get(next) >= (p + (2 * (p - 1))) && next != scores.size())
{
count++;
next++;
}
else
next++;
}
}
out.write("Case #" + (i + 1) + ": " + count + "\n");
count = 0;
next = 0;
scores.clear();
}
out.close();
}
catch (IOException e)
{
}
}
}
| 0 | 1,189,346 |
A11759 | A11727 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package t2012.classification;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Scanner;
public class ExB {
public void exec(String filename, String out_filename)
{
try{
FileInputStream fis = new FileInputStream(filename);
Scanner s = new Scanner(fis);
FileWriter output_fstream = new FileWriter(out_filename);
BufferedWriter out = new BufferedWriter(output_fstream);
// The problem
int T = Integer.parseInt(s.nextLine());
for(int testNum = 1; testNum <=T; testNum++)
{
System.out.println(testNum);
String line = s.nextLine();
String[] list = line.split(" ");
int N = Integer.parseInt(list[0]);
int S = Integer.parseInt(list[1]);
int p = Integer.parseInt(list[2]);
int numGood = 0;
int numSurp = 0;
int discarded = 0;
for(int i = 3; i < N+3; i++)
{
int sum = Integer.parseInt(list[i]);
if(sum >= 3*p-2 && sum >=p)
{
numGood++;
}
else if(sum < 3*p-2 && sum >= 3*p-4 && sum >=p)
{
numSurp++;
}
else
{
discarded++;
}
}
int result = numGood + Math.min(numSurp,S);
out.write("Case #"+testNum+": "+result+"\n");
}
// End the problem
out.close();
output_fstream.close();
}catch(Exception e)
{
System.out.println("Some error occurred");
}
}
public static void main(String args[])
{
String PATH= "/home/pau/development/workspace/CodeJam/testfiles/2012/";
ExB a = new ExB();
a.exec(PATH + "B-small-attempt0.in", PATH + "B-small-attempt0.out");
//a.exec(PATH + "B-large-practice.in", PATH + "B-large-practice.out");
}
}
| 0 | 1,189,347 |
A11759 | A12965 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package mgg.utils;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* @author manolo
* @date 13/04/12
*/
public class CombinatoryUtils {
public static List<Integer> findAddingCombination(int total,
List<Integer> listOfNumbers) {
ArrayList<Integer> solution = new ArrayList<Integer>();
for (int i = 0; i < listOfNumbers.size(); i++){
for (int j = 0; j < listOfNumbers.size(); j++){
if( (i != j) &&
(listOfNumbers.get(i) + listOfNumbers.get(j) == total) ){
solution.add(listOfNumbers.get(i));
solution.add(listOfNumbers.get(j));
return solution;
}
}
}
return null;
}
public static List<Integer> findAddingCombinationIndices(int total,
List<Integer> listOfNumbers) {
ArrayList<Integer> solution = new ArrayList<Integer>();
for (int i = 0; i < listOfNumbers.size(); i++){
for (int j = 0; j < listOfNumbers.size(); j++){
if( (i != j) &&
(listOfNumbers.get(i) + listOfNumbers.get(j) == total) ){
solution.add(i);
solution.add(j);
return solution;
}
}
}
return null;
}
public static List<Integer> findAddingCombinationIndicesBase1(int total,
List<Integer> listOfNumbers) {
ArrayList<Integer> solution = new ArrayList<Integer>();
for (int i = 0; i < listOfNumbers.size(); i++){
for (int j = 0; j < listOfNumbers.size(); j++){
if( (i != j) &&
(listOfNumbers.get(i) + listOfNumbers.get(j) == total) ){
solution.add(i+1);
solution.add(j+1);
return solution;
}
}
}
return null;
}
public static List<Triplet> possibleTriplets(int score) {
List<Triplet> listOfTriplets = new ArrayList<Triplet>();
for(Triplet t : allPossibleTriplets){
if(t.sum() == score){
listOfTriplets.add(t);
}
}
return listOfTriplets;
}
private final static List<Triplet> allPossibleTriplets = allPossibleTriplets();
private static List<Triplet> allPossibleTriplets() {
HashSet<Triplet> set = new HashSet<Triplet>();
// int cont = 0;
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10; j++) {
if(Math.abs(i-j) <= 2){
for (int k = 0; k <= 10; k++) {
if((Math.abs(i-k) <= 2) && (Math.abs(j-k) <= 2)){
// cont++;
// System.out.println("(" + i + ", " + j + ", " + k + ")\t\tcont = " + cont);7
set.add(new Triplet(i, j, k));
}
}
}
}
}
return new ArrayList<Triplet>(set);
}
}
| 0 | 1,189,348 |
A11759 | A10201 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class JamInputReader {
int numItem;
String thisLine = null;
BufferedReader in;
StringTokenizer tokenizer;
public JamInputReader(String fileName) {
try {
in = new BufferedReader(new FileReader(fileName));
/* String text = in.readLine();
numItem = Integer.parseInt(text);*/
readNextLine();
tokenizer = new StringTokenizer(thisLine, " ");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
void readNextLine() {
try {
thisLine = in.readLine();
} catch (IOException e) {
e.printStackTrace();
}
}
int getNumItems() {
numItem = Integer.parseInt(tokenizer.nextToken());
return numItem;
}
String getNextItem() {
if(false == tokenizer.hasMoreTokens()) {
readNextLine();
tokenizer = new StringTokenizer(thisLine, " ");
}
return tokenizer.nextToken();
}
String getNextLine() {
readNextLine();
return thisLine;
}
int getNextInt() {
return Integer.parseInt(getNextItem());
}
long getNextLong() {
return Long.parseLong(getNextItem());
}
byte[] getNextLineByte() {
readNextLine();
return thisLine.getBytes();
}
}
| 0 | 1,189,349 |
A11759 | A11021 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package fixjava;
public class StringUtils {
/** Repeat the given string the requested number of times. */
public static String repeat(String str, int numTimes) {
StringBuilder buf = new StringBuilder(Math.max(0, str.length() * numTimes));
for (int i = 0; i < numTimes; i++)
buf.append(str);
return buf.toString();
}
/**
* Pad the left hand side of a field with the given character. Always adds at least one pad character. If the length of str is
* greater than numPlaces-1, then the output string will be longer than numPlaces.
*/
public static String padLeft(String str, char padChar, int numPlaces) {
int bufSize = Math.max(numPlaces, str.length() + 1);
StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
buf.append(padChar);
for (int i = 1, mi = bufSize - str.length(); i < mi; i++)
buf.append(padChar);
buf.append(str);
return buf.toString();
}
/**
* Pad the right hand side of a field with the given character. Always adds at least one pad character. If the length of str is
* greater than numPlaces-1, then the output string will be longer than numPlaces.
*/
public static String padRight(String str, char padChar, int numPlaces) {
int bufSize = Math.max(numPlaces, str.length() + 1);
StringBuilder buf = new StringBuilder(Math.max(numPlaces, str.length() + 1));
buf.append(str);
buf.append(padChar);
while (buf.length() < bufSize)
buf.append(padChar);
return buf.toString();
}
/** Intern all strings in an array, skipping null elements. */
public static String[] intern(String[] arr) {
for (int i = 0; i < arr.length; i++)
arr[i] = arr[i].intern();
return arr;
}
/** Intern a string, ignoring null */
public static String intern(String str) {
return str == null ? null : str.intern();
}
}
| 0 | 1,189,350 |
A11759 | A12276 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.mohit.codejam;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
public class DancingGooglers {
/**
* @param args
*/
public static void main(String[] args) {
try{
int noOfTests = 0;
int noGooglers = 0;
int surprises = 0;
int exp_score = 0;
int total_score = 0;
int without_surprise = 0;
int with_surprise = 0;
int judges_score[] = new int[3];
int some_temp = 0;
FileInputStream fis = new FileInputStream("input.txt");
DataInputStream din = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(din));
FileWriter fstream = new FileWriter("out.txt");
BufferedWriter out = new BufferedWriter(fstream);
String strLine;
strLine = br.readLine();
if(strLine == null || strLine == "")
return;
strLine = strLine.trim();
noOfTests = Integer.parseInt(strLine);
int testNumber = 1;
while(noOfTests>0)
{
String output = "";
strLine = br.readLine();
if(strLine == null || strLine == "" || strLine == "\n" )
break;
strLine = strLine.trim().toLowerCase();
String[] records= strLine.split(" ");
noGooglers = Integer.parseInt(records[0]);
surprises = Integer.parseInt(records[1]);
exp_score = Integer.parseInt(records[2]);
without_surprise = 0;
with_surprise = 0;
// loop to get the various scores and store it in array
for (int i = 0; i < noGooglers; i++)
{
//logic to find score such that difference between them is not more than 1
total_score = Integer.parseInt(records[2 + i + 1]);
judges_score[0] = total_score / 3;
judges_score[1] = (total_score - judges_score[0]) / 2;
judges_score[2] = total_score - judges_score[0] - judges_score[1];
// sort the judges score
for (int k = 0;k<3;k++)
{
for (int l = k+1; l<3;l++)
{
if (judges_score [k] > judges_score [l])
{
some_temp = judges_score [k];
judges_score [k] = judges_score [l];
judges_score [l] = some_temp;
}
}
}
if (judges_score [2] >= exp_score)
without_surprise ++;
else if (judges_score [2] == (exp_score-1) && (total_score - judges_score [2] > 0) && (judges_score[1] == judges_score[2]))
with_surprise ++;
}
if (with_surprise > surprises)
with_surprise = surprises;
out.write("Case #" + testNumber + ": " + (without_surprise + with_surprise) + "\n");
testNumber ++;
}
br.close();
out.close();
}
catch(IOException e)
{
System.out.print(e.getMessage());
}
finally
{
}
}
}
| 0 | 1,189,351 |
A11759 | A12808 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.lang.Integer.*;
import static java.lang.Character.*;
public class B {
Scanner scan;
InputStream in;
int intLine(){
return parseInt(scan.nextLine());
}
long solve(){
long res=0;
int n = scan.nextInt();
int s = scan.nextInt();
int p = scan.nextInt();
int[]A = new int[n];
for(int i=0;i<n;i++)A[i]=scan.nextInt();
sort(A);
for(int i=n-1;i>=0;i--){
int x = (A[i]+2)/3;
if(x>=p)res++;
else {
x = (A[i]+4)/3;
if(x>=p && s>0 && A[i]>0){
res++;s--;
}
}
}
return res;
}
void solveAll(){
int N = parseInt(scan.nextLine());
for(int i=0;i<N;i++){
long r =solve();
System.out.format("Case #%d: %d\n",i+1,r);
}
}
B() throws Exception{
String cn = B.class.getName();
String sampleName = cn+"-sample.in";
String smallName = cn+"-small-attempt0.in";
String largeName = cn+"-large.in";
InputStream in = new BufferedInputStream(new FileInputStream(smallName));
scan = new Scanner(in);
}
public static void main(String[] args) throws Exception{
Locale.setDefault(Locale.US);
new B().solveAll();
}
}
| 0 | 1,189,352 |
A11759 | A11960 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
import java.lang.*;
public class Googlers {
private BufferedReader br;
private int numCases;
public Googlers(String input){
try{
FileInputStream fstream = new FileInputStream(input);
DataInputStream in = new DataInputStream(fstream);
br = new BufferedReader(new InputStreamReader(in));
numCases = Integer.parseInt(br.readLine());
for(int i=0;i<numCases;i++){
System.out.print("Case #"+(i+1)+": ");
this.Calculate(br.readLine());
}
in.close();
}
catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public void Calculate(String c){
StringTokenizer st = new StringTokenizer(c);
int numDancers = Integer.parseInt(st.nextToken());
int numSurprising = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
int[][]scores= new int[numDancers][3];
int[]totals = new int[numDancers];
int[]rem= new int[numDancers];
for(int i=0;i<numDancers;i++)totals[i]=Integer.parseInt(st.nextToken());
for(int i=0;i<numDancers;i++){
int avg=totals[i]/3;
rem[i]=totals[i]-(avg*3);
for(int j=0;j<3;j++)scores[i][j]=avg;
}
for(int i=0;i<numDancers;i++){
if(rem[i]>0 && totals[i]<30){
int temp=rem[i];
if(temp==2){
if(numSurprising >0){
if(scores[i][0]+2<=10 && scores[i][0]+2>=p){
scores[i][0]=scores[i][0]+2;
numSurprising--;
}
else{
scores[i][0]=scores[i][0]+1;
scores[i][1]=scores[i][1]+1;
}
}
else{
scores[i][0]=scores[i][0]+1;
scores[i][1]=scores[i][1]+1;
}
rem[i]=-1;
}
else if(temp==1){
scores[i][0]=scores[i][0]+1;
rem[i]=-1;
}
}
}
if(numSurprising >0){
for(int i=0;i<numDancers;i++){
if(rem[i]==0 && (scores[i][0]+1)>=p){
scores[i][0]=scores[i][0]+1;
scores[i][1]=scores[i][1]-1;
numSurprising--;
rem[i]=-1;
if(numSurprising==0)break;
}
}
}
if(numSurprising >0){
for(int i=0;i<numDancers;i++){
if(rem[i]==0){
scores[i][0]=scores[i][0]+1;
scores[i][1]=scores[i][1]-1;
numSurprising--;
if(numSurprising==0)break;
}
}
}
int count=0;
for (int i=0;i<numDancers;i++){
for(int j=0;j<3;j++){
if(scores[i][j]>=p){
count++;
break;
}
}
}
System.out.println(count);
}
public static void main(String[] args) {
Googlers g= new Googlers("input.txt");
}
}
| 0 | 1,189,353 |
A11759 | A12142 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package gcj.qualifier;
/**
* @(#)ProbB.java
*
*
* @author
* @version 1.00 2011/5/9
*/
import java.io.*;
import java.math.*;
import java.lang.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Integer.*;
public class ProbB
{
public FileReader fr;
public BufferedReader br;
public ProbB(String file, String output)
{
if (output!=null)
setOut(output);
try
{
fr=new FileReader(file);
br=new BufferedReader(fr);
int caseNo=parseInt(br.readLine());
//out.println(caseNo);
for (int i=0; i<caseNo; i++)
{
String caseAnswer=runCase();
out.println("Case #"+ (i+1) + ": " +caseAnswer);
}
}
catch (IOException e)
{
}
}
public void setOut(String output)
{
try
{
System.setOut(new PrintStream(output));
}
catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
public String runCase() throws IOException
{
String ss=br.readLine();
StringTokenizer st=new StringTokenizer(ss);
int t=Integer.parseInt(st.nextToken());
int s=Integer.parseInt(st.nextToken());
int p=Integer.parseInt(st.nextToken());
int [] tt=new int[t];
int test=4;
if (p>2)
test=(p-2)*3;
// out.println();
// out.println(test);
int num=0;
//double test=((double)p-((double)2/3));
int div; int mod;
for (int i=0; i<t; i++)
{
tt[i]=Integer.parseInt(st.nextToken());
div=tt[i]/3;mod=tt[i]%3;
if (tt[i]>=p)
{
if (div>=p-2)
{
if (div>=p || (div==(p-1)&&(mod==2||mod==1)))
{
num++;
}
else if (s>0)
{
if ((div==(p-2)&&mod==2)||(div==(p-1)&&mod==0))
{
s--;
// out.print("*");
num++;
}
}
else continue;
/*
out.print(tt[i]);
out.print(" : ");
out.print(tt[i]/3);
out.print(" : ");
out.print(tt[i]%3);
out.print(" : ");
out.println();
*/
}
}
// out.println(p+":::"+tt[i]+":"+tt[i]/3+":"+tt[i]%p);
//out.println(tt[i]);
}
//out.println(num);
return new Integer(num).toString();
}
public static void main(String [] args)
{
ProbB gjct=new ProbB("C:/JavaPgms/workspace/codejam/2012/in/qualifier/B-small-attempt3.in", "C:/JavaPgms/workspace/codejam/2012/out/qualifier/B.out");
}
} | 0 | 1,189,354 |
A11759 | A12090 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class DancingWiththeGooglers
{
public static void main(String[] args) throws IOException {
FileWriter wr=new FileWriter("Output.txt");
BufferedWriter buff=new BufferedWriter(wr);
FileReader read=new FileReader("B-small-attempt2.in");
BufferedReader buffr=new BufferedReader(read);
String str;
str=buffr.readLine();
int n=Integer.parseInt(str);
int j=1;
Scanner sc;
int googleres,s,p;
int list[];
int i;
int num;
int total=0;
while(j<=n)
{
int non[]={0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10};
int sup[]={-1,-1,-1,2,3,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,10,10,10,-1,-1,-1};
total=0;
str=buffr.readLine();
sc=new Scanner(str);
sc.useDelimiter(" ");
googleres=sc.nextInt();
s=sc.nextInt();
p=sc.nextInt();
i=1;
list=new int[googleres];
while(i<=googleres)
{
list[i-1]=sc.nextInt();
i++;
}
if(s==0)
{
for(int k=1;k<=googleres;k++)
{
num=list[k-1];
if(non[num]>=p)
++total;
}
}
else
{
for(int k=1;k<=googleres;k++)
{
if(s!=0)
{
num=list[k-1];
if(non[num]>=p)
++total;
else
{
if(sup[num]>=p)
{
--s;
++total;
}
}
}
else
{
num=list[k-1];
if(non[num]>=p)
++total;
}
}
}
StringBuffer temp = new StringBuffer("Case #"+j+": ");
temp=temp.append(Integer.toString(total));
buff.write(temp.toString());
buff.newLine();
j++;
}
buff.close();
}
}
| 0 | 1,189,355 |
A11759 | A12210 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
public class codejam2
{
public static void main(String args[]) throws FileNotFoundException, IOException
{
String address="g:\\cj2.txt";
BufferedReader br = new BufferedReader(new FileReader(address));
int test_case=Integer.parseInt(br.readLine());
int iindex,jindex,N,S,p;
int ul,ll;
int select;
String str,temp[];
for(iindex=0;iindex<test_case;iindex++)
{
select=0;
str=br.readLine();
temp=str.split(" ");
N=Integer.parseInt(temp[0]);
S=Integer.parseInt(temp[1]);
p=Integer.parseInt(temp[2]);
ul=(p*3)-2;
ll=ul-2;
for(jindex=3;jindex<N+3;jindex++)
{
if(Integer.parseInt(temp[jindex])==0)
continue;
if(Integer.parseInt(temp[jindex])>=ul)
select++;
else if(Integer.parseInt(temp[jindex])>=ll)
{
if(S>0)
{
S--;
select++;
}
}
}
System.out.print("Case #"+(iindex+1)+": ");
System.out.println(select);
}
}
}
| 0 | 1,189,356 |
A11759 | A10331 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package sample;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class SampleMain {
public static void main(String[] args) throws Exception {
String linesFile = //args[0];
"lines.txt";
String[] lines = getLines(linesFile);
for (int i = 0; i < lines.length; i++) {
if (i != 0) {
System.out.println("Case #" + i + ": " + getOutput(lines[i]));
}
}
}
public static String[] getLines(String pathName) throws Exception {
List<String> lines = new ArrayList<String>();
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(pathName)), "UTF-8"));
String line;
while ((line = br.readLine()) != null) {
lines.add(line);
}
br.close();
return (String[]) lines.toArray(new String[0]);
}
public static int getOutput(String line) throws Exception {
String[] value = line.split(" ");
int n = Integer.valueOf(value[0]);
int s = Integer.valueOf(value[1]);
int p = Integer.valueOf(value[2]);
int countS = 0;
int countP = 0;
for (int i = 0; i < n; i++) {
int t = Integer.valueOf(value[i + 3]);
int x = t / 3;
int y = t % 3;
switch (y) {
case 0:
if (x >= p) {
countP++;
} else if (x + 1 >= p) {
if (x != 0 && countS < s) {
countS++;
countP++;
}
}
break;
case 1:
if (x + 1 >= p) {
countP++;
}
break;
case 2:
if (x + 1 >= p) {
countP++;
} else if (x + 2 >= p) {
if (countS < s) {
countS++;
countP++;
}
}
break;
default:
break;
}
}
return countP;
}
}
| 0 | 1,189,357 |
A11759 | A12173 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package hk.polyu.cslhu.codejam.solution.impl.qualificationround;
import java.util.ArrayList;
import java.util.List;
import hk.polyu.cslhu.codejam.solution.Solution;
public class DancingWithTheGooglers extends Solution {
private int N, S, p;
private List<Integer> totalPointList;
@Override
public void setProblem(List<String> problemDesc) {
// TODO Auto-generated method stub
String[] splitArray = problemDesc.get(0).split(" ");
this.N = Integer.valueOf(splitArray[0]);
this.S = Integer.valueOf(splitArray[1]);
this.p = Integer.valueOf(splitArray[2]);
this.totalPointList = new ArrayList<Integer>();
for (int i = 3; i < splitArray.length; i++) {
this.totalPointList.add(Integer.valueOf(splitArray[i]));
}
if (this.totalPointList.size() != this.N)
logger.error("Found an error for " + problemDesc.get(0));
}
@Override
public void solve() {
// TODO Auto-generated method stub
int minNotSupSum = this.p * 3 - 2;
int minSupSum = this.p > 1 ? (this.p * 3 - 4) : 1;
int totalNotSup = 0;
int totalSup = 0;
for (Integer point : this.totalPointList) {
if (point >= minNotSupSum)
totalNotSup++;
else if (point >= minSupSum)
totalSup++;
}
if (totalSup + totalNotSup < this.S)
logger.error("Found an error for suprising cases");
this.result = String.valueOf(totalNotSup + Math.min(totalSup, this.S));
}
}
| 0 | 1,189,358 |
A11759 | A12522 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class Main implements Runnable {
BufferedReader reader;
StringTokenizer tokenizer;
PrintStream writer;
Main() {
reader = new BufferedReader(new InputStreamReader(System.in));
tokenizer = new StringTokenizer("");
writer = new PrintStream(new BufferedOutputStream(System.out));
}
public void run() {
try {
int testCount = nextInt();
for (int test = 1; test <= testCount; ++ test) {
int n = nextInt();
int m = nextInt();
int p = nextInt();
boolean v[][][] = new boolean[31][2][2];
for (int a = 0; a <= 10; ++ a) {
for (int b = a; b <= 10; ++ b) {
for (int c = 0; c <= 10; ++ c) {
if (c - a <= 2) {
v[a + b + c][c - a >= 2? 1: 0][c >= p? 1: 0] = true;
}
}
}
}
int dp[] = new int[m + 1];
for (int j = 1; j <= m; ++ j) {
dp[j] = Integer.MIN_VALUE;
}
for (int i = 0; i < n; ++ i) {
int ti = nextInt();
int dp2[] = new int[m + 1];
for (int j = 0; j <= m; ++ j) {
dp2[j] = Integer.MIN_VALUE;
for (int x = 0; x < 2; ++ x) {
for (int y = 0; y < 2; ++ y) {
if (v[ti][x][y] && j >= x) {
dp2[j] = Math.max(dp2[j], dp[j - x] + y);
}
}
}
}
dp = dp2;
}
System.out.printf("Case #%d: %d\n", test, dp[m]);
}
} catch (Exception e) {
}
}
String nextToken() throws IOException {
while (!tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public static void main(String args[]) {
new Thread(new Main()).run();
}
}
| 0 | 1,189,359 |
A11759 | A11524 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package codejam.is;
/**
* Created with IntelliJ IDEA.
* User: ofer
* Date: 4/13/12
* Time: 8:49 PM
* To change this template use File | Settings | File Templates.
*/
public abstract class TestAbstract implements Test {
private final static String newline = System.getProperty("line.separator");
@Override
public String getOutput(int testNum) {
return "Case #" + testNum + ": " + getTestResult() + newline;
}
protected abstract String getTestResult();
}
| 0 | 1,189,360 |
A11759 | A12723 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} |
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Chamika
*/
public class GDance {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int cases = s.nextInt();
for(int i = 0;i < cases;i++){
int x = s.nextInt();
int y = s.nextInt();
int z = s.nextInt();
int res = 0;
for(int j = 0;j < x;j++){
int a = s.nextInt();
int X = a/3;
int Y = a%3;
if (X >= z){
res++;
}else if (Y >= 1 && X != 0 && X + 1 >= z){
res++;
}else if( y != 0 && Y == 2 && X + Y >= z){
y--;
res++;
}else if (y != 0 && X != 0 && Y == 0 && X + 1 >= z){
y--;
res++;
}
}
System.out.println("Case #" + (i + 1) + ": " + res);
}
}
}
| 0 | 1,189,361 |
A11759 | A10463 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Dancer {
public static void main(String args[]) throws FileNotFoundException{
Scanner in=new Scanner(new FileInputStream("input2.txt"));
int T=in.nextInt();
System.out.println("T : " + T);
int N,P,S,temp;
int clear=0,surprise=0;
for(int i=1;i<=T;i++)
{
clear=0;
surprise=0;
N=in.nextInt();
S=in.nextInt();
P=in.nextInt();
//System.out.println("N : " + N);
//System.out.println("S : " + S);
//System.out.println("P : " + P);
if(P==0)
{
for(int j=1;j<=N;j++)
{
temp=in.nextInt();
clear++;
}
}
else if(P==1)
{
for(int j=1;j<=N;j++)
{
temp=in.nextInt();
if(temp>=P)
clear++;
}
}
else{
for(int j=1;j<=N;j++)
{
temp=in.nextInt();
if(temp>3*P-3)
clear++;
else if((temp==3*P-3)||(temp==3*P-4))
surprise++;
}
//System.out.println("clear: " + clear);
//System.out.println("surprise : " + surprise);
}
System.out.println("Case #" + i + ": " + (clear+Math.min(surprise,S)));
}
}
}
| 0 | 1,189,362 |
A11759 | A10430 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package MyAllgoritmicLib;
public class SimpleNumbers {
public static boolean[] masInt;
public static void initSimpleInt(int n) { // âõîäíûå äàííûå
masInt = new boolean[n + 1];
for(int i=0; i<=n;i++){
masInt[i] = true;
}
masInt[0] = masInt[1] = false; // åñëè êòî-òî áóäåò èñïîëüçîâàòü ýòè
// çíà÷åíèÿ
for (int i = 2; i <= n; ++i) {
if (masInt[i]) {
for (int j = i + i; j < n; j += i) {
masInt[j] = false;
}
}
}
}
public static void main(String[] args) {
initSimpleInt(1000000);
int col = 0;
int max = 0;
for (int i = 0; i < 1000000; i++) {
if (masInt[i]) {
col++;
max = i;
}
}
System.out.println(max);
System.out.println(col);
}
}
| 0 | 1,189,363 |
A11759 | A11938 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package dancingWithGooglers;
import java.util.ArrayList;
public class MainClass
{
public static void main(String[] z)throws Exception
{
String string ="";
ArrayList<String> list = new InputFile().readFile();
int caseNumber =1;
ArrayList<String> output = new ArrayList<String>();
for(int i=0 ;i<list.size();i++)
{
System.out.println(list.get(i));
string = "Case #" + caseNumber + ": " + new BestResult().result(list.get(i));
//string = "Case #" + caseNumber + ": " + new BestResult().result("3 0 0 12 13 0");
output.add(string);
caseNumber++;
System.out.println(string );
}
new OutputFile().writeFile(output);
}
} | 0 | 1,189,364 |
A11759 | A10632 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.awt.Container;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.JTextArea;
public class Dancing extends JFrame
{
private final int WIDTH = 800;
private final int HEIGHT = 400;
private Container pane;
private String[] unformatted;
private String[] formatted;
private char[][] formattedCharArray;
private int[] numberOfDancers;
private int[] numberOfSurprises;
private int[] theScoreToBeat;
private int[][] theScores;
private boolean[][] wasNatural;
private int[] numberOfNaturalWinners;
private int[] numberOfSurprisingWinners;
private int[] numberOfWinners;
private int numberOfLines;
private int[] naturals = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10};
private int[] surprises = {0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10};
private JTextArea input, output;
private Scanner scanner;
private PrintWriter out;
public Dancing() throws IOException
{
pane = new Container();
pane = getContentPane();
scanner = new Scanner(new File("c:/users/Christopher/Desktop/input.in"));
out = new PrintWriter(new FileWriter("c:/users/Christopher/Desktop/output.out"));
numberOfLines = Integer.parseInt(scanner.nextLine());
unformatted = new String[numberOfLines];
formatted = new String[numberOfLines];
numberOfDancers = new int[numberOfLines];
numberOfSurprises = new int[numberOfLines];
theScoreToBeat = new int[numberOfLines];
numberOfNaturalWinners = new int[numberOfLines];
numberOfSurprisingWinners = new int[numberOfLines];
numberOfWinners = new int[numberOfLines];
input = new JTextArea(100, numberOfLines);
input.setSize(300,200);
input.setLocation (10, 10);
output = new JTextArea(120, numberOfLines);
output.setSize(300,200);
output.setLocation(410, 10);
pane.setLayout(null);
pane.add(input);
pane.add(output);
theScores = new int[numberOfLines][];
wasNatural = new boolean[numberOfLines][];
for (int i = 0; i < numberOfLines; i++)
{
numberOfDancers[i] = scanner.nextInt();
numberOfSurprises[i] = scanner.nextInt();
theScoreToBeat[i] = scanner.nextInt();
input.append(numberOfDancers[i] + " " + numberOfSurprises[i] + " " + theScoreToBeat[i] + " ");
theScores[i] = new int[numberOfDancers[i]];
wasNatural[i] = new boolean[numberOfDancers[i]];
for (int j = 0; j < numberOfDancers[i]; j++)
{
theScores[i][j] = scanner.nextInt();
if (j < numberOfDancers[i] - 1)
input.append(theScores[i][j] + " ");
else
input.append(theScores[i][j] + "\n");
}
}
for (int i = 0; i < numberOfLines; i++)
{
numberOfWinners[i] = findWinners(i);
output.append("Case #" + (i + 1) + ": " + numberOfWinners[i] + "\n");
out.println("Case #" + (i + 1) + ": " + numberOfWinners[i] + "\n");
}
/* for (int i = 0; i < numberOfLines; i++)
{
formatted[i] = new String(formattedCharArray[i]);
formatted[i] = "Case #" + (i + 1) + ": " + formatted[i];
output.append(formatted[i] + "\n");
out.println(formatted[i]);
}
*/
scanner.close();
out.close();
setVisible(true);
setSize(WIDTH, HEIGHT);
setTitle("Tongues");
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String args[]) throws IOException
{
Dancing awesome = new Dancing();
}
int findWinners(int whichLine)
{
numberOfSurprisingWinners[whichLine] = 0;
for (int i = 0; i < numberOfDancers[whichLine]; i++)
{
if (naturals[theScores[whichLine][i]] >= theScoreToBeat[whichLine])
{
numberOfNaturalWinners[whichLine]++;
wasNatural[whichLine][i] = true;
}
}
for (int i = 0; i < numberOfDancers[whichLine]; i++)
{
if (surprises[theScores[whichLine][i]] >= theScoreToBeat[whichLine] && wasNatural[whichLine][i] == false)
{
numberOfSurprisingWinners[whichLine]++;
}
}
if (numberOfSurprisingWinners[whichLine] > numberOfSurprises[whichLine])
{
numberOfSurprisingWinners[whichLine] = numberOfSurprises[whichLine];
}
return numberOfNaturalWinners[whichLine] + numberOfSurprisingWinners[whichLine];
}
} | 0 | 1,189,365 |
A11759 | A13018 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.google.codejam.googlers;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
/**
*
* Class to generate Test Report.
* @author Sushant Deshpande
*/
public class OutputRecorder {
/**
* Method for generating Test Report.
* @param testCases List<TestCase> list of test cases for report is to be generated.
* @param outputFile String output file for writing TestReport.
*/
public static void generateTestReport(final List<TestCase> testCases, final String outputFile) {
BufferedWriter writer = null;
try {
writer = new BufferedWriter(new PrintWriter(outputFile));
for(TestCase testCase : testCases) {
writer.write(testCase.printTestResult());
writer.flush();
}
writer.flush();
} catch(IOException ie) {
System.out.println("Some error occured while generating test report " + ie.getMessage());
System.out.println("Printing result to standard output");
for(TestCase testCase : testCases) {
System.out.println(testCase.printTestResult());
}
} finally {
if(writer != null) {
try {
writer.close();
} catch(IOException ie) {
System.out.println("Some error occured while closing output stream");
}
}
}
}
} | 0 | 1,189,366 |
A11759 | A12668 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class Surp {
/**
* @param args
*/
public static void main(String[] args) {
int T,S,p,N=0;
String L="";
Scanner b = new Scanner(System.in);
T=b.nextInt();
L=b.nextLine();
for(int i=0;i<T;i++){
L=b.nextLine();
String F[]=L.split(" ");
N=0;
S=Integer.parseInt(F[1]);
p=Integer.parseInt(F[2]);
int min=p+2*(p-2);
if(min<=1){
min=p;
}
for(int j=3;j<F.length;j++){
int val=Integer.parseInt(F[j]);
if(min<=val){
if(min+1<val||min==0)
N++;
else
if(S>0){
S--;
N++;
}
}
}
System.out.println("Case #"+(i+1)+": "+N);
}
}
}
| 0 | 1,189,367 |
A11759 | A12829 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package google.codejam;
public class DanceGoogler implements GoogleSolver {
@Override
public String solve(String str) {
String[] input = str.split(" ");
int dancerNumber = Integer.parseInt(input[0]);
int surprisingCount = Integer.parseInt(input[1]);
int bestResult = Integer.parseInt(input[2]);
int surpriseingScore = (bestResult*3-4)>0?(bestResult*3-4):0;
int minScore = bestResult*3-2>0?((bestResult*3-2)):0;
//int[] scores = new int[dancerNumber];
int bestCount = 0;
for(int i=0; i<dancerNumber ; i++){
int scores = Integer.parseInt(input[i+3]);
//System.out.print(scores[i]+",");
if(scores<bestResult){
continue;
}
if(scores>=minScore){
bestCount++;
continue;
}
if(scores>=surpriseingScore && surprisingCount>0){
bestCount++;
surprisingCount--;
continue;
}
}
return bestCount+"";
}
}
| 0 | 1,189,368 |
A11759 | A13031 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.Scanner;
/**
* Created by IntelliJ IDEA.
* User: Veniversum
* Date: 4/15/12
* Time: 1:37 AM
*/
public class Q2 {
public static void main(String[] args) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("in.txt")));
int cases = Integer.parseInt(br.readLine());
int out[] = new int[cases];
for (int i = 0; i < cases; i++) {
Scanner sc = new Scanner(br.readLine());
int contestants = sc.nextInt();
int surprise = sc.nextInt();
int min = sc.nextInt();
int max = 0;
for (int j =0; j<contestants; j++){
int score = sc.nextInt();
if (score-min < 2*(min-1)){
//not more than min
if (surprise > 0 && score >= (3*min-4) && score != 0){
//use surprise
surprise--;
max++;
}
} else {
max++;
}
}
out[i] = max;
}
PrintWriter outp = new PrintWriter(new FileOutputStream("out.txt"));
for (int i = 0; i<cases; i++){
System.out.print("Case #" + (i+1) + ": " + out[i] + "\n");
outp.print("Case #" + (i+1) + ": " + out[i] + "\n");
}
outp.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| 0 | 1,189,369 |
A11759 | A13057 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Dan {
static Scanner sc;
public static void main(String[] args) throws FileNotFoundException {
sc=new Scanner(new File("input.txt"));
int num_of_cases=sc.nextInt();
int num_of_googlers;
int num_of_surp_tup;
int max_best_eval;
int []scores;
for (int i = 1; i <= num_of_cases; i++) {
num_of_googlers=sc.nextInt();
num_of_surp_tup=sc.nextInt();
max_best_eval=sc.nextInt();
scores=new int[num_of_googlers];
for (int k = 0; k < scores.length; k++) {
scores[k]=sc.nextInt();
}
compute(scores,num_of_googlers,num_of_surp_tup,max_best_eval,i);
}
}
static void compute(int[] scores, int num_of_googlers,
int num_of_surp_tup, int max_best_eval, int case_num) {
int winners=0;
for (int i = 0; i < scores.length; i++) {
if((scores[i] >= max_best_eval*3-2)){//&&(max_best_eval*3-2 >0)){
winners++;
}
else if(num_of_surp_tup>0){
if((scores[i] >= max_best_eval*3-4)&&(max_best_eval!=1)){//(scores[i] > 0)){
num_of_surp_tup--;
winners++;
}
}
}
System.out.println("Case #"+case_num+": "+winners);
}
}
| 0 | 1,189,370 |
A11759 | A12932 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package google.loader;
public interface Challenge {
String getResult();
}
| 0 | 1,189,371 |
A11759 | A10457 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Solution {
/**
* @param args
* @throws Exception
*/
public static void doMain() throws Exception {
Scanner sc = new Scanner(new FileReader("input.txt"));
PrintWriter pw = new PrintWriter(new FileWriter("output.txt"));
int caseCnt = sc.nextInt();
sc.nextLine();
for (int caseNum = 0; caseNum < caseCnt; caseNum++) {
pw.print("Case #" + (caseNum + 1) + ": ");
//# googlers
int n = sc.nextInt();
//# surprising
int s = sc.nextInt();
//min score
int p = sc.nextInt();
ArrayList<Integer> scores = new ArrayList<Integer>();
int res = 0;
for (int i = 0; i<n; i++) {
scores.add(sc.nextInt());
}
int minNumberP = (p-2);
if (minNumberP < 0) {
minNumberP = 0;
}
int minNumberNormal = p-1;
if (minNumberNormal < 0) {
minNumberNormal = 0;
}
int minSurprisingNumber = minNumberP*2+p;
int minNumber = minNumberNormal*2+p;
int sUsed = 0;
for (int score : scores) {
if (score>=minNumber) {
res++;
} else if (score>=minSurprisingNumber && sUsed < s) {
res++;
sUsed++;
}
}
pw.println(res);
// System.out.println(n+" "+s+" "+p+" ");
// for (int score : scores) {
// if (score>=minNumber) {
// res++;
// }
// }
// System.out.println("min score: "+minNumber);
}
pw.flush();
pw.close();
sc.close();
}
public static void main(String[] args) throws Exception {
// System.out.println((int)'a');
new Solution().doMain();
}
}
| 0 | 1,189,372 |
A11759 | A10473 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package google2012;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Scanner;
public class Main2 {
static boolean[][] unsurprising = new boolean[11][31];
static boolean[][] surprising = new boolean[11][31];
public static void main(String[] args) throws FileNotFoundException {
for (int i = 0; i <= 10; i++) {
for (int j = 0; j <= 10; j++) {
int t = Math.max(i, j);
for (int k = 0; k <= 10; k++) {
int max = Math.max(t, k);
if (unsurp(i, j, k) || surp(i, j, k)) {
//System.out.println((i+j+k)+": "+i + ", " + j + ", " + k + ": " + unsurp(i, j, k) + ": " + surp(i, j, k));
}
for (int p = 0; p <= max; p++) {
unsurprising[p][i + j + k] |= unsurp(i, j, k);
surprising[p][i + j + k] |= surp(i, j, k);
}
}
}
}
Scanner sc = new Scanner(new File("B-small-attempt0.in"));
PrintStream print = new PrintStream(new File("out2.txt"));
int input = sc.nextInt();
for (int i = 0; i < input; i++) {
int out = check(sc);
String t = "Case #" + (i + 1) + ": " + out;
print.println(t);
System.out.println(t);
}
}
private static int check(Scanner sc) {
int N = sc.nextInt();
int S = sc.nextInt();
int p = sc.nextInt();
int maxPossible = 0;
//System.out.println("Test");
for (int i = 0; i < N; i++) {
int test = sc.nextInt();
//System.out.println(test + ", " + unsurprising[p][test] + ", " + surprising[p][test]);
if (unsurprising[p][test]) {
maxPossible++;
} else if (S > 0 && surprising[p][test]) {
S--;
maxPossible++;
}
}
return maxPossible;
}
static boolean unsurp(int i, int j, int k) {
return unsurp(i, j) && unsurp(i, k) && unsurp(j, k);
}
static boolean unsurp(int i, int j) {
return Math.abs(i - j) < 2;
}
static boolean surp(int i, int j, int k) {
return !unsurp(i, j, k) && surp(i, j) && surp(i, k) && surp(j, k);
}
static boolean surp(int i, int j) {
return Math.abs(i - j) <= 2;
}
}
| 0 | 1,189,373 |
A11759 | A12068 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class Q2 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int ncases = Integer.parseInt(in.nextLine());
for(int q = 1; q <= ncases; q++) {
System.out.print("Case #" + q + ": ");
int n = in.nextInt();
int s = in.nextInt();
int p = in.nextInt();
int total = 0;
for(int i = 0; i < n; i++) {
int t = in.nextInt();
int noSurprise = (int) Math.ceil((double) t / 3);
if(noSurprise >= p) {
total++;
continue;
}
if(s > 0 && (t != 0) && (t < 28) && (t % 3 == 0 || t % 3 == 2)) {
if(noSurprise + 1 >= p) {
total++;
s--;
continue;
}
}
}
System.out.println(total);
}
}
}
| 0 | 1,189,374 |
A11759 | A13239 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
public class DancingWithGooglers {
public int numberOfGooglers;
public int exptectedSurprisingScores;
public int realSurprisingScores = 0;
public int bestScore;
public int googlersBetterThanBestScore = 0;
public static void main(String[] args) throws NumberFormatException,
IOException {
File file = new File("C:\\Users\\xebia\\Downloads\\B-small-attempt0.in");
FileInputStream fis = new FileInputStream(file);
DataInputStream in = new DataInputStream(fis);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
int numberOfTestCases = new Integer(br.readLine());
for (int k = 0; k < numberOfTestCases; k++) {
DancingWithGooglers da = new DancingWithGooglers();
String[] strings = br.readLine().split(" ");
da.numberOfGooglers = new Integer(strings[0]);
da.exptectedSurprisingScores = new Integer(strings[1]);
da.bestScore = new Integer(strings[2]);
for (int i = 0; i < da.numberOfGooglers; i++) {
Googlers googler = new Googlers();
int totalScore = new Integer(strings[3 + i]);
googler.setTotalScore(totalScore);
da.calculateOptimizedTriplet(googler);
}
// if (da.realSurprisingScores < da.exptectedSurprisingScores) {
// da.googlersBetterThanBestScore = da.googlersBetterThanBestScore
// - (da.exptectedSurprisingScores - da.realSurprisingScores);
// }
System.out.println("Case #" + (k+1) + ": " + da.googlersBetterThanBestScore);
}
}
public void calculateOptimizedTriplet(Googlers googler) {
if (googler.getTotalScore() >= ((3 * bestScore) - 2)) {
googlersBetterThanBestScore++;
} else if (googler.getTotalScore() == (3 * (bestScore) - 3)
|| googler.getTotalScore() == (3 * (bestScore) - 4)) {
if(googler.getTotalScore() == 0 || googler.getTotalScore() == 1){
}else if (realSurprisingScores < exptectedSurprisingScores) {
realSurprisingScores++;
googlersBetterThanBestScore++;
}
}
}
}
class Googlers {
private int firstScore;
private int secondScore;
private int thirdScore;
private int totalScore;
private boolean surprisingScore = false;
private boolean invalidScore = false;
public Googlers() {
// TODO Auto-generated constructor stub
}
public Googlers(int firstScore, int secondScore, int thirdScore) {
this.firstScore = firstScore;
this.secondScore = secondScore;
this.thirdScore = thirdScore;
}
public void setFirstScore(int firstScore) {
this.firstScore = firstScore;
}
public int getFirstScore() {
return firstScore;
}
public void setSecondScore(int secondScore) {
this.secondScore = secondScore;
}
public int getSecondScore() {
return secondScore;
}
public void setThirdScore(int thirdScore) {
this.thirdScore = thirdScore;
}
public int getThirdScore() {
return thirdScore;
}
public int getHighestScore() {
int highestScore = firstScore;
if (secondScore > highestScore) {
highestScore = secondScore;
}
if (thirdScore > highestScore) {
highestScore = thirdScore;
}
return highestScore;
}
public int getSmallestScore() {
int smallestScore = firstScore;
if (secondScore < smallestScore) {
smallestScore = secondScore;
}
if (thirdScore < smallestScore) {
smallestScore = thirdScore;
}
return smallestScore;
}
public void setSurprisingScore(boolean surprisingScore) {
this.surprisingScore = surprisingScore;
}
public boolean isSurprisingScore() {
return surprisingScore;
}
public void setTotalScore(int totalScore) {
this.totalScore = totalScore;
}
public int getTotalScore() {
return totalScore;
}
public void setInvalidScore(boolean invalidScore) {
this.invalidScore = invalidScore;
}
public boolean isInvalidScore() {
return invalidScore;
}
}
| 0 | 1,189,375 |
A11759 | A11041 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package fixjava;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map.Entry;
import java.util.Set;
/**
* Simple multimap class. <code>
MultiMap<String, String> map = MultiMapKeyToList.make();
map.put("a", "x");
map.put("a", "x");
map.put("a", "y");
map.put("b", "z");
System.out.println(Join.joinRecursive(map.entrySet(), ", ", "[", "]"));
</code>
*
* @author luke
*/
public class MultiMapKeyToList<S, T> {
HashMap<S, ArrayList<T>> map = new HashMap<S, ArrayList<T>>();
public static <K, V> MultiMapKeyToList<K, V> make() {
return new MultiMapKeyToList<K, V>();
}
public void put(S key, T value) {
ArrayList<T> list = map.get(key);
if (list == null) {
list = new ArrayList<T>();
map.put(key, list);
}
list.add(value);
}
public ArrayList<T> get(S key) {
return map.get(key);
}
public boolean containsKey(S key) {
return map.containsKey(key);
}
public int sizeKeys() {
return map.size();
}
public HashSet<T> valuesUnion() {
HashSet<T> result = new HashSet<>();
for (Entry<S, ArrayList<T>> ent : map.entrySet())
for (T val : ent.getValue())
result.add(val);
return result;
}
public Set<Entry<S, ArrayList<T>>> entrySet() {
return map.entrySet();
}
public HashMap<S, ArrayList<T>> getRawMap() {
return map;
}
public ArrayList<Pair<S, ArrayList<T>>> getRawMapAsList() {
ArrayList<Pair<S, ArrayList<T>>> result = new ArrayList<Pair<S, ArrayList<T>>>();
for (Entry<S, ArrayList<T>> ent : map.entrySet())
result.add(Pair.make(ent.getKey(), ent.getValue()));
return result;
}
public void putAll(S key, Iterable<T> values) {
boolean putSomething = false;
for (T val : values) {
put(key, val);
putSomething = true;
}
if (!putSomething && !map.containsKey(key))
// If putting an empty collection, need to create an empty set at the key
map.put(key, new ArrayList<T>());
}
public void putAll(S key, T[] values) {
if (values.length == 0 && !map.containsKey(key))
// If putting an empty collection, need to create an empty set at the key
map.put(key, new ArrayList<T>());
else
for (T val : values)
put(key, val);
}
/** Invert the mapping */
public MultiMapKeyToList<T, S> invert() {
MultiMapKeyToList<T, S> inv = new MultiMapKeyToList<T, S>();
for (Entry<S, ArrayList<T>> ent : map.entrySet()) {
S s = ent.getKey();
for (T t : ent.getValue())
inv.put(t, s);
}
return inv;
}
public ArrayList<Pair<S, ArrayList<T>>> toList() {
ArrayList<Pair<S, ArrayList<T>>> result = new ArrayList<Pair<S, ArrayList<T>>>();
for (Entry<S, ArrayList<T>> ent : map.entrySet())
result.add(Pair.make(ent.getKey(), ent.getValue()));
return result;
}
/** Write out to a TSV file */
public void writeOutToFile(String tsvFile) throws IOException {
PrintWriter writer = new PrintWriter(tsvFile);
for (Entry<S, ArrayList<T>> ent : map.entrySet()) {
S key = ent.getKey();
StringBuilder buf = new StringBuilder();
buf.append(key);
for (T val : ent.getValue())
buf.append("\t" + val);
writer.println(buf.toString());
}
writer.close();
}
/** Read in a String->String map from a TSV file */
public static MultiMapKeyToList<String, String> readFromFile(String tsvFile) throws IOException {
MultiMapKeyToList<String, String> map = new MultiMapKeyToList<String, String>();
for (String line : new FileLineIterator(tsvFile)) {
String[] parts = Split.split(line, "\t");
String key = parts[0];
for (int i = 1; i < parts.length; i++)
map.put(key, parts[i]);
}
return map;
}
}
| 0 | 1,189,376 |
A11759 | A11001 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication1;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
/**
*
* @author kutub
*/
public class dwg {
public boolean valid(int score1,int score2,int score3,int total)
{
if(score1>=0 && score2>=0 && score3>=0 && score1+score2+score3==total)
{
return true;
}
else
return false;
}
public boolean same(int s1,int s2,int s3)
{
if(s1==s2 && s2==s3)
{
return true;
}
else
return false;
}
public boolean surprising(int score1,int score2,int score3)
{
if(Math.abs(score1-score2)==2 || Math.abs(score2-score3)==2 || Math.abs(score3-score1)==2)
{
return true;
}
else
return false;
}
public int possibilities(int [] total,int b,int sur)
{
int best=0,sc=0,score1=0,score2=0,score3=0;
for(int i=0;i<total.length;i++)
{
if(total[i]%3!=0)
{
score1=Math.round(total[i]/3);
score2=Math.round(total[i]/3)+1;
score3=Math.round(total[i]/3);
if(valid(score1, score2, score3, total[i]))
{
if(score1>=b || score2>=b || score3>=b)
{
best++;
}
else
{
if(sc<sur)
{
score1++;
score3--;
if(valid(score1, score2, score3, total[i]))
{
if(score1>=b || score2>=b || score3>=b)
{
best++;
}
else
{
sc--;
}
if(surprising(score1, score2, score3))
{
sc++;
}
}
}
}
}
else
{
score1=Math.round(total[i]/3);
score2=Math.round(total[i]/3)+1;
score3=Math.round(total[i]/3)+1;
if(valid(score1, score2, score3, total[i]))
{
if(score1>=b || score2>=b || score3>=b)
{
best++;
}
else
{
if(sc<sur)
{
score2++;
score3--;
if(valid(score1, score2, score3, total[i]))
{
if(score1>=b || score2>=b || score3>=b)
{
best++;
}
else
{
sc--;
}
if(surprising(score1, score2, score3))
{
sc++;
}
}
}
}
}
}
}
else
{
score1=Math.round(total[i]/3);
score2=Math.round(total[i]/3);
score3=Math.round(total[i]/3);
if(valid(score1, score2, score3, total[i]))
{
if(score1>=b || score2>=b || score3>=b)
{
best++;
}
else
{
if(sc<sur)
{
score2++;
score3--;
if(valid(score1, score2, score3, total[i]))
{
if(score1>=b || score2>=b || score3>=b)
{
best++;
}
else
{
sc--;
}
if(surprising(score1, score2, score3))
{
sc++;
}
}
}
}
}
}
}
return best;
}
public static void main(String args[]) throws FileNotFoundException
{
File f=new File("C:/Users/kutub/Documents/NetBeansProjects/JavaApplication1/src/javaapplication1/input1.txt");
Scanner s=new Scanner(f);
int n=0,noofg=0,sur=0,b=0,best=0,sc=0;
int score[];
while(s.hasNext())
{
n=s.nextInt();
for(int j=1;j<=n;j++)
{
s.nextLine();
noofg=s.nextInt();
score=new int[noofg];
sur=s.nextInt();
b=s.nextInt();
for(int i=0;i<noofg;i++)
{
score[i]=s.nextInt();
}
dwg d=new dwg();
best=d.possibilities(score, b, sur);
System.out.print("Case #"+j+": ");
System.out.println(best);
}
}
}
}
| 0 | 1,189,377 |
A11759 | A12495 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args) throws Exception
{
PrintWriter writer = new PrintWriter(new FileWriter("output.txt"));
BufferedReader input = new BufferedReader(new FileReader("B-small-attempt0.in"));
int size=Integer.parseInt(input.readLine());
for(int i=0; i<size; i++)
{
String testCase = input.readLine();
String tokens[] = testCase.split(" ");
int N = Integer.parseInt(tokens[0]);
int S = Integer.parseInt(tokens[1]);
int p = Integer.parseInt(tokens[2]);
int count=0;
for(int j=3; j<N+3; j++)
{
int testNum = Integer.parseInt(tokens[j]);
if((testNum - p) >= 2*(p-1) && (testNum-p)>=0)
{
count++;
}
else if((testNum - p) < 2*(p-1) && (testNum-p)>=0)
{
if(S!=0 && (testNum - p) >= 2*(p-2) )
{
count++;
S--;
}
}
}
writer.println("Case #"+(i+1)+": "+count);
}
writer.close();
input.close();
}
}
| 0 | 1,189,378 |
A11759 | A11662 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileNotFoundException;
import java.util.Formatter;
import java.util.Scanner;
public final class DancingWithTheGooglers {
private static String solve(final int N, int S, final int p, int points[]) {
int res = 0;
for (int t:points) {
switch (t%3) {
case 0:
if (t/3>=p) res++;
else if (t >= 3 && t<30 && t>=3 && t/3+1>=p && S>0) { res++; S--; }
break;
case 1:
if (t/3+1>=p) res++;
break;
case 2:
if (t/3+1>=p) res++;
else if (t<29 && t/3+2>=p && S>0) { res++; S--; }
break;
}
}
return ""+res;
}
public static void main(String[] args) throws FileNotFoundException {
//String filename = "B-test.in";
String filename = "B-small-attempt0.in";
assert filename.endsWith(".in");
Scanner in = new Scanner(new File(filename));
Formatter out = new Formatter(new File(filename.replace(".in", ".out")));
assert in.hasNext();
int T = in.nextInt();
in.nextLine();
for (int t = 0; t < T; t++) {
int N = in.nextInt();
int S = in.nextInt();
int p = in.nextInt();
int points[] = new int[N];
for (int i = 0; i < N; i++)
points[i] = in.nextInt();
String ans = solve(N, S, p, points);
String result;
if (t < T - 1)
result = String.format("Case #%d: %s%n", t + 1, ans);
else
result = String.format("Case #%d: %s", t + 1, ans);
out.format(result);
System.out.format(result);
}
out.flush();
out.close();
}
}
| 0 | 1,189,379 |
A11759 | A10893 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package utils;
/**
*
* @author Fabien Renaud
*/
public abstract class JamCase implements Runnable, JamCaseSolver {
protected final int number;
protected String result;
private final StopWatch timer;
private final Jam parent;
protected JamCase(Jam parent, int number) {
this.parent = parent;
this.number = number;
this.timer = new StopWatch();
}
public final int getNumber() {
return number;
}
public final String getResult() {
return result;
}
public final StopWatch getTimer() {
return timer;
}
@Override
public final void run() {
timer.start();
parse();
solve();
if (parent != null) {
parent.appendOutput(number, result);
}
timer.stop();
}
} | 0 | 1,189,380 |
A11759 | A11477 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package problem.b.dancing.with.the.googlers;
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
/**
*
* @author Park
*/
public class ProblemBDancingWithTheGooglers {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
PrintStream out = new PrintStream(new File("/Users/Park/Desktop/output.txt"));
Scanner in = new Scanner(new File("/Users/Park/Desktop/B-small-attempt0.in"));
int testCase = Integer.parseInt(in.next());
for (int n = 0; n < testCase; n++) {
int count = 0;
int googlers = Integer.parseInt(in.next());
int surprising = Integer.parseInt(in.next());
int wantScores = Integer.parseInt(in.next());
for (int g = 0; g < googlers; g++) {
int scores = Integer.parseInt(in.next());
if (scores - (wantScores * 3) >= -2) {
count++;
} else if ((surprising > 0) && (((scores - (wantScores * 3) == -4)&&scores>=2) || ((scores - (wantScores * 3) == -3)&&scores>=3))) {
surprising--;
count++;
}
}
out.println("Case #" + (n + 1) + ": " + count);
System.out.println("Case #" + (n + 1) + ": " + count);
}
in.close();
out.close();
}
}
| 0 | 1,189,381 |
A11759 | A10767 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
class Factory implements TestCaseFactory {
@Override
public TestCase getInstance(int number) {
return new DancingWithGooglers(number);
}
}
public class DancingWithGooglers extends TestCase {
int caseItem;
int ngooglers;
int[] scores;
int surprising;
int target;
int max;
public DancingWithGooglers(int caseItem) {
this.caseItem = caseItem;
}
@Override
public void readInput(BufferedReader in) throws IOException,
MalformedInputFileException {
final String str1 = in.readLine();
final String[] tokens = str1.split("\\s");
ngooglers = Integer.parseInt(tokens[0]);
surprising = Integer.parseInt(tokens[1]);
target = Integer.parseInt(tokens[2]);
scores = new int[ngooglers];
for (int i = 0; i < ngooglers; i++) {
scores[i] = Integer.parseInt(tokens[i + 3]);
}
}
private int guaranteedMax(int googler) {
if (scores[googler] == 0) {
return 0;
} else {
return (scores[googler] - 1) / 3 + 1;
}
}
private int higherScores(int googler) {
if (scores[googler] == 3) {
return 0;
} else {
return (scores[googler] - 1) % 3 + 1;
}
}
@Override
public void solve() {
int guaranteed = 0;
int marginal = 0;
for (int googler = 0; googler < ngooglers; googler++) {
final int guaranteedMax = guaranteedMax(googler);
if (guaranteedMax >= target) {
guaranteed++;
} else if (guaranteedMax == target - 1
&& higherScores(googler) >= 2 && scores[googler] > 0) {
marginal++;
}
}
max = guaranteed + Math.min(marginal, surprising);
}
@Override
public void writeOutput(PrintWriter out) {
out.print("Case #" + (caseItem + 1) + ": ");
out.print(max);
out.print("\n");
}
public static void main(String[] args) throws IOException,
MalformedInputFileException {
new Processor().process(new Factory(), args[0], args[1]);
}
} | 0 | 1,189,382 |
A11759 | A10897 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.Vector;
public class Main {
public static int problemC(Vector<Integer> V,int N,int S,int P)
{
int Nbr=0;
for(int i=0;i<N;i++)
{
if((3*P-2)<=V.elementAt(i))
Nbr++;
else if((3*P-4)<=V.elementAt(i)&&0<S&&0<=(3*P-4))
{
Nbr++;
S--;
}
}
return Nbr;
}
public static void main(String[] args) throws FileNotFoundException {
Scanner in =new Scanner(new File("B-small.in"));
PrintWriter out=new PrintWriter("B-small.out");
int T,N,S,P;
T=in.nextInt();
for(int i=0;i<T;i++)
{
N=in.nextInt();
S=in.nextInt();
P=in.nextInt();
Vector<Integer> V = new Vector<Integer>();
for(int j=0;j<N;j++)
V.add(in.nextInt());
out.print("Case #"+(i+1)+": ");
out.print(problemC(V,N,S,P));
if(i+1!=T) out.println("");
}
out.close();
in.close();
}
} | 0 | 1,189,383 |
A11759 | A12441 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package org.mlai.google.codejam;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class DancingWithTheGooglers {
private static void processLine(String line, int lineNumber) {
if (lineNumber == 1) {
return;
}
String outputLine = "";
String[] lineArray = line.split(" ");
outputLine = "Case #" + String.valueOf(lineNumber - 1) + ": ";
int numberOfGooglers = 0;
int numberOfSurprisingTripletScores = 0;
int maximumBestResultOfAtLeast = 0;
int totalOfBestScorers = 0;
numberOfGooglers = Integer.valueOf(lineArray[0]);
numberOfSurprisingTripletScores = Integer.valueOf(lineArray[1]);
maximumBestResultOfAtLeast = Integer.valueOf(lineArray[2]);
ArrayList<Scores> myScores = new ArrayList<Scores>();
for (int i = 3; i < lineArray.length; i++) {
Scores myScore = new Scores();
myScore.total = Integer.valueOf(lineArray[i]);
int defaultScore = (myScore.total / 3); //already rounded down
myScore.setDefaultScore(defaultScore);
myScore.scoreToEqual = maximumBestResultOfAtLeast;
if (!myScore.correct()) {
myScore.score1Added = true;
myScore.score1++;
}
if (!myScore.correct()) {
myScore.score2Added = true;
myScore.score2++;
}
if (!myScore.correct()) {
System.out.println("Should not ever happen");
outputLine += "Should not ever happen";
}
myScores.add(myScore);
}
for (int i = myScores.size() - 1; i >= 0; i--) {
if (myScores.get(i).bestScore()) {
totalOfBestScorers++;
myScores.remove(i);
}
}
for (int i = 0; i < myScores.size(); i++) {
// if (((myScores.get(i).score2 > 0) && (myScores.get(i).score2Added) && (myScores.get(i).score1Added)) || ((myScores.get(i).score2 > 0) && (!myScores.get(i).score1Added) && (!myScores.get(i).score2Added))) {
// myScores.get(i).score1++;
// myScores.get(i).score2--;
// }
if ((myScores.get(i).score2 > 0) && (myScores.get(i).score2Added) && (myScores.get(i).score1Added)) {
myScores.get(i).score1++;
myScores.get(i).score2--;
} else if ((myScores.get(i).score1 > 0) && (myScores.get(i).score2 > 0) && (!myScores.get(i).score1Added) && (!myScores.get(i).score2Added)) {
myScores.get(i).score1++;
myScores.get(i).score2--;
}
}
for (int i = myScores.size() - 1; i >= 0; i--) {
if (myScores.get(i).bestScore()) {
if (numberOfSurprisingTripletScores <= 0) {
break;
}
totalOfBestScorers++;
myScores.remove(i);
numberOfSurprisingTripletScores--;
}
}
outputLine += String.valueOf(totalOfBestScorers);
writeFile(outputLine);
}
private static class Scores {
int total = 0;
int score1 = 0;
int score2 = 0;
int score3 = 0;
int scoreToEqual = 0;
boolean score2Added = false;
boolean score1Added = false;
public int getTotal() {
return score1 + score2 + score3;
}
public boolean correct() {
if (getTotal() == total) {
return true;
} else {
return false;
}
}
public void setDefaultScore (int defaultScore) {
score1 = defaultScore;
score2 = defaultScore;
score3 = defaultScore;
}
public boolean bestScore() {
if ((score1 >= scoreToEqual) || (score2 >= scoreToEqual) || (score3 >= scoreToEqual)) {
return true;
} else {
return false;
}
}
}
public static void main(String[] args) {
try{
FileInputStream fstream = new FileInputStream("input.txt");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
int lineNumber = 0;
while ((strLine = br.readLine()) != null) {
lineNumber++;
processLine(strLine, lineNumber);
}
in.close();
}catch (Exception e){
System.err.println("Error Main: " + e.getMessage());
e.printStackTrace();
}
}
private static void writeFile(String line) {
try{
System.out.println(line);
FileWriter fstream = new FileWriter("out.txt",true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(line + "\n");
out.close();
}catch (Exception e){
System.err.println("Error writeFile: " + e.getMessage());
}
}
}
| 0 | 1,189,384 |
A11759 | A11966 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author DEV
*/
import java.util.*;
import java.io.*;
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
try{
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
// BufferedReader bf = new BufferedReader(new FileReader("input.in"));
int t = Integer.parseInt(bf.readLine());
for(int i=0;i<t;i++){
String si = bf.readLine();
System.out.print("Case #"+(i+1)+": ");
String[] a = si.split(" ");
int n = Integer.parseInt(a[0]);
int s = Integer.parseInt(a[1]);
int p = Integer.parseInt(a[2]);
int out=0;
for(int m=3;m<a.length;m++)
{
int num = Integer.parseInt(a[m]);
int rem = num%3;
int div = num/3;
if(div==0){if(p==0)out++; continue;}
if(rem==0)
{
if((div)>=p)
{ out++;}
else
{
if((div+1)>=p&&s>0&&(div+1)<=10)
{
out++; s--;
}
}
}
else if(rem==2)
{
if((div+1)>=p)
{ out++;}
else
{
if((div+2)>=p&&s>0&&(div+2)<=10)
{
out++; s--;
}
}
}
else
{
if((div+rem)>=p)
out++;
}
}
System.out.println(out);
}
}
catch(Exception ex)
{
System.out.println(ex);
}
}
}
| 0 | 1,189,385 |
A11759 | A12881 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
public class q2 {
public static void main(String args[]){
new q2().run();
}
Scanner input = new Scanner(System.in);
void run(){
int N = input.nextInt();
for(int i=1;i<=N;i++){
System.out.print("Case #"+i+": ");
solve();
}
}
void solve(){
int i,j,k;
int T = input.nextInt();
int s = input.nextInt();
int p = input.nextInt();
int x,m,ans = 0;
double y;
Integer [] a = new Integer [T];
boolean [] used = new boolean[T];
for(i=0;i<T;i++)
a[i] = input.nextInt();
for(i=0;i<T;i++){
x = a[i]/3;
if(a[i]%3==0){
if(x >= p)ans++;
else if(s > 0 && x > 0 && x + 1 >= p){
ans++;
s--;
}
}
else if(a[i]%3==1){
if(x>=p || x+1>=p)
ans++;
else if (s > 0 && x + 1 >= p){
ans++;
s--;
}
}
else if(a[i]%3==2){
if(x+1 >= p || x>= p)
ans++;
else if(s>0 && x+2 >= p){
ans++;
s--;
}
}
}
System.out.println(ans);
}
}
| 0 | 1,189,386 |
A11759 | A10780 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class Dance {
private static final String inFile = "B-small-attempt0.in";
private static final String outFile = "output.txt";
private static final int CONTESTANTS = 0;
private static final int SURPRISES = 1;
private static final int WINNERS = 2;
private static final int POINTS_START = 3;
public static void main(String[] args) throws IOException {
/* * * Initialization -- START * * */
BufferedReader iStream = new BufferedReader(new FileReader(inFile));
BufferedWriter oStream = new BufferedWriter(new FileWriter(outFile));
int contestants = 0;
int surprises = 0;
int threshold = 0;
int total = 0;
int winners = 0;
List<Scores> scores = null;
String[] elements = null;
/* * * Initialization -- END * * */
total = new Integer(iStream.readLine());
for(int i = 0; i < total; i++) {
String line = iStream.readLine();
scores = new ArrayList<Scores>();
winners = 0;
elements = line.split(" ");
// Grab over-head data
contestants = new Integer( elements[CONTESTANTS] );
surprises = new Integer( elements[SURPRISES] );
threshold = new Integer( elements[WINNERS] );
// Allocate the scores
for(int j = 0; j < contestants; j++) {
int value = new Integer( elements[POINTS_START+j] );
scores.add( new Scores(value) );
}
// Order from highest total to lowest
Collections.sort(scores, Collections.reverseOrder());
// Tally the contestants that are above the threshold
for(int k = 0; k < scores.size(); k++) {
if(scores.get(k).getHighest() >= threshold)
winners += 1;
else if(surprises > 0){ //Skew if available
scores.get(k).skew();
if(scores.get(k).getHighest() >= threshold)
winners += 1;
surprises -= 1;
}
}
oStream.write("Case #" + (i+1) + ": " + winners);
oStream.newLine();
}
iStream.close();
oStream.close();
}
}
| 0 | 1,189,387 |
A11759 | A12215 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public class DancingWithGoogler {
private static FileReader freader;
private static BufferedReader buffreader;
private static FileWriter fwriter;
private static BufferedWriter buffwriter;
public static void main(String[] args) throws IOException {
freader = new FileReader("B-small-attempt0.in");
buffreader = new BufferedReader(freader);
fwriter= new FileWriter("result.txt");
buffwriter = new BufferedWriter(fwriter);
String str = null;
int linenum = 0;
int i=1;
while((str=buffreader.readLine())!=null){
if(i==1)
linenum=Integer.parseInt(str);
else{
int arrSize = Integer.parseInt(str.split(" ")[0]);
int num = Integer.parseInt(str.split(" ")[1]);
int p = Integer.parseInt(str.split(" ")[2]);
int[] scores = new int[arrSize];
for(int j=0; j<arrSize; j++){
scores[j]= Integer.parseInt(str.split(" ")[j+3]);
}
int count = getMostNum(p,num,scores);
String finalStr = "Case #"+Integer.toString(i-1)+": "+Integer.toString(count)+"\n";
buffwriter.write(finalStr);
}
i++;
}
/*int num = 1;
int p = 1;
int[] scores = {8, 0};*/
//System.out.println(getMostNum(p,num,scores));
buffwriter.close();
fwriter.close();
buffreader.close();
freader.close();
}
public static int getMostNum(int p, int num, int[] scores){
if(p==0)
return scores.length;
else if(p==1){
int val1 = 1;
int count = 0;
for(int i=0; i<scores.length; i++){
if(scores[i]>=val1){
count++;
}
}
//System.out.println(num);
return count;
}
else{
int count=0;
int val1 = 3*p-2;
int val2 = 3*p-4;
for(int i=0; i<scores.length; i++){
if(scores[i]>=val1){
count++;
}
else if(scores[i]<val1 && scores[i]>=val2){
if(num>0){
count++;
num--;
}
}
}
return count;
}
}
}
| 0 | 1,189,388 |
A11759 | A12114 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
import java.math.*;
public class B {
public static void main(String[] args) throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("B-small-attempt1.in"));
BufferedReader br = new BufferedReader(new InputStreamReader(bis));
PrintWriter out = new PrintWriter("B-small-attempt1.out");
int cases = Integer.parseInt(br.readLine().trim());
StringTokenizer st;
for (int c = 1; c <= cases; c++) {
st = new StringTokenizer(br.readLine());
int N = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
int res = 0;
for (int i = 0; i < N; i++) {
int curr = Integer.parseInt(st.nextToken());
int currBest = curr/3+Math.min(curr%3, 1);
int curSurBest = curr/3+Math.max(1, curr%3);
if(curr == 0)
res += p>0?0:1;
else if(currBest >= p)
res++;
else if(s > 0 && curSurBest >= p) {
res++;
s--;
}
}
out.println("Case #" + c + ": " + res);
}
out.close();
}
} | 0 | 1,189,389 |
A11759 | A12448 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package GoogleCodeJam;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
public class DancingWithGooglers {
static List<String> fullList = new ArrayList<String>();
public static void main(String[] args) {
String pathIn = "D://B-small-attempt0.in";
String pathOut = "D://B-small-attempt0.out";
String line;
try {
BufferedReader input = new BufferedReader(new InputStreamReader(new FileInputStream(pathIn)));
while( (line = input.readLine()) !=null) {
fullList.add(line);
}
BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(pathOut)));
// int cases = Integer.parseInt(fullList.get(0));
for (int i = 1; i < fullList.size(); i++) {
String[] tmpStringArray = fullList.get(i).split(" ");
int[] tmpIntArray = new int[tmpStringArray.length];
for(int j = 0; j < tmpIntArray.length; j++) {
tmpIntArray[j] = Integer.parseInt(tmpStringArray[j]);
}
// int player = tmpIntArray[0];
int suprisings = tmpIntArray[1];
int best = tmpIntArray[2];
int checks = 0;
for (int j = 3; j < tmpIntArray.length; j++) {
if (tmpIntArray[j] >= (best * 3) - 2) {
checks++;
} else if (tmpIntArray[j] >= (best * 3) - 4 && suprisings > 0 && (best * 3) - 4 > 0) {
checks++;
suprisings -= 1;
}
}
output.write("Case #" + i + ": " + checks + "\n");
}
output.close();
} catch (FileNotFoundException e1) {
System.err.println("File not found: ");
} catch (IOException e2) {
e2.printStackTrace();
}
}
}
| 0 | 1,189,390 |
A11759 | A10553 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author ZAMAN
*/
import java.io.*;
public class test {
public static void main(String args[]) {
try {
BufferedReader a = new BufferedReader(new FileReader("B-small-attempt2.in"));
BufferedWriter b = new BufferedWriter(new FileWriter("B-small-attempt2.out"));
int Case = Integer.parseInt(a.readLine());
for (int i = 1; i <= Case; i++) {
String line[] = a.readLine().split(" ");
int c[] = new int[line.length];
b.append("Case #" + i + ": ");
for (int j = 0; j <= line.length - 1; j++) {
c[j] = Integer.parseInt(line[j]);
}
int contestants = c[0];
int suprise = c[1];
int margin = c[2];
int best = 0;
if (suprise == 0) {
for (int j = 0; j < contestants; j++) {
if (c[j + 3] % 3 == 0) {
if (c[j + 3] / 3 >= margin) {
best++;
}
} else if (c[j + 3] % 3 == 1 || c[j + 3] % 3 == 2) {
if (((c[j + 3] / 3) + 1) >= margin) {
best++;
}
}
}
} else {
for (int j = 0, k = suprise; j < contestants; j++) {
int remain = c[j + 3] % 3;
int dv = c[j + 3] / 3;
if (remain == 0) {
if (dv >= margin) {
best++;
} else if (k > 0 && (dv + 1) >= margin && (dv + 1) <= c[j + 3]) {
best++;
k--;
}
} else if (remain == 1) {
if (((dv) + 1) >= margin && (dv + 1) <= c[j + 3]) {
best++;
}
} else if (remain == 2) {
if (((dv) + 1) >= margin && (dv + 1) <= c[j + 3]) {
best++;
} else if (k > 0 && (dv + 2) >= margin && (dv + 1) <= c[j + 3]) {
best++;
k--;
}
}
}
}
b.append("" + best);
b.newLine();
}
b.flush();
a.close();
b.close();
} catch (Exception e) {
e.printStackTrace();
}
}
} | 0 | 1,189,391 |
A11759 | A12902 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package qual2012;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Kattio extends PrintWriter {
public Kattio(InputStream i) {
super(new BufferedOutputStream(System.out));
r = new BufferedReader(new InputStreamReader(i));
}
public Kattio(InputStream i, OutputStream o) {
super(new BufferedOutputStream(o));
r = new BufferedReader(new InputStreamReader(i));
}
public boolean hasMoreTokens() {
return peekToken() != null;
}
public int getInt() {
return Integer.parseInt(nextToken());
}
public double getDouble() {
return Double.parseDouble(nextToken());
}
public long getLong() {
return Long.parseLong(nextToken());
}
public String getWord() {
return nextToken();
}
private BufferedReader r;
private String line;
private StringTokenizer st;
private String token;
private String peekToken() {
if (token == null)
try {
while (st == null || !st.hasMoreTokens()) {
line = r.readLine();
if (line == null) return null;
st = new StringTokenizer(line);
}
token = st.nextToken();
} catch (IOException e) {
}
return token;
}
private String nextToken() {
String ans = peekToken();
token = null;
return ans;
}
} | 0 | 1,189,392 |
A11759 | A13177 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class DancingWithTheGooglers {
public static void main (String[] args) throws IOException {
Scanner in = new Scanner(new File("B-small.txt"));
int cases;
cases = in.nextInt();
int google, s, p;
int count;
int temp;
for (int n = 0; n < cases; n++) {
google = in.nextInt();
s = in.nextInt();
p = in.nextInt();
count = 0;
for (int i = 0; i < google; i++) {
temp = in.nextInt();
if (p == 0) {
count ++;
} else if (p == 1 && temp == 0) {
continue;
} else if (temp/3 >= p) {
count ++;
} else if (temp/3 == p - 1 && temp%3 >= 1) {
count ++;
} else if (temp/3 == p - 1 && temp%3 == 0){
if (s != 0) {
count ++;
s--;
}
} else if (temp/3 == p - 2 && temp%3 == 2) {
if (s != 0) {
count ++;
s--;
}
}
}
System.out.println("Case #" + (n+1) + ": " + count);
}
}
} | 0 | 1,189,393 |
A11759 | A11332 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class DancingWithTheGooglers
{
static int surprise, target;
static int [] scores;
static int numGooglers;
static int [][] matrix;
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(new File("b_small.in"));
int numCases = scan.nextInt();
for (int z = 1; z <= numCases; z++)
{
numGooglers = scan.nextInt();
surprise = scan.nextInt();
target = scan.nextInt();
scores = new int[numGooglers];
for (int i = 0; i < numGooglers; i++)
scores[i] = scan.nextInt();
matrix = new int[numGooglers][surprise+1];
for (int [] arr : matrix)
Arrays.fill(arr, -1);
int max = magic(0, surprise);
System.out.println("Case #"+z+": " + max);
}
}
static int magic(int pos, int surpriseLeft)
{
if (surpriseLeft < 0)
return -1000000;
if (pos == numGooglers)
{
if (surpriseLeft != 0)
return -1000000;
else
return 0;
}
if (matrix[pos][surpriseLeft] >= 0)
return matrix[pos][surpriseLeft];
int best = 0;
for (int i = 0; i <= 10; i++)
{
for (int j = Math.max(i-2, 0); j <= Math.min(10,i+2); j++)
{
for (int k = Math.max(i-2, 0); k <= Math.min(10,i+2); k++)
{
if (Math.abs(i-j) > 2 || Math.abs(j-k) > 2 || Math.abs(i-k) > 2)
continue;
if (i + j + k != scores[pos])
continue;
int score = 0;
if (i >= target || j >= target || k >= target)
score = 1;
if (Math.abs(i-j) > 1 || Math.abs(j-k) > 1 || Math.abs(i-k) > 1)
best = Math.max(best, score+magic(pos+1, surpriseLeft-1));
else
best = Math.max(best, score+magic(pos+1, surpriseLeft));
}
}
}
matrix[pos][surpriseLeft] = best;
return best;
}
}
| 0 | 1,189,394 |
A11759 | A13081 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.PrintWriter;
import java.util.ArrayList;
public class B {
private String nombreInputOutput;
private BufferedReader input;
public int surprising = 0;
public B(String nombreInputOutput) {
this.nombreInputOutput = nombreInputOutput;
}
public void run() {
try {
input = new BufferedReader(new FileReader(new File(nombreInputOutput + ".in")));
PrintWriter output = new PrintWriter(new File(nombreInputOutput + ".out"));
int num_cases = Integer.parseInt(input.readLine().trim());
String Solution;
for (int runs = 1; runs <= num_cases; runs++) {
Solution = new Solution().solve_case(input.readLine().trim());
String result = "Case #" + runs + ": " + Solution;
output.println(result);
System.out.println(result);
}
output.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public class Solution {
public String solve_case(String caseline) throws Exception {
String[] inputs = caseline.split("\\s+");
int numGooglers = Integer.parseInt(inputs[0]);
surprising = Integer.parseInt(inputs[1]);
int bestResult = Integer.parseInt(inputs[2]);
ArrayList<Double> googlers = new ArrayList<Double>();
int inputsTotal = inputs.length;
for (int i = 1; i <= numGooglers; i++) {
googlers.add(Double.parseDouble(inputs[inputsTotal - i]));
}
int maxNumGooglers = 0;
for (Double g : googlers) {
if (checkGoogler(g, bestResult)) {
maxNumGooglers++;
}
}
String Solution = Integer.toString(maxNumGooglers);
return Solution;
}
private Boolean checkGoogler(Double result, int bestResult) {
Double resultbythree = result / 3;
if (resultbythree > bestResult-1) {
return true;
} else if (bestResult*3 > 5 && result > bestResult*3-5) {
if (surprising > 0) {
surprising--;
return true;
} else {
return false;
}
} else {
return false;
}
}
}
public static void main(String[] args) {
B b = new B("B-small");
b.run();
}
} | 0 | 1,189,395 |
A11759 | A10611 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.util.Scanner;
public final class GoogleDanceJudge {
public static enum TripletType {
INVALID,
USUAL,
SURPRISING
};
public static TripletType findResultType (final int resultsSum, final int bestResult) {
final int meanValue = resultsSum / 3;
if (meanValue > bestResult)
return TripletType.USUAL;
//else
final int unknownTwoResultsSum = resultsSum - bestResult; //hypothesing
if (unknownTwoResultsSum < 0)
return TripletType.INVALID;
final int lowestAcceptedResult = unknownTwoResultsSum / 2;
switch (bestResult - lowestAcceptedResult) {
case 0:
case 1:
return TripletType.USUAL;
case 2:
return TripletType.SURPRISING;
default:
return TripletType.INVALID;
}
}
private static final String OUTPUT_FILE_EXTENSION = "out";
public static void main (final String[] args) throws Exception {
//input init
if (args.length < 1)
throw new IllegalArgumentException();
final String inputFileName = args[0];
final int lastDotIndex = inputFileName.lastIndexOf('.');
final String fileName = (lastDotIndex < 0) ? inputFileName : inputFileName.substring(0, lastDotIndex);
final String outputFileName = fileName + "." + OUTPUT_FILE_EXTENSION;
final File inputFile = new File(inputFileName);
final File outputFile = new File(outputFileName);
Scanner inputScanner = null;
PrintWriter outputWriter = null;
try {
inputScanner = new Scanner(inputFile);
outputWriter = new PrintWriter(outputFile);
final int numberLines = inputScanner.nextInt();
inputScanner.nextLine(); //go to first text line
for (int i = 0; i < numberLines; ++i) {
final int googlersNumber = inputScanner.nextInt();
final int maxSurprisingTripletsNumber = inputScanner.nextInt();
final int minimumBestResult = inputScanner.nextInt();
int possibleResultsNumber = 0;
int unusualResultsNumber = 0;
for (int j = 0; j < googlersNumber; ++j) {
final int result = inputScanner.nextInt();
final TripletType resultType = findResultType(result, minimumBestResult);
switch (resultType) {
case SURPRISING:
if (unusualResultsNumber >= maxSurprisingTripletsNumber)
break; //not acceptable anymore
++unusualResultsNumber;
//no break
case USUAL:
++ possibleResultsNumber;
break;
//invalid, don't count
}
}
outputWriter.println("Case #" + (i+1) + ": " + possibleResultsNumber);
}
} catch (final NoSuchElementException noSuchElementException) {
System.err.println("invalid input");
throw noSuchElementException;
} finally {
if (inputScanner != null) {
inputScanner.close();
}
if (outputWriter != null) {
outputWriter.flush();
outputWriter.close();
}
}
}
}
| 0 | 1,189,396 |
A11759 | A10001 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class Qual2 {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(new File("B-small-attempt0.in"));
FileWriter fw = new FileWriter("B-output.txt");
int total = sc.nextInt();
for(int i = 1; i <= total; i++) {
int n = sc.nextInt(), s = sc.nextInt(), p = sc.nextInt();
int[] scores = new int[n];
for(int j = 0; j < n; j++) scores[j] = sc.nextInt();
int count = 0;
for(int j = 0; j < n; j++) {
int div = scores[j] / 3, rem = scores[j] % 3;
if(rem == 0) {
if(div >= p) count++;
else if(div == p-1 && div > 0 && s > 0) {
s--;
count++;
}
}
else if(rem == 1) {
if(div + 1 >= p) count++;
}
else if(rem == 2) {
if(div + 1 >= p) count++;
else if(div + 2 >= p && s > 0) {
s--;
count++;
}
}
/*if(div >= p) count++;
else if(rem == 1 && div + rem >= p) count++;
else if(rem == 2) {
if(div + rem == p) {
if(s > 0) {
s--;
count++;
}
}
else if(div + rem > p) count++;
}
else if(rem == 0 && div == p-1 && s > 0) {
s--;
count++;
}*/
}
fw.write("Case #" + i + ": " + count + "\n");
System.out.println("Case #" + i + ": " + count);
}
fw.close();
}
}
| 0 | 1,189,397 |
A11759 | A11330 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.lsworks.google.codejam.qualification2012;
import java.io.File;
import java.io.IOException;
import java.util.List;
import com.google.common.base.Charsets;
import com.google.common.io.Files;
public class GooglersDance {
public static void main(String[] args) throws IOException {
GooglersDance text2googleresse = new GooglersDance();
text2googleresse.t2g();
}
private void t2g() throws IOException {
// File inputFile = new File(
// "src/main/resources/qualification2012/B-sample.in");
File inputFile = new File(
"src/main/resources/qualification2012/B-small-attempt3.in");
// File inputFile = new File(
// "src/main/resources/qualification2012/A-large-practice.in");
List<String> inputs = Files.readLines(inputFile, Charsets.UTF_8);
int totalTest = Integer.parseInt(inputs.remove(0));
for (int test = 1; test <= totalTest; test++) {
String[] inStr = inputs.remove(0).split(" ");
int S = Integer.parseInt(inStr[1]);
int p = Integer.parseInt(inStr[2]);
int nm = 0;
int sm = 0;
if (p == 0) {
nm = 0;
sm = 0;
} else if (p == 1) {
nm = 1;
sm = 1;
} else if (p == 2) {
nm = 4;
sm = 2;
} else {
nm = 3 * (p - 1) + 1;
sm = 3 * (p - 2) + 2;
}
int output = 0;
for (int i = 3; i < inStr.length; i++) {
int t = Integer.parseInt(inStr[i]);
if (t >= nm) {
output++;
} else if (t >= sm && S > 0) {
output++;
S--;
}
}
System.out.format("Case #%d: %s\n", test, output);
}
}
}
| 0 | 1,189,398 |
A11759 | A11866 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
import java.io.*;
import java.util.ArrayList;
public class Main2
{
public static void main(String[] args) throws IOException
{
String line = " ";
String line2 = " ";
String line3 = " ";
FileReader reader = new FileReader("B-small-attempt2.in");
Scanner in = new Scanner(reader);
ArrayList<String> list = new ArrayList<String>();
ArrayList<String> list2 = new ArrayList<String>();
int number = 0;
int numb = 0;
int index = 0;
int c;
int N;
int nprob;
int hnum;
int calc;
boolean suc;
int p;
int[] num = new int[103];
int count = in.nextInt();
in.nextLine();
for(int i = 0; i < count; i++)
{
line = in.nextLine();
list.add(line);
}
while(count > 0)
{
p = 0;
line2 = list.get(numb);
number = 0;
while(line2.length() > 0)
{
index = line2.indexOf(' ');
if(index > 0)
{
line = line2.substring(0,index);
num[number] = Integer.parseInt(line);
line2 = line2.substring(index);
line2 = line2.trim();
}
else if(index == -1)
{
num[number] = Integer.parseInt(line2);
line2 = "";
}
number++;
}
N = num[0];
nprob = num[1];
hnum = num[2];
suc = false;
for(int j = 0; j < N; j++)
{
c = 3;
calc = num[j+3];
while(c > 0)
{
calc -= hnum;
c--;
}
if(calc >= 0)
suc = true;
else if(calc == -1)
suc = true;
else if(calc == -2)
suc = true;
else if(nprob > 0 && calc == -3 && num[j+3] > 0)
{
suc = true;
nprob--;
}
else if(nprob > 0 && calc == -4 && num[j+3] > 0)
{
suc = true;
nprob--;
}
else
suc = false;
if(suc)
p++;
}
line3 = "Case #" + (numb+1) + ": " + p;
list2.add(line3);
count--;
numb++;
}
for(String a : list2)
System.out.println(a);
}
} | 0 | 1,189,399 |