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
A12296
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 Solution { public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader (new FileReader("input.in"))); PrintWriter out = new PrintWriter(new File("output.out")); in.nextToken(); int t = (int)in.nval; for (int i = 0; i<t; i++){ out.print("Case #" + (i+1) + ": "); in.nextToken(); int n = (int)in.nval; in.nextToken(); int s = (int)in.nval; in.nextToken(); int p = (int)in.nval; int[] points = new int[n]; int ans = 0; for (int j = 0; j<n; j++){ in.nextToken(); points[j] = (int)in.nval; int ost = points[j]%3; if (ost == 0) ans += (points[j]/3 >= p) ? 1 : 0; else ans += (points[j]/3+1 >= p) ? 1 : 0; } for (int j = 0; j<n && s>0; j++){ if (points[j]<2 || points[j]>28) continue; int ost = points[j]%3; if (ost != 1) { int current = points[j]/3; if (ost == 2) current++; if (current == p-1) { s--; ans++; } } } out.println(ans); } out.close(); } }
0
1,189,700
A11759
A13224
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.first; import java.io.*; import java.util.ArrayList; public class ReadWriteFileForCodeJam { String fileRead; String fileWrite; String fileContentToWrite; String fileSeparatorForWrite, fileSeparatorForRead; boolean firstTimeRead; int readCursor; ArrayList<String> fileContentAsArrayList; public ReadWriteFileForCodeJam(){ fileContentToWrite = new String(); fileRead = new String(); fileWrite = new String(); fileSeparatorForWrite = new String(); fileSeparatorForRead = new String(); firstTimeRead = true; fileContentAsArrayList = new ArrayList<String>(); } public void setFileNameForRead(String fileName){ fileRead = fileName; } public void setFileNameForWrite(String fileName){ fileWrite = fileName; } public void setFileSeperatorForWrite(String separator){ fileSeparatorForWrite = separator; } public void setFileContentToWrite(String content, boolean append, boolean newLine){ String separator = new String(); if (append){ if (newLine){ separator = System.getProperty("line.separator"); } else{ separator = fileSeparatorForWrite; } } if (fileContentToWrite != null && fileContentToWrite.length() == 0) fileContentToWrite = content; else fileContentToWrite = fileContentToWrite + separator + content; } public String ReadFile(boolean returnContent) { StringBuilder content = new StringBuilder(); File aFile = new File(fileRead); if (firstTimeRead){ firstTimeRead = false; try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while ((line = input.readLine()) != null) { content.append(line); fileContentAsArrayList.add(line); content.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException io) { return (io.toString()); } if (returnContent) return content.toString(); } return null; } public String GetSingleLineFromFile(int lineNumber){ try{ return fileContentAsArrayList.get(lineNumber - 1).toString(); }catch (IndexOutOfBoundsException e){ return null; } } public int getNoOfLinesInFile(){ return fileContentAsArrayList.size(); } public boolean WriteFile(boolean appendLine) { File aFile = new File(fileWrite); Boolean writeSuccess = true; try { Writer output = new BufferedWriter(new FileWriter(aFile)); try { output.write(fileContentToWrite); } finally { output.close(); } } catch (IOException io) { writeSuccess = false; } return writeSuccess; } }
0
1,189,701
A11759
A10728
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.PrintWriter; import java.util.Scanner; public class googler { public static void main(String args[]) throws FileNotFoundException { Scanner in=new Scanner(new FileReader("input.in")); PrintWriter pw=new PrintWriter("ans.txt"); int cases=in.nextInt(); in.nextLine(); for(int counter=1;counter<=cases;counter++) { int n=in.nextInt(); int s=in.nextInt(); int p=in.nextInt(); System.out.println(n+" "+s+" "+p); int req; if(p==0) { pw.println("Case #"+(counter)+": "+n); in.nextLine(); continue; } else req=p*3-2; int min=req-2>0?req-2:1; int answer=0; for(int j=0;j<n;j++) { int score=in.nextInt(); if(score>=req) { answer++; continue; } else if(score>=min&&s>0) { answer++; s--; } } pw.println("Case #"+(counter)+": "+answer); } pw.close(); } }
0
1,189,702
A11759
A13025
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 year2012; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashSet; import java.util.Set; public class Dancing { static PrintWriter out; static int count(int[] scores, int N, int S, int p) { int result = 0; for (int i = 0; i < N; ++i) { if (scores[i] >= p) { int rest = scores[i] - p; if (rest/2 > (p - 2)) { result ++; } else if (S > 0 && rest/2 == (p - 2)) { result ++; S --; } else { continue; } } } return result; } static void deal(String file) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(file), "utf8")); String line = reader.readLine(); int T = Integer.parseInt(line); for (int no = 1; no <= T; no++) { String[] args = reader.readLine().split("\\s"); int N = Integer.parseInt(args[0]); int S = Integer.parseInt(args[1]); int p = Integer.parseInt(args[2]); int scores[] = new int[N]; for (int i = 0; i < N; ++i) { scores[i] = Integer.parseInt(args[3 + i]); } out.println("Case #" + no + ": " + count(scores, N, S, p)); } } public static void main(String[] args) throws Exception { out = new PrintWriter(new File("result-out.txt")); //deal("B-large.in"); deal("B-small-attempt1.in"); out.close(); } }
0
1,189,703
A11759
A10434
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.util.Scanner; public class BSmall { public static void get() { try { File inputFile = new File("B-small-attempt3.in"); inputFile.createNewFile(); Scanner scan = new Scanner(inputFile); int t = Integer.parseInt(scan.nextLine()); File out = new File("out.txt"); FileWriter fw = new FileWriter(out); for (int i = 0; i < t - 1; i++) { fw.append("Case #" + (i + 1) + ": "); int counter = 0; int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); for (int j = 0; j < n; j++) { int g1 = scan.nextInt(); if (g1 == 0 && p > 0) { continue; } if (p > 0) { int key = g1 / p; if (key >= 3) { counter++; } else { if (key == 2) { int talet = p + (g1 % p); int v = talet / 2; if (p - v == 1) { counter++; } else { if (p - v == 2 && s > 0) { counter++; s--; } } } else { int x = g1 - p; x = x / 2; if (p - x == 1) { counter++; } else { if (p - x == 2 && s > 0) { s--; counter++; } } } } } else { counter++; } } fw.append("" + counter + "\n"); } fw.append("Case #" + (t) + ": "); int counter = 0; int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); for (int j = 0; j < n; j++) { int g1 = scan.nextInt(); if (p > 0) { int key = g1 / p; if (key >= 3) { counter++; } else { if (key == 2) { int talet = p + g1 % p; int v = talet / 2; if (p - v == 1) { counter++; } else { if (p - v == 2 && s > 0) { counter++; s--; } } } } } else { counter++; } } fw.append("" + counter); fw.close(); } catch (Exception e) { } } public static void main(String[] args) { get(); } }
0
1,189,704
A11759
A13165
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 tr0llhoehle.cakemix.googleCodejam; import java.io.IOException; import java.text.ParseException; import tr0llhoehle.cakemix.utility.googleCodeJam.IOManager; public class Main { /** * @param args */ public static void main(String[] args) { if (args.length >= 1) { IOManager<DWGSolver, DWGProblem> io = new IOManager<DWGSolver, DWGProblem>( new DWGSolver(), (Class<DWGProblem>) new DWGProblem().getClass()); try { io.start(args[0]); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
0
1,189,705
A11759
A10204
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 DG { private static String fileName = DG.class.getSimpleName().replaceFirst("_.*", ""); private static String inputFileName = "D:\\cj12\\"+fileName + ".in"; private static String outputFileName = "D:\\cj12\\"+fileName + ".out"; private static Scanner in; private static PrintWriter out; public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); if (args.length >= 2) { inputFileName = args[0]; outputFileName = args[1]; } in = new Scanner(new FileReader(inputFileName)); out = new PrintWriter(outputFileName); int tests = in.nextInt(); //in.nextLine(); for (int t = 1; t <= tests; t++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int res = 0; for(int i=0;i<n;i++) { int tot = in.nextInt(); if(tot >= ((3*p)-2)) res++; else if(tot > 0 && s > 0 && (tot >= ((3*p)-4))) { res++; s--; } } System.out.println("Case #" + t + ": "+res); out.println("Case #" + t + ": "+res); } in.close(); out.close(); } }
0
1,189,706
A11759
A12147
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; import java.util.List; public interface CombinationValidator<T> { public boolean isValid(List<T> comb); }
0
1,189,707
A11759
A12651
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 Dancing { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); for (int i = 0; i < T; i++) { int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); int count = 0; for (int j = 0; j < n; j++) { int m = scan.nextInt(); if (m - p < 0) continue; if ((m - p) / 2 >= p - 1) count++; else if ((m - p) / 2 >= p - 2 && s > 0) { count++; s--; } } System.out.println("Case #" + (i + 1) + ": " + count); } } }
0
1,189,708
A11759
A10917
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_with_googler; import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.FileOutputStream; import java.io.OutputStreamWriter; import java.util.Scanner; public class Solution { /** * @param args */ public void doit() throws Exception{ BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512); Scanner s = new Scanner(new BufferedInputStream(System.in)); int cases = s.nextInt(); for(int i=0;i<cases;i++){ int N = s.nextInt();//# of googler int S = s.nextInt();//# of suprising int P = s.nextInt();//expected value int score[] = new int[N]; int non_surprising[] = {0,1,4,7,10,13,16,19,22,25,28}; int surprising[] = {2,2,2,5,8,11,14,17,20,23,26}; int count = 0; for(int j=0;j<N;j++){ score[j] = s.nextInt(); if(non_surprising[P]<=score[j]){ count++; }else if(S>0&&surprising[P]<=score[j]){ S--;count++; } } out.append("Case #" + (i+1) + ": " + count); out.append('\n'); } out.flush(); } public static void main(String[] args) { // TODO Auto-generated method stub Solution s = new Solution(); try{ s.doit(); }catch(Exception e){ e.printStackTrace(); } } }
0
1,189,709
A11759
A12445
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 Dancing_Googlers { public static void main(String args[]) throws Exception { FileWriter ofstream = new FileWriter("outp.out"); BufferedWriter out = new BufferedWriter(ofstream); FileInputStream fstream = new FileInputStream("inp.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); long n,sur,p,ng,rem; int i,ans=0; int countn=1; String strLine; long[] li = new long[250]; String[] ls = new String[250]; strLine = br.readLine(); n = Long.parseLong(strLine); while ((strLine = br.readLine()) != null) { ans=0; ls = strLine.split(" "); for (i=0;i<ls.length;++i) { li[i] = Long.parseLong(ls[i]); } i=0; ng =li[i] ; ++i; sur = li[i]; ++i; p = li[i]; ++i; //System.out.println ("n=" +n); //System.out.println ("ng="+ng); //System.out.println ("Sur="+sur); //System.out.println ("p="+p); for(;i<=(ng+2);i++) { //System.out.println (li[i]); if(li[i]<p) //Eliminating lower values continue; if((li[i]/3)>=p) //Finalizing stage 1 { //System.out.println ("Hello thier " + (li[i]/3)); ++ans; continue; } //Without Surprise rem = li[i]-(2*p); if(((rem)+1) == p || ((rem)-1) == p || ((rem)+2) == p || ((rem)-2) == p) { ++ans; continue; } //With SUrprise rem = (li[i]-p)/2; if(sur>0) { if((rem==p) || ((rem+2)==p) || ((rem-2)==p)) { --sur; ++ans; } } } System.out.println (ans); out.write("Case #" +countn + ": " +ans + "\n"); ++countn; } in.close(); out.close(); } }
0
1,189,710
A11759
A10370
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.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class DancingWithGooglers { public static void main(String[] args) throws IOException { File in = new File("c:\\temp\\input.txt"); File out = new File("c:\\temp\\output.txt"); BufferedWriter w = new BufferedWriter(new FileWriter(out)); Scanner sc = new Scanner(in); int testCases = Utils.readIntegerLine(sc); for (int i = 1; i <= testCases; i++) { int googlers = Utils.readInteger(sc); int surprising = Utils.readInteger(sc); int minBestResult = Utils.readInteger(sc); int[] totalPoints = new int[googlers]; for(int j = 0; j < googlers; j++) { totalPoints[j] = Utils.readInteger(sc); } int maxGooglersWithBestResults = solve(googlers, surprising, minBestResult, totalPoints); String result = String.format("Case #%d: %d", i, maxGooglersWithBestResults); w.write(result); System.err.println(result); w.newLine(); } w.close(); } static int minTotalPointsForBestScore(int b, boolean s) { switch (b) { case 0: return s ? 2 : 0; case 1: return s ? 2 : 1; default: return s ? Math.max(2, b + b - 2 + b - 2) : b + b - 1 + b - 1; } } static int maxTotalPointsForBestScore(int b, boolean s) { return s ? 28 : 30; } static boolean canBeSurprising(int total) { return total >= 2 && total <= 28; } private static int solve(int googlers, int surprising, int minBestResult, int[] totalPoints) { int n = googlers; // Arrays.sort(totalPoints); Set<Integer> canBeSurprising = new HashSet<Integer>(); Set<Integer> okIfSurprising = new HashSet<Integer>(); Set<Integer> okIfNotSurprising = new HashSet<Integer>(); Set<Integer> areSurprising = new HashSet<Integer>(); int i = 0; for (int points : totalPoints) { int minPoints = 0; int maxPoints = 0; if (canBeSurprising(points)) { canBeSurprising.add(i); // assume surprising minPoints = minTotalPointsForBestScore(minBestResult, true); maxPoints = maxTotalPointsForBestScore(minBestResult, true); if (points >= minPoints && points <= maxPoints) { okIfSurprising.add(i); } } // assume not surprising minPoints = minTotalPointsForBestScore(minBestResult, false); maxPoints = maxTotalPointsForBestScore(minBestResult, false); if (points >= minPoints && points <= maxPoints) { okIfNotSurprising.add(i); } i++; } int count = 0; _outer: while (surprising > 0) { for(int j = 0; j < googlers; j++) { if (canBeSurprising.contains(j)) { if (okIfSurprising.contains(j) && !okIfNotSurprising.contains(j)) { surprising--; areSurprising.add(j); canBeSurprising.remove(j); continue _outer; } } } for(int j = 0; j < googlers; j++) { if (canBeSurprising.contains(j)) { if (!okIfSurprising.contains(j) && okIfNotSurprising.contains(j)) { surprising--; areSurprising.add(j); canBeSurprising.remove(j); continue _outer; } } } for(int j = 0; j < googlers; j++) { if (canBeSurprising.contains(j)) { if (okIfSurprising.contains(j)) { surprising--; areSurprising.add(j); canBeSurprising.remove(j); continue _outer; } } } for(int j = 0; j < googlers; j++) { if (canBeSurprising.contains(j)) { surprising--; areSurprising.add(j); canBeSurprising.remove(j); continue _outer; } } } for(int j = 0; j < googlers; j++) { if (okIfSurprising.contains(j) && areSurprising.contains(j)) { count++; } else if (okIfNotSurprising.contains(j) && !areSurprising.contains(j)) { count++; } } return count; } }
0
1,189,711
A11759
A11252
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.IOException; import java.util.Scanner; public class code12 { public static int nosurprise(int n){ int p= (n/3); if(n%3==0){return p;}else{return (p+1);}} public static int surprise(int n){ int p=(n/3); if(n%3==2){return (p+2);}else{ if(n%3==1){return (p+1);} else{if(p-1>0){return (p+1);}else{return p;}}}} public static int solution(int x, int[] p,int s){ int sur=s; int ans=0; for(int k=0;k<p.length;k++){ if(nosurprise(p[k])>=x){ans++;} else{ if(sur>0){if(surprise(p[k])>=x){ ans++;sur--;}else{}}else{}} } return ans;} public static void main(String[] args) throws IOException{ Scanner c = new Scanner(System.in); int times=c.nextInt(); for(int p=0;p<times;p++){ int n=c.nextInt(); int surprise=c.nextInt(); int val=c.nextInt(); int[] ci=new int[n]; for(int g=0; g<n;g++){ ci[g]=c.nextInt();} int answer= solution(val,ci,surprise); System.out.println("Case #"+(p+1)+": "+answer);} } }
0
1,189,712
A11759
A10064
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.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; public class DancingGooglers { private final String inputFile = "D:\\input.in"; private final String outputFile = "D:\\output.out"; private static class TestCase{ int n; int s; int p; int result = 0; List<Integer> ti = new ArrayList<Integer>(); public void calculateBest(){ result = 0; int max = p * 3; for (int i: ti){ if (p <= 0){ result++; continue; } if (i > 0 && i >= (max - 4)){ if (i >= max || (max - i) <= 2){ result++; }else if((max - i) <= 4 && s > 0){ result++; s--; } } } } } List<TestCase> input = new ArrayList<DancingGooglers.TestCase>(); public void parseInput(){ try { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(inputFile))); int numTestCases = Integer.parseInt(br.readLine()); for (int i = 0; i < numTestCases; i++){ String [] lineTokens = br.readLine().split(" "); TestCase tc = new TestCase(); tc.n = Integer.parseInt(lineTokens[0]); tc.s = Integer.parseInt(lineTokens[1]); tc.p = Integer.parseInt(lineTokens[2]); for (int j = 3; j < lineTokens.length; j++){ tc.ti.add(Integer.parseInt(lineTokens[j])); } tc.calculateBest(); input.add(tc); } br.close(); } catch (Exception e) { e.printStackTrace(); } } public void doOutput(){ try { PrintWriter pw = new PrintWriter(new FileOutputStream(outputFile)); for (int i = 0; i < input.size(); i++){ TestCase tc = input.get(i); pw.println("Case #" + (i + 1) + ": " + tc.result); } pw.flush(); pw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } public static void main(String [] args){ DancingGooglers dg = new DancingGooglers(); dg.parseInput(); dg.doOutput(); } }
0
1,189,713
A11759
A10756
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.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) { Scanner problem = new Scanner(System.in); int T = problem.nextInt(); for (int i = 0; i < T; i++) { int answer = 0; int N = problem.nextInt(); int S = problem.nextInt(); int p = problem.nextInt(); List<Triplet> googlers = new ArrayList<Triplet>(); for (int j = 0; j < N; j++) { googlers.add(new Triplet(problem.nextInt())); } int possibleSurprises = 0; for (Triplet triplet : googlers) { if (triplet.minMax() >= p) { answer++; continue; } if (triplet.maxMax() >= p) { possibleSurprises++; } } answer += possibleSurprises >= S ? S : possibleSurprises; System.out.println(String.format("Case #%s: %s", i + 1, answer)); } } } class Triplet { private int totalScore; public Triplet(int totalScore) { this.totalScore = totalScore; } private int min() { return new BigDecimal(totalScore).divide(new BigDecimal(3), RoundingMode.FLOOR).intValue(); } public int minMax() { return new BigDecimal(totalScore).divide(new BigDecimal(3), RoundingMode.CEILING).intValue(); } public int maxMax() { int lalala = this.totalScore % 3; if (lalala == 0) { lalala = 1; } if (this.totalScore == 0) { lalala = 0; } return this.min() + lalala; } }
0
1,189,714
A11759
A12804
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 E2 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = null; //sc = new Scanner(System.in); try { sc = new Scanner(new File("E2.txt")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } int fases = sc.nextInt(); for(int j=1; j<=fases; ++j){ int N = sc.nextInt(); // players int S = sc.nextInt(); // surprising int P = sc.nextInt(); int casos = 0; for(int i=0; i<N; ++i){ int ti = sc.nextInt(); int t = ti % 3; int base = ti / 3; if(t == 0){ if(base >= P){ casos++; } else if(S > 0 && base > 0 && base + 1 >= P){ casos++; S--; } } else if(t == 1){ if(base + 1 >= P){ casos++; } else if(S > 0 && base + 1 >= P){ casos++; S--; } } else{ if(base + 1 >= P){ casos++; } else if(S > 0 && base + 2 >= P){ casos++; S--; } } } System.out.println("Case #" + j + ": " + casos); } } }
0
1,189,715
A11759
A12127
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; public class gjam { public static void main(String[] args) { int TestCases = 0; int currentCase = 0; try { FileInputStream fstream = new FileInputStream("B-small-attempt2.in"); DataInputStream dstream = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(dstream)); String inputStr = br.readLine(); TestCases = Integer.parseInt(inputStr); while(currentCase != TestCases) { int N = 0; int S = 0; int p = 0; int[] scores; int result = 0; inputStr = br.readLine(); String[] variableStr = inputStr.split(" "); N = Integer.parseInt(variableStr[0]); S = Integer.parseInt(variableStr[1]); p = Integer.parseInt(variableStr[2]); String[] scoreStr = new String[N]; for(int i = 3; i < variableStr.length;i++) { scoreStr[i - 3] = variableStr[i]; } scores = new int[N]; for(int i = 0; i < scores.length; i++) { scores[i] = Integer.parseInt(scoreStr[i]); } for(int i = 0; i< scores.length; i++) { int tmp = scores[i]; float d = tmp/3.0f; if(d == p) { result++; } else { if(d > p) { int r = 0; r += d; if((r + r + r) == tmp) { result++; } else if((r + r + (r-1)) == tmp) { result++; } else if((r + (r-1) + (r-1)) == tmp) { result++; } else if((r + (r+1)+r)==tmp) { result++; } else if((r +(r+1) + (r+1))==tmp) { result++; } else { if(S > 0) { if((r + r + (r-2))==tmp) { result++; S--; } else if((r+(r-2)+(r-2)) == tmp) { result++; S--; } else if((r + (r-1) + (r-2)) == tmp) { result++; S--; } if((r + (r+2)+r)==tmp) { result++; S--; } else if((r +(r+2) + (r+2))==tmp) { result++; S--; } else if((r + (r+1)+(r+2))==tmp) { result++; S--; } } } } else if((p + p + (p-1)) == tmp) { result++; } else if((p + (p-1) + (p-1)) == tmp) { result++; } else { if((S > 0) && (tmp != 0)) { if((p + p + (p-2))==tmp) { result++; S--; } else if((p+(p-2)+(p-2)) == tmp) { result++; S--; } else if((p + (p-1) + (p-2)) == tmp) { result++; S--; } } } } } System.out.println("Case #" + (currentCase +1) + ": " + result); currentCase++; } } catch(Exception e) { System.err.println("Err: " + e.getMessage()); } } }
0
1,189,716
A11759
A12652
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 DancingWithGooglers { static int caseNumber; static int totalCases; public static void main(String[] args) throws Exception { caseNumber = 1; File fileIn = new File("C:\\GCJ\\DancingWithGooglers\\B-small-attempt0.in"); FileInputStream fileInputStream = null; BufferedInputStream inputStream = null; BufferedReader reader = null; Writer out; String newLine = System.getProperty("line.separator"); String fileOutPath = "C:\\GCJ\\DancingWithGooglers\\output.txt"; File fileOut = new File(fileOutPath); if (! fileOut.createNewFile()){ fileOut.delete(); fileOut.createNewFile(); } out = new OutputStreamWriter(new FileOutputStream(fileOutPath), "US-ASCII"); StringBuilder builder = new StringBuilder(); try { fileInputStream = new FileInputStream(fileIn); // Here BufferedInputStream is added for fast reading. inputStream = new BufferedInputStream(fileInputStream); reader = new BufferedReader(new InputStreamReader(inputStream)); totalCases = Integer.parseInt(reader.readLine()); while (caseNumber <= totalCases){ builder.append(handleTestCase(reader)); builder.append(newLine); caseNumber++; } // dispose all the resources after using them. fileInputStream.close(); inputStream.close(); reader.close(); } catch (Exception e) { e.printStackTrace(); } System.out.print(builder.toString()); out.write(builder.toString()); out.close(); } public static String handleTestCase(BufferedReader reader) throws IOException{ String[] splitLine = reader.readLine().split(" "); int[] ints = stringArrayToIntArray(splitLine); int numScores = ints[0]; int numSurprises = ints[1]; int goal = ints[2]; int surprisesLeft = numSurprises; int metGoal = 0; for(int i = 3; i < ints.length; i++){ //Base cases if(ints[i] == 0) { if(goal == 0) metGoal++; } else if(ints[i] == 1){ if(goal == 1) metGoal++; } //Handles if the number is divisible by 3 //If the average is >= the goal, it is trivially meeting the goal //If you allow for a surprise, the max can grow by 1 else if(ints[i] % 3 == 0){ if(ints[i] / 3 >= goal) metGoal++; else if ( ints[i] / 3 == goal - 1){ if(surprisesLeft > 0) { surprisesLeft--; metGoal++; } } } //The value of the maximum doesn't change even with a surprise with ints[i] % 3 ==1 //So I don't even evaluate it here and worry about deducting available surprises else if(ints[i] % 3 == 1){ if(ints[i] / 3 >= goal-1) metGoal++; } //Value of the maximum with % 3 == 2 is one above the average by default //Allowing for a surprise allows for it to be one higher else if(ints[i] % 3 == 2){ //Unecessary "if" statement kept to remind about the last case if(ints[i] / 3 >= goal-1) metGoal++; else if(ints[i] / 3 == goal - 2){ if(surprisesLeft > 0) { surprisesLeft--; metGoal++; } } } } if(surprisesLeft > 0) System.out.println("Surprises were left: "+surprisesLeft+" on case "+caseNumber); return "Case #"+caseNumber+": "+metGoal; } public static int[] stringArrayToIntArray(String[] input){ int[] ints = new int[input.length]; for (int i = 0; i < input.length; i++){ ints[i] = Integer.parseInt(input[i]); } return ints; } }
0
1,189,717
A11759
A10098
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 Dancing { /** * @param args */ public static void main(String[] args) throws IOException { new Dancing().run(); } Integer[] best = new Integer[31]; int best(int x) { if (best[x] != null) return best[x]; for (int l = 0; l <= Math.min(x, 8); l++) { for (int m = l; m <= l + 2 && m + l <= x; m++) { int h = l + 2; if (l + m + h == x) { best[x] = h; } } } if (best[x] == null) best[x] = -1; return best[x]; } void run() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); for (int i = 0; i <= 30; i++) System.err.println("" + i + "," + best(i) + "," + ((i + 2) / 3)); int T = nextInt(); for (int tt = 0; tt < T; tt++) { int n = nextInt(), s = nextInt(), p = nextInt(); int ans = 0; ArrayList<Integer> list = new ArrayList<Integer>(); for (int i = 0; i < n; i++) { int x = nextInt(); if (x < 2) { if (x >= p) ans++; } else if (x > 28) { ans++; } else { list.add(x); } } Integer[] arr = new Integer[0]; arr = list.toArray(arr); Arrays.sort(arr); int rem = s; for (int i = 0; i < arr.length; i++) { int x = arr[i]; if (best(x) >= p && (x + 2) / 3 < p && rem > 0) { ans++; rem--; } else if ((x + 2) / 3 >= p) { ans++; } } System.out.println("Case #" + (tt + 1) + ": " + ans); } out.close(); } BufferedReader br; StringTokenizer st; PrintWriter out; String next() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } }
0
1,189,718
A11759
A11853
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; public class FileOut { /** * コンストラクタ. * @param filename 書き出すファイル名 * @param s 書き出す文字列 */ public FileOut(String filename, String s) { File f = new File(filename); FileWriter fw = null; try { fw = new FileWriter(f); fw.write(s); } catch (IOException e) { e.printStackTrace(); } finally { try { fw.close(); } catch (IOException e) { e.printStackTrace(); } } } }
0
1,189,719
A11759
A12055
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.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintStream; import java.util.regex.Pattern; /** * @(#)DancingGoogler.java, 2012-4-14. * * Copyright 2012 Netease, Inc. All rights reserved. * NETEASE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ /** * * @author bjdengdong * */ public class DancingGoogler { /** * @param args */ public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("E:\\google_code_jam\\B-small-attempt0.in"))); PrintStream out = new PrintStream(new FileOutputStream("E:\\google_code_jam\\B-small-attempt0.out")); int cases = Integer.parseInt(br.readLine()); for (int i = 1; i <= cases; i++) { String line = br.readLine(); String[] sp = line.split(Pattern.quote(" ")); int n = Integer.parseInt(sp[0]);//num of googlers int s = Integer.parseInt(sp[1]);//num of surprises int p = Integer.parseInt(sp[2]);//best score p int[] scores = new int[n]; int result = 0; int usedSurprise = s; for (int j = 0; j < n; j++) { scores[j] = Integer.parseInt(sp[j + 3]); if (canReachWithoutSuprise(scores[j], p)) { result++; } else if (canReachWithSuprise(scores[j], p)) { if (usedSurprise > 0) { result++; usedSurprise--; } } } out.println("Case #" + i + ": " + result); } out.close(); } private static boolean canReachWithSuprise(int score, int p) { if (score == 0 || score == 1) return false; return (score >= (3 * p - 4)) && (score <= (3 * p - 3)); } private static boolean canReachWithoutSuprise(int score, int p) { if (p == 0) return true; return score >= (3 * p - 2); } }
0
1,189,720
A11759
A11530
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 ProbB { public static int solve(int N, int S, int p, int[] scores) { int count = 0; for(int i = 0; i<scores.length; i++) { if(p*3<=scores[i]) count++; else if(Math.max(0, p-1)*2+p <=scores[i]) count++; else { int tmp = scores[i] - p; if(Math.max(0, p-2) *2 <= tmp) { if(S > 0) { count++; S--; } } } } return count; } public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new FileWriter("B.out")); String line = in.readLine(); int T = Integer.parseInt(line); for(int i=1; i<=T; i++) { line = in.readLine(); String[] comp = line.split("\\s+"); int N = Integer.parseInt(comp[0]); int S = Integer.parseInt(comp[1]); int p = Integer.parseInt(comp[2]); int[] scores = new int[N]; for(int j = 0; j<N; j++) scores[j] = Integer.parseInt(comp[3+j]); out.print("Case #" + i+ ": "); out.println(solve(N, S, p, scores)); } out.flush(); in.close(); out.close(); } }
0
1,189,721
A11759
A11272
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.IOException; import java.io.PrintWriter; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; /* run with JDK7 */ public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { List<String> input = Files.readAllLines(Paths.get("K:/B-small-attempt0.in"), Charset.defaultCharset()); PrintWriter output = new PrintWriter("K:/B-small-attempt0.out"); int testCount = Integer.parseInt(input.get(0)); for (int i = 1; i <= testCount; ++i) { String[] parts = input.get(i).split(" "); int n = Integer.parseInt(parts[0]); int s = Integer.parseInt(parts[1]); int p = Integer.parseInt(parts[2]); int[] t = new int[n]; for (int j = 0; j < n; ++j) t[j] = Integer.parseInt(parts[3 + j]); // solution int alwaysCount = 0, surpriseCount = 0; for (int j=0; j<n; ++j) { switch (findResult(t[j], p)) { case ALWAYS: ++alwaysCount; break; case SURPRISE: ++surpriseCount; break; } } output.printf("Case #%d: %d\n", i, alwaysCount + Math.min(s, surpriseCount)); } output.close(); } private static Result findResult(int t, int p) { int base = t / 3; int rem = t - base * 3; Result r = null; switch (rem) { case 0: r = tryResult(t, p, base, base, base); if (r == null) r = tryResult(t, p, base - 1, base, base + 1); break; case 1: r = tryResult(t, p, base, base, base + 1); if (r == null) r = tryResult(t, p, base - 1, base + 1, base + 1); break; case 2: r = tryResult(t, p, base, base + 1, base + 1); if (r == null) r = tryResult(t, p, base, base, base + 2); break; default: assert false; } return r != null ? r : Result.NEVER; } private static Result tryResult(int t, int p, int a, int b, int c) { assert a + b + c == t; assert a <= b && b <= c; if (a < 0) return null; if (c >= p) { return c - a == 2 ? Result.SURPRISE : Result.ALWAYS; } return null; } public enum Result { ALWAYS, SURPRISE, NEVER, } }
0
1,189,722
A11759
A11917
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.silverduner.codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.HashMap; public class Dancing { public static void main(String[] args) throws Exception { File input = new File("B-small-attempt0.in"); BufferedReader in = new BufferedReader(new FileReader(input)); File output = new File("1.out"); BufferedWriter out = new BufferedWriter(new FileWriter(output)); // parse input int N = Integer.parseInt(in.readLine()); for(int i=0;i<N;i++) { String str = in.readLine(); out.write("Case #"+(i+1)+": "); System.out.println("-------"); String[] words = str.split(" "); int n = Integer.parseInt(words[0]); int suprise = Integer.parseInt(words[1]); int threshold = Integer.parseInt(words[2]); int[] scores = new int[n]; for(int j=0;j<n;j++) { scores[j] = Integer.parseInt(words[3+j]); } int count = 0; for(int score : scores) { int a,b,c; boolean find = false; boolean sfind = false; for(a = 10; a>=0 && !find; a--) { if(3*a-4>score) continue; for(b = a; b>=0 && b >=a-2 && !find; b--) { for(c = b; c>=0 && c >=b-2 && c >=a-2 && !find; c--) { System.out.println(a+","+b+","+c); if(a+b+c==score) { if(a >= threshold) { if(a-c <= 1){ count++; find = true; System.out.println("find!"); } else if(a-c == 2){ sfind = true; System.out.println("suprise!"); } } } } } } if(!find && sfind && suprise > 0) { count++; suprise --; } } int maxCount = count; out.write(maxCount+"\n"); } out.flush(); out.close(); in.close(); } }
0
1,189,723
A11759
A10750
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; /* * Google Code Jam 2012 * Program by Tommy Ludwig * Problem: Dancing With the Googlers * Date: 2012-04-13 */ public class dancing { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T, N, S, p; T = in.nextInt(); for (int i = 1; i <= T; i++) { int y = 0; N = in.nextInt(); S = in.nextInt(); p = in.nextInt(); int [] t = new int[N]; for (int j = 0; j < N; j++) t[j] = in.nextInt(); //minimum number with surprise case int minNumS = (3 * p) - 4; if (minNumS < 2) minNumS = 2; //minimum number without surprise case int minNum = (3 * p) - 2; //if (minNum < 0) minNum = 0; for (int j = 0; j < N; j++) { if (t[j] >= minNum) y++; else if (t[j] >= minNumS && S > 0) { y++; S--; } } System.out.printf("Case #%d: %d\n", i, y); } } }
0
1,189,724
A11759
A12517
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.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class mainclass { public static void main(String args[]) throws IOException { int cases; int n; int s; int p; int t; int flag; int counter; int[] data; int[] arr; int surp; FileWriter fstream = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream); FileReader isr = new FileReader(args[0]); Scanner src = new Scanner(isr); cases = src.nextInt(); for(int j=0;j<cases;j++) { counter = 0; surp = 0; n = src.nextInt(); s = src.nextInt(); p = src.nextInt(); data = new int [n]; arr = new int[31]; for(int i=0;i<31;i++) arr[i] = 0; for(int i=0;i<n;i++) { arr[src.nextInt()]++; } for(int i=0;i<31;i++) { if(i>=(p*3-2)) counter = arr[i]+counter; if((i==p*3-3||i==p*3-4)&&i>0) surp = arr[i]+surp; } if(surp>s) counter = s+counter; else counter = surp+counter; try{ out.write("Case #"+(j+1)+": "+counter); out.write("\r\n"); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } out.close(); } }
0
1,189,725
A11759
A10387
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.*; import java.util.StringTokenizer; public class Dancing { /** * @param args */ private static int[] values = null; private static int[] googlers= null; private static int total =0; public static void main(String[] args) { BufferedReader fin = null; int t = 0; StringTokenizer str = null; try { fin = new BufferedReader(new FileReader(new File("/home/bamdad/NetBeansProjects/Dancing/src/dancing/B-small-attempt0.in"))); } catch (FileNotFoundException e) { e.printStackTrace(); } try { t = Integer.parseInt(fin.readLine()); //System.out.println(t); } catch (NumberFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } values = new int[3]; for(int i=0;i<t;i++){ System.out.print("Case #"+(i+1)+": "); try { total = 0; str=new StringTokenizer(fin.readLine()); int ctr =0; while(ctr<3) { values[ctr]=Integer.parseInt(str.nextToken()); ctr++; } //System.out.print(values[0]+" "+values[1]+" "+values[2]+" "); ctr=0; googlers = new int[values[0]]; while(str.hasMoreElements()){ googlers[ctr]=Integer.parseInt(str.nextToken()); //System.out.print(googlers[ctr]+" "); ctr++; } //System.out.println(); } catch (IOException e) { e.printStackTrace(); } calculate(); } } private static void calculate() { int value = 0 ; int remainder = 0; for(int i=0;i<values[0];i++){ value = googlers[i]/3; remainder = googlers[i]%3; if (googlers[i]==0&&values[2]!=0) continue; if(value>=values[2]) total++; else if(remainder==0&&values[1]>0&&(value+1)>=values[2]){ values[1]--; total++; } else if(remainder>0&&(value+1)>=values[2]) total++; else if(remainder==2&&(value+2)>=values[2]&&values[1]>0){ total++; values[1]--; } } System.out.println(total); } }
0
1,189,726
A11759
A11807
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.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; /** * Qualification B * @author Cristian Piacente */ public class QualificationB { public static void main(String args[]) { /*for (int i = 20; i < 24; i++) { System.out.println("Value:" + i); Case c = new Case(i); System.out.println(c.isDot0()); System.out.println(c.isDot33()); System.out.println(c.isDot66()); System.out.println("Medium value:" + c.getMediumValue()); System.out.println("Normal value:" + c.getNormalValue()); System.out.println("Special value:" + c.getSpecialCaseValue()); }*/ try { //Read input file and translate BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\B-small-attempt0.in"))); BufferedWriter pw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("c:\\output.txt"))); int ncases = Integer.parseInt(br.readLine()); for (int ccase = 0; ccase < ncases; ccase++) { ArrayList<Case> cases=new ArrayList<Case>(); String line = br.readLine(); StringTokenizer st=new StringTokenizer(line," "); int googlers=Integer.parseInt(st.nextToken()); int specialCases=Integer.parseInt(st.nextToken()); int minVal=Integer.parseInt(st.nextToken()); int result=0; for(int k=0;k<googlers;k++){ cases.add(new Case(Integer.parseInt(st.nextToken()))); } Collections.sort(cases, new NormalCaseComparator()); /* * First find out how many are already ok, and remove them */ for(int i=0;i<cases.size();i++){ Case c = cases.get(i); if(c.getNormalValue()>=minVal){ cases.remove(i); result++; i--; continue; } } /* * Then based on the max num of specialCase explore their special value */ for(int i=0;i<cases.size() && result<=googlers && specialCases>0;i++){ Case c = cases.get(i); if(c.getSpecialCaseValue()>=minVal){ cases.remove(i); result++; specialCases--; i--; } } pw.write("Case #"+(ccase+1)+": "+result+"\r\n"); } br.close(); pw.close(); } catch (IOException ex) { Logger.getLogger(Qualification.class.getName()).log(Level.SEVERE, null, ex); } } } class Case { boolean dot66 = false; boolean dot33 = false; boolean dot0 = false; private int value = -1; private int mediumValue; private float mediumFloatValue; public Case(int value) { this.value = value; this.mediumFloatValue=this.value/3f; this.mediumValue = (int) Math.floor(this.value / 3f); if (this.value / 3f - (int) Math.floor(this.value / 3f) == 0) { dot0 = true; } else { if (this.value / 3f - (int) Math.floor(this.value / 3f) > 0.4f) { dot66 = true; } else { dot33 = true; } } } public boolean isDot0() { return dot0; } public boolean isDot33() { return dot33; } public boolean isDot66() { return dot66; } public int getMediumValue() { return mediumValue; } public void setMediumValue(int mediumValue) { this.mediumValue = mediumValue; } public int getNormalValue() { if(this.value==0){ return 0; } if (isDot0()) { return mediumValue; } else { if (isDot66()) { return mediumValue + 1; } else { return mediumValue + 1; } } } public int getSpecialCaseValue() { if(this.value==0){ return 0; } if (isDot0()) { return mediumValue + 1; } else { if (isDot66()) { return mediumValue + 2; } else { return mediumValue + 1; } } } public int getValue() { return value; } public void setValue(int value) { this.value = value; } public float getMediumFloatValue() { return mediumFloatValue; } } class NormalCaseComparator implements Comparator<Case>{ @Override public int compare(Case o1, Case o2) { if(o1.getNormalValue()==o2.getNormalValue()){ return 0; } else{ if(o1.getNormalValue()>o2.getNormalValue()){ return -1; } else{ return 1; } } } } class SpecialCaseComparator implements Comparator<Case>{ @Override public int compare(Case o1, Case o2) { if(o1.getSpecialCaseValue()==o2.getSpecialCaseValue()){ return 0; } else{ if(o1.getSpecialCaseValue()>o2.getSpecialCaseValue()){ return -1; } else{ return 1; } } } }
0
1,189,727
A11759
A10424
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 Sort { public static int partition(int[] m, int a, int b) { int i = a; for (int j = a; j <= b; j++) // ïðîñìàòðèâàåì ñ a ïî b { if (m[j] >= m[b]) // åñëè ýëåìåíò a[j] íå ïðåâîñõîäèò // a[b], { int t = m[i]; // ìåíÿåì ìåñòàìè a[j] è a[a], a[a+1], a[a+2] è // òàê äàëåå... m[i] = m[j]; // òî åñòü ïåðåíîñèì ýëåìåíòû ìåíüøèå a[b] â // íà÷àëî, m[j] = t; // à çàòåì è ñàì a[b] «ñâåðõó» i++; // òàêèì îáðàçîì ïîñëåäíèé îáìåí: a[b] è a[i], ïîñëå ÷åãî // i++ } } return i - 1; // â èíäåêñå i õðàíèòñÿ <íîâàÿ ïîçèöèÿ ýëåìåíòà a[b]> + 1 } public static void quicksort(int[] m, int a, int b) // a - íà÷àëî ïîäìíîæåñòâà, // b - // êîíåö { // äëÿ ïåðâîãî âûçîâà: a = 0, b = <ýëåìåíòîâ â ìàññèâå> - 1 if (a >= b) return; int c = partition(m, a, b); quicksort(m, a, c - 1); quicksort(m, c + 1, b); } }
0
1,189,728
A11759
A11591
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.IOException; import java.util.*; public class Dancers { /** * @param args */ private static Hashtable<Integer, int[]> ns = new Hashtable<Integer, int[]>(); private static Hashtable<Integer, int[]> s = new Hashtable<Integer, int[]>(); public static void main(String[] args) { // TODO Auto-generated method stub int tests; try{ BufferedReader stdin = new BufferedReader(new FileReader(args[0])); tests = Integer.parseInt(stdin.readLine()); for(int i = 0; i < tests; i++){ System.out.print("Case #"+(i+1) + ": "); solve(stdin.readLine()); System.out.println(); } }catch(IOException e){ e.printStackTrace(); } System.exit(0); } private static void solve(String in){ String[] det = in.split(" "); int googlers = Integer.parseInt(det[0]); int surprises = Integer.parseInt(det[1]); int p = Integer.parseInt(det[2]); int max = 0; for(int i = 3; i < 3+googlers; i++){ ns.clear(); s.clear(); analyze(i, Integer.parseInt(det[i])); switch(inclusion(i, p)){ case 2: max +=1; break; case 1: if(surprises>=1) { max += 1; surprises -= 1;} break; default: break; } } System.out.print(max); } public static void analyze(int googler, int n){ HashSet<Integer> h = new HashSet<Integer>(); for(int i = Math.max(0, n/3 - 1); i <= Math.min(n/3 + 1, 10); i++){ for(int j = Math.max(0, (n-i)/2 - 1); j <= Math.min((n-i)/2 + 1, 10); j++){ for(int k = Math.max(0, (n-i-j) - 1); k <= Math.min(n-i-j + 1, 10); k++){ if(n == i + j + k && !h.contains(new Integer(i*100 + j*10 + k))){ //System.out.println(i + "," + j + "," + k); if(categorize(googler,i,j,k)) addPerms(i,j,k,h); } } } } } private static void addPerms(int i, int j, int k, HashSet<Integer> h){ h.add(new Integer(100*i + 10*j + k)); h.add(new Integer(100*i +10*k + j)); h.add(new Integer(100*j + 10*i + k)); h.add(new Integer(100*j + 10*k + i)); h.add(new Integer(100*k + 10*i + j)); h.add(new Integer(100*k + 10*j + i)); } public static boolean categorize(int googler, int i, int j, int k){ if(Math.abs(i-j)<2 && Math.abs(i-k)<2 && Math.abs(j-k)<2){ int[] arr = {i,j,k}; ns.put(new Integer(googler),arr); return true; } else if((Math.abs(i-j)==2 && Math.abs(i-k)<=2 && Math.abs(j-k)<=2) || (Math.abs(i-k)==2 && Math.abs(i-j)<=2 && Math.abs(j-k)<=2) || (Math.abs(j-k)==2 && Math.abs(i-j)<=2 && Math.abs(i-k)<=2)){ int[] arr = {i,j,k}; s.put(new Integer(googler), arr); return true; } return false; } private static byte inclusion(int googler, int p){ int[] sur = s.get(new Integer(googler)); int[] nsur = ns.get(new Integer(googler)); boolean withSur = false; boolean withoutSur = false; for(int i = 0; i < 3; i++){ if(sur != null && sur[i] >= p) withSur = true; if(nsur[i] >= p) withoutSur = true; } if(withoutSur) return 2; else if(withSur) return 1; else return 0; } }
0
1,189,729
A11759
A12682
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 b { static int n,s,p; static int[] v; static int[][] memo; public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for(int t=1; t<=T; t++) { n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); v = new int[n]; for(int i=0; i<n; i++) v[i] = in.nextInt(); memo = new int[n][s+1]; for(int[] x : memo) Arrays.fill(x,-1); System.out.printf("Case #%d: %d%n", t, go(0,s)); } } static int go(int pos, int left) { if(left < 0) return -10000; if(pos == n) return left == 0 ? 0:-10000; if(memo[pos][left] != -1) return memo[pos][left]; int best = -10000; for(int i=0; i<=10; i++) for(int j=i; j<=i+2; j++) for(int k=j; k<=i+2; k++) if(i+j+k==v[pos]) { int sup = 0; if(k-i==2) sup = 1; int win = 0; if(k >= p) win = 1; best = Math.max(best,win+go(pos+1,left-sup)); } return memo[pos][left] = best; } }
0
1,189,730
A11759
A12954
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.FileWriter; import java.io.IOException; public class OutputPrinter { public OutputPrinter() { try { m_writer = new FileWriter("C:/AHK/output.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } FileWriter m_writer; int m_case = 1; public void print(String result) { try { m_writer.write("Case #"+ (m_case++)+": " + result + "\n"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
1,189,731
A11759
A10405
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; import java.io.*; public class FileRead { String fileName; FileReader fr; BufferedReader br; FileRead(String fileName) { this.fileName=fileName; File f=new File("K:\\CodeJam\\Input\\"+fileName);//Create a file object FileReader fr; try { fr = new FileReader(f); br=new BufferedReader(fr); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } //function to read next line. public String readNextLine(){ String text=null; try { text=br.readLine(); } catch (IOException e) { e.printStackTrace(); } return text; } public int readNextInt(){ int n = 0; try{ n=Integer.parseInt(br.readLine().trim()); }catch(Exception e){ System.out.println("Invalid integer"); } return n; } public int [] readNextIntArray(){ int []n=null; try{ String []numarray=br.readLine().split(" "); n=new int[numarray.length]; for(int i=0;i<numarray.length;i++){ n[i]=Integer.parseInt(numarray[i].trim()); } }catch(Exception e){ System.out.println("Invalid integer"); } return n; } public void close(){ try { //fr.close(); br.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
1,189,732
A11759
A10640
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.util.HashMap; import java.util.Scanner; public class DanceWithGoogler { public static void main(String[] args) { try { Scanner sc = new Scanner(new File("Redownload B-small.in.txt")); int T = 0; FileWriter fw = new FileWriter("output.txt"); T = Integer.parseInt(sc.nextLine()); for (int i = 1; i <= T; i++) { fw.append("Case #" + i + ": " + hadleCase(i, sc.nextLine()) + "\n"); } fw.close(); } catch (Exception e) { } } private static int hadleCase(int line, String next) { String[] param = next.split(" "); int N = Integer.parseInt(param[0]); int S = Integer.parseInt(param[1]); int P = Integer.parseInt(param[2]); int y = 0; HashMap<Integer, Integer[]> map = new HashMap<Integer, Integer[]>(); for (int i = 0; i < N; i++) { int score_total = Integer.parseInt(param[i + 3]); int score_avg = score_total / 3; int score_remain = score_total % 3; map.put(i, new Integer[] { score_avg, score_remain }); } for (int key : map.keySet()) { Integer[] score = map.get(key); int score_avg = score[0]; int score_remain = score[1]; if (score_avg < P && (score_avg > 0 || score_remain > 0)) { if ((score_avg + 1) >= P) { int score_total = Integer.parseInt(param[key + 3]); int big = score_avg + 1; int mid = (score_total - big) / 2; int small = score_total - big - mid; if (big - small <= 1 && big - mid <= 1) { score_avg += 1; } else if (S > 0 && big - small <= 2 && big - mid <= 2) { score_avg += 1; S--; } } else if (S > 0 && (score_avg + 2) >= P && (score_avg + 2) <= 30) { int score_total = Integer.parseInt(param[key + 3]); int big = score_avg + 2; int mid = (score_total - big) / 2; int small = score_total - big - mid; if (big - small <= 2 && big - mid <= 2) { score_avg += 2; S--; } } } if (score_avg >= P) { y++; } } return y; } }
0
1,189,733
A11759
A12008
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.utility; public enum Constants { BLANK(""), SPACE_REG_EXP("\\s+"), RESOURCES_LOCATION("/Users/sandeep/Work/WorkSpace/Sample/src/main/resources/"); private void Constants() { } private Constants(String constant) { this.constant = constant; } private String constant; public String getConstant() { return constant; } public void setConstant(String constant) { this.constant = constant; } }
0
1,189,734
A11759
A11582
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.ArrayList; import java.util.Arrays; public class p2 { public static void main(String args[]) throws Exception { String inputPath = "D:\\B-small-attempt0.in"; String outputPath = "D:\\abc.out"; p2 dwg = new p2(); String[] str = dwg.readFromFile(inputPath); str = dwg.solution(str); dwg.writeToFile(outputPath, str); } private String[] solution(String[] str){ String[] strNew = new String[str.length-1]; for(int i=0; i<strNew.length; i++){ strNew[i] = "Case #" +(i+1)+ ": " + find(str[i + 1]); } return strNew; } public int find(String str){ String s1[] = str.split(" "); int n = Integer.parseInt(s1[0]); int s = Integer.parseInt(s1[1]); int p = Integer.parseInt(s1[2]); int y=0; int[] t = new int[n]; for(int i=0; i<n; i++){ t[i] = Integer.parseInt(s1[i+3]); } Arrays.sort(t); for(int x : t){ int max1=0; int max2=0; if(x < 2){ max1=max2=x; } else if(x==2){ max1=1; if(s > 0){ max2=2; } if(max2 >= p){ s--; } } else if(x%3 == 0){ max1 = x/3; if(s > 0 && max1<p){ max2 = x/3 + 1; if(max2 >= p){ s--; } } } else if(x%3 == 1){ max1 = x/3 + 1; } else{ max1 = x/3 + 1; if(s > 0 && (x/3 + 2) <= 10 && max1<p){ max2 = x/3 + 2; if(max2 >= p){ s--; } } } if(max1>=p || max2>=p){ y++; } } return y; } public String[] readFromFile(String inputPath) throws FileNotFoundException,IOException { FileInputStream fis = null; DataInputStream dis = null; BufferedReader br = null; ArrayList<String> strArrList = new ArrayList<String>(); try{ fis = new FileInputStream(inputPath); dis = new DataInputStream(fis); br = new BufferedReader(new InputStreamReader(dis)); String strLine; while ((strLine = br.readLine()) != null) { strArrList.add(strLine); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ try{ if (br != null) { br.close(); } if (dis != null) { dis.close(); } if (fis != null) { fis.close(); } } catch(IOException e) { e.printStackTrace(); } } return strArrList.toArray(new String[strArrList.size()]); } public void writeToFile(String outputPath, String[] strArr) { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(outputPath)); for(int i=0; i<strArr.length; i++){ bw.write(strArr[i]); bw.newLine(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (bw != null) { bw.flush(); bw.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
0
1,189,735
A11759
A12538
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 small; 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 javax.swing.plaf.basic.BasicInternalFrameTitlePane.MaximizeAction; public class DancingGooglers { private static int noOfCases; private static int[] noOfGooglers; private static int[] noOfSurprisingTriplets; private static int[] bestResult; private static int[][] scores; private static String[] result; public static void main(String[] args) { readInputFile(); result = new String[noOfCases]; for (int i = 0; i < noOfCases; i++) { int totalSum = 0; int surprisingCount = 0; for (int j = 0; j < noOfGooglers[i]; j++) { // System.out.print(" "+scores[i][j]); if (scores[i][j] >= bestResult[i]) { if ((scores[i][j] - bestResult[i]) / 2 >= bestResult[i] - 2) { totalSum++; if ((scores[i][j] - bestResult[i]) / 2 == bestResult[i] - 2) { surprisingCount++; } } } } if (surprisingCount > noOfSurprisingTriplets[i]) { totalSum = totalSum - (surprisingCount - noOfSurprisingTriplets[i]); } System.out.println(); System.out.println("Case #" + (i + 1) + ": " + totalSum); result[i] = "Case #" + (i + 1) + ": " + totalSum; } writeToFile(result); } private static void readInputFile() { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); noOfCases = Integer.parseInt(br.readLine()); String strLine; scores = new int[noOfCases][]; noOfGooglers = new int[noOfCases]; noOfSurprisingTriplets = new int[noOfCases]; bestResult = new int[noOfCases]; for (int i = 0; i < noOfCases; i++) { strLine = br.readLine(); String[] temp = strLine.split(" "); noOfGooglers[i] = Integer.parseInt(temp[0]); noOfSurprisingTriplets[i] = Integer.parseInt(temp[1]); bestResult[i] = Integer.parseInt(temp[2]); scores[i] = new int[noOfGooglers[i]]; // System.out.println("No of Googlers: "+noOfGooglers); // System.out.println("No of surp trip: "+noOfSurprisingTriplets); // System.out.println("Best Result: "+bestResult); for (int j = 0; j < noOfGooglers[i]; j++) { scores[i][j] = Integer.parseInt(temp[3 + j]); System.out.println(scores[i][j]); } } in.close(); } catch (Exception e) { e.printStackTrace(); System.err.println("Error: " + e.getMessage()); } } public static void writeToFile(String args[]) { try { FileWriter fstream = new FileWriter("B-small-attempt0.out"); BufferedWriter out = new BufferedWriter(fstream); for (int i = 0; i < args.length; i++) { out.write(args[i]); if (i != args.length - 1) out.newLine(); } out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
1,189,736
A11759
A12644
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 jp.ne.sakura.yuki2006.CodeJam; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class CodeJam { private FileWriter file; static int caseNumber = 0; private Scanner stdIn; private void write(String data) { caseNumber++; try { file.append("Case #"); file.append(String.valueOf(caseNumber)); file.append(": "); file.append(data); file.append("\n"); file.flush(); } catch (IOException e) { // TODO 自動生成された catch ブロック e.printStackTrace(); } } public CodeJam(ITestCase test, String fileName) { try { file = new FileWriter(fileName); } catch (IOException e) { e.printStackTrace(); } stdIn = new Scanner(System.in); stdIn.nextLine(); while (stdIn.hasNext()) { write(test.testCase(stdIn)); } } }
0
1,189,737
A11759
A12497
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 judgescore; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Kocmi */ public class JudgeScore { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st; st = new StringTokenizer(br.readLine()); int tests = Integer.parseInt(st.nextToken()); int[] results = new int[tests]; //final result int dancers, surprises, limit; int[] scores; for (int i = 0; i < tests; i++) { st = new StringTokenizer(br.readLine()); dancers = Integer.parseInt(st.nextToken()); surprises = Integer.parseInt(st.nextToken()); limit = Integer.parseInt(st.nextToken()); scores = new int[dancers]; for (int j = 0; j < dancers; j++) { scores[j] = Integer.parseInt(st.nextToken()); } results[i] = bestscore(scores, surprises, limit); } for (int i = 0; i < tests; i++) { System.out.println("Case #"+(i+1)+": "+results[i]); } } catch (Exception ex) { } } public static int bestscore(int[] scores,int surprises,int limit){ int score = 0; int ifsur = 0; int root, rest; for (int i = 0; i < scores.length; i++) { root = scores[i]/3; rest = scores[i]%3; if(scores[i]==0){ if(root>=limit){ score++; } }else if(rest==0){ if(root>=limit){ score++; }else{ if((root+1)>=limit){ ifsur++; } } }else if(rest==1){ if((root+1)>=limit){ score++; } }else{ if((root+1)>=limit){ score++; }else{ if((root+2)>=limit){ ifsur++; } } } } if(ifsur<=surprises){ return (score+ifsur); }else{ return (score+surprises); } } }
0
1,189,738
A11759
A10588
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.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc=new Scanner(new FileInputStream(args[0])); BufferedWriter bw=new BufferedWriter(new FileWriter(args[1])); int testCases=sc.nextInt(); for(int i=0;i<testCases;i++) { int cnt1=0; int best=0; int n=sc.nextInt(); int a1[]=new int[n]; int surprise=sc.nextInt(); int limit=sc.nextInt(); for(int j=0;j<n;j++) { a1[j]=sc.nextInt(); } for(int q=0;q<n;q++) { /*System.out.println("The value of array is "+a1[q]); */ } int array1[][]=new int[n][3]; for(int j=0;j<n;j++) { array1[j][0]=a1[j]/3; int t=a1[j]-array1[j][0]; int data1=t/2; int data2=t-data1; if(a1[j]!=0) { if(data1-data2==0) { if(limit-data1==1) { if(cnt1<surprise) { cnt1++; best++; array1[j][1]=data1--; array1[j][2]=data2++; } else { array1[j][1]=data1; array1[j][2]=data2; } } else if (limit-data1==0) { array1[j][1]=data1; array1[j][2]=data2; best++; } else if(limit-data1>1) { array1[j][1]=data1; array1[j][2]=data2; } else if(limit-data1<0) { array1[j][1]=data1; array1[j][2]=data2; best++; } } else if((data2-data1)==1) { if(limit<=data2) { array1[j][1]=data1; array1[j][2]=data2; best++; } else { array1[j][1]=data1; array1[j][2]=data2; } } } else{ if(limit==0) { best++; } } } bw.write("Case #"+(i+1)+": " +best); bw.newLine(); bw.flush(); } bw.close(); } }
0
1,189,739
A11759
A10220
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()); } } }
// no.of users // no. of sets // minimum best // scores import java.io.*; import java.util.Scanner; public class abc { public static void main(String args[]) { try{ FileWriter fstream = new FileWriter("outB.out"); FileInputStream fstream1=new FileInputStream("B-small-attempt1.in"); DataInputStream in=new DataInputStream(fstream1); BufferedReader input=new BufferedReader(new InputStreamReader(in)); BufferedWriter out = new BufferedWriter(fstream); String strLine; strLine=input.readLine(); int T=Integer.parseInt(strLine); int j=1; while(j<=T) { int N,S,P; strLine=input.readLine(); String[] numbers=strLine.split(" "); int nums[]=new int[numbers.length]; N=Integer.parseInt(numbers[0]); S=Integer.parseInt(numbers[1]); P=Integer.parseInt(numbers[2]); int Score[]=new int[N]; int i=0; for( i=0;i<N;i++){ Score[i]=Integer.parseInt(numbers[i+3]); } int Flag=0; int avg; int rem=0; for(i=0;i<N;i++) { avg=Score[i]/3; //System.out.print(avg); rem=Score[i]%3; //System.out.print(rem); switch(rem) { case 0: { if(P<=avg) Flag=Flag+1; else if(P==avg+1&&S>0&&avg!=0) { S=S-1; Flag=Flag+1;} break; } case 1: { if(P<=avg+1) Flag=Flag+1; break; } case 2: { if(P<=avg+1) Flag=Flag+1; if(P==avg+2&&S>0) { S=S-1; Flag=Flag+1; } break; } } //switch close //System.out.println(Flag); } //System.out.println(Flag); out.write("Case #"+j+": "+Flag+"\r\n"); j=j+1; } out.close(); input.close();}catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
1,189,740
A11759
A11650
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 uk.co.epii.codejam.common; import java.io.IOException; /** * * @author jim */ public class AbstractMain { public static void main(String[] args, AbstractProcessor p) { FileLoader fileLoader = new FileLoader(); try { Input input = new Input(fileLoader.loadFile(args[0]), 1); Output output = p.process(input); output.export(args.length < 2 ? null : args[1]); } catch (IOException ioe) { System.out.println(ioe); ioe.printStackTrace(); } } }
0
1,189,741
A11759
A11226
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; /** * author - coolprosu * Problem - B */ public class DancingWithTheGooglers { private int T = 0; int N[], S[], p[], t[][]; public static void main(String[] args) { DancingWithTheGooglers solveProb = new DancingWithTheGooglers(); solveProb.solve(); } private void solve() { Scanner sc = new Scanner(System.in); //Input no. of test cases T = sc.nextInt(); //Solved strings String solutionArray[] = new String[T]; N = new int[T]; S = new int[T]; p = new int[T]; t = new int[T][]; for(int i=0;i<T;i++) { solutionArray[i] = "Case #"+(i+1)+": "; N[i] = sc.nextInt(); S[i] = sc.nextInt(); p[i] = sc.nextInt(); t[i] = new int[N[i]]; for(int j=0;j<N[i];j++) { t[i][j] = sc.nextInt(); } solutionArray[i] += solveCase(N[i],S[i],p[i],t[i]); } //Output result for(int i=0;i<T;i++) { System.out.println(solutionArray[i]); } } private int solveCase(int N, int S, int p, int t[]) { int maxPossibility = 0; /** * Eliminitation */ //Reject impossible cases (where total points <= (p+p-2+p-2)) int possibleN = 0; int possibleT[] = new int [N]; int minPossibleTotal = p+p-2+p-2; minPossibleTotal = (p>minPossibleTotal)?p:minPossibleTotal; //minPossibleTotal should be at least p for(int i=0;i<N;i++) { if(t[i]>=minPossibleTotal) { possibleT[possibleN++] = t[i]; //System.out.println("Possible:"+t[i]+" Possible N:"+possibleN); } } // Run recursion maxPossibility = solveRecursion(possibleN, S, p, possibleT, 0, 0); return maxPossibility; } private int solveRecursion(int N, int S, int p, int t[], int surpriseScoreCount, int currN) { //System.out.println(currN+" "+t[currN]); if(currN>=N) return 0; int totalScore = t[currN]; int possibility = 0; int highestPossible = 0; //Find possible combinations with max. score p for(int i=-10;i<=10;i++) { for(int j=-10;j<=10;j++) { for(int k=-10;k<=10;k++) { if(totalScore==(p+i+p+j+p+k)) { //System.out.println("For:"+currN+" "+(p+i)+":"+(p+j)+":"+(p+k)); if(isValid(p,p+i,p+j,p+k)) //Check if diff >2 { if(isSurprise(p+i,p+j,p+k)) //Surprising score { if(surpriseScoreCount+1 <= S) { //System.out.println("Surprise"+" For:"+currN+" "+(p+i)+":"+(p+j)+":"+(p+k)); //Continue with recursion possibility = 1+solveRecursion(N, S, p, t, surpriseScoreCount+1, currN+1); if(possibility>highestPossible) highestPossible = possibility; } } else { //System.out.println("Possible"+" For:"+currN+" "+(p+i)+":"+(p+j)+":"+(p+k)); //Continue with recursion possibility = 1+solveRecursion(N, S, p, t, surpriseScoreCount, currN+1); if(possibility>highestPossible) highestPossible = possibility; } } } } } } if(highestPossible==0) highestPossible = solveRecursion(N, S, p, t, surpriseScoreCount+1, currN+1); return highestPossible; } private boolean isSurprise(int a, int b, int c) { return(Math.abs(a-b)==2||Math.abs(a-c)==2||Math.abs(b-c)==2); } private boolean isValid(int min, int a, int b, int c) { if(!(a>=min||b>=min||c>=min)) return false; else if(a<0||b<0||c<0) return false; else if (a>10||b>10||c>10) return false; else return(!(Math.abs(a-b)>2||Math.abs(a-c)>2||Math.abs(b-c)>2)); } }
0
1,189,742
A11759
A10162
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 CodeJam { public static void main(String[] args) { try { //recycleLarge(1000000, 2000000); // read FileInputStream instream = new FileInputStream("A-small.in"); DataInputStream in = new DataInputStream(instream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); // write FileOutputStream outstream = new FileOutputStream("A-small.out"); DataOutputStream out = new DataOutputStream(outstream); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); // reading file information int testcases = Integer.parseInt(br.readLine()); for (int i = 0; i < testcases; i++) { // ------------------------------------------------------------------------------------------------------------- String line = br.readLine(); String[] items = line.split(" "); int N = Integer.parseInt(items[0]); int S = Integer.parseInt(items[1]); int p = Integer.parseInt(items[2]); long howManyP = 0; if (p == 0) { howManyP = N; } else { for(int j=3; j<items.length; j++){ int score = Integer.parseInt(items[j]); if (p == 1){ if (score > 0) { howManyP++; } } else { int relaxedScore = (3 * p) - 2; int minimumScore = (3 * p) - 4; if (score >= relaxedScore) howManyP++; else if (score >= minimumScore && S > 0) { howManyP++; S--; } } } } // ------------------------------------------------------------------------------------------------------------- bw.write("Case #" + (i + 1) + ": " + howManyP + "\r\n"); } // close input file in.close(); // close output file bw.flush(); out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } private static void printArray(Object[] array) { for (Object ch : array) System.out.print(ch); } }
0
1,189,743
A11759
A10713
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.File; import java.io.FileOutputStream; import java.io.PrintWriter; import java.text.DecimalFormat; /** * * */ public class B { public static void main(String[] args) { try { Scanner scanner = (new Scanner(new File("c:/input.txt"))); int N = scanner.nextInt(); FileOutputStream out = new FileOutputStream("c:/output.txt"); PrintWriter wr = new PrintWriter(out); scanner.nextLine(); for (int i = 0; i < N; i++) { doCase(i+1, scanner, wr); } wr.close(); out.close(); } catch (Exception e) { System.out.println("Error: " + e.getMessage()); e.printStackTrace(); } } private static void doCase(int caseNum, Scanner scanner, PrintWriter wr) { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int notSurp = 3 * p - 2; int surp = 3 * p - 4; if (p == 1) { surp = 1; } int cnt = 0; for (int i = 0; i < N; i++) { int res = scanner.nextInt(); if (res >= notSurp) { cnt++; } else if (res >= surp) { if (S > 0) { S--; cnt++; } } } wr.println("Case #" + caseNum + ": " + cnt); } private static String formatNumber(int result, String format) { DecimalFormat f = new DecimalFormat(format); return f.format(result); } }
0
1,189,744
A11759
A11125
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 QualRound; 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; public class DancingWiththeGooglers { String inFile = "c:/temp/DancingWiththeGooglers/B-small-attempt0.in"; String outFile = "c:/temp/DancingWiththeGooglers/B-small-attempt0.out"; ArrayList<String> input = new ArrayList<String>(); ArrayList<String> output = new ArrayList<String>(); int T; public DancingWiththeGooglers(){ input = readInput(); process(input); createOutputFile(output); } public void process(ArrayList<String> input){ T = Integer.valueOf(input.get(0)); for(int i = 1; i<input.size();i++){ String[] temp = input.get(i).split(" "); output.add(String.valueOf(solveTest(temp))); } } public int solveTest(String[] temp){ int N = Integer.valueOf(temp[0]); int S = Integer.valueOf(temp[1]); int P = Integer.valueOf(temp[2]); int result = 0; for(int i = 3; i<temp.length; i++){ int value = Integer.valueOf(temp[i]); if(value%3==0){ if(value/3>=P){ result++; }else if(value/3+1<=10 && value/3+1>=P && S>0 && value/3-1>=0){ S--; result++; } } if(value - 3*(value/3)==2){ if(value/3+1>=P){ result++; } else if(value/3+2>=P && value/3+2<=10 && S>0){ S--; result++; } } if(value - 3*(value/3)==1){ if(value/3+1>=P){ result++; } } } return result; } public void createOutputFile(ArrayList<String> output){ try{ FileWriter fstream = new FileWriter(outFile); BufferedWriter out = new BufferedWriter(fstream); int i = 1; for(String str : output) { out.write("Case #"+i+": "); out.write(str); out.newLine(); i++; } out.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public ArrayList<String> readInput(){ ArrayList<String> inp = new ArrayList<String>(); try{ FileInputStream fstream = new FileInputStream(inFile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //T = Integer.parseInt(br.readLine()); while ((strLine = br.readLine()) != null) { inp.add(strLine); } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } return inp; } public static void main(String[] args) { DancingWiththeGooglers dancingWiththeGooglers = new DancingWiththeGooglers(); } }
0
1,189,745
A11759
A11941
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.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.ArrayList; public class OutputFile { public void writeFile(ArrayList<String> data) throws Exception { File file = new File("C:\\Users\\Nikhil\\Desktop\\googleCodeJam\\output.txt"); BufferedWriter bufferedReader = new BufferedWriter(new FileWriter(file)); for(int i=0;i<data.size();i++) { bufferedReader.write(data.get(i)); bufferedReader.newLine(); } bufferedReader.flush(); } }
0
1,189,746
A11759
A10282
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 qual1; import java.io.*; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws IOException { for (int i=0; i<=10; i++) { System.out.println(Math.max((i-2)+(i-2)+i,i)); } // Use BufferedReader rather than RandomAccessFile; it's much faster BufferedReader f = new BufferedReader(new FileReader("B-small-attempt4.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("B-small-attempt4.out"))); HashMap<Integer, ArrayList<String>> debug = new HashMap<Integer, ArrayList<String>>(); int cases = Integer.parseInt(f.readLine()); for (int zz = 1; zz <= cases; zz++) { String x = f.readLine(); StringTokenizer st = new StringTokenizer(x); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); //At least p for BEST score. int[] points = new int[n]; int ans = 0; // Assume p = 5 int magicNum = Math.max((p - 2) + (p - 2) + p,p); // 3 3 5 or 3 4 5 // magicNum and MagicNum+1 are always be surprising // 3 5 5 or 4 4 5 // magicNum+2 may be surprising or not. //p=0 -2 -2 0 //p=1 -1 -1 1 //p=2 0 0 2 //p=3 1 1 3 //p=4 2 2 4 for (int xx = 0; xx < n; xx++) { points[xx] = Integer.parseInt(st.nextToken()); if (p==0 || p==1) { if (points[xx]>=p) ans++; continue; } if (s > 0 && (points[xx] == magicNum || points[xx] == magicNum + 1)) { s--; ans++; } else if (points[xx] >= magicNum + 2) { ans++; } } out.println("Case #" + zz + ": " + ans); } out.close(); // close the output file System.exit(0); // don't omit this! } }
0
1,189,747
A11759
A11555
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 GoogJam2 { public static void main(String args[]) { try{ BufferedReader br=new BufferedReader(new FileReader(args[0])); int T=Integer.parseInt(br.readLine()); BufferedWriter bw=new BufferedWriter(new FileWriter("output.txt",true)); for(int i1=0;i1<T;i1++) { String st=br.readLine(); String sam[]=st.split(" "); int N=Integer.parseInt(sam[0]); int s=Integer.parseInt(sam[1]); int p=Integer.parseInt(sam[2]); int a[]=new int[N]; for(int k=0;k<N;k++) {a[k]=Integer.parseInt(sam[k+3]); } int b[][]=new int[N][2]; int count=0; for(int i=0;i<N;i++) { b[i][0]=a[i]/3; b[i][1]=a[i]%3; //System.out.println(b[i][0]+" "+b[i][1]+"\n"); } for(int i=0;i<N;i++) { if((b[i][0]>=p)||((b[i][0]==p-1)&&(b[i][1]==1))||((b[i][0]==p-1)&&(b[i][1]==2))) {//System.out.println("c1"); count++; } else if(s>0) { if((b[i][0]==p-1)&&(b[i][1]==0)) {if(a[i]>=1) {//System.out.println(b[i][0]+" c2"); count++; s--; } } else if((b[i][0]==p-2)&&(b[i][1]==2)) {//System.out.println(b[i][0]+" "+b[i][1]+"\n"); if(a[i]>=2) {//System.out.println(b[i][0]+" c2"); count++; s--; } } } } bw.write("Case #"+(i1+1)+": "+count+"\n"); //System.out.println(count); } bw.close(); br.close(); } catch(Exception e) {} } }
0
1,189,748
A11759
A10849
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 CodeJam2012; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class Q2 { public static void main(String[] args) throws IOException { FileReader buf = new FileReader("Input.in"); BufferedReader br = new BufferedReader(buf); int cases = Integer.parseInt(br.readLine()); String[] outputs = new String[cases]; for (int i = 1; i <= cases; i++) { String input = br.readLine(); String[] splits = input.split(" "); int N = Integer.parseInt(splits[0]); int S = Integer.parseInt(splits[1]); int p = Integer.parseInt(splits[2]); int thresh = 0; int special = S; int[] points = new int[splits.length - 3]; for (int k = 0; k < points.length; k++) { points[k] = Integer.parseInt(splits[k + 3]); } for (int j = 0; j < points.length; j++) { int v = (int) (points[j] / 3); int rem = points[j] % 3; switch (rem) { case 2: if (v + 1 >= p || v >= p) { thresh++; } else if (special > 0 && v + 2 >= p) { thresh++; special--; } break; case 1: if (v >= p || v + 1 >= p) { thresh++; } else if (special > 0 && v + 1 >= p) { thresh++; special--; } break; case 0: if (v >= p) { thresh++; } else if (special > 0 && v > 0 && v + 1 >= p) { thresh++; special--; } break; } } if (i != cases) outputs[i - 1] = "Case #" + i + ": " + thresh + "\n"; else outputs[i - 1] = "Case #" + i + ": " + thresh; } br.close(); buf.close(); FileWriter buf1 = new FileWriter(new File("OutputDance.txt"), true); BufferedWriter bw1 = new BufferedWriter(buf1); for (int i = 0; i < cases; i++) { bw1.write(outputs[i]); } bw1.close(); buf1.close(); } }
0
1,189,749
A11759
A10702
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 Test { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in, "UTF-8")); int num = Integer.parseInt(br.readLine()); int nline = 1; String line; while ((line = br.readLine()) != null && nline <=num) { String[] tok = line.split(" "); int N = Integer.parseInt(tok[0]); int S = Integer.parseInt(tok[1]); int p = Integer.parseInt(tok[2]); int max = N; if (p == 1) { for (int i = 3; i < N+3; i++) { if ((Integer.parseInt(tok[i]) == 0)) { --max; } } } if (p >= 2) { for (int i = 3; i < N+3; i++) { if (Integer.parseInt(tok[i]) <= 3*p-5) { --max; } if ((Integer.parseInt(tok[i]) == 3*p-3) || (Integer.parseInt(tok[i]) == 3*p-4)) { if (S > 0) --S; else --max; } } } System.out.println("Case #" + nline + ": " + max); nline++; } } }
0
1,189,750
A11759
A11489
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; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class ProblemB { public static int solve(String in){ int n; int s; int p; int need = 0; int count = 0; String[] segs = in.split("\\s+"); n = Integer.parseInt(segs[0]); s = Integer.parseInt(segs[1]); p = Integer.parseInt(segs[2]); for (int i = 3; i < segs.length; i++){ int score = Integer.parseInt(segs[i]); if (score >= 3*p && p >= 0) count++; else if (score >= (3*p - 2) && (p >= 1)) count++; else if (score >= (3*p - 4) && (p >= 2)) need++; } if (need <= s) count += need; else count += s; return count; } public static void main(String[] args) { try{ BufferedReader br = new BufferedReader(new FileReader("B-small-attempt0.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("outputB")); String line = br.readLine(); int ans = 0; int num = Integer.parseInt(line); for (int i = 0; i < num; i++){ line = br.readLine(); ans = solve(line); bw.write("Case #" + (i+1) + ": " + ans + "\n"); } br.close(); bw.close(); }catch(Exception e){ e.printStackTrace(); } } }
0
1,189,751
A11759
A12760
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.Vector; public class ScoreSet implements Runnable { int NumGooglers; int NumSuprises; int BestResult; int[] Totals; int Result; public ScoreSet(String line) { String[] fields = line.split(" "); NumGooglers = Integer.parseInt(fields[0]); NumSuprises = Integer.parseInt(fields[1]); BestResult = Integer.parseInt(fields[2]); Totals = new int[NumGooglers]; for(int g = 0; g < NumGooglers; g ++) { Totals[g] = Integer.parseInt(fields[3 + g]); } } @Override public void run() { int[][][] ScoreSet = new int[NumGooglers][][]; for(int g = 0; g < NumGooglers; g ++) { ScoreSet[g] = GenerateScore(Totals[g]); } int[] Tracker = new int[NumGooglers]; int Best = 0; do { int supprise = 0; for(int g = 0; g < NumGooglers; g ++) { if(isSuprise(ScoreSet[g][Tracker[g]])) { supprise ++; } } if(supprise == NumSuprises) { int thisBest = 0; for(int g = 0; g < NumGooglers; g ++) { for(int s = 0; s < 3; s ++) { if(getBest(ScoreSet[g][Tracker[g]]) >= BestResult) { thisBest ++; break; } } } if(thisBest > Best) Best = thisBest; } }while(incrementTracker(Tracker, ScoreSet, NumGooglers -1)); Result = Best; } public int getResult() { return Result; } private boolean isValid(int[] Score) { if(Math.abs(Score[0] - Score[1]) > 2) return false; else if(Math.abs(Score[0] - Score[2]) > 2) return false; else if(Math.abs(Score[1] - Score[2]) > 2) return false; else return true; } private boolean isSuprise(int[] Score) { if(Math.abs(Score[0] - Score[1]) > 1) return true; else if(Math.abs(Score[0] - Score[2]) > 1) return true; else if(Math.abs(Score[1] - Score[2]) > 1) return true; else return false; } private int getBest(int[] Score) { int b = Score[0]; for(int i = 1; i < Score.length; i ++) { if( b < Score[i]) b = Score[i]; } return b; } private int[][] GenerateScore(int _Total) { Vector<int[]> Scores = new Vector<int[]>(); int[][] S; for(int a = 0; a < 11; a ++) { for(int b = 0; b < 11; b ++) { for(int c = 0; c < 11; c ++) { if(a + b + c == _Total) { int[] s = new int[] {a,b,c}; if(isValid(s)) Scores.add(s); } } } } S = new int[Scores.size()][3]; Scores.toArray(S); return S; } private boolean incrementTracker(int[] Track, int[][][] ScoreSet, int index) { if(index < 0) return false; Track[index] ++; if(Track[index] == ScoreSet[index].length) { Track[index] = 0; return incrementTracker(Track, ScoreSet, index - 1); } else return true; } }
0
1,189,752
A11759
A10622
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 codejam; import java.io.*; /** * * @author wijebandara */ public class DancingWithTheGooglers { public static void main(String[] args) throws FileNotFoundException, IOException { //java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in)); java.io.BufferedReader in=new java.io.BufferedReader(new java.io.FileReader("/home/wijebandara/Desktop/B-small-attempt0.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("/home/wijebandara/Desktop/B-small-attempt0.out"))); int n = Integer.parseInt(in.readLine()); java.util.StringTokenizer st; for (int i = 0; i < n; i++) { st = new java.util.StringTokenizer(in.readLine()); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); int c = Integer.parseInt(st.nextToken()); int answer = 0; for (int j = 0; j < a; j++) { int hold = Integer.parseInt(st.nextToken()); int s = check(hold, c); if (s == 1) { answer++; } if (s == 2 && b > 0) { b--; answer++; } } System.out.print("Case #" + (i + 1) + ": "); out.print("Case #" + (i + 1) + ": "); System.out.println(answer); out.println(answer); } out.close(); System.exit(0); } static int check(int x, int y) // 0-no,1 yes no *,2 yes yes * { if (x % 3 == 0) { if (x / 3 >= y) { // System.out.println("1"); return 1; } } if ((x - 1) % 3 == 0) { int hold = (x - 1) / 3; if (hold >= 0 && hold + 1 >= y) { //System.out.println("2"); return 1; } } if ((x - 2) % 3 == 0) { int hold = (x - 2) / 3; if (hold >= 0 && hold + 1 >= y) { //System.out.println("3"); return 1; } if (hold >= 0 && hold + 2 >= y) { //System.out.println("4"); return 2; } } if ((x - 3) % 3 == 0) { int hold = (x - 3) / 3; if (hold >= 0 && hold + 2 >= y) { // System.out.println("5"); return 2; } } if ((x - 4) % 3 == 0) { int hold = (x - 4) / 3; if (hold >= 0 && hold + 2 >= y) { //System.out.println("6"); return 2; } } return 0; } }
0
1,189,753
A11759
A12600
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 QR_2012; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class B { static BufferedWriter writer; public static void main(String[] args) throws IOException { writer = new BufferedWriter(new FileWriter("output.out")); Scanner reader = new Scanner(new FileReader("input.in")); int nt = reader.nextInt(); reader.nextLine(); for(int tc = 1; tc <= nt; tc++) { writer.write("Case #" + tc + ": "); int n = reader.nextInt(); int s = reader.nextInt(); int p = reader.nextInt(); int count = 0; for(int i = 0; i < n; i++) { int t = reader.nextInt(); if(canDoNormally(t, p)) { count++; } else if(s > 0 && canDoNormallyWith2(t, p)) { count++; s--; } } writer.write(Integer.toString(count)); writer.newLine(); } writer.close(); } static boolean canDoNormallyWith2(int t, int p) { for(int i = 3; i <= 4; i++) { if((t + i) % 3 == 0 && (t + i) / 3 >= p && (t + i) / 3 - 2 >= 0) { return true; } } return false; } static boolean canDoNormally(int t, int p) { if(t % 3 == 0 && t / 3 >= p) { return true; } if((t + 1) % 3 == 0 && (t + 1) / 3 >= p && (t + 1) / 3 - 1 >= 0) { return true; } if((t + 2) % 3 == 0 && (t + 2) / 3 >= p && (t + 2) / 3 - 1 >= 0) { return true; } return false; } }
0
1,189,754
A11759
A11813
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.codejam_2012; import java.io.*; import java.util.Arrays; import java.util.Scanner; /** * Created by IntelliJ IDEA. * User: csrazvan * Date: 14.04.2012 * Time: 02:43 * To change this template use File | Settings | File Templates. */ public class DancingWithGooglers { static private boolean DEBUG = false; public void solve() throws Exception { Scanner scanner = new Scanner(new File("dancing.in")); int t = scanner.nextInt(); scanner.nextLine(); BufferedWriter bw = new BufferedWriter(new FileWriter(new File("dancing.out"))); for (int i = 1; i <= t; i++) { String split[] = scanner.nextLine().split(" "); System.out.println("Solving " + i); solveCase(split, i, bw); } bw.close(); } public void solveCase(String[] split, int caseNr, BufferedWriter bw) throws FileNotFoundException, IOException { int n = Integer.parseInt(split[0]); int surprisingCount = Integer.parseInt(split[1]); int p = Integer.parseInt(split[2]); Case[][] matrix = new Case[n][7]; int size[] = new int[n]; for (int i = 0; i < n; i++) { int j = 0; int number = Integer.parseInt(split[3 + i]); // 1:a a a if (number % 3 == 0) { int a = number / 3; boolean ge = false; if (a >= p) { ge = true; } matrix[i][j++] = new Case(false, ge, 1); size[i]++; } // 2:a a a+1 if ((number - 1 >= 0) & ((number - 1) % 3 == 0)) { int a = (number - 1) / 3; boolean ge = false; if ((a + 1) >= p) { ge = true; } matrix[i][j++] = new Case(false, ge, 2); size[i]++; } // 3:a a+1 a+1 if ((number - 2 >= 0) & ((number - 2) % 3 == 0)) { int a = (number - 2) / 3; boolean ge = false; if ((a + 1) >= p) { ge = true; } matrix[i][j++] = new Case(false, ge, 3); size[i]++; } // 4:a a a+2 if ((number - 2 >= 0) & ((number - 2) % 3 == 0)) { int a = (number - 2) / 3; boolean ge = false; if ((a + 2) >= p) { ge = true; } matrix[i][j++] = new Case(true, ge, 4); size[i]++; } // 5:a a a+2 if ((number - 4 >= 0) & ((number - 4) % 3 == 0)) { int a = (number - 4) / 3; boolean ge = false; if ((a + 2) >= p) { ge = true; } matrix[i][j++] = new Case(true, ge, 5); size[i]++; } // 6:a a+1 a+2 if ((number - 3 >= 0) & ((number - 3) % 3 == 0)) { int a = (number - 3) / 3; boolean ge = false; if ((a + 2) >= p || (a + 1) >= p) { ge = true; } matrix[i][j++] = new Case(true, ge, 6); size[i]++; } } if (DEBUG) { for (int i = 0; i < n; i++) { for (int j = 0; j < size[i]; j++) { System.out.print(matrix[i][j] + " "); } System.out.println(); } } // a little backtracking .....:( int combinations[] = new int[n]; Arrays.fill(combinations, 0); int bestScore = 0; int k = n - 1; while (combinations[0] < size[0] && k >= 0) { // do some logic int nrStrange = 0; int bestLocal = 0; for (int i = 0; i < n; i++) { if (matrix[i][combinations[i]].hasGE) { bestLocal++; } if (matrix[i][combinations[i]].isSurprising()) { nrStrange++; } if (nrStrange > surprisingCount) { break; } } if (nrStrange == surprisingCount && bestLocal > bestScore) { bestScore = bestLocal; if (DEBUG) { System.out.println(Arrays.toString(combinations) + " - " + bestLocal); } } // next combi if (combinations[k] < size[k] - 1) { combinations[k]++; } else { combinations[k] = 0; if (k - 1 >= 0) { combinations[--k]++; }else {break;} while (k >= 1 && combinations[k] >= size[k]) { combinations[k] = 0; combinations[--k]++; } k = n - 1; } } if (bw != null) { bw.write(String.format("Case #%s: %s\n", caseNr, bestScore)); } else { System.out.println(String.format("Case #%s: %s\n", caseNr, bestScore)); } } public static void main(String[] args) { try { new DancingWithGooglers().solve(); // new DancingWithGooglers().solveCase("1 0 7 16".split(" "), 1, null); // new DancingWithGooglers().solveCase("3 1 5 15 13 11".split(" "),1,null); // new DancingWithGooglers().solveCase("3 0 8 23 22 21".split(" "),1,null); // new DancingWithGooglers().solveCase("2 1 1 8 0".split(" "),1,null); // new DancingWithGooglers().solveCase("6 2 8 29 20 8 18 18 21".split(" "), 1,null); } catch (Exception e) { e.printStackTrace(); } } } class Case { boolean surprising = false; boolean hasGE = false; int caz = 0; public int getCaz() { return caz; } public void setCaz(int caz) { this.caz = caz; } public boolean isSurprising() { return surprising; } public void setSurprising(boolean surprising) { this.surprising = surprising; } public boolean isHasGE() { return hasGE; } public void setHasGE(boolean hasGE) { this.hasGE = hasGE; } Case(boolean surprising, boolean hasGE, int caz) { this.surprising = surprising; this.hasGE = hasGE; this.caz = caz; } @Override public String toString() { return "Case{" + "surprising=" + surprising + ", hasGE=" + hasGE + ", caz=" + caz + '}'; } }
0
1,189,755
A11759
A12065
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 Dance { public static void main(String[] args) { Scanner jin=new Scanner(System.in); int numtries=jin.nextInt(); jin.nextLine(); for(int line=0; line<numtries; line++) { jin.nextInt(); int surprises=jin.nextInt(), goal=jin.nextInt(), impossible=0; //System.out.println(jin.nextLine()); String[] totals=jin.nextLine().substring(1).split(" "); //for(String it : totals) System.out.println(it); System.out.print("Case #"+(line+1)+": "); for(String each : totals) { //System.out.println("DEBUG: "+each); int total=Integer.parseInt(each), surprising=surprising(total, goal); //if(surprising) {surprises--; System.out.println(total+" comes as a surprise");} if(surprising!=1) //either tough or impossible { if(surprising==0) surprises--; //System.out.println(total+" surprising");} else impossible++; //System.out.println(total+" impossible");} //don't lose allowed surprises for impossibilities } //else System.out.println(total+" easy"); } if(surprises>=0) System.out.print(totals.length-impossible); else System.out.print(totals.length+surprises-impossible); System.out.println(); } } private static int surprising(int totalPoints, int bestScore) { if(bestScore>totalPoints) return -1; //impossible ... I can't score that well! double remaining=(totalPoints-bestScore)/2.0; if(remaining==bestScore) return 1; //unsurprising else if(remaining<bestScore) //return bestScore-(int)remaining<=1?1:0; //unsurprising or surprising, round down { int result=bestScore-(int)remaining; if(result<=1) return 1; //unsurprising else if(result<=2) return 0; //surprising else return -1; //impossible (diff gte 2) } else /*remaining>bestScore*/ return 1; //unsurprising //(int)(remaining+0.5)-bestScore>1; //round up } }
0
1,189,756
A11759
A12574
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 util; import java.math.BigInteger; public class CombinationGenerator { private int[] a; private int n; private int r; private BigInteger numLeft; private BigInteger total; //------------ // Constructor //------------ public CombinationGenerator (int n, int r) { if (r > n) { throw new IllegalArgumentException (); } if (n < 1) { throw new IllegalArgumentException (); } this.n = n; this.r = r; a = new int[r]; BigInteger nFact = getFactorial (n); BigInteger rFact = getFactorial (r); BigInteger nminusrFact = getFactorial (n - r); total = nFact.divide (rFact.multiply (nminusrFact)); reset (); } //------ // Reset //------ public void reset () { for (int i = 0; i < a.length; i++) { a[i] = i; } numLeft = new BigInteger (total.toString ()); } //------------------------------------------------ // Return number of combinations not yet generated //------------------------------------------------ public BigInteger getNumLeft () { return numLeft; } //----------------------------- // Are there more combinations? //----------------------------- public boolean hasMore () { return numLeft.compareTo (BigInteger.ZERO) == 1; } //------------------------------------ // Return total number of combinations //------------------------------------ public BigInteger getTotal () { return total; } //------------------ // Compute factorial //------------------ private static BigInteger getFactorial (int n) { BigInteger fact = BigInteger.ONE; for (int i = n; i > 1; i--) { fact = fact.multiply (new BigInteger (Integer.toString (i))); } return fact; } //-------------------------------------------------------- // Generate next combination (algorithm from Rosen p. 286) //-------------------------------------------------------- public int[] getNext () { if (numLeft.equals (total)) { numLeft = numLeft.subtract (BigInteger.ONE); return a; } int i = r - 1; while (a[i] == n - r + i) { i--; } a[i] = a[i] + 1; for (int j = i + 1; j < r; j++) { a[j] = a[i] + j - i; } numLeft = numLeft.subtract (BigInteger.ONE); return a; } }
0
1,189,757
A11759
A11408
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.PrintWriter; import java.util.ArrayList; import java.util.Scanner; public class Solver { Scanner inFile=null; PrintWriter outFile=null; int N=0;//number of googlers int S=0;//surprising triplet int p=0; int t[]; int caseNo; int candidatecount=0; public Solver(int caseNo){ this.caseNo=caseNo; } public void processInput(Scanner inFile,PrintWriter outFile){ this.inFile=inFile; this.outFile=outFile; readInput(); produceoutput(); } private void produceoutput() { outFile.printf("Case #"+caseNo+": %d\n",candidatecount); } public void readInput(){ String s=""; if(inFile.hasNext()){ //get the store credit N=Integer.parseInt(inFile.next().trim()); S=Integer.parseInt(inFile.next().trim()); p=Integer.parseInt(inFile.next().trim()); t=new int[N]; for(int i=0;i<N;i++){ t[i]=Integer.parseInt(inFile.next().trim()); Goggledance d=new Goggledance(t[i],p); if(d.isCandidate()&& !d.isSurprising()){ candidatecount++; } else if(d.isCandidate()&& d.isSurprising() && S>0){ candidatecount++; S--; } } if(inFile.hasNext())inFile.nextLine(); } } }
0
1,189,758
A11759
A12626
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.util.Scanner; public class DancingWithTheGooglersSmall { public static void main(String[] args) { File file = new File("/Users/NoK/Desktop/B-small-attempt1.in"); int counter = 1; try { Scanner sc = new Scanner(file); int numOfCases = sc.nextInt(); sc.nextLine(); for (int i = 0; i < numOfCases; i++) { int numOfGooglers = sc.nextInt(); int numOfSupTrip = sc.nextInt(); int bestScores = sc.nextInt(); int maxBestGooglers = 0; for (int j = 0; j < numOfGooglers; j++) { int googlerPoint = sc.nextInt(); if (googlerPoint == 0) { if (bestScores == 0) { maxBestGooglers++; } continue; } else if (googlerPoint == 1) { if ((bestScores == 0) || (bestScores == 1)) { maxBestGooglers++; } continue; } else if (googlerPoint == 2) { if ((bestScores == 0) || (bestScores == 1)) { maxBestGooglers++; } else if (bestScores == 2) { if (numOfSupTrip > 0) { maxBestGooglers++; numOfSupTrip--; } } continue; } if (googlerPoint % 3 == 0) { if (googlerPoint / 3 >= bestScores) { maxBestGooglers++; } else { if (numOfSupTrip > 0) { if ((googlerPoint/3)+1 == bestScores) { maxBestGooglers++; numOfSupTrip--; } } } } else if (googlerPoint % 3 == 1) { if ((googlerPoint/3)+1 >= bestScores) { maxBestGooglers++; } } else if (googlerPoint % 3 == 2) { if ((googlerPoint/3)+1 >= bestScores) { maxBestGooglers++; } else { if (numOfSupTrip > 0) { if ((googlerPoint/3)+2 == bestScores) { maxBestGooglers++; numOfSupTrip--; } } } } } try { FileWriter fw = new FileWriter("/Users/NoK/Desktop/B-small-attempt1.out", true); BufferedWriter bw = new BufferedWriter(fw); System.out.println("Case #" + counter + ": " + maxBestGooglers); bw.write("Case #" + counter + ": " + maxBestGooglers); bw.newLine(); bw.close(); counter++; } catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } } catch (FileNotFoundException e ) { e.printStackTrace(); } } }
0
1,189,759
A11759
A10395
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.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; public class MainClass { /** * @param args */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner sc = new Scanner(new File("B-small-attempt1.in")); PrintWriter out = new PrintWriter(new File("Dancing-small.out")); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int ans = 0; int N = sc.nextInt(), S = sc.nextInt(), p = sc.nextInt(); ArrayList<Integer> sums = new ArrayList<Integer>(); for (int j = 0; j < N; j++) { sums.add(sc.nextInt()); } for (int j = 0; j < N; j++) { int tempP = p; int sum = sums.get(j); int sumBackup = sum; while (tempP <= 10 && tempP <= sumBackup) { sum = sums.get(j); sum -= tempP; int half = sum / 2; int half2 = sum - half; if ((Math.abs(half2 - half) <= 1) && (Math.abs(half2 - tempP) <= 1) && (Math.abs(tempP - half) <= 1)) { ans++; int test = sums.remove(j); // System.out.println(test + "\t " + tempP + "\t" + half // + "\t" + half2); j--; N--; break; } tempP++; } } // System.out.println(S); outer: for (int j = 0; j < N; j++) { int tempP = p; int sum = sums.get(j); int sumBackup = sum; while (tempP <= 10 && tempP <= sumBackup) { sum = sums.get(j); sum -= tempP; int half = sum / 2; int half2 = sum - half; if ((Math.abs(half2 - half) <= 2) && (Math.abs(half2 - tempP) <= 2) && Math.abs(tempP - half) <= 2) { if (S != 0) { ans++; S--; int test = sums.remove(j); // System.out.println(test + "\t " + tempP + "\t" // + half + "\t" + half2 + "\t" + S); j--; N--; break; } if (S == 0) { // System.out.println("broke"); break outer; } } tempP++; } } /* System.out.println(sums); */ out.println("Case #" + (i + 1) + ": " + ans); } out.close(); } }
0
1,189,760
A11759
A13094
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.resec; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class Dancing_With_the_Googlers { public static void main(String[] args) { String filename = "B-small-attempt5"; String sep = java.io.File.separator; try { FileInputStream input = new FileInputStream("c:" + sep + filename + ".in"); FileOutputStream output = new FileOutputStream("c:" + sep + filename + ".out"); int T = Integer.parseInt(readLine(input)); for (int i = 1; i <= T; i++) { String G = readLine(input); String outLine = "Case #" + i + ": "; Go(input, output, G, outLine); } input.close(); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static String readLine(FileInputStream FIS) { boolean EOL = true; String S = ""; int in = 0; try { do { in = FIS.read(); if (in == -1 || in == '\n') EOL = false; else S += (char) in; } while (EOL); } catch (IOException e) { e.printStackTrace(); } return S; } public static int writeLine(FileOutputStream FOS, String S) { int i = 0; try { for (; i < S.length(); i++) FOS.write(S.charAt(i)); } catch (IOException e) { e.printStackTrace(); } return i; } public static void Go(FileInputStream FIS, FileOutputStream FOS, String G, String outLine) { String[] data = G.split(" "); int N = Integer.parseInt(data[0]); int S = Integer.parseInt(data[1]); int p = Integer.parseInt(data[2]); int cases = 0; for (int i = 0; i < N; i++) { int score = Integer.parseInt(data[i + 3]); int base = (int) (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 >= p || base + 1 >= p) cases++; else { if (S > 0 && base + 1 >= p) { cases++; S--; } } break; } case 2: { if (base + 1 >= p || base >= p) cases++; else { if (S > 0 && base + 2 >= p) { cases++; S--; } } break; } } } writeLine(FOS, outLine + cases + '\n'); } }
0
1,189,761
A11759
A11669
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()); } } }
public class testCase { public testCase(int n){ T = n; cases = new String[T]; count=0; } public void addCase(String s){ if(count > T-1){ System.out.println("STOP ! too many test cases !!"); return; } cases[count++] = s; } int count; int T; String[] cases; }
0
1,189,762
A11759
A11254
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; import java.io.PrintStream; public class round1 { /** * @param args */ static BufferedReader openRead(String fileName){ BufferedReader in = null; try { in = new BufferedReader(new FileReader(fileName)); } catch (FileNotFoundException e) { System.err.println("Error Opening the input file"); e.printStackTrace(); } return in; } static void processLine( String line , int k, PrintStream ps){ ps.format("Case #%d: ", k); String[] lineItems = line.split(" "); int N = Integer.parseInt(lineItems[0]); int S = Integer.parseInt(lineItems[1]); int p = Integer.parseInt(lineItems[2]); int c = 3; int n = 0; for (int i = 0; i < N; i++){ int pi = Integer.parseInt(lineItems[c++]); if (pi >= 3*p) n++; else if (pi >= 3*p -1) n++; else if (pi >= 3*p -2) n++; else if (pi >= 3*p - 4 && (3*p - 4)>=0 && S > 0){ S--; n++; } } ps.format("%d\n", n); } public static void main(String[] args) throws IOException { if (args.length < 1){ System.err.println("not suffucient args"); System.exit(-1); } BufferedReader in = openRead(args[0]); PrintStream ps = new PrintStream(new File(args[1])); // read size int T = 0; String TStr = in.readLine(); T = Integer.parseInt(TStr); if ( T < 1 || T > 100) System.exit(-1); // read contents String line; for (int i = 0; i < T && (line = in.readLine())!= null; i++){ processLine( line, i+1, ps); } System.out.println("Done!"); } }
0
1,189,763
A11759
A10402
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.FileOutputStream; import java.io.PrintStream; import java.util.Scanner; public class B { public static void main(String ... args) throws Exception{ Scanner in = new Scanner(new File("B-small-attempt0.in")); PrintStream out = new PrintStream(new File("B-small-attempt0.out")); int[] max1 = new int[31]; int[] max2 = new int[31]; max1[0] = 0; max2[0] = 0; max1[1] = 1; max2[1] = 1; max1[2] = 1; max2[2] = 2; max1[3] = 1; max2[3] = 2; max1[4] = 2; max2[4] = 2; max1[5] = 2; max2[5] = 3; max1[6] = 2; max2[6] = 3; max1[7] = 3; max2[7] = 3; max1[8] = 3; max2[8] = 4; max1[9] = 3; max2[9] = 4; max1[10] = 4; max2[10] = 4; max1[11] = 4; max2[11] = 5; max1[12] = 4; max2[12] = 5; max1[13] = 5; max2[13] = 5; max1[14] = 5; max2[14] = 6; max1[15] = 5; max2[15] = 6; max1[16] = 6; max2[16] = 6; max1[17] = 6; max2[17] = 7; max1[18] = 6; max2[18] = 7; max1[19] = 7; max2[19] = 7; max1[20] = 7; max2[20] = 8; max1[21] = 7; max2[21] = 8; max1[22] = 8; max2[22] = 8; max1[23] = 8; max2[23] = 9; max1[24] = 8; max2[24] = 9; max1[25] = 9; max2[25] = 9; max1[26] = 9; max2[26] = 10; max1[27] = 9; max2[27] = 10; max1[28] = 10; max2[28] = 10; max1[29] = 10; max2[29] = 10; max1[30] = 10; max2[30] = 10; 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 cnt1 = 0; int cnt2 = 0; for(int n=0;n<N;n++){ int num = in.nextInt(); cnt1+= max1[num]>=p?1:0; cnt2+= max2[num]>=p?1:0; } cnt1 += Math.min(cnt2-cnt1, S); out.println("Case #" + (t+1) + ": " + cnt1); } } }
0
1,189,764
A11759
A13035
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.*; public class Q2 { public static void main(String[] args) throws IOException { Scanner w = new Scanner(new File("D:/sample.txt")); int cases = Integer.parseInt(w.nextLine()); for (int i = 0; i < cases; i++) { int count = 0; int n = w.nextInt(); int s = w.nextInt(); int p = w.nextInt(); for (int j = 0; j < n; j++) { int total = w.nextInt(); int k = total / 3; int r = total % 3; if (total == 0) { if (0 >= p) count++; } else if(r==0){ if(k>=p)count++; else if(s>0&&k+1>=p){ s--; count++; } } else if(r==1){ if(k+1>=p)count++; } else if(r==2){ if(k+1>=p)count++; else if(s>0&&k+2>=p){ s--; count++; } } } System.out.println("Case #" + (i + 1) + ": " + count); } } }
0
1,189,765
A11759
A11233
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.StringTokenizer; public class CodeJam3 { static BufferedReader br; static PrintWriter pw; static int n,surp,p,total[],count; static Triplet scores[]; public static void main(String[] args)throws Exception{ br=new BufferedReader (new FileReader ("in.txt")); pw=new PrintWriter (new FileWriter("out.txt")); int t=Integer.parseInt( br.readLine() ); for (int i=1;i<=t;i++){ input(); work(0,surp); pw.printf("Case #%d: %d%n",i,count); } pw.close(); } public static void input()throws Exception{ StringTokenizer data=new StringTokenizer(br.readLine()); n=Integer.parseInt( data.nextToken() ); surp=Integer.parseInt( data.nextToken() ); p=Integer.parseInt( data.nextToken() ); total=new int[n]; scores=new Triplet[n]; for (int i=0;i<n;i++){ total[i]=Integer.parseInt( data.nextToken() ); } count=0; } public static void work(int iter,int surpLeft){ if (surpLeft<0) return; if (iter>=n){ if (surpLeft!=0) return; int c=0; for (Triplet t:scores){ if (t.hasBest(p)) c++; } if (c>count) count=c; return; } if (total[iter]==0 || total[iter]==1 || total[iter]==30 || total[iter]==29){ scores[iter]=new Triplet( total[iter] , false); work(iter+1,surpLeft); } else { scores[iter]=new Triplet( total[iter] , false); work(iter+1,surpLeft); scores[iter]=new Triplet( total[iter] , true); work(iter+1,surpLeft-1); } } private static class Triplet { int a,b,c; public Triplet(int total,boolean surp){ int rem=total%3; int x=total/3; switch(rem){ case 0: if (surp){ a=x-1; b=x; c=x+1; } else { a=b=c=x; } break; case 1: if (surp){ a=x-1; b=x+1; c=x+1; } else { a=b=x; c=x+1; } break; case 2: if (surp){ a=b=x; c=x+2; } else { a=x; b=c=x+1; } break; } } public boolean hasBest(int p){ if (c>=p) return true; if (b>=p) return true; if (a>=p) return true; return false; } } }
0
1,189,766
A11759
A10707
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.sql.ResultSet; import java.util.Arrays; import java.util.Scanner; public class B { public int s = 0; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int t = scanner.nextInt(); for (int i = 0; i < t; i++) { B b = new B(); int y = 0; int n = scanner.nextInt(); b.s = scanner.nextInt(); int p = scanner.nextInt(); int[] points = new int[n]; for (int j = 0; j < n; j++) { points[j] = scanner.nextInt(); } // // for (int j = 0; j < n; j++) { // // if(3*p < ) // int[] results = new int[3]; // results[0] = p; // results[1] = (points[j] - p)/2; // results[2] = points[j] - results[0] - results[1]; // // while(results[0] <= 10 && results) { // // if(b.isValid(results, p)) { // System.out.println(points[j] + " - " + results[0] + ", " + results[1]+ ", " + results[2]); // y++; // break; // } // results[0]++; // results[1]--; // } // } // // System.out.println("Case #"+(i+1)+": "+y); // } // // // } // // public boolean isValid(int[] results, int p) { // if(Math.abs(results[0]-results[1]) < 2 && Math.abs(results[0]-results[2]) < 2) { //testo (Math.abs(results[1]-results[2]) ? // return true; // } // else { // if((Math.abs(results[0]-results[1]) <= 2 || Math.abs(results[0]-results[2]) <= 2) && s > 0) { // s--; // return true; // } // } // return false; // } Arrays.sort(points); for (int j = 0; j < points.length; j++) { int maxToDrop = p + 2*(p - 2); if(p <= 1) { maxToDrop = p; } if(points[j] < maxToDrop) { continue; } int minToPass = maxToDrop + 2; if(maxToDrop == 0) { minToPass = 0; } if(points[j] >= minToPass) { y++; continue; } if(b.s > 0) { b.s--; y++; continue; } } System.out.println("Case #"+(i+1)+": "+y); } } // public static boolean isLimitMax(int point, int p) { // if(point >= 3 * p) { // return true; // } // return false; // } // // public static boolean isLimitMin(int point, int p) { // if(point >= 4) { // return true; // } // return false; // } }
0
1,189,767
A11759
A13023
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; import java.util.Scanner; import java.util.StringTokenizer; public class DancingWiththeGooglers { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int cases = Integer.parseInt(scan.nextLine()); for (int i = 0; i < cases; i++) { String temp = scan.nextLine(); StringTokenizer token = new StringTokenizer(temp); int N = Integer.parseInt(token.nextToken()); int S = Integer.parseInt(token.nextToken()); int P = Integer.parseInt(token.nextToken()); int[] total = new int[N]; for (int j = 0; j < total.length; j++) { total[j] = Integer.parseInt(token.nextToken()); } System.out.println("Case #" + (i + 1) + ": " + solve(total, S, P)); } } private static int solve(int[] total, int s, int p) { int ser = s; int numberOfWinners = 0; for (int i = 0; i < total.length; i++) { if (total[i] == 0) { if (p == 0) numberOfWinners++; } else if (total[i] == 1) { if (p <= 1) numberOfWinners++; } else if (total[i] == 2) { if (p <= 1) numberOfWinners++; else if (p == 2 && ser > 0) { numberOfWinners++; ser--; } } else { int k = total[i] % 3; if (k == 0) { if (total[i] / 3 >= p) numberOfWinners++; else if (((total[i] / 3) + 1) >= p && ser > 0) { numberOfWinners++; ser--; } } else if (k == 2) { int sum = (total[i] / 3) + 1; if (sum >= p) numberOfWinners++; else if ((sum + 1) >= p && ser > 0) { numberOfWinners++; ser--; } } else if (k == 1) { int sum = (total[i] / 3) + 1; if (sum >= p) numberOfWinners++; } } } return numberOfWinners; } }
0
1,189,768
A11759
A12885
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.code.p_b; 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 Main { private static final String fromFile = "D:\\hobbies & work\\programing\\CodeJamTextFiles\\2012\\B-small-attempt0.in"; private static final String toFile = "D:\\hobbies & work\\programing\\CodeJamTextFiles\\2012\\B-small-attempt0.out"; /** * @param args */ public static void main(String[] args) { System.out.println("Problem B start"); try { FileInputStream fstream = new FileInputStream(fromFile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fstreamout = new FileWriter(toFile); BufferedWriter out = new BufferedWriter(fstreamout); String strLine; boolean firstLine = true; int i = 1; while ((strLine = br.readLine()) != null) { if (!firstLine) { System.out.println(strLine); System.out.println("Case #" + i + ": " + ansForLine(strLine) + "\n"); out.write("Case #" + i + ": " + ansForLine(strLine) + "\n"); i++; } else { firstLine = false; } } out.close(); in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } System.out.println("Problem B end"); } private static int ansForLine(String strLine) { String [] splitedLine = strLine.split(" "); int nRes = Integer.parseInt(splitedLine[0]); int nSurprises = Integer.parseInt(splitedLine[1]); int nMax = Integer.parseInt(splitedLine[2]); System.out.println("res: " + nRes + ", surprises: " + nSurprises +", max: " + nMax); int count = 0; for (int i = 3; i < splitedLine.length; i++) { int j = Integer.parseInt(splitedLine[i]); int avg = j / 3; int m = j % 3; if (j == 0) { if (nMax == 0) count ++; continue; } if (avg >= nMax) { count ++; } else if (avg + 1 >= nMax) { if (m == 0 && nSurprises > 0) { count ++; nSurprises --; } else if (m == 1 || m == 2) { count ++; } } else if (avg + 2 >= nMax) { if (m == 2 && nSurprises > 0) { count ++; nSurprises --; } } } return count; } }
0
1,189,769
A11759
A10925
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.math.BigInteger; import java.util.InputMismatchException; /** * Created by César Passoni */ public class TaskB implements Runnable { private InputReader in; private PrintWriter out; public static void main(String[] args) { new Thread(new TaskB()).start(); } public TaskB() { try { String fileName; // fileName = "sampleB.in"; fileName = "B-small-attempt9.in"; //fileName = "B-large.in"; System.setIn(new FileInputStream(fileName)); System.setOut(new PrintStream(new FileOutputStream(fileName.replace("in", "out")))); } catch (FileNotFoundException e) { throw new RuntimeException(); } in = new InputReader(System.in); out = new PrintWriter(System.out); } public void run() { int numTests = in.readInt(); for (int testNumber = 0; testNumber < numTests; testNumber++) { out.print("Case #" + (testNumber + 1) + ": "); int n = in.readInt(); int s = in.readInt(); int p = in.readInt(); boolean surprise = s!=0; int count = 0; int countSurprise = 0; for (int i = 0 ; i < n ; i ++) { int testCase = in.readInt(); if (testCase == 0) { if (p == 0) { count ++; } } else if (testCase >= (p*3-2)) { count ++; } else if (testCase >= (p*3-4) && surprise) { count ++; countSurprise ++; if (countSurprise >= s) { surprise = false; } } // if (testCase == 0) // { // if (s == 0) // { // count ++; // } // } // // else if (testCase%3 == 0) // { // if ((testCase/3 ) >= p) // { // count ++; // } // else if ((testCase/3 + 1) >= p && surprise) // { // count ++; // countSurprise ++; // if (countSurprise >= s) // { // surprise = false; // } // } // // } // else // { // if ((testCase/3 + 1) >= p) // { // count ++; // // } // else if ((testCase/3 + 2) >= p && surprise) // { // count ++; // countSurprise ++; // if (countSurprise >= s) // { // surprise = false; // } // } // } } // System.out.println("CASE " + (testNumber + 1) +"countSurprise " +countSurprise + " s " + s); out.println(count); } out.close(); } private static class InputReader { private InputStream stream; private byte[] buf = new byte[1000]; private int curChar, numChars; public InputReader(InputStream stream) { this.stream = stream; } private int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } private boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuffer buf = new StringBuffer(); int c = read(); while (c != '\n' && c != -1) { buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) return readLine(); else return readLine0(); } public BigInteger readBigInteger() { try { return new BigInteger(readString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } } }
0
1,189,770
A11759
A11467
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.List; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Map; public class Dancing { /** * @param args */ public static void main(String[] args) { try{ BufferedReader bf=null; try { int T; bf = new BufferedReader(new FileReader("src/com/codejam/input/B-small-attempt2.in")); T = Integer.parseInt(bf.readLine()); for(int i=0;i<T;i++){ //Map<String,ArrayList<Triplet> > googlers = new HashMap<String, ArrayList<Triplet> >(); ArrayList<Googler> googlers = new ArrayList<Googler>(); String line = bf.readLine(); String[] numbers = line.split(" "); int N = Integer.parseInt(numbers[0]); int S = Integer.parseInt(numbers[1]); int P = Integer.parseInt(numbers[2]); for(int index=3;index<numbers.length;index++){ ArrayList<Triplet> triplets= getTripletList(numbers[index],P); if(triplets!=null) googlers.add(new Googler(numbers[index],triplets)); //googlers.put(numbers[index],triplets); } int count = 0; int surprising = 0; for(Googler g:googlers){ boolean isNotSurprisingfound = false; for(Triplet tr:g.getTriplets()){ if(tr.isSurprising()==false){ isNotSurprisingfound = true; count++; break; } } if(!isNotSurprisingfound){ surprising++; } } if(surprising<S) count+=surprising; else count+=S; System.out.println("Case #"+(i+1)+": "+count); // for(Googler g:googlers){ // System.out.println(g.getTotal()); // System.out.println("------"); // for(Triplet tr:g.getTriplets()){ // System.out.println(tr.getS1()+" "+tr.getS2()+" "+tr.getS3()+" "+tr.isSurprising()); // } // System.out.println("------"); // } } } catch (FileNotFoundException e) { e.printStackTrace(); } finally{ bf.close(); } }catch(IOException e){ e.printStackTrace(); } } public static ArrayList<Triplet> getTripletList(String total,int best){ ArrayList<Triplet> triplets=null; for(int s1=0;s1<11;s1++){ for(int s2=0;s2<11;s2++){ for(int s3=0;s3<11;s3++){ if( (s1+s2+s3)==Integer.parseInt(total) && Math.abs(s1-s2)<=2 && Math.abs(s1-s3)<=2 && Math.abs(s2-s3)<=2 ){ Triplet tr = new Triplet(s1,s2,s3); if(tr.getMax()>=best){ if(triplets==null) triplets=new ArrayList<Triplet>(); triplets.add(tr); } } } } } if(triplets !=null) Collections.sort(triplets); return triplets; } }
0
1,189,771
A11759
A12072
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.renoux.gael.codejam.utils; import java.util.ArrayList; import java.util.List; /** * Pour tests unitaires * * @author renouxg */ public final class ListUtils { public static List<Integer> parseInts(List<String> strings) { ArrayList<Integer> list = new ArrayList<Integer>(); for (String s : strings) { list.add(Integer.valueOf(s)); } return list; } }
0
1,189,772
A11759
A12857
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 DancingWithTheGooglers { public static void main(String[] argv) { int lineCounter,numberOfLines,people,currentScore; int surprises,scoreToBeat,counter,answer; int possibleScore; Scanner input = null; try {input = new Scanner(System.in);} catch (Exception e) { System.err.println("FileNotFoundException: " + e.getMessage()); } numberOfLines = input.nextInt(); for (lineCounter = 0; lineCounter < numberOfLines; lineCounter++) { answer = 0; input.nextLine(); people = input.nextInt(); surprises = input.nextInt(); scoreToBeat = input.nextInt(); for (counter = 0; counter < people; counter++) { currentScore = input.nextInt(); possibleScore = scoreNoSurprise(currentScore); if (possibleScore >= scoreToBeat) answer++; else if (surprises > 0) { possibleScore = scoreSurprise(currentScore); if (possibleScore >= scoreToBeat) { answer++; surprises--; } } } System.out.printf("Case #%d: %d\n",lineCounter+1,answer); } } public static int scoreNoSurprise(int value) { if (value < 2) return value; if (value == 2) return 1; int totalScore = value; int divergence = totalScore%3; int baseScore = totalScore/3; if (divergence == 2) { return baseScore+1; } else if (divergence == 1) { return baseScore+1; } else { // divergence == 0 return baseScore; } } public static int scoreSurprise(int value) { if (value < 3) return value; int totalScore = value; int divergence = totalScore%3; int baseScore = totalScore/3; if (divergence == 2) { return baseScore+2; } else if (divergence == 1) { return baseScore+1; } else { // divergence == 0 return baseScore+1; } } }
0
1,189,773
A11759
A11571
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.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Dancing { /** * @param args */ public static void main(String[] args) { try { FileReader fs = new FileReader("/tmp/dancing.in"); BufferedReader in = new BufferedReader(fs); FileWriter fso = new FileWriter("/tmp/dancing.out"); BufferedWriter out = new BufferedWriter(fso); String strLine; int i=0; int matches; while ((strLine = in.readLine()) != null) { if (i > 0) { // parse input line String[] strings = strLine.split(" "); final int[] ints = new int[strings.length]; for (int j = 0; j < strings.length; j++) { ints[j] = Integer.parseInt(strings[j]); } matches = findMatches(ints[1], ints[2], Arrays.copyOfRange(ints, 3, 3+ints[0])); out.write(new StringBuilder("Case #").append(i) .append(": ").append(matches).append("\n") .toString()); } i++; } in.close(); out.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } private static int findMatches(int surprises, int bestResult, int[] ts) { int matches = 0; List<Integer> totalScores = new ArrayList<Integer>(ts.length); for (int index = 0; index < ts.length; index++){ totalScores.add(ts[index]); } Collections.sort(totalScores, Collections.reverseOrder()); System.out.print("Surprises: " + surprises + " Best: " + bestResult + " Scores: " + totalScores); for (int totalScore : totalScores) { int min = totalScore / 3; int delta = totalScore % 3; int max = min + delta; System.out.print(" [Min: " + min + " / Max: " + max + "]"); if ((max == bestResult) && (delta == 2) && (surprises > 0)) { matches++; surprises--; } else if ((min + 1 == bestResult) && (max + 1 == bestResult) && (min > 0) && (surprises > 0)) { matches++; surprises--; } else if ((min + 1 >= bestResult) && (max >= bestResult)) { matches++; } } System.out.println(" Result: " + matches); return matches; } }
0
1,189,774
A11759
A11839
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.*; public class main { main() throws FileNotFoundException { Scanner sc = new Scanner(new File("B-small-attempt0.in")); PrintWriter out = new PrintWriter("result.txt"); int tests = sc.nextInt(); for (int t = 1; t <= tests; t++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); Map<Integer, ArrayList<D>> map = new TreeMap<>(); ArrayList<Integer> scores = new ArrayList<>(); for (int m = 0; m < n; m++) { int g = sc.nextInt(); scores.add(g); map.put(g, dec(g)); } int ww = 0; int w = 0; int cw = 0; for (int i = 0; i < n; i++) { if (isDecomposeThere(map.get(scores.get(i)), p, true) && isDecomposeThere(map.get(scores.get(i)), p, false)) { ww++; } else if (isDecomposeThere(map.get(scores.get(i)), p, true)) { w++; } else if (isDecomposeThere(map.get(scores.get(i)), p, false)) { cw++; } } out.printf("Case #%d: %d\n", t, (w >= s) ? (s + cw + ww) : (w + ww + cw)); } out.flush(); } public static void main(String[] args) throws FileNotFoundException { main m = new main(); } public boolean isDecomposeThere(ArrayList<D> ds, int p, boolean surprise) { for (D dec : ds) { if (dec.a >= p && dec.surprise == surprise) return true; } return false; } public ArrayList<D> dec(int n) { ArrayList<D> list = new ArrayList<>(); for (int i = 0; i <= 10; i++) { for (int j = 0; j <= i; j++) { for (int k = 0; k <= j; k++) { if (i - j <= 2 && j - k <= 2 && i - k <= 2 && i + j + k == n) { boolean surprise = (i - j == 2 || j - k == 2 || i - k == 2); list.add(new D(i, j, k, surprise)); } } } } return list; } class D { int a, b, c; boolean surprise; public D(int a, int b, int c, boolean surprise) { this.a = a; this.b = b; this.c = c; this.surprise = surprise; } @Override public String toString() { return "" + a + " " + b + " " + c + " " + surprise; } } }
0
1,189,775
A11759
A11574
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.io.IOException; public class Dance { public static void main(String[] args) { BufferedReader reader = null; BufferedWriter writer = null; try { if (args.length == 0) { System.out.println("Usage Dance <input_file>"); System.exit(0); } File inputFile = new File(args[0]); if (!inputFile.exists()) System.out.println(String.format("File {0} not found in the current directory", args[0])); FileReader fileReader = new FileReader(inputFile.getAbsolutePath()); reader = new BufferedReader(fileReader); FileWriter fileWriter = new FileWriter("Output.txt"); writer = new BufferedWriter(fileWriter); String line = reader.readLine(); int numberOfTestCases = Integer.parseInt(line); for (int i = 0; i < numberOfTestCases; i++) { line = reader.readLine(); String[] tokens = line.split(" "); int N = Integer.parseInt(tokens[0]); int S = Integer.parseInt(tokens[1]); int P = Integer.parseInt(tokens[2]); int[] totalScores = new int[N]; for (int j = 3; j < tokens.length; j++) { totalScores[j - 3] = Integer.parseInt(tokens[j]); } writer.write("Case #" + (i + 1) + ": " + maxWithScoreGreaterThanP(P,S,totalScores)); writer.newLine(); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (reader!=null) { reader.close(); } if (writer!=null) { writer.close(); } } catch(Exception e) {} } } private static int maxWithScoreGreaterThanP(int p, int s, int[] totalScores) { int count = 0; int remainingSurprises = s; for (int i = 0; i < totalScores.length; i++) { boolean found = false; int required = totalScores[i]; for (int x=p; x<=10 && !found;x++) { for (int y = x; y >= x - 2 && y>= 0 && !found;y--) { for (int z = x; z >= y && z >=0 ;z--) { if (x + y + z == required ) { int min = Math.min(y, z); if (min == x - 2 && remainingSurprises > 0){ found = true; count++; remainingSurprises--; break; } else if (min > x-2) { found = true; count++; break; } } } } } } return count; } }
0
1,189,776
A11759
A10938
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.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Scanner; public class TaskB { /** last number is always highest score */ private static Integer[][] noJump = new Integer[31][]; private static Integer[][] withJump = new Integer[31][]; private static int bestP; public static void main(String[] args ) throws IOException { File fileName = new File("taskb/B-small-attempt0.in"); Scanner inFile = new Scanner(fileName); int n = inFile.nextInt(); inFile.useDelimiter("\\r?\\n"); String[] cases = new String[n]; for (int i = 0; i < n; i++) cases[i] = inFile.next(); List<String> result = new ArrayList<String>(); constructAllScores(); printArray(noJump); printArray(withJump); //constructScore(new Integer[3], 10, 0); for (String caseString: cases) { bestP = 0; Scanner caseScanner = new Scanner(caseString); int dancerNr = caseScanner.nextInt(); int surprisingNr = caseScanner.nextInt(); int threshold = caseScanner.nextInt(); int[] dancerTotal = new int[dancerNr]; for (int i = 0; i < dancerNr; i++) dancerTotal[i] = caseScanner.nextInt(); findBestRoute(dancerTotal, surprisingNr, threshold, 0, 0); result.add("" + bestP); } PrintWriter out = new PrintWriter(new FileWriter("taskb/b-short.out")); for (int i = 0; i < result.size(); i++) { out.println("Case #" + (i+1) + ": " + result.get(i)); } out.close(); System.out.println("Finished!"); } private static void findBestRoute(int[] dancerTotal, int surprisingNr, int threshold, int p, int depth) { if (depth == dancerTotal.length) { if (p > bestP) bestP = p; return; } if (withJump[dancerTotal[depth]] != null && surprisingNr > 0) { if (withJump[dancerTotal[depth]][2] >= threshold) findBestRoute(dancerTotal, surprisingNr-1, threshold, p+1, depth+1); else findBestRoute(dancerTotal, surprisingNr-1, threshold, p, depth+1); } if (noJump[dancerTotal[depth]][2] >= threshold) findBestRoute(dancerTotal, surprisingNr, threshold, p+1, depth+1); else findBestRoute(dancerTotal, surprisingNr, threshold, p, depth+1); } private static void printArray(Integer[][] array) { for (int i = 0; i < array.length; i++) System.out.println("sum: " + i + ": " + Arrays.toString(array[i])); } private static void constructAllScores() { for (int i = 0; i <= 10; i++) { for (int j = i; j <= i+2 && j <= 10; j++) { for (int k = i; k <= i+2 && k <= 10; k++) { Integer[] scoreBoard = {i,j,k}; int sum = sum(scoreBoard); Integer[][] array = noJump; if (j == i + 2 || k == i + 2) array = withJump; if (array[sum] == null || highest(scoreBoard) > highest(array[sum])) array[sum] = scoreBoard; } } } } private static int highest(Integer[] scoreBoard) { assert scoreBoard.length == 3; return scoreBoard[2]; } private static Integer sum(Integer[] score) { assert score.length == 3; return score[0]+score[1]+score[2]; } }
0
1,189,777
A11759
A10596
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 CaseSolvers; import Controller.IO; public abstract class CaseSolver { private int order; public CaseSolver(int order, int numberOfLines, IO io) { this.order = order; initializeVars(); addAllLines(io, numberOfLines); } public abstract void addLine(String line); public abstract void initializeVars(); public abstract void printSolution(); public abstract CaseSolver process(); public void addAllLines(IO io, int numberOfLines) { for (int i = 0; i < numberOfLines; i++) { addLine(io.readLine()); } } public int getOrder() { return order; } }
0
1,189,778
A11759
A12800
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()); } } }
/** * B.java * @author Joel C. Soares */ import java.util.Scanner; import java.util.LinkedList; import java.util.Collections; class Googlers implements Comparable<Googlers> { int n1, n2, n3; int restando; Googlers( int a, int b, int c, int r) { n1 = a; n2 = b; n3 = c; restando = r; } public int compareTo( Googlers g ) { if( n3 > g.n3 ) return 1; else if( n3 < g.n3 ) return -1; else return 0; } } // fim de classe public class B { // remove grupos que tem notas maiores que p public static int countGooglers( LinkedList<Googlers> lista, int p ) { int count = 0; for( int i = 0; i < lista.size(); i++ ) { if( lista.get( i ).n3 >= p ) count++; } return count; } // faz ajuste para casos surpreendentes public static void ajusteGooglersSurpreendentes( LinkedList<Googlers> lista, int p, int s ) { Googlers g; // coloca em ordem Collections.sort( lista ); for( int i = lista.size() - 1; i >= 0; i-- ) { g = lista.get( i ); if( s > 0 && g.n3 < p ) { if( g.restando >= 2 ) { g.restando -= 2; g.n3 += 2; if( g.restando > 0 ) { g.restando--; g.n2++; } s--; } } } // fim de for } public static void ajusteGooglers( LinkedList<Googlers> lista, int p, int s ) { for( Googlers g : lista ) { if( g.n3 + 1 >= p || g.n3 + 2 < p || g.restando == 1 || s == 0 ) { if( g.restando > 0 ) { g.restando--; g.n3++; } if( g.restando > 0 ) { g.restando--; g.n2++; } if( g.restando > 0 ) { g.restando--; g.n1++; } } // fim de if } // fim de for } // fim de método public static boolean existeResto( LinkedList<Googlers> lista ) { for( Googlers g : lista ) if( g.restando > 0 ) return true; return false; } public static void main( String args[] ) { Scanner input = new Scanner( System.in ); int t, n, s, p, x, v; LinkedList<Googlers> lista = new LinkedList<Googlers>(); t = input.nextInt(); for( int i = 0; i < t; i++ ) { n = input.nextInt(); s = input.nextInt(); p = input.nextInt(); lista.clear(); for( int j = 0; j < n; j++ ) { x = input.nextInt(); v = x / 3; x = x % 3; // ajusta if( x == 0 && v > 0 ) { x = 3; v = v - 1; } lista.add( new Googlers( v, v, v, x ) ); } // fim de for // faz ajuste triviais ajusteGooglers( lista, p, s ); // faz ajuste surpreendentes ajusteGooglersSurpreendentes( lista, p, s ); System.out.printf( "Case #%d: %d\n", i + 1, countGooglers( lista, p ) ); } // fim de for externo } }
0
1,189,779
A11759
A11842
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 gcj2012.qualification; import java.io.File; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Scanner; public class B_Dancing_With_the_Googlers { private static boolean SMALL = true; private static String PROBLEM = "B"; public static void main(String[] args) { try { Scanner scan = new Scanner(new File(String.format("%s-%s.in", PROBLEM, (SMALL ? "small" : "large")))); PrintWriter pw = new PrintWriter(new File(String.format("%s-%s.out", PROBLEM, (SMALL ? "small" : "large")))); int NUM_CASES = scan.nextInt(); scan.nextLine(); System.out.println(String.format("%d test cases:", NUM_CASES)); long start = System.currentTimeMillis(), t1, left; for (int CASE = 1; CASE <= NUM_CASES; ++CASE) { t1 = System.currentTimeMillis(); System.out.print(String.format("%d.[%s] ", CASE, new SimpleDateFormat("HH:mm:ss.SSS").format(new Date(t1)))); final int N = scan.nextInt(), S = scan.nextInt(), p = scan.nextInt(); int cntGreat = 0, cntOK = 0; for (int i = 0; i < N; ++i) { final int t = scan.nextInt(); if ((t - p) >= 0 && (t - p) / 2 >= p - 1) { cntGreat++; } else if (p - 2 >= 0 && (t - p - (p - 2)) >= p - 2) { cntOK++; } } String res = String.format("%d", cntGreat + Math.min(S, cntOK)); pw.println(String.format("Case #%d: %s", CASE, res)); left = (System.currentTimeMillis() - start) * (NUM_CASES - CASE) / CASE; System.out.println(String.format("%s (%dms, ~%dms left)", res, (System.currentTimeMillis() - t1), left)); } pw.close(); scan.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
1,189,780
A11759
A11083
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.codegem.zaidansari; import java.io.File; import java.util.ArrayList; import java.util.List; class Score { int score1, score2, score3; int bestScore; boolean isSurprising; public Score(int score1, int score2, int score3) { super(); this.score1 = score1; this.score2 = score2; this.score3 = score3; this.bestScore = Math.max(Math.max(score1, score2), score3); this.isSurprising = (Math.abs(score1 - score2) == 2) || (Math.abs(score1 - score3) == 2) || (Math.abs(score2 - score3) == 2); } public int getScore1() { return score1; } public void setScore1(int score1) { this.score1 = score1; } public int getScore2() { return score2; } public void setScore2(int score2) { this.score2 = score2; } public int getScore3() { return score3; } public void setScore3(int score3) { this.score3 = score3; } public int getBestScore() { return bestScore; } public void setBestScore(int bestScore) { this.bestScore = bestScore; } public boolean isSurprising() { return isSurprising; } public void setSurprising(boolean isSurprising) { this.isSurprising = isSurprising; } public static List<Score> getPossibleScoreCombinations(int totalScore) { List<Score> possibleScores = new ArrayList<Score>(); if (totalScore == 0) { possibleScores.add(new Score(0, 0, 0)); possibleScores.add(new Score(0, 0, 0)); return possibleScores; } int mean = totalScore / 3; int remainder = totalScore % 3; switch (remainder) { case 0: possibleScores.add(new Score(mean, mean, mean)); possibleScores.add(new Score(mean, mean - 1, mean + 1)); break; case 1: possibleScores.add(new Score(mean, mean, mean + 1)); possibleScores.add(new Score(mean - 1, mean + 1, mean + 1)); break; case 2: possibleScores.add(new Score(mean, mean, mean + 2)); possibleScores.add(new Score(mean, mean + 1, mean + 1)); break; } return possibleScores; } } public class ProblemB { private int noofGooglers; private int surprisingCount; public static int bestResult; // private List<PersonScore> googlers = new ArrayList<PersonScore>(); private BTree tree; public static List<Node> leafLevelNodes = new ArrayList<Node>(); public ProblemB(int noofGooglers, int surprisingCount, int bestResult, int[] totalScores) { super(); ProblemB.bestResult = bestResult; Node rootNode = new Node(new Score(0, 0, 0), totalScores, 0, 0); tree = new BTree(rootNode); this.noofGooglers = noofGooglers; this.surprisingCount = surprisingCount; } public static void main(String[] args) { File file = new File("/Users/zaansari/Desktop/CodeGem2012/InputFiles/ProblemB-Small.txt"); // File file = new File("/Users/zaansari/Desktop/CodeGem2012/InputFiles/ProblemB-Large.txt"); List<String> inputData = CodeGemUtil.getInputValues(file); int noOfInputs = Integer.parseInt(inputData.get(0)); inputData.remove(0); List<String> outputData = new ArrayList<String>(); for (int index = 0; index < noOfInputs; index++) { String line = inputData.get(index); String[] inputValues = line.split(" "); int noofGooglers = Integer.parseInt(inputValues[0]); int surprisingCount = Integer.parseInt(inputValues[1]); int bestResult = Integer.parseInt(inputValues[2]); ProblemB.bestResult = bestResult; int[] totalScores = new int[noofGooglers]; for (int _index = 0; _index < noofGooglers; _index++) { totalScores[_index] = Integer.parseInt(inputValues[3 + _index]); } ProblemB problemB = new ProblemB(noofGooglers, surprisingCount, bestResult, totalScores); int result = -1; for (Node node : ProblemB.leafLevelNodes) { if (node.getParentNodesSuprisingCount() == surprisingCount) { result = Math.max(result, node.getParentBestMatchCount()); } } outputData.add("" + result); ProblemB.leafLevelNodes.clear(); } boolean createdOutputFile = CodeGemUtil.createOutputFile(outputData, "ProblemB-Small-Output.txt"); // boolean createdOutputFile = CodeGemUtil.createOutputFile(outputData, "ProblemB-Large-Output.txt"); if (createdOutputFile) { System.out.println("Successfully created output file"); } else { System.out.println("Failed to create output file"); } // // String inputLine = "2 0 3 25 24"; // String[] inputValues = inputLine.split(" "); // int noofGooglers = Integer.parseInt(inputValues[0]); // int surprisingCount = Integer.parseInt(inputValues[1]); // int bestResult = Integer.parseInt(inputValues[2]); // int[] totalScores = new int[noofGooglers]; // // for (int index = 0; index < noofGooglers; index++) { // totalScores[index] = Integer.parseInt(inputValues[3 + index]); // } // ProblemB problemB = new ProblemB(noofGooglers, surprisingCount, bestResult, totalScores); // int result = -1; // for (Node node : ProblemB.leafLevelNodes) { // if (node.getParentNodesSuprisingCount() == surprisingCount) { // result = Math.max(result, node.getParentBestMatchCount()); // } // } // System.out.println(result); } } class BTree { private Node rootNode; public BTree(Node rootNode) { super(); this.rootNode = rootNode; } public Node getRootNode() { return rootNode; } public void setRootNode(Node rootNode) { this.rootNode = rootNode; } } class Node { private int parentNodesSuprisingCount; private int parentBestMatchCount; private Score score; private Node leftNode; private Node rightNode; public Node(Score score, int[] scores, int parentNodesSuprisingCount, int parentBestMatchCount) { this.parentNodesSuprisingCount = parentNodesSuprisingCount; this.parentBestMatchCount = parentBestMatchCount; this.score = score; int[] childNodeScores = null; if (scores != null && scores.length > 0) { childNodeScores = new int[scores.length - 1]; for (int index = 1; index < scores.length; index++) { childNodeScores[index - 1] = scores[index]; } } List<Score> scoresList = null; if (scores != null && scores.length > 0) scoresList = Score.getPossibleScoreCombinations(scores[0]); if (score != null) { this.setLeftNode(new Node((scoresList != null ? scoresList.get(0) : null), childNodeScores, parentNodesSuprisingCount + (scoresList != null && scoresList.get(0) != null && scoresList.get(0).isSurprising ? 1 : 0), parentBestMatchCount + (scoresList != null && scoresList.get(0) != null && scoresList.get(0).getBestScore() >= ProblemB.bestResult ? 1 : 0))); this.setRightNode(new Node((scoresList != null ? scoresList.get(1) : null), childNodeScores, parentNodesSuprisingCount + (scoresList != null && scoresList.get(1) != null && scoresList.get(1).isSurprising ? 1 : 0), parentBestMatchCount + (scoresList != null && scoresList.get(1) != null && scoresList.get(1).getBestScore() >= ProblemB.bestResult ? 1 : 0))); if (childNodeScores != null && childNodeScores.length == 0) { ProblemB.leafLevelNodes.add(this.leftNode); ProblemB.leafLevelNodes.add(this.rightNode); } } } public int getParentNodesSuprisingCount() { return parentNodesSuprisingCount; } public void setParentNodesSuprisingCount(int parentNodesSuprisingCount) { this.parentNodesSuprisingCount = parentNodesSuprisingCount; } public int getParentBestMatchCount() { return parentBestMatchCount; } public void setParentBestMatchCount(int parentBestMatchCount) { this.parentBestMatchCount = parentBestMatchCount; } public Score getScore() { return score; } public void setScore(Score score) { this.score = score; } public Node getLeftNode() { return leftNode; } public void setLeftNode(Node leftNode) { this.leftNode = leftNode; } public Node getRightNode() { return rightNode; } public void setRightNode(Node rightNode) { this.rightNode = rightNode; } }
0
1,189,781
A11759
A12521
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.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; public class DancingWiththeGooglers { public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter("output.out"); Scanner in = new Scanner(new File("B-small-attempt19.in")); int testCases = in.nextInt(); for (int i = 1; i <= testCases; i++){ int N = in.nextInt(),counter=0; int S = in.nextInt(); int P = in.nextInt(); for(int j = 0 ; j < N ;j++){ int googler= in.nextInt(); if(googler%3 == 0 && googler!=0){ if(googler/3 >= P){ counter++; } else if(googler/3 + 1 >= P && S!=0){ counter++; S--; } } else if (googler==0 && P==0){ counter++; } else if(googler%3==1){ if(googler/3 + 1 >= P){ counter++; } } else if(googler%3==2){ if(googler/3 + 1 >= P){ counter++; } else if(googler/3 + 2 >= P && S!=0){ counter++; S--; } } } out.printf("Case #%d: %d",i,counter); out.printf("\n"); } out.close(); in.close(); } }
0
1,189,782
A11759
A12686
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 ab.gcj; import java.io.BufferedReader; import java.io.InputStreamReader; public class Surprising { public static void main(String args[]) { Surprising s = new Surprising(); } public Surprising() { try{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int numOfTests = Integer.parseInt(reader.readLine()); for(int j = 0 ; j < numOfTests ; j++) { String[] tstr = reader.readLine().split(" "); int numGooglers = Integer.parseInt(tstr[0]); int surprising = Integer.parseInt(tstr[1]); int p = Integer.parseInt(tstr[2]); int [] t = new int[numGooglers]; for(int i =0 ; i < t.length; i++) { t[i] = Integer.parseInt(tstr[i+3]); } System.out.println("Case #"+(j+1)+": "+test(numGooglers,surprising,p,t) ); } }catch(Exception e) { } } public int test(int n , int s , int p, int[] t) { int count = 0 ; int surprising = s; for(int i = 0 ; i < t.length; i++) { if(t[i] == 0 ) { if(p == 0) count++; continue; } int a = t[i]/3; int b = a * 3; int rem = t[i] - b; if(a >= p) { count++; } else { if((surprising != 0) && rem == 0 && (a + 1 >= p)) { surprising--; count++; continue; } if( rem == 1 && a+1 >=p) { count++; } if(rem == 2) { if(a + 1 >= p ) { count++; continue; } if(surprising != 0 && a+2 >=p) { surprising--; count++; } } } } return count; } }
0
1,189,783
A11759
A11565
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()); } } }
/** * * @author amit */ import java.io.*; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collections; import java.util.StringTokenizer; //import java.util.Arrays; //import java.math.BigInteger; public class GCJ { BufferedReader rin; BufferedWriter wout; int numCases; public String getNextInput() { try { String line = rin.readLine(); String[] aVars = line.split(" "); long count = 0; long N = Long.parseLong(aVars[0]); long S = Long.parseLong(aVars[1]); long P = Long.parseLong(aVars[2]); ArrayList<Long> gc = new ArrayList<Long>(); for (int i=0; i<N; i++) { gc.add(Long.parseLong(aVars[i+3])); } Collections.sort(gc); for (int i=gc.size()-1; i>=0; i--) { long t1 = gc.get(i); System.out.println("\nnum: " + t1); long t2 = (long) Math.ceil((double)t1/3.0); if (t1 ==1 && P==2) break; if (t1 ==0 && P>0) break; if (P<= t2) { count ++; System.out.println("\nadded without S"); } else if (S>0 && P<=t2+1) { count ++; S--; System.out.println("\nadded with S"); } else break; } /* long t = Long.parseLong(aVars[i+3]); System.out.println("\nscore" + t); if ((t%3)==2) { System.out.println("mod2"); if (P <= t/3+1) { count ++; } } else if ((t%3)==1) { System.out.println("mod1"); S--; if (P <= t/3 +1) { count++; } } else { gc.add(t); System.out.println("mod3"); } } Collections.sort(gc); if (!(gc.isEmpty())) { for (int i=gc.size()-1; i>=0; i--) { //System.out.println("\ni: " + i); long t1 = gc.get(i); if (P<=t1/3) { count ++; } else if (P<=t1/3+1) { count ++; S--; } else if (S>0) { System.out.println("\nError!"); } else break; } }*/ return Long.toString(count); } catch (IOException e) { System.out.println("File Error! Could not read line from file"); } return null; } public void writeNextOutput(String s) { try { wout.write(s); wout.write("\n"); } catch (IOException e) { System.out.println("Error! Could not write to the file!"); } } public GCJ(String s1, String s2) { try { rin = new BufferedReader( new FileReader(s1)); wout = new BufferedWriter(new FileWriter(s2)); numCases = Integer.parseInt(rin.readLine()); for(int i=1; i <= numCases; i++){ System.out.println("case#" + i); String sout = getNextInput(); sout = "Case #" + Integer.toString(i) + ":" + " " + sout; writeNextOutput(sout); //System.out.println("case#" + i); } rin.close(); wout.close(); } catch (IOException e) { System.out.println("File error"); System.exit(0); } } public static void main(String[] args) {/* if (args.length!=2) { System.out.println("Enter input file!"); System.exit(0); }*/ GCJ a = new GCJ("infile.txt", "out.txt"); } }
0
1,189,784
A11759
A11859
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.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Dancers { public static void main(final String[] args) throws IOException { if (args.length < 2) { System.out.println("Input and output file must be given"); return; } PrintWriter pw = null; try { pw = new PrintWriter(new BufferedWriter(new FileWriter(args[1]))); final List<TestCase> cases = parseInput(args[0]); for(final TestCase test : cases) { pw.println("Case #" + test.getCaseNum() + ": " + test.solve()); } } finally { if(pw != null) { pw.close(); } } } private static List<TestCase> parseInput(String filename) throws IOException { final List<TestCase> res = new ArrayList<TestCase>(); BufferedReader br = null; try { br = new BufferedReader(new FileReader(filename)); int caseNum = Integer.parseInt(br.readLine()); for(int i = 0; i < caseNum; ++i) { String[] args = br.readLine().split("\\s"); int n = Integer.parseInt(args[0]); int s = Integer.parseInt(args[1]); int p = Integer.parseInt(args[2]); int [] scores = new int[n]; for(int j = 0; j < n; ++j) { scores[j] = Integer.parseInt(args[3 + j]); } res.add(new TestCase(i + 1, n, s, p, scores)); } } finally { if(br != null) { br.close(); } } return res; } private static class TestCase { private int caseNum; private int numberOfGooglers; private int suprisingTriplets; private int minBestResult; private int[] scores; public TestCase(int caseNum, int numberOfGooglers, int suprisingTriplets, int minBestResult, int[] scores) { super(); this.caseNum = caseNum; this.numberOfGooglers = numberOfGooglers; this.suprisingTriplets = suprisingTriplets; this.minBestResult = minBestResult; this.scores = scores; } public int solve() { int res = 0; int [] x = new int[suprisingTriplets]; for(int i = 0; i < suprisingTriplets; ++i) { x[i] = i; } while(true) { int maxGooglersForPermutation = countMaxGooglersForPermutation(x); res = Math.max(res, maxGooglersForPermutation); if(!nextPermutation(x)) { break; } } return res; } private boolean nextPermutation(int[] x) { int k = -1; for(int i = suprisingTriplets - 1; i >= 0; --i) { if(x[i] < numberOfGooglers + suprisingTriplets - i) { k = i; break; } } if(k >= 0) { x[k]++; for(int i = k + 1; i < suprisingTriplets; ++i) { x[i] = x[k] + i - k; } } return k >= 0; } private int countMaxGooglersForPermutation(int[] arr) { List<Integer> x = new ArrayList<Integer>(); for(int i = 0; i < suprisingTriplets; ++i) { x.add(arr[i]); } int res = 0; for(int i = 0; i < numberOfGooglers; ++i) { int score = scores[i]; int maxForGoogler = -1; if(x.contains(i)) { maxForGoogler = countMaxForSuprising(score); } else { maxForGoogler = countMaxForNotSuprising(score); } if(maxForGoogler >= minBestResult) { ++res; } } return res; } private int countMaxForNotSuprising(int score) { if(score % 3 == 0) { return score / 3; } else if(score % 3 == 1) { return ((score - 1) / 3) + 1; } else { return ((score - 2) / 3) + 1; } } private int countMaxForSuprising(int score) { if(score % 3 == 0) { return score == 0 ? -1 : ((score - 3) / 3) + 2; } else if(score % 3 == 1) { return score == 1 ? -1 : ((score - 4) / 3) + 2; } else { return ((score - 2) / 3) + 2; } } public int getCaseNum() { return caseNum; } } }
0
1,189,785
A11759
A10515
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 _2012_qual; import static java.lang.Math.*; import java.util.*; import java.io.*; public class B { boolean showDebug = true; static boolean fromFile = false; static String filePath = "E:/AAA/_gcj/"; static boolean intoFile = !false; public void solve() throws Exception { int testCasesCnt = nextInt(); nextCase: for(int testCase=1; testCase<=testCasesCnt; testCase++) { print("Case #"+testCase+": "); int n = nextInt(), s = nextInt(), p =nextInt(); int lim = p+2*max(0,(p-1)), lims = p+2*max(0,(p-2)); int res = 0; for (int i=0; i<n; ++i) { int t = nextInt(); if (t>=lim) res++; else if (t>=lims && s>0) { res++; s--; } } println(res); } } //////////////////////////////////////////////////////////////////////////// double EPS = 1e-7; int INF = Integer.MAX_VALUE; long INFL = Long.MAX_VALUE; double INFD = Double.MAX_VALUE; int absPos(int num) { return num<0 ? 0:num; } long absPos(long num) { return num<0 ? 0:num; } double absPos(double num) { return num<0 ? 0:num; } int min(int... nums) { int r = Integer.MAX_VALUE; for (int i: nums) if (i<r) r=i; return r; } int max(int... nums) { int r = Integer.MIN_VALUE; for (int i: nums) if (i>r) r=i; return r; } long minL(long... nums) { long r = Long.MAX_VALUE; for (long i: nums) if (i<r) r=i; return r; } long maxL(long... nums) { long r = Long.MIN_VALUE; for (long i: nums) if (i>r) r=i; return r; } double minD(double... nums) { double r = Double.MAX_VALUE; for (double i: nums) if (i<r) r=i; return r; } double maxD(double... nums) { double r = Double.MIN_VALUE; for (double i: nums) if (i>r) r=i; return r; } long sumArr(int[] arr) { long res = 0; for (int i: arr) res+=i; return res; } long sumArr(long[] arr) { long res = 0; for (long i: arr) res+=i; return res; } double sumArr(double[] arr) { double res = 0; for (double i: arr) res+=i; return res; } long partsFitCnt(long partSize, long wholeSize) { return (partSize+wholeSize-1)/partSize; } boolean odd(long num) { return (num&1)==1; } boolean hasBit(int num, int pos) { return (num&(1<<pos))>0; } long binpow(long a, int n) { long r = 1; while (n>0) { if ((n&1)!=0) r*=a; a*=a; n>>=1; } return r; } boolean isLetter(char c) { return (c>='a' && c<='z') || (c>='A' && c<='Z'); } boolean isLowercase(char c) { return (c>='a' && c<='z'); } boolean isUppercase(char c) { return (c>='A' && c<='Z'); } boolean isDigit(char c) { return (c>='0' && c<='9'); } boolean charIn(String chars, String s) { if (s==null) return false; if (chars==null || chars.equals("")) return true; for (int i=0; i<s.length(); ++i) for (int j=0; j<chars.length(); ++j) if (chars.charAt(j)==s.charAt(i)) return true; return false; } String stringn(String s, int n) { if (n<1 || s==null) return ""; StringBuilder sb = new StringBuilder(s.length()*n); for (int i=0; i<n; ++i) sb.append(s); return sb.toString(); } String str(Object o) { if (o==null) return ""; return o.toString(); } long timer = System.currentTimeMillis(); void startTimer() { timer = System.currentTimeMillis(); } void stopTimer() { System.err.println("time: "+(System.currentTimeMillis()-timer)/1000.0); } static class InputReader { private byte[] buf; private int bufPos = 0, bufLim = -1; private InputStream stream; public InputReader(InputStream stream, int size) { buf = new byte[size]; this.stream = stream; } private void fillBuf() throws IOException { bufLim = stream.read(buf); bufPos = 0; } char read() throws IOException { if (bufPos>=bufLim) fillBuf(); return (char)buf[bufPos++]; } boolean hasInput() throws IOException { if (bufPos>=bufLim) fillBuf(); return bufPos<bufLim; } } static InputReader inputReader; static BufferedWriter outputWriter; char nextChar() throws IOException { return inputReader.read(); } char nextNonWhitespaceChar() throws IOException { char c = inputReader.read(); while (c<=' ') c=inputReader.read(); return c; } String nextWord() throws IOException { StringBuilder sb = new StringBuilder(); char c = inputReader.read(); while (c<=' ') c=inputReader.read(); while (c>' ') { sb.append(c); c = inputReader.read(); } return new String(sb); } String nextLine() throws IOException { StringBuilder sb = new StringBuilder(); char c = inputReader.read(); while (c<=' ') c=inputReader.read(); while (c!='\n' && c!='\r') { sb.append(c); c = inputReader.read(); } return new String(sb); } int nextInt() throws IOException { int r = 0; char c = nextNonWhitespaceChar(); boolean neg = false; if (c=='-') neg=true; else r=c-48; c = nextChar(); while (c>='0' && c<='9') { r*=10; r+=c-48; c=nextChar(); } return neg ? -r:r; } long nextLong() throws IOException { long r = 0; char c = nextNonWhitespaceChar(); boolean neg = false; if (c=='-') neg=true; else r = c-48; c = nextChar(); while (c>='0' && c<='9') { r*=10L; r+=c-48L; c=nextChar(); } return neg ? -r:r; } double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextWord()); } int[] nextArr(int size) throws NumberFormatException, IOException { int[] arr = new int[size]; for (int i=0; i<size; ++i) arr[i] = nextInt(); return arr; } long[] nextArrL(int size) throws NumberFormatException, IOException { long[] arr = new long[size]; for (int i=0; i<size; ++i) arr[i] = nextLong(); return arr; } double[] nextArrD(int size) throws NumberFormatException, IOException { double[] arr = new double[size]; for (int i=0; i<size; ++i) arr[i] = nextDouble(); return arr; } String[] nextArrS(int size) throws NumberFormatException, IOException { String[] arr = new String[size]; for (int i=0; i<size; ++i) arr[i] = nextWord(); return arr; } char[] nextArrCh(int size) throws IOException { char[] arr = new char[size]; for (int i=0; i<size; ++i) arr[i] = nextNonWhitespaceChar(); return arr; } char[][] nextArrCh(int rows, int columns) throws IOException { char[][] arr = new char[rows][columns]; for (int i=0; i<rows; ++i) for (int j=0; j<columns; ++j) arr[i][j] = nextNonWhitespaceChar(); return arr; } char[][] nextArrChBorders(int rows, int columns, char border) throws IOException { char[][] arr = new char[rows+2][columns+2]; for (int i=1; i<=rows; ++i) for (int j=1; j<=columns; ++j) arr[i][j] = nextNonWhitespaceChar(); for (int i=0; i<columns+2; ++i) { arr[0][i] = border; arr[rows+1][i] = border; } for (int i=0; i<rows+2; ++i) { arr[i][0] = border; arr[i][columns+1] = border; } return arr; } void printf(String format, Object... args) throws IOException { outputWriter.write(String.format(format, args)); } void print(Object o) throws IOException { outputWriter.write(o.toString()); } void println(Object o) throws IOException { outputWriter.write(o.toString()); outputWriter.newLine(); } void print(Object... o) throws IOException { for (int i=0; i<o.length; ++i) { if (i!=0) outputWriter.write(' '); outputWriter.write(o[i].toString()); } } void println(Object... o) throws IOException { print(o); outputWriter.newLine(); } void printn(Object o, int n) throws IOException { String s = o.toString(); for (int i=0; i<n; ++i) { outputWriter.write(s); if (i!=n-1) outputWriter.write(' '); } } void printnln(Object o, int n) throws IOException { printn(o, n); outputWriter.newLine(); } void printArr(int[] arr) throws IOException { for (int i=0; i<arr.length; ++i) { if (i!=0) outputWriter.write(' '); outputWriter.write(Integer.toString(arr[i])); } } void printArr(long[] arr) throws IOException { for (int i=0; i<arr.length; ++i) { if (i!=0) outputWriter.write(' '); outputWriter.write(Long.toString(arr[i])); } } void printArr(double[] arr) throws IOException { for (int i=0; i<arr.length; ++i) { if (i!=0) outputWriter.write(' '); outputWriter.write(Double.toString(arr[i])); } } void printArr(String[] arr) throws IOException { for (int i=0; i<arr.length; ++i) { if (i!=0) outputWriter.write(' '); outputWriter.write(arr[i]); } } void printArr(char[] arr) throws IOException { for (char c: arr) outputWriter.write(c); } void printlnArr(int[] arr) throws IOException { printArr(arr); outputWriter.newLine(); } void printlnArr(long[] arr) throws IOException { printArr(arr); outputWriter.newLine(); } void printlnArr(double[] arr) throws IOException { printArr(arr); outputWriter.newLine(); } void printlnArr(String[] arr) throws IOException { printArr(arr); outputWriter.newLine(); } void printlnArr(char[] arr) throws IOException { printArr(arr); outputWriter.newLine(); } void halt(Object... o) throws IOException { if (o.length!=0) println(o); outputWriter.flush(); outputWriter.close(); System.exit(0); } void debug(Object... o) { if (showDebug) System.err.println(Arrays.deepToString(o)); } public static void main(String[] args) throws Exception { Locale.setDefault(Locale.US); if (!fromFile) { inputReader = new InputReader(System.in, 1<<16); } else { inputReader = new InputReader(new FileInputStream(new File(filePath)), 1<<16); } if (!intoFile) { outputWriter = new BufferedWriter(new OutputStreamWriter(System.out)); } else { File f = new File(System.getProperty("user.dir")+"\\src\\"+B.class.getPackage().getName()+"\\"+B.class.getSimpleName()+".out" ); outputWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(f))); } new B().solve(); outputWriter.flush(); outputWriter.close(); } }
0
1,189,786
A11759
A11363
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 { static Scanner in = new Scanner(System.in); int solve() { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int yesLimit = p + 2 * Math.max(0, p-1); int maybeLimit = p + 2 * Math.max(0, p-2); int yes = 0; int maybe = 0; for (int i=0; i<N; ++i) { int totalPoints = in.nextInt(); if (totalPoints >= yesLimit) { ++yes; } else if (totalPoints >= maybeLimit) { ++maybe; } } return yes + Math.min(S, maybe); } public static void main(String[] args) { int T = in.nextInt(); for (int i=1; i<=T; ++i) { int ans = new B().solve(); System.out.println("Case #" + i + ": " + ans); } } }
0
1,189,787
A11759
A11976
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 Scoring { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numLines = sc.nextInt(); int lineCount = 1; while (numLines > 0) { int numGoogler = sc.nextInt(); int numSurprisingScores = sc.nextInt(); int scoreThreshold = sc.nextInt(); int result = 0; // System.out.println(numGoogler +" "+ numSurprisingScores +" "+ scoreThreshold); while (numGoogler > 0) { int totalScore = sc.nextInt(); // System.out.println(totalScore); boolean passed = processScore(scoreThreshold, totalScore); if (passed) { result++; // System.out.println("here!!!"); } else if (!passed && numSurprisingScores > 0) { int maxPossibleScore = calculateMaxScore(totalScore); if (maxPossibleScore >= scoreThreshold) { result++; numSurprisingScores--; // System.out.println("here!"); } // System.out.println("here!!"); } numGoogler--; } System.out.println("Case #" + lineCount + ": " + result); lineCount++; numLines--; } } private static int calculateMaxScore(int totalScore) { int avg = totalScore/3; int mod = totalScore%3; int max = 0; if (totalScore != 0) { if (mod <= 1) { max = avg+1; } else if (mod == 2) { max = avg+2; } } return max; } public static boolean processScore(int scoreThreshold, int totalScore) { int avg = totalScore/3; int mod = totalScore%3; // System.out.println(avg+" "+mod); if (mod > 0) { if (avg+1 >= scoreThreshold) { return true; } } else if (mod == 0) { if (avg >= scoreThreshold) { return true; } } return false; } }
0
1,189,788
A11759
A12744
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.ArrayList; import java.util.List; import java.util.Scanner; public class Parser { File instance; Scanner sc; public Parser(String f){ instance = new File(f); } public List<List<List<String>>> parse(int nbLinePerCase) throws FileNotFoundException{ sc = new Scanner(instance); int nbCase = sc.nextInt(); List<List<List<String>>> input = new ArrayList<List<List<String>>>(nbCase); String line; sc.nextLine(); for(int i = 0; i < nbCase; i++){ List<List<String>> ll = new ArrayList<List<String>>(nbLinePerCase); for(int j = 0; j < nbLinePerCase; j++){ List<String> l = new ArrayList<String>(); line = sc.nextLine(); Scanner sc2 = new Scanner(line); while(sc2.hasNext()){ l.add(sc2.next()); } ll.add(l); } input.add(ll); } return input; } }
0
1,189,789
A11759
A10319
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; public class TestTwoSolver extends SolverModule { public StringBuilder process(BufferedReader in, StringBuilder builder) throws IOException { in.readLine(); String line = in.readLine(); int count = 1; while (line != null) { line = processline(line); appendLine(line, builder, count); count++; line = in.readLine(); } return builder; } private String processline(String line) { int[] lines = toIntegers(line.split(" ")); int bestResultCount = 0; int S = lines[1]; int p = lines[2]; for (int i = 3; i < lines.length; i++) { if (lines[i] >= (p - 1) * 2 + p) { bestResultCount++; } else { if (lines[i] >= (p - 2) * 2 + p) { if (S > 0 && (p - 2) >= 0) { S--; bestResultCount++; } } } } return String.valueOf(bestResultCount); } private int[] toIntegers(String[] split) { int[] ints = new int[split.length]; for (int i = 0; i < split.length; i++) { ints[i] = Integer.valueOf(split[i]); } return ints; } }
0
1,189,790
A11759
A11710
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 Googlers_Dance { FileWriter fstream; BufferedWriter out; Googlers_Dance() { try { fstream = new FileWriter("E:\\Yoxos\\EclipseNew\\workspace\\TestProject\\Dance_op.txt"); out = new BufferedWriter(fstream); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Googlers_Dance obj = new Googlers_Dance(); obj.getInput(); //Close the output stream //out.close(); } void printFile(String strLine) { try{ // Create file out.write(strLine); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } void getInput() { try{ // Open the file that is the first // command line parameter int iNumberOfLines = 0 ; FileInputStream fstream = new FileInputStream("E:\\Yoxos\\EclipseNew\\workspace\\TestProject\\src\\B-small-attempt0.in"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line if ((strLine = br.readLine()) != null) { // Print the content on the console //System.out.println (""+strLine); iNumberOfLines = Integer.parseInt(strLine); } int j=1; while(iNumberOfLines-- > 0 && ((strLine = br.readLine())!=null)) { int iTempCount = getGooglersBestNumber(strLine); String strTemp= "Case #"+j+": "+iTempCount; System.out.println(strTemp); j++; } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any e.printStackTrace(); } } int getGooglersBestNumber(String strLine) { int iGooglersBestCount=0; String strWords[] = strLine.split(" "); int iN = Integer.parseInt(strWords[0]); int iSurprising = Integer.parseInt(strWords[1]); int iP = Integer.parseInt(strWords[2]); int l=3,k=0; while(l < strWords.length) { k=iP; int iT = Integer.parseInt(strWords[l++]); while(k>=0 && k<=10) { int iTempMaxVal = (k*3); if(iT >= iTempMaxVal) { if((iT==iTempMaxVal) || (iT == iTempMaxVal+1) || (iT == iTempMaxVal+2)) { iGooglersBestCount++; break; } if(iSurprising>0) { if((iT == iTempMaxVal+3) || (iT == iTempMaxVal+4)) { iSurprising--; iGooglersBestCount++; break; } } k++; } else { if(iT <= iTempMaxVal) { if((iT==iTempMaxVal) || (iT == iTempMaxVal-1) || (iT == iTempMaxVal-2)) { iGooglersBestCount++; break; } if(iSurprising>0) { if(iT!=0 && (iT == iTempMaxVal-3) || (iT == iTempMaxVal-4)) { iGooglersBestCount++; iSurprising--; break; } } break; } } } } return iGooglersBestCount; } }
0
1,189,791
A11759
A10052
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 dancingwiththegooglers; import java.util.*; import java.io.*; /** * Google Code Jam 2012 * Problem B. Dancing With the Googlers * @author STEVEN GANTENG * step.v4n@gmail.com */ public class DancingWithTheGooglers { public static int cases; public static String result=""; /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try { FileInputStream fin = new FileInputStream("B-small-attempt5.in"); FileOutputStream fout = new FileOutputStream("B-small-attempt5.out"); Scanner source = new Scanner(fin); cases = source.nextInt(); Double t[] = new Double[100]; int count=0; int a=1; for (int j=0;j<cases;j++) { int N = source.nextInt(); int S = source.nextInt(); double p = source.nextDouble();//System.out.println(p) Double tmp[] = new Double[3]; for (int i=0;i<N;i++) { t[i]=source.nextDouble(); //System.out.print(t[i]+" "); tmp[i] = t[i]/3; } for (int k=0;k<N;k++) { if (tmp[k]>=p) { count++; } else if (tmp[k]==0) { if (p>0) { } } else if ((tmp[k]-p)>-0.7) { count++; } else if ((tmp[k]-p)>-1.34) { if (S==0) { } else if (S!=0) { count++; S-=1; } } //System.out.print(tmp[k]+" "); } System.out.println(); result += "Case #"+a+": "+count+"\n"; a++; fout.write(result.getBytes()); result=""; count=0; System.out.println(); } } catch (IOException e) { } //System.out.print(0/3); } }
0
1,189,792
A11759
A11333
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.Locale; import java.util.Scanner; public class B { void solve(int icase) { int n = si(); int s = si(); int p = si(); int[] t = new int[31]; for (int i = 0; i < n; i++) { t[si()]++; } int res = Math.min(p < 2 ? 0 : t[3 * p - 4] + t[3 * p - 3], s); for (int i = Math.max(3 * p - 2, 0); i <= 30; i++) { res += t[i]; } printf("Case #%d: %d\n", icase, res); } public static void main(String[] args) throws Exception { Locale.setDefault(Locale.US); new B().repSolve(); } void repSolve() throws Exception { scanner = new Scanner(System.in); // scanner = new Scanner(new java.io.File("")); int ncase = si(); sline(); for (int icase = 1; icase <= ncase; icase++) { solve(icase); System.err.println("[[ " + icase + " ]]"); } } Scanner scanner; int si() { return scanner.nextInt(); } long sl() { return scanner.nextLong(); } String ss() { return scanner.next(); } String sline() { return scanner.nextLine(); } void printf(String format, Object... args) { System.out.printf(format, args); } }
0
1,189,793
A11759
A12288
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 Dance { public static void main(String[] args) { try { InputStreamReader inReader = new InputStreamReader(new FileInputStream("input.txt")); BufferedReader br = new BufferedReader(inReader); File out = new File("output.txt"); Writer output = new BufferedWriter(new FileWriter(out)); int amount = Integer.parseInt(br.readLine()); for (int i=0; i < amount; i++) { output.write("Case #" + (i+1) + ": "); String line = br.readLine(); String[] values = line.split(" "); int dancers = Integer.parseInt(values[0]); int surprise = Integer.parseInt(values[1]); int minPoints = Integer.parseInt(values[2]); int minResultSur = (minPoints-2)*2 + minPoints; int minResult = (minPoints-1)*2 + minPoints; int endResult = 0; minResultSur = (minResultSur < 0) ? minPoints : minResultSur; minResult = (minResult < 0) ? minPoints : minResult; for (int j=0; j < dancers; j++) { int tmpResult = Integer.parseInt(values[3+j]); if (tmpResult >= minResult) endResult++; else if (tmpResult >= minResultSur && surprise > 0) { surprise--; endResult++; } } output.write(endResult + "\n"); } output.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
1,189,794
A11759
A11749
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 dancing { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("dancing.in")); PrintWriter out = new PrintWriter(new File("dancing.out")); StringTokenizer st = new StringTokenizer(br.readLine()); int cases = Integer.parseInt(st.nextToken()); int answer; for (int i = 0; i < cases; i++){ answer = 0; StringTokenizer data = new StringTokenizer(br.readLine()); int[] googlers = new int[Integer.parseInt(data.nextToken())]; int surprising = Integer.parseInt(data.nextToken()); int threshold = Integer.parseInt(data.nextToken()); for (int a = 0; a < googlers.length; a++){ googlers[a] = Integer.parseInt(data.nextToken()); } Arrays.sort(googlers); for (int z = googlers.length-1; z >= 0; z--){ if (googlers[z] == 0 && (threshold * 3) > 0){ } else if (googlers[z] >= ((threshold * 3) - 2)){ answer++; } else if (surprising > 0 && ((googlers[z] <= ((threshold * 3) - 2)) && (googlers[z] >= ((threshold * 3) - 4)))){ surprising--; answer++; } } out.println("Case #" + (i + 1) + ": " + answer); } out.close(); } }
0
1,189,795
A11759
A10716
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.io.File; import java.io.FileNotFoundException; import java.util.Scanner; /** * * Problem You're watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. No triplet of scores contains scores that are more than 2 apart. For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? For example, suppose there were 6 Googlers, and they had the following total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising triplets of scores, and you want to know how many Googlers could have gotten a best result of 8 or better. With those total points, and knowing that two of the triplets were surprising, the triplets of scores could have been: 10 9 10 6 6 8 (*) 2 3 3 6 6 6 6 6 6 6 7 8 (*) The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one score of 8 or better. There's no series of triplets of scores that would give us a higher number than 3, so the answer is 3. Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing integers separated by single spaces. The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. Output For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum number of Googlers who could have had a best result of greater than or equal to p. Limits 1 ≤ T ≤ 100. 0 ≤ S ≤ N. 0 ≤ p ≤ 10. 0 ≤ ti ≤ 30. At least S of the ti values will be between 2 and 28, inclusive. Small dataset 1 ≤ N ≤ 3. Large dataset 1 ≤ N ≤ 100. Sample Input 4 3 1 5 15 13 11 3 0 8 23 22 21 2 1 1 8 0 6 2 8 29 20 8 18 18 21 Output Case #1: 3 Case #2: 2 Case #3: 1 Case #4: 3 * 2012.04.14. 15:09 - 15:44 * @author Chei */ public class DancingWithTheGooglers { Scanner scanner; public static void main(String[] args) throws FileNotFoundException { new DancingWithTheGooglers().solve(); } void solve() throws FileNotFoundException { scanner = new Scanner(new File("resources/B-small-attempt0.in")); //scanner = new Scanner(new File("resources/B-example.in")); int numberOfTestCases = scanner.nextInt(); for (int testCaseIndex = 1; testCaseIndex <= numberOfTestCases; testCaseIndex++) { int result = solveTestCase(); System.out.format("Case #%d: %d%n", testCaseIndex, result); } } int solveTestCase() { int dancerCount = scanner.nextInt(); int surpriseCount = scanner.nextInt(); int bestResultToReach = scanner.nextInt(); int result = 0; for (int i = 1; i <= dancerCount; i++) { int totalPoints = scanner.nextInt(); int margin = 3 * (bestResultToReach - 1); // enough points without surprise if (totalPoints > margin) { result++; } else { if (surpriseCount > 0 && totalPoints > 0 && totalPoints + 2 > margin) { result++; surpriseCount--; } } } return result; } }
0
1,189,796
A11759
A11850
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 Q1; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; public class Dancing { /** * @param args */ public static void main(String[] args) { //Open the file for reading String thisLine; int numTest = 0; try { BufferedReader br = new BufferedReader(new FileReader("c:\\CodeJam\\Q1\\B-small-attempt0.in")); Writer output = new BufferedWriter(new FileWriter("c:\\CodeJam\\Q1\\B-small-attempt0.out")); numTest = Integer.parseInt(br.readLine()); int ansCount = 0; for (int i = 0; i < numTest; i++) { ansCount = 0; thisLine = br.readLine(); String[] inputArray = thisLine.split("\\s+"); int dancerNum = Integer.parseInt(inputArray[0]); int surpriseNum = Integer.parseInt(inputArray[1]); int pNum = Integer.parseInt(inputArray[2]); //System.out.println("Line 1 : d, s, p = "+dancerNum+", "+surpriseNum+", "+pNum); for (int j = 0; j < dancerNum; j++) { int total = Integer.parseInt(inputArray[3+j]); if (total < pNum) { continue; } int middleScore = total/3; int modScore = total%3; if (middleScore == 0 && modScore >= pNum) { ansCount++; continue; } if (middleScore >= pNum) { ansCount++; }else if (modScore == 0 && middleScore+1 >= pNum && surpriseNum > 0){ ansCount++; surpriseNum--; }else if (modScore == 1 && middleScore+1 >= pNum) { ansCount++; }else if (modScore == 2 && middleScore+1 >= pNum) { ansCount++; }else if (modScore == 2 && middleScore+2 >= pNum && surpriseNum > 0) { ansCount++; surpriseNum--; } //System.out.println("total "+ j +" : "+total + ", div = "+middleScore+", mod = "+modScore); } System.out.println("Case #"+(i+1)+": "+ansCount); if (i == numTest-1) { output.write("Case #"+(i+1)+": "+ansCount); }else { output.write("Case #"+(i+1)+": "+ansCount+"\n"); } } // end while output.close(); } // end try catch (IOException e) { System.err.println("Error: " + e); } } }
0
1,189,797
A11759
A10053
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; import javax.swing.text.html.MinimalHTMLWriter; public class B { public static void main(String[] args) throws FileNotFoundException { //File fich = new File("C:\\b-teste.in"); File fich = new File("C:\\B-small-attempt5.in"); Scanner input = new Scanner(fich); int num_googlers, num_surp, score_min; int num_casos, resultado, tmp, resto; num_casos = input.nextInt(); for(int i = 0; i < num_casos; i++){ resultado = 0; num_googlers = input.nextInt(); num_surp = input.nextInt(); score_min = input.nextInt(); int googlers[] = new int[num_googlers]; for(int j = 0; j < num_googlers; j++){ googlers[j] = input.nextInt(); if (score_min == 0){ resultado++; continue; } if (googlers[j] == 0) continue; tmp = googlers[j] / 3; resto = googlers[j] % 3; if (resto == 0){ if (tmp >= score_min) resultado++; else if (num_surp > 0 && tmp + 1 >= score_min){ resultado++; num_surp--; } }else if (resto == 1 ){ if (tmp + 1 >= score_min) resultado++; else if (num_surp > 0 && tmp + 1 >= score_min){ resultado++; num_surp--; } }else if (resto == 2){ if (tmp + 1 >= score_min) resultado++; else if (num_surp > 0 && tmp + 2 >= score_min){ resultado++; num_surp--; } } } System.out.println("Case #" + (i+1) + ": " + resultado); } } }
0
1,189,798
A11759
A13100
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 cj2012.qual; import java.io.*; import java.util.Arrays; public class ProblemB extends PrintWriter { private final static String PREFIX = "ProblemB_"; private final static String INPUT_FILE = PREFIX + "in.txt"; private final static String OUTPUT_FILE = PREFIX + "out.txt"; private static final int BUFF_SIZE = 64 * 1024; int pos = 0; int len = -1; final DataInputStream dis; final byte[] b = new byte[BUFF_SIZE]; public static void main(String[] args) throws Exception { ProblemB problem = new ProblemB(new BufferedOutputStream(System.out)); problem.solve(); problem.flush(); problem.close(); } public ProblemB(OutputStream os) throws FileNotFoundException { super(new BufferedOutputStream(new FileOutputStream(OUTPUT_FILE))); dis = new DataInputStream(new BufferedInputStream(new FileInputStream(INPUT_FILE))); } public int read() { if (pos >= len) { pos = 0; len = -1; try { len = dis.read(b); } catch (IOException ex) { } } return pos < len ? b[pos++] : -1; } public int nextInt() throws IOException { int ret = 0; int ch = skipWhite(); int sign = 1; if (ch == '-') { sign = -1; ch = read(); } while (!isSpaceChar(ch) && ch != -1) { ret *= 10; ret += ch - '0'; ch = read(); } return ret * sign; } public long nextLong() throws IOException { long ret = 0; int ch = skipWhite(); int sign = 1; if (ch == '-') { sign = -1; ch = read(); } while (!isSpaceChar(ch) && ch != -1) { ret *= 10; ret += ch - '0'; ch = read(); } return ret * sign; } public int skipWhite() throws IOException { int ch = read(); while (true) { if (ch == -1) { return -1; } if (!isSpaceChar(ch)) { return ch; } ch = read(); } } public boolean isSpaceChar(int c) { return c <= 32 && c >= 0; } public int next(char[] buff) throws IOException { int c = skipWhite(); int len = 0; while (!isSpaceChar(c) && c != -1) { buff[len++] = (char) c; c = read(); } return len; } public String next() throws IOException { int c = skipWhite(); StringBuilder res = new StringBuilder(); while (!isSpaceChar(c) && c != -1) { res.appendCodePoint(c); c = read(); } return res.toString(); } public String nextLine() throws IOException { int c = skipWhite(); StringBuilder res = new StringBuilder(); while (c != '\n' && c != '\r' && c != -1) { res.appendCodePoint(c); c = read(); } return res.toString(); } void debug(Object... obj) { println("-->" + Arrays.deepToString(obj)); } void solve() throws Exception { int cases = nextInt(); for (int kk = 1; kk <= cases; kk++) { int n = nextInt(); int s = nextInt(); int p = nextInt(); int sol = 0; for (int i = 0; i < n; i++) { int v = nextInt(); if (v >= (p * 3 - 2)) { sol++; continue; } if (s > 0 && v >= (p * 3 -4) && p>1) { s--; sol++; continue; } } println(String.format("Case #%d: %d", kk, sol)); } } }
0
1,189,799