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
A12304
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 sc = new Scanner(System.in); int lines = sc.nextInt(); for (int i=0; i<lines; i++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int rNormal = p; int rSurprise = p; if (p>1) { rNormal = p*3 - 2; rSurprise = p*3 - 4; } int countPassedNormal = 0; int countPassedSurprise = 0; for (int j=0; j<n; j++) { int t = sc.nextInt(); if (t>=rNormal) { countPassedNormal++; } else if (t>=rSurprise) { countPassedSurprise++; } } if (countPassedSurprise>s) countPassedSurprise = s; System.out.println("Case #"+(i+1)+": "+(countPassedNormal+countPassedSurprise)); } } }
0
1,188,900
A11759
A10030
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.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class GoogleB { /** * @param args */ public String szamol(String input){ String result=""; String a=input; Integer countgooglers=Integer.parseInt(a.substring(0,a.indexOf(' '))); a=a.substring(a.indexOf(' ')+1); Integer surprize=Integer.parseInt(a.substring(0,a.indexOf(' '))); a=a.substring(a.indexOf(' ')+1); Integer[] totalscore=new Integer[countgooglers]; Integer all=0; Integer sur=0; if (countgooglers>0) { Integer minscore=Integer.parseInt(a.substring(0,a.indexOf(' '))); a=a.substring(a.indexOf(' ')+1); for (int i=0; i<countgooglers;i++){ if (i<countgooglers-1){ totalscore[i]=Integer.parseInt(a.substring(0,a.indexOf(' '))); a=a.substring(a.indexOf(' ')+1); } else totalscore[i]=Integer.parseInt(a); } for (int i=0; i<countgooglers;i++){ int maxscore=(totalscore[i]%3==2)?totalscore[i]/3+2:totalscore[i]/3+1; if (totalscore[i]==0) maxscore=0; if (totalscore[i]>=27) maxscore=10; if (maxscore<minscore) { } else if (maxscore==minscore) { if (totalscore[i]%3==1 || totalscore[i]==0 || totalscore[i]>28) all++; else sur++; } else all++; } } int maxgooglers=all; maxgooglers+=(sur<surprize)?sur:surprize; result=""+maxgooglers; return result; } public static void main(String[] args) { GoogleB a=new GoogleB(); //String filename="input.txt"; String filename="B-small-attempt1.in"; String thisLine; try { BufferedReader br = new BufferedReader(new FileReader(filename)); BufferedWriter bw= new BufferedWriter(new FileWriter(filename+".out")); thisLine=br.readLine(); Integer tnum=Integer.parseInt(thisLine); for(int i=0;i<tnum;i++) { // while loop begins here thisLine=br.readLine(); System.out.println(thisLine); System.out.println("Case #"+(i+1)+": "+a.szamol(thisLine)+"\n"); bw.write("Case #"+(i+1)+": "+a.szamol(thisLine)+"\n"); } // end while // end try br.close(); bw.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
1,188,901
A11759
A11143
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()); } } }
// Problem B import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Locale; import java.util.Scanner; public class B { private void processInput() throws IOException { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int testCase = 1; testCase <= T; testCase++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int[] arr = new int[N]; for (int j = 0; j < N; j++) { arr[j] = in.nextInt(); } int res = go(N, S, p, arr); System.out.printf(Locale.ENGLISH, "Case #%d: %d\n", testCase, res); } in.close(); } private int go(int N, int S, int p, int[] arr) { int res = 0; int s = S; for (int i = 0; i < N; i++) { int rr = -1; for (int P = p; P <= 10; P++) { int diff = arr[i] - P; if (diff >= 0) { int v1 = diff / 2; int v2 = diff - v1; if (P >= v1 && P >= v2) { if (P - v1 <= 1 && P - v2 <= 1) { rr = 0; } else if (P - v1 <= 2 && P - v2 <= 2) { if (rr == -1) { rr = 1; } } } } } if (rr == 0) { res++; } else if (rr == 1 && s > 0) { s--; res++; } } return res; } public static void main(String[] args) throws Exception { B temp = new B(); temp.processInput(); } }
0
1,188,902
A11759
A12813
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.Scanner; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Ankur */ public class DacingWithTheGooglers { public static void main(String[] args) { try { FileWriter fout = new FileWriter("out"); BufferedWriter out = new BufferedWriter(fout); try { Scanner in = new Scanner(new File("in")); int T = in.nextInt(); System.out.println(T); for(int i=0; i<T; ++i) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int t; int ans = 0; for(int j=0; j<N; ++j) { t = in.nextInt(); if(p==0) { ans = N; } else { if(t >= (3*p - 4) && t > 0) { if(t >= (3*p - 2)) ans++; else { if(S != 0) { S--; ans++; } } } } } out.write("Case #" + (i+1) + ": " + ans); out.newLine(); } out.close(); }catch(FileNotFoundException e) { System.out.println("ERROR: File Not Found!"); } }catch(IOException x) { System.out.println("ERROR: Can't create output file"); } } }
0
1,188,903
A11759
A11527
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.math.*; public class dancingGooglers { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner scan = new Scanner(System.in); int numStrings = scan.nextInt(); for(int i =1; i <= numStrings; i++){ int numGooglers = scan.nextInt(); int numSurprises = scan.nextInt(); int p = scan.nextInt(); int[] totalScores; totalScores = new int[numGooglers]; int withoutSurpriseCount, withSurpriseCount; withoutSurpriseCount = 0 ; withSurpriseCount = 0; for(int j = 1; j <= numGooglers; j++){ totalScores[j-1] = scan.nextInt(); if(totalScores[j-1] >= p + 2*Math.max(p-1, 0)){ withoutSurpriseCount = withoutSurpriseCount + 1; } else if(totalScores[j-1] >= p + 2*Math.max(p-2,0)){ withSurpriseCount = withSurpriseCount + 1; } } //System.out.println("\n " + numGooglers + " " + numSurprises + " " + withoutSurpriseCount + " " + withSurpriseCount); int temp1 = Math.min(withSurpriseCount, numSurprises); int temp2 = temp1 + withoutSurpriseCount; int temp3 = Math.min(numGooglers, temp2); System.out.format("Case #%d: %d\n", i, temp3); } } }
0
1,188,904
A11759
A10354
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 codejam2012; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; /** * * @author acer */ public class B { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { // TODO code application logic here FileInputStream input = new FileInputStream("input.txt"); DataInputStream in = new DataInputStream(input); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileOutputStream output = new FileOutputStream("output.txt"); int T = Integer.parseInt(br.readLine()); for (int i = 0; i < T; i++) { String[] temp = br.readLine().split(" "); int N = Integer.parseInt(temp[0]); int S = Integer.parseInt(temp[1]); int P = Integer.parseInt(temp[2]); int[] points = new int[N]; int count = 0, scount = 0; for (int j = 0; j < N; j++) { points[j] = Integer.parseInt(temp[j + 3]); int avg = points[j] / 3; if (points[j] % 3 == 0) { if (avg >= P) { count++; } else if ((avg + 1) == P && avg != 0 && avg != 10) { scount++; } } else if (points[j] % 3 == 1) { if ((avg+1) >= P) { count++; } } else if (points[j] % 3 == 2) { if ((avg + 1) >= P) { count++; } else if ((avg + 2) == P && avg != 9) { scount++; } } } if (S >= scount) { output.write(("Case #" + (i + 1) + ": " + (count + scount) + "\n").getBytes()); } else { output.write(("Case #" + (i + 1) + ": " + (count + S) + "\n").getBytes()); } } } }
0
1,188,905
A11759
A12206
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.rudy.cj2012; import java.io.*; import java.util.Scanner; /** * User: rudy */ public class Dancing { public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new BufferedInputStream(new FileInputStream("B-small-attempt0.in"))); PrintStream out = new PrintStream(new FileOutputStream("B-small.out")); int nTests = scanner.nextInt(); for (int test = 1; test <= nTests; test++) { int n = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); int [] t = new int[n]; int potential = 0; int already = 0; for (int f = 0; f < n; f++) { t[f] = scanner.nextInt(); int minScore = (t[f]+2) / 3; int maxScore = (t[f]+4) / 3; if (minScore >= p) { already++; continue; } if (maxScore >=p && t[f] > 1) potential++; } out.printf("Case #%d: %d\n", test, already + Math.min(potential, s)); } out.close(); } }
0
1,188,906
A11759
A11334
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.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; import java.util.Vector; public class Dancers { private static final int P_MIN = 0; private static final int P_MAX = 10; static final int MAXDIFFERENCEINTRIPLE=4; static final int REGULARDIFFERENCEINTRIPLE=2; static final Map<Integer, Integer> thresholdRegular=new HashMap<Integer, Integer>(); static final Map<Integer, Integer> thresholdSurprising=new HashMap<Integer, Integer>(); public static void main(String[] args) throws IOException { calcThresholdSumOfPointsForDifferentPs(); Vector<String> result=readAndevaluateCases(); writeResults(result); } // p between 0 and 10-> calculate min sum of points a dancer has to have been able to achieve at least p points once private static void calcThresholdSumOfPointsForDifferentPs() { Integer pointThresholdRegular=0; Integer pointThresholdSurprising=0; for (int p = P_MIN; p <= P_MAX; p++) { pointThresholdSurprising=Math.max(3*p-MAXDIFFERENCEINTRIPLE,p); thresholdSurprising.put(p, pointThresholdSurprising); pointThresholdRegular=Math.max(3*p-REGULARDIFFERENCEINTRIPLE,p); thresholdRegular.put(p, pointThresholdRegular); } } private static Vector<String> readAndevaluateCases() throws IOException { Vector<String> result = new Vector<String>(); try{ FileInputStream fstream = new FileInputStream("InputDancers"); BufferedReader br = new BufferedReader(new InputStreamReader(fstream)); String strLine; int caseCounter=0; int numberSurprisingTriplets; int counterSurprisingT; int p; int minPointsNecessaryToBeAbleToAchievePRegulary; int minPointsNecessaryToBeAbleToAchievePSurprisingly; int sumOfPointsGoogeler; int counterPAchieved=0; //jump over first line br.readLine(); while ((strLine = br.readLine()) != null) { String[] round=strLine.split(" "); caseCounter++; numberSurprisingTriplets=Integer.parseInt(round[1]); counterSurprisingT=0; p=Integer.parseInt(round[2]); minPointsNecessaryToBeAbleToAchievePRegulary=thresholdRegular.get(p); minPointsNecessaryToBeAbleToAchievePSurprisingly=thresholdSurprising.get(p); counterPAchieved=0; for (int i = 3; i < round.length; i++) { sumOfPointsGoogeler=Integer.parseInt(round[i]); if(employeAchievedThresholdForRegularT(sumOfPointsGoogeler,minPointsNecessaryToBeAbleToAchievePRegulary)) counterPAchieved++; else if (suprisingTripletsleft(numberSurprisingTriplets,counterSurprisingT) && employeeAchievedThresholdForSuprisingT(sumOfPointsGoogeler,minPointsNecessaryToBeAbleToAchievePSurprisingly)){ counterSurprisingT++; counterPAchieved++; } } //System.out.println("Case #"+caseCounter+": "+counterPAchieved); result.add("Case #"+caseCounter+": "+counterPAchieved); } fstream.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } return result; } private static boolean employeeAchievedThresholdForSuprisingT(int sumOfPointsGoogeler, int minPointsNecessaryToBeAbleToAchievePSurprisingly) { return sumOfPointsGoogeler>=minPointsNecessaryToBeAbleToAchievePSurprisingly; } private static boolean suprisingTripletsleft(int numberSurprisingTriplets, int counterSurprisingT) { return numberSurprisingTriplets>counterSurprisingT; } private static boolean employeAchievedThresholdForRegularT(int sumOfPoint, int threshold) { return sumOfPoint>=threshold; } private static void writeResults(Vector<String> result) { try{ FileWriter fw = new FileWriter("outputDancers"); BufferedWriter out = new BufferedWriter(fw); for (int i = 0; i < result.size(); i++) { out.write(result.get(i)); if(i<result.size()-1)out.write("\n"); } out.close(); }catch (Exception e){ } } }
0
1,188,907
A11759
A12904
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 googlers { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner fe = new Scanner(new FileInputStream( "/home/gllera/Desktop/data.in")); FileWriter fs = new FileWriter("/home/gllera/Desktop/data.out"); int cases = fe.nextInt(); for (int i = 0; i < cases; i++) { int n = fe.nextInt(); int s = fe.nextInt(); int p = fe.nextInt(); int sol = 0; for (int j = 0; j < n; j++) { int num = fe.nextInt(); if (num == 0) { if (p == 0) sol++; continue; } if (num / 3 >= p) { sol++; continue; } if (num % 3 != 0) if (num / 3 + 1 >= p) { sol++; continue; } if (num % 3 != 1) if (s != 0) if (num % 3 != 0) { if (num / 3 + 2 >= p) { sol++; s--; } } else { if (num / 3 + 1 >= p) { sol++; s--; } } } fs.write("Case #" + (i + 1) + ": " + sol + '\n'); } fe.close(); fs.flush(); fs.close(); } }
0
1,188,908
A11759
A12066
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 DancingGooglers { public static void main(String args[]) { try { String strFileName = args[0]; BufferedReader bfReader = new BufferedReader(new FileReader(strFileName)); long nTestCases = Integer.parseInt(bfReader.readLine()); for(int testCaseCounter=0;testCaseCounter<nTestCases;testCaseCounter++) { StringTokenizer st = new StringTokenizer(bfReader.readLine()); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int i=0; int t[] = new int[N]; while(st.hasMoreTokens()) { t[i++]=Integer.parseInt(st.nextToken()); } int p1 = (p*3)-3; int p2 = (p*3)-4; int px = (p*3)-2; int ret=0; int s=0; for(i=0;i<N;i++) { if((t[i]>=p)&&(t[i]==p1||t[i]==p2)) s++; else if((t[i]>=p)&&(t[i]>=px)) ret++; } if(s<=S) ret+=s; else ret+=S; System.out.println("Case #" + (testCaseCounter+1) + ": " + ret); } } catch(FileNotFoundException e) { System.out.println(e.getMessage()); } catch(IOException e) { System.out.println(e.getMessage()); e.printStackTrace(); } } }
0
1,188,909
A11759
A12295
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; public class DancingWithTheGooglers { private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); private static Scanner sc = new Scanner(br); public static void main ( String [] args ) throws IOException { int N = Integer.parseInt(br.readLine()); for(int i = 0;i < N; i++) { System.out.print("Case #" + (i+1) + ": "); new DancingWithTheGooglers().cal(); } } private void cal() throws IOException { int ret = 0; int number = sc.nextInt(); int[] numberArray = new int[number]; int surprising = sc.nextInt(); int p = sc.nextInt(); int sDeadLine = p*3-4; int deadLine = p*3-2; if (p == 0){ sDeadLine = 100; deadLine = 0; } if (p == 1){ sDeadLine = 100; deadLine = 1; } boolean[] okay = new boolean[number]; boolean[] sOkay = new boolean[number]; int okayCounter = 0, sOkayCounter = 0; for(int i = 0; i < number; i++){ numberArray[i] = sc.nextInt(); if (numberArray[i] >= deadLine){ okay[i] = true; okayCounter++; sOkay[i] = true; sOkayCounter++; } else if( numberArray[i] >= sDeadLine ){ okay[i] = false; sOkay[i] = true; sOkayCounter++; } else { okay[i] = false; sOkay[i] = false; } } ret = okayCounter; ret += (sOkayCounter - okayCounter) > surprising? surprising : (sOkayCounter - okayCounter); System.out.println(ret); } }
0
1,188,910
A11759
A11478
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()); } } }
/** * Dancing With the Googlers */ package com.google.jam.qualification; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Scanner; public class B { public static void main(String[] args) { try { FileOutputStream fos = new FileOutputStream("B-small-attempt0.out"); System.setOut(new PrintStream(fos, true)); FileInputStream fis=new FileInputStream(new File("B-small-attempt0.in")); InputStreamReader in=new InputStreamReader(fis); BufferedReader br=new BufferedReader(in); String line=""; int nbTest = Integer.parseInt(br.readLine()); for(int i=1; i<=nbTest; i++) { line = br.readLine(); Scanner sc = new Scanner(line); int nbJ = sc.nextInt(); int nbS = sc.nextInt(); int minPoint = sc.nextInt(); int res = 0; boolean stop = false; for(int j=0; j<nbJ && !stop; j++) { int total = sc.nextInt(); int moy = total / 3; int reste = total%3; if(moy >= minPoint) res++; else if((moy+1)>= minPoint) { if(reste==2 || reste ==1) res++; else if(nbS>0 && reste==0 && moy>0) { res++; nbS--; } } else if((moy+2)>= minPoint) { if(nbS>0 && reste==2) { res++; nbS--; } } } System.out.println("Case #" + i + ": " + res); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block System.out.println("File not found"); e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
1,188,911
A11759
A10883
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.util.ArrayList; import java.util.List; public class Dancers implements Solver { int N; int S; int p; List<Integer> dan = new ArrayList<Integer>(); public Dancers(List<String> lineas) { String[] cosa = lineas.get(0).split(" "); N=Integer.parseInt(cosa[0]); S=Integer.parseInt(cosa[1]); p=Integer.parseInt(cosa[2]); for (int i=0; i<N; i++){ dan.add(Integer.parseInt(cosa[i+3])); } // TODO Auto-generated constructor stub } @Override public String solve() { int conta=0; for (int i=0; i<N; i++){ if (dan.get(i)>=p+p-1+p-1 && dan.get(i)>=p){ conta++; } else if(dan.get(i)>=p+p-2+p-2 && dan.get(i)>=p && S>0){ conta++; S--; } } // TODO Auto-generated method stub return conta+""; } }
0
1,188,912
A11759
A12156
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 luis.miguel.serrano.utilities; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; import luis.miguel.serrano.settings.GlobalSettings; /** * Data class for processing input and generating output * @author Luis Miguel Serrano * */ public class DataB { private File inputFile; private File outputFile; public DataB(String inputFilePath, String outputFilePath) { this.inputFile = new File(inputFilePath); outputFile = new File(outputFilePath); } public DataB(File inputFile) { this.inputFile = inputFile; outputFile = new File(GlobalSettings.OUTPUT_FILE_PATH); } /** * Processes the file passed as argument in the constructor * @throws FileNotFoundException */ public void processFile() throws FileNotFoundException { if(outputFile.exists()) outputFile.delete(); Scanner scanner = new Scanner(inputFile); final int casesNumber = scanner.nextInt(); scanner.nextLine(); for(int i = 0; i!=casesNumber; ++i) processCase(scanner, i); System.out.println("Done processing file: "+inputFile); } //Format-specific private void processCase(Scanner scanner, int caseNumber) { //System.out.println("New Case"); int numberGooglers = scanner.nextInt(); int numberSurprisingTripletScores = scanner.nextInt(); int p = scanner.nextInt(); int[] totalScores = new int[numberGooglers]; for(int i = 0; i!=numberGooglers; ++i) totalScores[i] = scanner.nextInt(); int solution; solution = getSolution(numberGooglers, numberSurprisingTripletScores, p, totalScores); //Write solution to file try { FileWriter fw = new FileWriter(outputFile, true); fw.write("Case #"+(caseNumber+1)+": "+solution+"\r\n"); fw.flush(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } //Problem-specific private int getSolution(int numberGooglers, int numberSurprisingTripletScores, int p, int[] totalScores){ int solution = 0; int[][] triplets = new int[numberGooglers][3]; //Generate Score Triplets int surprisingTripletsRemaining = numberSurprisingTripletScores; for(int i = 0; i!= triplets.length; ++i) { int baseValue = totalScores[i]/3; int rest = totalScores[i]%3; if(rest == 2) { int max = baseValue+2; //If it is "worth it" spending one surprising triplet to make this one count for "the most" if(p == max && surprisingTripletsRemaining != 0) --surprisingTripletsRemaining; else { ++baseValue; rest -= 3; } } for(int j = 0; j!=triplets[i].length; ++j){ if(j == 0) { triplets[i][j] = baseValue+rest; } else { triplets[i][j] = baseValue; } } //Integrity Check int total = 0; for(int j = 0; j!=triplets[i].length; ++j) total += triplets[i][j]; if(total != totalScores[i]) System.out.println("Total Scores Mismatch ERROR!"); } //If there are remaining triplets to spend, try to spend them in cases in which rest was = 0 for(int i = 0; i!=triplets.length; ++i) if(surprisingTripletsRemaining != 0){ if(triplets[i][0] == triplets[i][1] && triplets[i][0] == triplets[i][2] && triplets[i][0] + 1 == p && triplets[i][0] != 0) { triplets[i][0] += 1; triplets[i][1] -= 1; --surprisingTripletsRemaining; } } else break; // //Print (DEBUG) // for(int i = 0; i!=triplets.length; ++i) // for(int j = 0; j!= triplets[i].length; ++j) // System.out.println("triplets["+i+"]["+j+"] = "+triplets[i][j]); //Find solution for(int i = 0; i!=triplets.length; ++i){ for(int j = 0; j!= triplets[i].length; ++j) { if(triplets[i][j] >= p){ ++solution; break; } } } return solution; } /** * @param args */ public static void main(String[] args) { //DataB dataSample = new DataB(GlobalSettings.PROJECT_PATH+"\\input\\input_sample.in", GlobalSettings.PROJECT_PATH+"\\output\\input_sample.out"); DataB dataSmall = new DataB(GlobalSettings.PROJECT_PATH+"\\input\\B-small-attempt0.in", GlobalSettings.PROJECT_PATH+"\\output\\B-small-attempt0.out"); //Data dataLarge = new Data(GlobalSettings.PROJECT_PATH+"\\input\\A-large-practice.in", GlobalSettings.PROJECT_PATH+"\\output\\A-large-practice.out"); try { //dataSample.processFile(); dataSmall.processFile(); //dataLarge.processFile(); } catch (FileNotFoundException e) { e.printStackTrace(); } System.out.println("Finished processing all input!"); } }
0
1,188,913
A11759
A12449
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 Googlers { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int test = scan.nextInt(); for (int a = 1; a <= test; a++){ int x = scan.nextInt(); int surprising = scan.nextInt(); int cutoff = scan.nextInt(); //int c0 = 3*cutoff; int c1 = cutoff + (2*(cutoff-1)); int c2 = cutoff + (2*(cutoff-2)); int count = 0; int[] scores = new int[x]; for (int i = 0; i < x; i++) scores[i] = scan.nextInt(); for (int b = 0; b < x; b++){ int points = scores[b]; if ( points >= c1 ) count++; else if ( surprising > 0 ){ if (cutoff > 1){ if ( points >= c2 ){ count++; surprising--; } } } } System.out.println( "Case #" + a + ": " + count); } } }
0
1,188,914
A11759
A12287
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.util.Scanner; public class B { /** * @param args */ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int nbr_case = scan.nextInt(); for(int i = 0; i < nbr_case; i++) { int N = scan.nextInt(); int S = scan.nextInt(); int p = scan.nextInt(); int possible_max = 0; int curr =0; //int[] vec = new int[N]; for( int j = 0; j<N;j++) { curr = scan.nextInt(); if(S> 0) { if(curr > (p*3 - 3) && (curr >= p)) { possible_max++; } else { if(curr > (p*3-5) && (curr >= p)) { possible_max++; S--; } } } else { if(curr > (p*3 - 3) && (curr >= p)) { possible_max++; } } //vec[j] = scan.nextInt(); } //System.out.println(vec.toString()); System.out.format("Case #%d: %d\n", i+1, possible_max); } } }
0
1,188,915
A11759
A10362
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.*; import java.math.*; import java.awt.*; import static java.lang.Math.*; import static java.lang.Integer.parseInt; import static java.lang.Double.parseDouble; import static java.lang.Long.parseLong; import static java.lang.System.*; import static java.util.Arrays.*; import static java.util.Collection.*; public class B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(in)); int T = parseInt(br.readLine()); for(int t = 0; t++ < T; ) { String[] line = br.readLine().split(" "); int N = parseInt(line[0]); int S = parseInt(line[1]); int p = parseInt(line[2]); int C = 0; for(int n = 0; n < N; ++n) { int g = parseInt(line[n + 3]); if(3*p - 2 <= g) C++; else if((p == 1 ? 1 : 3*p - 4) <= g && S != 0) { C++; S--; } } out.println("Case #" + t +": " + C); } } }
0
1,188,916
A11759
A12139
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.FileInputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; import java.util.Scanner; public class Run3 { class ll { public lln f; public lln l; } class lln { public Object v; public lln n; } private static Scanner sc; public static int gi() { return Integer.parseInt(sc.next()); } public static String gn() { return sc.next(); } public static void main(String[] args) throws IOException { System.setIn(new FileInputStream("B-small-attempt8.in")); System.setOut(new PrintStream("output.txt")); sc = new Scanner(System.in); int T = gi(); for (int z = 0; z < T; z++) { int N = gi(); int S = gi(); int P = gi(); int[] ti = new int[N]; for(int i = 0; i < N; i++) { ti[i] = gi(); } int c = 0; int[][] sc = new int[N][3]; //System.out.println("z: " + z); //System.out.println("N: " + N); //System.out.println("S: " + S); //ystem.out.println("P: " + P); //System.out.println(/*N + " " + */S + " " + P /*+ ' ' + z + " "*/); int temp = 0; for(int i = 0; i < N; i++) { temp = ti[i]; for(int j = 2; j >= 0; j--) { sc[i][j] = temp/(j+1); temp -= temp/(j+1); } Arrays.sort(sc[i]); //System.out.println(ti[i] + "\t" + sc[i][0] + "," + sc[i][1] + "," + sc[i][2] + "\t" + (sc[i][0] + sc[i][1] + sc[i][2])); } int c2 = 0; boolean incc2; for (int i = 0; i < N; i++) { incc2 = false; if(c2 < S) { if(sc[i][2] < P && sc[i][2] + 1 == P) { /*if(sc[i][2] - sc[i][0] == 1 && sc[i][2] - sc[i][1] == 0) { sc[i][2] += 1; sc[i][1] -= 1; incc2 = true; } else */ if(sc[i][0] > 0 && sc[i][2] - sc[i][0] == 0) { sc[i][2] += 1; sc[i][0] -= 1; incc2 = true; } else if(sc[i][1] > 0 && sc[i][2] - sc[i][0] == 1 && sc[i][2] - sc[i][1] == 0) { sc[i][2] += 1; sc[i][1] -= 1; incc2 = true; } } if(incc2) { c2++; } } if(sc[i][2] >= P) { c++; } } System.out.format("Case #%d: %d\r\n", z + 1, c); } } }
0
1,188,917
A11759
A13134
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.irabin.google.codejam.problem2; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Scanner; public class DanceWithGoogler { class Score { private Long score; private Long firstJury; private Long secondJury; private Long thirdJury; public Score() { } public Long getScore() { return score; } public void setScore(Long score) { this.score = score; } public Long getFirstJury() { return firstJury; } public void setFirstJury(Long firstJury) { this.firstJury = firstJury; } public Long getSecondJury() { return secondJury; } public void setSecondJury(Long secondJury) { this.secondJury = secondJury; } public Long getThirdJury() { return thirdJury; } public void setThirdJury(Long thirdJury) { this.thirdJury = thirdJury; } public boolean isSuprisedResult() { boolean suprise = false; if (Math.abs(firstJury - secondJury) >= 2 || Math.abs(firstJury - thirdJury) >= 2 || Math.abs(secondJury - thirdJury) >= 2) { suprise = true; } return suprise; } } private Scanner scanner; private PrintWriter writer; public DanceWithGoogler(InputStream in, OutputStream os) { scanner = new Scanner(in); writer = new PrintWriter(os); } public void solve() { int n = Integer.parseInt(scanner.nextLine()); for (int i = 1; i <= n; i++) { writer.print("Case #" + i + ": "); if (i == n-1) { System.out.println("Debug"); } int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); String output = ""; int totalBetterThanP = 0; int foundSuprise = 0; Score[] scores = new Score[N]; for (int j = 0; j < N; j++) { scores[j] = new Score(); scores[j].setScore(scanner.nextLong()); } // sort ascending for (int j = 0; j < N; j++) { for (int k = j + 1; k < N; k++) { if (scores[k].getScore() > scores[j].getScore()) { Score tempScore = scores[k]; scores[k] = scores[j]; scores[j] = tempScore; } } } for (int j = 1; j <= N; j++) { Long equalScore = scores[j - 1].getScore() / 3; Long firstJury = equalScore; Long secondJury = equalScore; Long thirdJury = equalScore; Long dividen = scores[j - 1].getScore() % 3; while (dividen > 0) { firstJury = firstJury + 1; dividen = dividen - 1; if (dividen > 0) { secondJury = secondJury + 1; dividen = dividen - 1; } if (dividen > 0) { thirdJury = thirdJury + 1; dividen = dividen - 1; } } scores[j - 1].setFirstJury(firstJury); scores[j - 1].setSecondJury(secondJury); scores[j - 1].setThirdJury(thirdJury); } for (int j = 1; j <= N; j++) { if (scores[j - 1].isSuprisedResult()) { foundSuprise = foundSuprise + 1; } else { if (foundSuprise < S && ((scores[j-1].getFirstJury()<p && scores[j-1].getSecondJury()<p && scores[j-1].getThirdJury()<p)||(j<N && scores[j].getScore()<5))) { scores[j - 1].setFirstJury(scores[j-1].getFirstJury() - 1); if (scores[j - 1].getSecondJury() < p) { scores[j - 1].setSecondJury(scores[j - 1].getSecondJury() + 1); } else if (scores[j - 1].getThirdJury() < p) { scores[j - 1].setThirdJury(scores[j - 1].getThirdJury() + 1); } else { scores[j - 1].setSecondJury(scores[j - 1].getSecondJury() + 1); } foundSuprise = foundSuprise + 1; } } if (scores[j-1].getFirstJury() >= p || scores[j-1].getSecondJury() >= p || scores[j-1].getThirdJury() >= p) { totalBetterThanP = totalBetterThanP + 1; } } output = String.valueOf(totalBetterThanP); writer.println(output); writer.flush(); } writer.close(); } public static void main(String args[]) { InputStream input = null; input = DanceWithGoogler.class.getResourceAsStream(args[0]); OutputStream output = null; try { output = new FileOutputStream(args[1]); } catch (FileNotFoundException e) { e.printStackTrace(); } DanceWithGoogler practise1 = new DanceWithGoogler(input, output); practise1.solve(); } }
0
1,188,918
A11759
A11566
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.lang.*; import java.util.*; public class B { public static void main(String[] args) { B prob = new B(); prob.run(args[0]); } public void run(String fileName) { try { Scanner fin = new Scanner(new File(fileName)); PrintWriter fout = new PrintWriter(new File(fileName + ".out")); int T = fin.nextInt(); for (int t = 1; t <= T; ++t) { fout.format("Case #%d: ", t); int N = fin.nextInt(); int S = fin.nextInt(); int p = fin.nextInt(); int result = 0; for (int i = 0; i < N; ++i) { int ti = fin.nextInt(); if (p == 0) { ++result; continue; } if (ti >= (3 * p - 2)) { ++result; continue; } if (p == 1) continue; if (ti >= (3 * p - 4)) { if (S == 0) continue; ++result; --S; } } fout.format("%d\n", result); } fin.close(); fout.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
1,188,919
A11759
A10275
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.qualification; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; public class ProblemB { public static void main(String[] args) throws IOException { String problem = "ProblemB"; Scanner in = new Scanner(ClassLoader.getSystemResourceAsStream(String.format("%s.in", problem))); PrintStream out = new PrintStream(String.format("C:\\workplace\\GoogleCodeJam\\src\\codejam2012\\qualification\\%s.out", problem)); // out = System.out; // 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 int numInputs = in.nextInt(); in.nextLine(); for (int i = 0; i < numInputs; i++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int c = 0; for (int j = 0; j < N; j++) { int n = in.nextInt(); int t; if (n % 3 == 0) { t = n / 3; } else { t = n / 3 + 1; } if (t >= p) { c++; continue; } if (t + 1 == p && n % 3 != 1 && t != 0 && S > 0) { c++; S--; } } out.println("Case #" + (i+1) + ": " + c); // out.println(map); } } }
0
1,188,920
A11759
A12379
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 blacky.codejam.qualifications; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.StringTokenizer; public class DancingGoogler { public static void main(String args[]) throws NumberFormatException, IOException { File file = new File(args[0]); BufferedReader reader = new BufferedReader(new FileReader(file)); int numberOfTestCases = Integer.parseInt(reader.readLine()); for(int i = 0; i < numberOfTestCases; i++) { StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); int minimumerGooglers = 0; int usedSurprisingTriplets = 0; final int numberOfGooglers = Integer.parseInt(tokenizer.nextToken()); final int surprisingTriplets = Integer.parseInt(tokenizer.nextToken()); final int bestResultMinimum = Integer.parseInt(tokenizer.nextToken()); int results[] = new int[numberOfGooglers]; for(int j = 0; j < numberOfGooglers; j++) { results[j] = Integer.parseInt(tokenizer.nextToken()); } for(int j = 0; j < numberOfGooglers; j++) { boolean possibleSurprising = false; boolean possibleNonSurprising = false; enumarate: for(int judge1 = 0; judge1 <= 10; judge1++) { for(int judge2 = judge1 - 2; judge2 <= judge1 + 2; judge2++) { for(int judge3 = judge1 - 2; judge3 <= judge1 + 2; judge3++) { if(judge1 + judge2 + judge3 == results[j]) { if(judge1 < 0 || judge2 < 0 || judge3 < 0) { continue; // Illegal case } else if(2 < Math.abs(judge1 - judge2) || 2 < Math.abs(judge1 - judge3)|| 2 < Math.abs(judge2 - judge3)) { continue; // Illegal case } else if (bestResultMinimum <= judge1 || bestResultMinimum <= judge2 || bestResultMinimum <= judge3) { if(Math.abs(judge1 - judge2) == 2 || Math.abs(judge1 - judge3) == 2 || Math.abs(judge2 - judge3) == 2) { possibleSurprising = true; } else { possibleNonSurprising = true; break enumarate; } } } } } } if(possibleNonSurprising) { minimumerGooglers++; } else if (possibleSurprising && usedSurprisingTriplets < surprisingTriplets) { minimumerGooglers++; usedSurprisingTriplets++; } } System.out.println(String.format("Case #%d: %d", i + 1, minimumerGooglers)); } } }
0
1,188,921
A11759
A10785
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.FileReader; import java.io.LineNumberReader; import java.util.ArrayList; import java.util.List; public class CodeJam2 { public static void calcMax(int numLines, String[] gLines) { int numGoog; int numSurp; int minScore; for (int i = 0; i< numLines; i++) { int result = 0; int numSurpUsed = 0; String[] data = gLines[i].split(" "); numGoog = Integer.parseInt(data[0]); numSurp = Integer.parseInt(data[1]); minScore = Integer.parseInt(data[2]); for (int j = 0; j< numGoog; j++) { int googlerScore = Integer.parseInt(data[j+3]); if ((googlerScore+4) < minScore*3) continue; if (googlerScore <= 1) { if (googlerScore >= minScore) result++; continue; } if ((googlerScore)% 3 == 0) { if ((googlerScore/3) >= minScore) result++; else if ((googlerScore/3) +2 >= minScore && (numSurpUsed < numSurp)) { result++; numSurpUsed++; } } else if ((googlerScore+1)% 3 == 0) { googlerScore += 1; if ((googlerScore/3) >= minScore) result++; else if ((googlerScore/3) +1 >= minScore && (numSurpUsed < numSurp)) { result++; numSurpUsed++; } } else if ((googlerScore-1)% 3 == 0) { googlerScore -= 1; if ((googlerScore/3) +1 >= minScore) result++; } } System.out.println("Case #" + (i+1) + ": " + result); } } public static void main(String[] args) { File f = new File(args[0]); if (!f.isFile()) { System.out.println("The argument must be a file"); return; } int numLines = -1, i = 0; String[] gLines = null; String currentLine; try { LineNumberReader lineReader = new LineNumberReader(new FileReader(args[0])); try { while ((currentLine = lineReader.readLine()) != null) { if (numLines < 0) { numLines = Integer.parseInt(currentLine); gLines = new String[numLines]; } else { gLines[i] = currentLine; i++; if (i == numLines) break; } } } catch(Exception e) {e.printStackTrace();} finally { lineReader.close(); } } catch(Exception e) {e.printStackTrace();} CodeJam2.calcMax(numLines, gLines); } }
0
1,188,922
A11759
A12728
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 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = Integer.parseInt(in.nextLine()); for (int test = 0 ; test < T ; test ++) { String input = in.nextLine(); String[] bIn = input.split(" "); int googlersNum = Integer.parseInt(bIn[0]); int suprisingMax = Integer.parseInt(bIn[1]); int requirement = Integer.parseInt(bIn[2]); int okay=0; int suprising=0; for (int run = 0 ; run < googlersNum ; run ++) { int S = Integer.parseInt(bIn[3+run]); int temp = S; boolean testCase = false,done=false; for (int i = 10 ; i >= 0 ; i--) { for (int j = i ; j >= i-1 && j >= 0; j--) { for (int k = i ; k >= i-1 && k >= 0; k --) { temp = temp - k - i - j; if (temp == 0) { if ((i >= requirement || j >= requirement || k >= requirement) && !done) { okay++; done = true; } } temp = S; } } } temp = S; if (!testCase && suprising < suprisingMax) { for (int i = 10 ; i >= 0 ; i--) { for (int j = i ; j >= i-2 && j >= 0 ; j--) { for (int k = i ; k >= i-2 && k >= 0 ; k--) { temp = temp - i - k - j; if (temp == 0) { if ((i >= requirement || j >= requirement || k >= requirement) && !done) { testCase = true; suprising++; okay++; done = true; } } temp = S; } } } } } System.out.println("Case #"+(test+1)+": "+okay); } in.close(); } }
0
1,188,923
A11759
A11883
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()); } } }
/** * Created by IntelliJ IDEA. * User: ashevenkov * Date: 14.04.12 * Time: 11:17 */ package codejam.codejam2012; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.Arrays; /** * @author ashevenkov */ public class QualificationB { public static void main(String[] args) throws Exception { new QualificationB().calculate( "/home/ashevenkov/projects/codejam/B-small-attempt0.in", "/home/ashevenkov/projects/codejam/B-small-attempt0.out"); } public void calculate(String in, String out) throws Exception { BufferedReader br = new BufferedReader(new FileReader(in)); FileWriter fw = new FileWriter(out); String line = br.readLine(); int cases = Integer.parseInt(line); for(int i = 0; i < cases; i++) { line = br.readLine(); String[] parts = line.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 = 3; j < parts.length; j++) { t[j - 3] = Integer.parseInt(parts[j]); } String result = dance(S, p, t); System.out.println("Case #" + (i + 1) + ": " + result); fw.write("Case #" + (i + 1) + ": " + result); fw.write("\n"); } fw.flush(); fw.close(); } private String dance(int s, int p, int[] t) { int result = 0; int a1 = p + p - 1 + p - 1; int a2 = p + p - 2 + p - 2; if(p == 0) { return Integer.toString(t.length); } if(p == 1) { a1 = 1; a2 = 1; } Arrays.sort(t); boolean firstPhase = true; boolean secondPhase = false; int leftSurprise = s; for(int i = t.length - 1; i >= 0; i--) { int num = t[i]; if(firstPhase) { if(num >= a1) { result++; } else { firstPhase = false; secondPhase = true; } } if(secondPhase) { if(num >= a2 && leftSurprise > 0) { result++; leftSurprise--; } else { return Integer.toString(result); } } } return Integer.toString(result); } }
0
1,188,924
A11759
A11149
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.Arrays; import java.util.Scanner; public class DancingGooglers { public static void main(String[] args) throws FileNotFoundException { int T; //Scanner sc = new Scanner(System.in); Scanner sc = new Scanner(new File("input.in")); T=sc.nextInt(); for( int i=0;i<T;i++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int ti[]=new int[N]; for(int j=0;j<N;j++) { ti[j]=sc.nextInt(); } Arrays.sort(ti); int count=0; for(int j=N-1;j>=0;j--) { if(ti[j]/3>=p) { count++; } else if(ti[j]==0) { break; } else{ float temp = ((float) ti[j])/3; if(p-temp<.9) { count++; } else if(p-temp==1 || p-temp<1.4) { if(S>0) { count++; S--; } } } } System.out.println("Case #"+(i+1)+": "+count); } } }
0
1,188,925
A11759
A10018
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; public class R1P2 { /** * @param args */ public static void main(String[] args) throws Exception{ BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("small2.out")); String inLine; int t = Integer.parseInt(in.readLine()); int counter = 0; while((inLine = in.readLine()) != null){ counter++; int n, s, p; String[] toks = inLine.split(" "); n = Integer.parseInt(toks[0]); s = Integer.parseInt(toks[1]); p = Integer.parseInt(toks[2]); //System.out.println(n+ " " + s + " " + p); int j1 = p; int j2 = p - 1; int j3 = p - 2; if(j2 < 0) j2 = 0; if(j3 < 0) j3 = 0; int nTotal = j1 + j2 + j2; int sTotal = j1 + j3 + j3; //System.out.println(nTotal + " " + sTotal); int pos = 0; for(int i=3; i<toks.length; i++){ int score = Integer.parseInt(toks[i]); if(score>=nTotal) pos++; else if(score >= sTotal && s > 0){ pos++; s--; } } System.out.println("Case #" + counter + ": " + pos); bw.write("Case #" + counter + ": " + pos); bw.newLine(); } in.close(); bw.close(); } }
0
1,188,926
A11759
A13186
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.ArrayList; import java.util.List; import java.util.Scanner; public class Core { public static void main(String[] args) { int t, n, s, p; try { Scanner scan = new Scanner(new File(args[0])); t = scan.nextInt(); for (int i = 1; i <= t; i++) { n = scan.nextInt(); s = scan.nextInt(); p = scan.nextInt(); System.out.println(solve(i, n, s, p, scan)); } } catch (FileNotFoundException e) { e.printStackTrace(); } } public static String solve(int caseNumber, int n, int s, int p, Scanner scan) { int rangeMin, rangeMax; rangeMin = p + (2 * Math.max(0, p - 2)); // inc rangeMax = p + (2 * Math.max(0, p - 1)); // exc List<Integer> aboveP = new ArrayList<Integer>(); int score, used; used = 0; for (int i = 0; i < n; i++) { score = scan.nextInt(); if (score < rangeMin) continue; else if (score >= rangeMax) aboveP.add(score); else if (((score - rangeMin) <= 1) && (used < s)) { used++; aboveP.add(score); } } return "Case #" + caseNumber + ": " + aboveP.size(); } }
0
1,188,927
A11759
A11227
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; public class B{ public static void main(String[] args) throws Exception{ BufferedReader fin = new BufferedReader(new FileReader("B.txt")); PrintWriter fout = new PrintWriter(new FileWriter("Bout.txt")); String s = fin.readLine(); int t = Integer.parseInt(s); s = fin.readLine(); for(int i = 0; i < t; i++){ String[] sp = s.split(" "); int n = Integer.parseInt(sp[0]); int S = Integer.parseInt(sp[1]); int p = Integer.parseInt(sp[2]); int[] scores = new int[n]; for(int j = 3; j < sp.length; j++){ scores[j-3] = Integer.parseInt(sp[j]); } int[][] mat = new int[31][2]; mat[0][0] = 0; mat[1][0] = 1; mat[2][0] = 1; mat[3][0] = 1; mat[4][0] = 2; mat[5][0] = 2; mat[6][0] = 2; mat[7][0] = 3; mat[8][0] = 3; mat[9][0] = 3; mat[10][0] = 4; mat[11][0] = 4; mat[12][0] = 4; mat[13][0] = 5; mat[14][0] = 5; mat[15][0] = 5; mat[16][0] = 6; mat[17][0] = 6; mat[18][0] = 6; mat[19][0] = 7; mat[20][0] = 7; mat[21][0] = 7; mat[22][0] = 8; mat[23][0] = 8; mat[24][0] = 8; mat[25][0] = 9; mat[26][0] = 9; mat[27][0] = 9; mat[28][0] = 10; mat[29][0] = 10; mat[30][0] = 10; mat[0][1] = 0; mat[1][1] = 0; mat[2][1] = 1; mat[3][1] = 1; mat[4][1] = 0; mat[5][1] = 1; mat[6][1] = 1; mat[7][1] = 0; mat[8][1] = 1; mat[9][1] = 1; mat[10][1] = 0; mat[11][1] = 1; mat[12][1] = 1; mat[13][1] = 0; mat[14][1] = 1; mat[15][1] = 1; mat[16][1] = 0; mat[17][1] = 1; mat[18][1] = 1; mat[19][1] = 0; mat[20][1] = 1; mat[21][1] = 1; mat[22][1] = 0; mat[23][1] = 1; mat[24][1] = 1; mat[25][1] = 0; mat[26][1] = 1; mat[27][1] = 1; mat[28][1] = 0; mat[29][1] = 0; mat[30][1] = 0; int numreach = 0; int numcould = 0; for(int j = 0; j < scores.length; j++){ if(mat[scores[j]][0] >= p){ numreach++; } else if(mat[scores[j]][0] + 1 >= p && mat[scores[j]][1] == 1){ numcould++; } } numreach += Math.min(numcould, S); fout.println("Case #" + (i + 1) + ": " + numreach); fout.flush(); s = fin.readLine(); } } }
0
1,188,928
A11759
A11805
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 Googler { int total; boolean prizeSurprise = false; boolean prizeNoSurprise = false; boolean failSurprise = false; boolean failNoSurprise = false; boolean used = false; int trueCounter = 0; public Googler poss(int total, int prize){ this.used = false; this.total = total; for (int i=10; i>-1; i--){ if (total>=i){ int twoA = total - (2*i); if (twoA >=0 && twoA<= i){ if (twoA == i || twoA == i-1){ if (i>=prize){ if (prizeNoSurprise == false){trueCounter++;} prizeNoSurprise = true; } else { if (failNoSurprise == false){trueCounter++;} failNoSurprise = true; } } if (twoA == i-2){ if (i>=prize){ if (prizeSurprise == false){trueCounter++;} prizeSurprise = true; } else { if (failSurprise == false){trueCounter++;} failSurprise = true; } } } int oneA = total - i - (i-1); if (oneA >=0 && oneA<= i){ if (oneA == i ||oneA == i-1){ if (i>=prize){ if (prizeNoSurprise == false){trueCounter++;} prizeNoSurprise = true; } else { if (failNoSurprise == false){trueCounter++;} failNoSurprise = true; } } if (oneA == i-2){ if (i>=prize){ if (prizeSurprise == false){trueCounter++;} prizeSurprise = true; } else { if (failSurprise == false){trueCounter++;} failSurprise = true; } } } int splitA = total - i - (i-2); if (splitA >=0 && oneA<= i){ if (splitA == i ||oneA == i-1 || splitA== i-2){ if (i>=prize){ if (prizeSurprise == false){trueCounter++;} prizeSurprise = true; } else { if (failSurprise == false){trueCounter++;} failSurprise = true; } } } } } return this; } }
0
1,188,929
A11759
A11646
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 qualify; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.Scanner; public class B { public static void main(String[] args) throws Exception { Scanner input = new Scanner(new FileInputStream("B-small-attempt0.in")); PrintWriter output = new PrintWriter(new FileOutputStream("B-small-attempt0.out")); int T,ca; int N,S,p,t; int r; T = input.nextInt(); for(ca=1;ca<=T;ca++) { N = input.nextInt(); S = input.nextInt(); p= input.nextInt(); r = 0; for(int i=0;i<N;i++) { t = input.nextInt(); if((t+2)/3 >= p ) { r++; } else if((t+4)/3 >= p && (t+4)/3 >= 2) { S--; if(S>=0) r++; } } output.println(String.format("Case #%d: %d", ca,r)); } input.close(); output.close(); } }
0
1,188,930
A11759
A12321
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 br.com.atama.google.jam.dancing; public class TripletScore implements Comparable<TripletScore> { private final int threshold = Context.INSTANCE.getThreshold(); private final int total; private final int mod; private final int gap; private int potential = 0; private int numGoodScore = 0; private boolean isSurprise = false; public TripletScore(int total) { this.total = total; final int div = total / 3; mod = total % 3; gap = threshold - div; calculateGoodScore(); } private void calculateGoodScore() { if (total == 0) { numGoodScore = 0; isSurprise = false; if (gap <= 0) numGoodScore = 3; potential = Integer.MIN_VALUE; } else if (isSurprise) { numGoodScore = 0; if (mod == 0) { if (gap == 1) { numGoodScore = 1; potential = -1; } else if (gap == 0) { numGoodScore = 2; potential = 1; } else if (gap < 0) { numGoodScore = 3; potential = 0; } } else if (mod == 1) { if (gap == 1) { numGoodScore = 2; potential = -1; } else if (gap == 0) { numGoodScore = 2; potential = 1; } else if (gap < 0) { numGoodScore = 3; potential = 0; } } else if (mod == 2) { if (gap == 2) { numGoodScore = 1; potential = -1; } else if (gap == 1) { numGoodScore = 1; potential = 1; } else if (gap <= 0) { numGoodScore = 3; } } else { assert false; } } else { numGoodScore = 0; if (mod == 0) { if (gap == 1) { potential = 1; } else if (gap == 0) { numGoodScore = 3; potential = -1; } else if (gap < 0) { numGoodScore = 3; } } else if (mod == 1) { if (gap == 1) { numGoodScore = 1; potential = 1; } else if (gap == 0) { numGoodScore = 3; potential = -1; } else if (gap < 0) { numGoodScore = 3; potential = 0; } } else if (mod == 2) { if (gap == 2) { potential = 1; } else if (gap == 1) { numGoodScore = 2; potential = -1; } else if (gap <= 0) { numGoodScore = 3; potential = 0; } } else { assert false; } } } @Override public int compareTo(TripletScore o) { if (numGoodScore == 0) { if (o.numGoodScore == 0) return potential - o.potential; return 1; } else { if (o.numGoodScore == 0) return -1; return potential - o.potential; } } public boolean isSurprise() { return isSurprise; } public void setSurprise(boolean b) { isSurprise = b; calculateGoodScore(); } public int getNumGoodScore() { return numGoodScore; } public boolean isZero() { return total == 0; } }
0
1,188,931
A11759
A10045
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; class B { public static void main(String args[]) throws FileNotFoundException { Scanner in = new Scanner(new File(args[0])); int t; t = Integer.parseInt(in.nextLine()); for (int i=0; i<t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int m = 0; int ti[] = new int[n]; for (int j=0; j<n; j++) { ti[j] = in.nextInt(); } for (int j=0; j<n; j++) { int d = ti[j]/3; int r = ti[j]%3; int x = p - d; if (x <= 0) m++; else if (x+d <= 10) { if (x==2 && r==2 && s>0) { m++; s--; } else if ( x == 1) { if (r==0 && d>0 && s>0) { m++; s--; } else if (r > 0) m++; } } if (m > n) m=n; } System.out.println("Case #" + (i+1) + ": " + m); } } }
0
1,188,932
A11759
A12834
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 javaapplication2; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class DancingWithTheGooglers { private final static String INPUT_PATH = "resources/dancing_with_the_googlers.in"; private final static String OUTPUT_PATH = "resources/dancing_with_the_googlers.out"; private static int caseNumber = 0; public static void main(String[] args) throws FileNotFoundException, IOException { try (Scanner scanner = new Scanner(new File(INPUT_PATH))) { int T = scanner.nextInt(); try (FileWriter out = new FileWriter(OUTPUT_PATH)) { for (int i = 0; i < T; ++i) { processCase(scanner, out); } } } } private static void processCase(Scanner scanner, FileWriter out) throws IOException { out.write("Case #" + (++caseNumber) + ": "); int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int result = 0; for (int i = 0; i < N; ++i) { int P = scanner.nextInt(); if ((P + 2) / 3 >= p) { ++result; } else if (p + 2 * Math.max(p - 2, 0) <= P && S > 0) { ++result; --S; } } out.write(result + ""); out.write("\n"); } }
0
1,188,933
A11759
A12191
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 QR_Bsmall { public static void main(String[] args) throws Exception{ // Scanner sc = new Scanner(System.in); // PrintWriter pw = new PrintWriter(System.out); // Scanner sc = new Scanner(new FileReader("input.in")); // PrintWriter pw = new PrintWriter(new FileWriter("output.out")); Scanner sc = new Scanner(new FileReader("B-small-attempt0.in")); PrintWriter pw = new PrintWriter(new FileWriter("B-small-attempt0.out")); int T; int N, S, p; int[] t = new int[100]; int ans; T = sc.nextInt(); for(int times = 1; times <= T; times++){ N = sc.nextInt(); S = sc.nextInt(); p = sc.nextInt(); for(int i = 0; i < N; i++){ t[i] = sc.nextInt(); } ans = 0; for(int i = 0; i < N; i++){ if(t[i] <= 1){ if(p <= t[i]){ ans++; } continue; } t[i] = t[i] - (p * 3); if(t[i] > -3){ ans++; }else if(t[i] > -5 && S > 0){ ans++; S--; } } System.out.print("Case #" + times + ": "); System.out.print(ans); System.out.println(); pw.print("Case #" + times + ": "); pw.print(ans); pw.println(); } sc.close(); pw.close(); } }
0
1,188,934
A11759
A11991
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 Main { final static String FNAME = "A-small-practice"; public BufferedReader in; public PrintWriter out; static char[][] map = new char[2][26]; void open() throws IOException { in = new BufferedReader( new FileReader( new File( FNAME + ".in" ) ) ); out = new PrintWriter( new File( FNAME + ".out" ) ); } void close() throws IOException { out.close(); } void run() throws IOException { String str = in.readLine(); String[] input; int n,s,p, noSmin, Smin,count; int num = new Integer( str ); for(int i = 0; i<num ; i++){ input = in.readLine().split(" "); n= new Integer(input[0]); s= new Integer(input[1]); p= new Integer(input[2]); count = 0; if(p>=2){ Smin= p+2*(p-1); noSmin= p+2*(p-2); }else if(p==1){ Smin=p+2*(p-1); noSmin=p+2*(p-1); }else{ Smin=0; noSmin=0; } for(int j = 3; j<3+n;j++) { int no = new Integer(input[j]); if (no >= noSmin) { if (no >= Smin) { count++; } if(no < Smin && s>0) { count++; s--; } } } out.println( "Case #" + (i+1) + ": " + count ); } } public static void main( String[] args ) throws IOException { new Thread() { public void run() { try { Main solution = new Main(); solution.open(); solution.run(); solution.close(); } catch ( Exception e ) { throw new RuntimeException( e ); } } }.start(); } }
0
1,188,935
A11759
A12189
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.StringTokenizer; public class DancingWithTheGooglers { public static int Solve(String q) { StringTokenizer st = new StringTokenizer(q, " "); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int t; int d; int r; int ans = 0; while(st.hasMoreTokens()) { t = Integer.parseInt(st.nextToken()); d = t / 3; r = t % 3; if(p - d <= 0) ans++; else if(p - d == 1) { if(r != 0) ans++; else if(s > 0 && r == 0 && t != 0) { s--; ans++; } } else if(p - d == 2 && s > 0 && r == 2) { ans++; s--; } } return ans; } }
0
1,188,936
A11759
A11560
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 codejam3 { public static void main(String[] args) throws FileNotFoundException, IOException { File file = new File("B-small-attempt0.in"); FileReader fr = new FileReader(file); Scanner ob = new Scanner(fr); File outFile = new File("outFile3.txt"); FileWriter outFilew = new FileWriter(outFile); int t, r = 1; t = ob.nextInt(); while (t != 0) { int n, s, p, count = 0; n = ob.nextInt(); s = ob.nextInt(); p = ob.nextInt(); int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ob.nextInt(); if (a[i] >= p) { if (a[i] >= 3 * p - 2) { count++; } else if ((a[i] == 3 * p - 4 || a[i] == 3 * p - 3) && s != 0) { s--; count++; } } } System.out.println(count); outFilew.append("Case #"+r+": "+count+"\n"); t--; r++; } outFilew.close(); } }
0
1,188,937
A11759
A10019
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; import java.math.*; public class Main { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer=null; public static void main(String[] args) throws IOException { new Main().execute(); } void debug(Object...os) { System.out.println(Arrays.deepToString(os)); } int ni() throws IOException { return Integer.parseInt(ns()); } long nl() throws IOException { return Long.parseLong(ns()); } double nd() throws IOException { return Double.parseDouble(ns()); } String ns() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) tokenizer = new StringTokenizer(br.readLine()); return tokenizer.nextToken(); } String nline() throws IOException { tokenizer=null; return br.readLine(); } //Main Code starts Here int totalCases, testNum; int m,n; void execute() throws IOException { totalCases = ni(); for(testNum = 1; testNum <= totalCases; testNum++) { input(); System.out.print("Case #"+testNum+": "); solve(); } } void solve() { int sur=0,nons=0; int a = 3*p-4; if(p==1) { for(int i = 0 ;i<t;i++) if(arr[i]!=0) nons++; } else { for(int i=0;i<t;i++) { if(arr[i]<a) continue; if(arr[i]-a<2) sur++; else nons++; } } System.out.println(Math.min(s,sur)+nons); } void printarr(int [] a,int b) { for(int i = 0;i<=b;i++) { if(i==0) System.out.print(a[i]); else System.out.print(" "+a[i]); } System.out.println(); } int t,s,p; int[] arr; boolean input() throws IOException { t = ni(); s = ni(); p = ni(); arr = new int[t]; for(int i=0;i<t;i++) arr[i] = ni(); return true; } }
0
1,188,938
A11759
A12490
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.Scanner; public class Dance { public static void main(String[] args) throws IOException { //new FileReader("dancing.in") Scanner input = new Scanner(System.in); int next = Integer.parseInt(input.nextLine()); // PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter("dancing.out"))); for (int i = 1; i <= next; i++) { System.out.print("Case #" + i + ": "); int totalNums = input.nextInt(); int numSurprises = input.nextInt(); int bestScore = input.nextInt(); int recordedSurprisesWithP = 0; int notSurprisesWithP = 0; for (int k = 0; k < totalNums; k++) { int temp = input.nextInt(); if (temp == ((3 * bestScore) - 3) || temp == ((3 * bestScore) - 4)) { if (bestScore != 1) recordedSurprisesWithP++; } else if (temp > (3 * bestScore) - 3) notSurprisesWithP++; } System.out.println(notSurprisesWithP + Math.min(numSurprises, recordedSurprisesWithP)); } } }
0
1,188,939
A11759
A11076
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.HashMap; import java.util.StringTokenizer; public class Dance { private String strLine; private BufferedReader f; private PrintWriter out; private ArrayList<Integer> hasil; public Dance() { strLine = new String(); try { f = new BufferedReader(new FileReader("b0.in")); out = new PrintWriter(new BufferedWriter(new FileWriter("dance.out"))); } catch(IOException i) { } hasil = new ArrayList<Integer>(); } public void find(int N, int S, int p, ArrayList<Integer> save) { int temp; int count = 0; int sTemp = S; System.out.println("ha = " + N + "|" + S + "|" + p); for (int i = 0; i < N; i++) { temp = save.get(i); if ((temp % 3) == 1) { if (temp / 3 + 1 >= p) { System.out.println("a" + i); count++; } } else if ((temp % 3) == 2) { if (sTemp == 0) { if (temp / 3 + 1 >= p) { System.out.println("b" + i); count++; } } else { if (temp / 3 + 1 < p) { sTemp--; if (temp /3 + 2 >= p && temp /3 + 2 <= 10) { System.out.println("c" + i); count++; } else { sTemp++; } } else { if (temp / 3 - 1 >= 0) { System.out.println("d" + i); count++; } } } } else { if (sTemp > 0) { if (temp / 3 >= p) { System.out.println("f" + i); count++; } else if (temp / 3 + 1 >= p) { if (temp / 3 - 1 <= 0) { } else if (temp / 3 + 1 >= 10) { } else { System.out.println("e" + i); count++; sTemp--; } } } else { if (temp / 3 >= p) { System.out.println("g" + i); count++; } } } } hasil.add(count); } public static void main(String[] args) throws IOException { Dance dance = new Dance(); int N; int S; int T; int p; StringTokenizer st; ArrayList<Integer> save; T = Integer.parseInt(dance.f.readLine()); System.out.println("T = " + T); if (T > 100 || T < 1) { System.out.println("Error"); } else { for (int i = 0; i < T; i++) { if ((dance.strLine = dance.f.readLine()) != null) { System.out.println("dance = " + dance.strLine); st = new StringTokenizer(dance.strLine); N = Integer.parseInt(st.nextToken()); S = Integer.parseInt(st.nextToken()); p = Integer.parseInt(st.nextToken()); save = new ArrayList<Integer>(); for (int j = 0; j < N; j++) { save.add(Integer.parseInt(st.nextToken())); } dance.find(N,S,p,save); } } // while ((dance.giver = dance.f.readLine()) != null) { // if (dance.giver.length() > 100) { // System.out.println("Error"); // isError = true; // break; // } else { // for (int l = 0; l < dance.giver.length(); l++) { // if (dance.giver.charAt(l) != ' ') // s = s + dance.member.get(dance.giver.charAt(l)); // else // s = s + dance.giver.charAt(l); // } // dance.hasil.add(s); // s = ""; // } // } for (int x = 0; x < dance.hasil.size(); x++) { dance.out.println("Case #" + (x + 1)+ ": " +dance.hasil.get(x)); } dance.out.close(); // close the output file System.exit(0); } } }
0
1,188,940
A11759
A13077
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 Googlers { public static int google(int N, int S, int P, int[] googler) { int counter = 0; for (int j = 0; j < googler.length; j++) { if (googler[j] % 3 == 0 && P >= 0) { if (googler[j] != 0) { if (googler[j] / 3 >= P) { counter++; } else if (googler[j] / 3 + 1 >= P && S != 0) { counter++; S--; } } else if (googler[j] == 0 && P == 0) { counter++; } } else if (googler[j] % 3 == 1) { if (googler[j] / 3 + 1 >= P) { counter++; } } else if (googler[j] % 3 == 2) { if (googler[j] / 3 + 1 >= P) { counter++; } else if (googler[j] / 3 + 2 >= P && S != 0) { counter++; S--; } } } return counter; } }
0
1,188,941
A11759
A11435
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.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Qualification_B { private static final boolean DEBUG = false; /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { List<String> input = readFile(args[0]); int testCases = Integer.parseInt(input.get(0)); String outputFilename = args[0].substring(0, args[0].length() - 2) + "out"; FileOutputStream output = new FileOutputStream(outputFilename); try { for (int i = 1; i <= testCases; i++) { String[] oneTest = input.get(i).split(" "); int noOfGooglers = Integer.parseInt(oneTest[0]); int noOfSurprising = Integer.parseInt(oneTest[1]); int minPoint = Integer.parseInt(oneTest[2]); int[] googlerMarks = new int[noOfGooglers]; for (int j = 0; j < noOfGooglers; j++) { googlerMarks[j] = Integer.parseInt(oneTest[3 + j]); } if (DEBUG) { debug("Test Case: " + i); debug("==============="); debug(input.get(i)); } int result = getResult(noOfGooglers, noOfSurprising, minPoint, googlerMarks); outputResult(output, i, String.valueOf(result)); } } finally { if (output != null) { output.close(); } } } private static int getResult(final int noOfGooglers, final int noOfSurprising, final int minPoint, final int[] googlerMarks) { int result = 0; int remainSurprising = noOfSurprising; Arrays.sort(googlerMarks); int minValue = 0; int maxValue = 0; int modValue = 0; for (int i = 0; i < noOfGooglers; i++) { minValue = googlerMarks[i] / 3; modValue = (minValue == 0)? googlerMarks[i] : googlerMarks[i] % 3; if (minValue > 0) { maxValue = (modValue == 0)? minValue : minValue + 1; } else { maxValue = 1; } maxValue = (maxValue > googlerMarks[i])? minValue : maxValue; if (DEBUG) { debug("No: " + noOfGooglers); debug("Surprise: " + remainSurprising); debug("MinPoint: " + minPoint); debug("Mark: " + googlerMarks[i]); debug("Min: " + minValue + " - " + "Max: " + maxValue); debug("Mod: " + modValue); } // if (maxValue >= minPoint) { // debug("Meet: " + googlerMarks[i]); // result++; // } else { // if (remainSurprising > 0 && maxValue < googlerMarks[i]) { if (modValue > 0) { if (minValue >= minPoint) { // debug("Meet: " + googlerMarks[i]); result++; } else if ((modValue == 1) && (minValue + modValue) == minPoint) { // debug("Meet: " + googlerMarks[i]); result++; } else if ((modValue == 2) && (minValue + 1) >= minPoint) { // debug("Meet: " + googlerMarks[i]); result++; } else if ((remainSurprising > 0) && (minValue + modValue) >= minPoint) { // debug("Meet *: " + googlerMarks[i]); remainSurprising--; result++; } else { // debug("Does not meet"); // debug("No: " + noOfGooglers); // debug("Surprise: " + remainSurprising); // debug("Mark: " + googlerMarks[i]); // debug("Min: " + minValue + " - " + "Max: " + maxValue); } } else { if (minValue >= minPoint) { // debug("Meet: " + googlerMarks[i]); result++; } else if (remainSurprising > 0 && minValue > 0 && (minValue + 1) == minPoint) { // debug("Meet *: " + googlerMarks[i]); remainSurprising--; result++; } else { // debug("Does not meet"); // debug("No: " + noOfGooglers); // debug("Surprise: " + remainSurprising); // debug("Mark: " + googlerMarks[i]); // debug("Min: " + minValue + " - " + "Max: " + maxValue); } } // } // } } return result; } public static List<String> readFile(String filename) throws IOException { List<String> lines = new ArrayList<String>(); BufferedReader reader = new BufferedReader(new InputStreamReader( new FileInputStream(filename))); try { String data; while ((data = reader.readLine()) != null) { lines.add(data); } } finally { reader.close(); } return lines; } private static void outputResult(FileOutputStream output, int caseNo, String result) throws IOException { output.write(String.format("Case #%d: %s\r\n", caseNo, result).getBytes()); // debug(String.format("Case #%d: %s\r\n", caseNo, result)); } private static void debug(String debug) { System.out.print(debug + "\r\n"); } }
0
1,188,942
A11759
A12524
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.BufferedWriter; import java.io.FileWriter; import java.io.File; public class B_Small { static int[][] table = { {0}, {1}, {1,2}, {1,2}, {2}, {2,3}, {2,3}, {3}, {3,4}, {3,4}, {4}, {4,5}, {4,5}, {5}, {5,6}, {5,6}, {6}, {6,7}, {6,7}, {7}, {7,8}, {7,8}, {8}, {8,9}, {8,9}, {9}, {9,10}, {9,10}, {10}, {10}, {10}}; public static void main(String[] args) { try { FileWriter writer = new FileWriter("B-small-attempt.out"); BufferedWriter out = new BufferedWriter(writer); String current, result; result = ""; Scanner sc = new Scanner(new File("B-small-attempt1.in")); int x = Integer.parseInt(sc.nextLine()); for (int k = 0; k < x; k++) { result = "Case #" + (k+1) + ": "; current = sc.nextLine(); int count = 0; String[] cur = current.split(" "); int z = Integer.parseInt(cur[0]); int s = Integer.parseInt(cur[1]); int p = Integer.parseInt(cur[2]); for (int t = 3; t < cur.length; t++) { int score = Integer.parseInt(cur[t]); int[] special = table[score]; if (special[0] >= p) { count++; } else if (s > 0 && special.length > 1) { if (special[1] >=p) { count++; s--; } } } result += count; out.write(result); out.newLine(); } out.close(); } catch (Exception e) { System.out.println("error"); } } }
0
1,188,943
A11759
A12078
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.io.BufferedReader; import java.io.Closeable; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; public class Input implements Closeable { BufferedReader reader; private Input(BufferedReader reader) { this.reader = reader; } public static Input open(File f) { final BufferedReader r; try { r = FileUtils.getReader(f); } catch (FileNotFoundException e) { throw new TechnicalException(e); } return new Input(r); } public void close() { try { reader.close(); } catch (IOException e) { throw new TechnicalException(e); } } public String readLine() { try { return reader.readLine(); } catch (IOException e) { throw new TechnicalException(e); } } }
0
1,188,944
A11759
A11299
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.IOException; import java.io.InputStreamReader; import java.io.Writer; import java.util.Arrays; /** * Competition * @author shibink * */ public class DancingScore { public static int getCount(String googleLang) { int count = 0; if ((googleLang == null) || (googleLang.isEmpty())) { return 0; } String[] strArray = googleLang.split(" "); // Min 1 player should be there if (strArray.length <= 3) { return 0; } int numPlayers = Integer.parseInt(strArray[0]); int numSurprises = Integer.parseInt(strArray[1]); int key = Integer.parseInt(strArray[2]); int [] totalPoints = new int [numPlayers]; boolean isSurprise = false; if (key == 0) { return numPlayers; } for (int i =0, j = 3; i<numPlayers; i++, j++) { totalPoints[i] = Integer.parseInt(strArray[j]); } Arrays.sort(totalPoints); for (int i=numPlayers - 1; i >=0; i--) { isSurprise = false; if (key == 1) { if (totalPoints[i] != 0) { count++; } continue; } if ((key * 3) <= totalPoints[i]) { count++; continue; } if (key + ((key - 2) * 2) <= totalPoints[i]) { if (((key * 3) == totalPoints[i]) || (((key * 2) + key-1) == totalPoints[i]) || ((((key-1)*2) + key) == totalPoints[i]) || (((key * 2) + key+1) == totalPoints[i]) || ((((key+1)*2) + key) == totalPoints[i])) { isSurprise = false; } else { isSurprise = true; } if (isSurprise) { if (numSurprises > 0) { numSurprises--; count++; } } else { count++; } } else { // No more triplets can be part of the target count since array is sorted break; } } return count; } public static void processFile(String fileName) throws IOException { FileInputStream fstream = new FileInputStream(fileName); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); // use buffering Writer output = new BufferedWriter(new FileWriter("output.txt")); try { String strLine = null; int numPlayers = 0; int count = 0; if ((strLine = br.readLine()) != null) { count = Integer.parseInt(strLine); } // Read File Line By Line for (int i = 1; i <= count; i++) { if ((strLine = br.readLine()) == null) { return; } numPlayers = getCount(strLine); System.out.println("Case #" + i + ": " + numPlayers); StringBuffer outBuff = new StringBuffer("Case #" + i + ": " + numPlayers + "\n"); output.write(outBuff.toString()); } } finally { // Close the input stream in.close(); output.close(); } } /** * @param args */ public static void main(String[] args) { String fileName = "input.in"; try { processFile(fileName); } catch (IOException e) { // TODO Log error } return; } }
0
1,188,945
A11759
A10336
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.io.PrintWriter; import java.util.StringTokenizer; public class Main implements Runnable { final String fileName = "B-small-attempt1"; void solveCase(int test) throws Exception { out.print("Case #" + test + ": "); int n = nextInt(); int s = nextInt(); int p = nextInt(); int answer = 0; for (int i = 0; i < n; i++) { int t = nextInt(); int c = t / 3 + (t % 3 >= 1 ? 1 : 0); if (c >= p) answer++; else if (s > 0 && t % 3 != 1 && t >= 2 && c < 10 && c + 1 >= p) { answer++; s--; } } out.println(answer); } void solution() throws Exception { int t = nextInt(); for (int i = 0; i < t; i++) solveCase(i + 1); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } String next() throws IOException { while (st == null || !st.hasMoreTokens()) { String l = in.readLine(); if (l == null) return null; st = new StringTokenizer(l); } return st.nextToken(); } public static void main(String args[]) { //Locale.setDefault(Locale.UK); new Thread(new Main()).start(); } public void run() { try { in = new BufferedReader(new FileReader(fileName + ".in")); //out = new PrintWriter(System.out); out = new PrintWriter(fileName + ".out"); solution(); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(202); } } BufferedReader in; StringTokenizer st; PrintWriter out; }
0
1,188,946
A11759
A12948
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 CodeJam2{ public static HashMap<Integer,Vector<Integer>> perm = new HashMap<Integer,Vector<Integer>>(); public static void main(String args[]) throws IOException{ llenar(); BufferedReader lector = new BufferedReader(new FileReader(args[0])); String tmp = lector.readLine(); int uu = 1; while((tmp = lector.readLine())!=null){ String tar[] = tmp.split(" "); int sorpr = Integer.parseInt(tar[1]),r = 1<<Integer.parseInt(tar[0]); int cond = Integer.parseInt(tar[2]); int max =0; for(int n = 0;n<=r;n++){ int tmpMax = 0; int cont = 0,contt=0,mm=n; do{ if((mm&1)==1) cont++; if(sat(Integer.parseInt(tar[3+contt]),cond,mm&1))tmpMax++; contt++; }while((mm>>=1)>0 && contt<Integer.parseInt(tar[0])); if(cont!=sorpr)continue; for(int u = contt;u<Integer.parseInt(tar[0]);u++) if(sat(Integer.parseInt(tar[3+u]),cond,0))tmpMax++; max = Math.max(tmpMax,max); } System.out.println("Case #"+(uu++)+": "+max); } } public static boolean sat(int num,int cond,int r){ Vector<Integer> tmpp = perm.get(num); return tmpp.get(r*3+2)>=cond; } public static void llenar(){//0 no sat, 1 sat for(int n = 0;n<31;n++){ int tmpMaxx[][] = new int[2][3]; for(int nn = 0;nn<=n;nn++) for(int nnn = 0;nnn<=nn;nnn++) for(int nnnn =0;nnnn<=nnn;nnnn++) if((nn-nnnn)<=2 && ((nn+nnn+nnnn)==n)){ if((nn-nnnn)==2 && nn>tmpMaxx[1][2]){ tmpMaxx[1][0]=nnnn; tmpMaxx[1][1]=nnn; tmpMaxx[1][2]=nn; }else if((nn-nnnn)!=2 && nn>tmpMaxx[0][2]){ tmpMaxx[0][0]=nnnn; tmpMaxx[0][1]=nnn; tmpMaxx[0][2]=nn; } } Vector<Integer> rejoder = new Vector<Integer>(); for(int k =0;k<tmpMaxx.length;k++) for(int kk = 0;kk<tmpMaxx[k].length;kk++) rejoder.add(tmpMaxx[k][kk]); perm.put(n,rejoder); //System.out.println(n+" "+rejoder); } } }
0
1,188,947
A11759
A12737
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class BMain { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int casesCnt = Integer.parseInt(reader.readLine()); for (int i = 0; i < casesCnt; i++) { String line = reader.readLine(); solve(i + 1, line); } // int[] sIdx = {0,1,2}; // int[] sIdx = {0,3,4}; // int[] sIdx = {}; // int size = 5; // System.out.println(Arrays.toString(sIdx)); // for (int i = 0; i < 16; i++) { // boolean ok = nextSurprises(sIdx, size); // if (!ok) break; // System.out.println(Arrays.toString(sIdx)); // } } private static void solve(int caseN, String line) { final StringTokenizer tokens = new StringTokenizer(line); final int nGooglers = Integer.parseInt(tokens.nextToken()); final int surprises = Integer.parseInt(tokens.nextToken()); final int pMinScore = Integer.parseInt(tokens.nextToken()); final int[] scores = new int[nGooglers]; for (int i = 0; i < scores.length; i++) { scores[i] = Integer.parseInt(tokens.nextToken()); } int result = 0; int[] suprIdx = initSurprises(surprises, nGooglers); mainloop: do { int resultTmp = 0; boolean[] isSurprise = new boolean[nGooglers]; for (int i : suprIdx) { isSurprise[i] = true; if (scores[i]<2) continue mainloop; } for (int i = 0; i < scores.length; i++) { for (int best = pMinScore; best <= 10; best++) { int tripleBest = 3 * best; if (isSurprise[i]) { // if surprise .. -2,-3,-4 if (scores[i] <= tripleBest - 2 && scores[i] >= tripleBest - 4) { resultTmp++; } } else { // if !surprise .. sum = 3*best -0,-1,-2 if (scores[i] <= tripleBest && scores[i] >= tripleBest - 2) { resultTmp++; } } } } if (resultTmp > result) result = resultTmp; } while (nextSurprises(suprIdx, nGooglers)); System.out.printf("Case #%d: %d%n", caseN, result); } private static int[] initSurprises(int surprCnt, int googlers) { int [] result = new int[surprCnt]; for (int i = 1; i < result.length; i++) { result[i] = result[i-1] + 1; } return result; } private static boolean nextSurprises(int[] sIdx, int googlers) { int i = sIdx.length - 1; boolean overflow = true; while (i >= 0 && overflow) { if (sIdx[i] >= googlers - 1 - (sIdx.length - i - 1)) { // overflow i--; } else { // no overflow overflow = false; //inc idx sIdx[i]++; // fix remaining indexes for (int y = i + 1; y < sIdx.length; y++) { sIdx[y] = sIdx[y - 1] + 1; } return true; } } return false; } }
0
1,188,948
A11759
A11857
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.HashMap; public class GCJB { public static void main(String[] args) { try { FileReader in = new FileReader("./B-small-attempt1.in"); BufferedReader br = new BufferedReader(in); File file = new File("./smallB.txt"); FileWriter fw = new FileWriter(file); String line; int num = Integer.valueOf(br.readLine()); int caseNum = 1; while ((line = br.readLine()) != null) { StringBuilder sb = new StringBuilder(); sb.append("Case #" + caseNum + ": "); caseNum++; String[] lineArray = line.split(" "); int n = Integer.valueOf(lineArray[0]); int s = Integer.valueOf(lineArray[1]); int p = Integer.valueOf(lineArray[2]); int res = 0; for(int i = 3; i < lineArray.length ; i++){ if(Integer.valueOf(lineArray[i]) == 0){ if(p == 0) res++; continue; } int m = Integer.valueOf(lineArray[i])%3; int d = Integer.valueOf(lineArray[i])/3; if(d >= p) res++; else if(m == 0){ if(d >= (p-1) && s != 0){ res++; s--; } } else if(m == 1){ if(d >= (p-1))res++; } else if(m == 2){ if(d >= (p-1))res++; else if(d >= (p-2) && s != 0){ res++; s--; } } } sb.append(res); fw.write(new String(sb)); fw.write("\n"); } br.close(); in.close(); fw.close(); } catch (IOException e) { e.printStackTrace(); } } }
0
1,188,949
A11759
A11206
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; import java.math.*; public class Solution { static int miracles=-1; static int tresh=1000; public static void main(String args[]) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t = 0; t < T; t++) { int N=sc.nextInt(); miracles=sc.nextInt(); tresh=sc.nextInt(); int count=0; for(int i=0;i<N;i++) { int v=sc.nextInt(); if(isAboveThres(v)||isAboveThresMiracle(v)) { count++; } } System.out.println("Case #"+(t+1)+": "+count); } } public static boolean isAboveThres(int v) { switch(v%3) { case 0: return (v/3)>=tresh; case 1: return ((v/3)+1)>=tresh; case 2: return ((v+1)/3)>=tresh; } return false; } public static boolean isAboveThresMiracle(int v) { if(miracles<=0) return false; switch(v%3) { case 0: if(v>0&&(v/3)+1>=tresh) { miracles--; return true; } break; case 2: if(((v+1)/3)+1>=tresh) { miracles--; return true; } break; } return false; } }
0
1,188,950
A11759
A10219
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package dancingwithgooglers; import java.util.Scanner; public class Main { static enum Mark { IMPOSSIBLE, SURPRISING, REGULAR; } static class Googler { private int total = 0; public Googler(int total) { this.total = total; } public Mark canGetMark(int mark) { if(mark > 10 || mark < 0) return Mark.IMPOSSIBLE; if(canGetMark(mark+1) == Mark.REGULAR) return Mark.REGULAR; if(mark + mark + mark == total) return Mark.REGULAR; if(mark > 0) if(mark + mark + mark - 1 == total) return Mark.REGULAR; if(mark > 0) if(mark + mark - 1 + mark - 1 == total) return Mark.REGULAR; if(mark < 10) if(mark + mark + mark + 1 == total) return Mark.REGULAR; if(mark < 10) if(mark + mark + 1 + mark + 1 == total) return Mark.REGULAR; if(canGetMark(mark+1) == Mark.SURPRISING) return Mark.SURPRISING; if(mark < 9) if(mark + mark + 1 + mark + 2 == total) return Mark.SURPRISING; if(mark < 9) if(mark + mark + 2 + mark + 2 == total) return Mark.SURPRISING; if(mark > 1) if(mark + mark - 1 + mark - 2 == total) return Mark.SURPRISING; if(mark > 1) if(mark + mark - 2 + mark - 2 == total) return Mark.SURPRISING; return Mark.IMPOSSIBLE; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int testCase = 1; testCase <= T; testCase++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int result = 0; for(int i = 0; i < N; i++) { Googler googler = new Googler(sc.nextInt()); Mark mark = googler.canGetMark(p); if(mark == Mark.REGULAR) { result++; } else if(mark == Mark.SURPRISING && S > 0) { result++; S--; } } System.out.println("Case #"+testCase+": "+result); } } }
0
1,188,951
A11759
A11799
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.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class Googler { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int i =1; int n = Integer.parseInt(reader.readLine()); for(; i<=n; i++) { String input = reader.readLine(); System.out.print("Case #" + i + ": "); String[] sp = input.split(" "); int numData = Integer.parseInt(sp[0]); int s = Integer.parseInt(sp[1]); int p = Integer.parseInt(sp[2]); int[] data = new int[numData]; for(int j=0; j<numData; j++) { data[j] = Integer.parseInt(sp[j+3]); } System.out.println(count(data, s, p)); } } public static int count(int[] data, int s, int p) { Arrays.sort(data); int count = 0; for(int i=data.length-1; i>=0 && s>=0; i--) { if(data[i] % 3 == 0) { if(data[i]/3 >= p) { count++; continue; } else if(data[i]/3 + 1 >=p && s>0 && data[i]/3 -1 >=0) { count++; s--; continue; } else { break; } } else if(data[i] % 3 == 2) { if((data[i]/3 >= p) || data[i]/3 + 1 >=p) { count++; continue; } else if(data[i]/3 + 2 >=p && s>0) { count++; s--; continue; } else { break; } } else { if((data[i]/3 >= p) || data[i]/3 + 1 >=p) { count++; continue; } else if(data[i]/3 - 1 >=p && s>0 && data[i]/3 - 1>=0) { count++; s--; continue; } else { break; } } } return count; } }
0
1,188,952
A11759
A10831
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 knucle.y2012.B; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class B { public static void main(String[] args) throws Exception { FileReader fr = new FileReader("b-small.in"); BufferedReader br = new BufferedReader(fr); BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt")); int currentCase = 1; int caseNum = Integer.parseInt(br.readLine()); for(currentCase=1; currentCase<=caseNum; currentCase++){ String line = br.readLine(); String[] inputs = line.split(" "); int itemNum = Integer.parseInt(inputs[0]); int end = itemNum + 3; int suprisingNum = Integer.parseInt(inputs[1]); int minScore = Integer.parseInt(inputs[2]); int minTotalScore = Math.max(minScore*3 - 2, minScore); int minSuprisingTotalScore = Math.max(minScore*3 - 4, minScore); int qualifiedNum = 0; for(int i=3; i<end; i++){ double totalScore = Double.parseDouble(inputs[i]); if(totalScore >= minTotalScore){ qualifiedNum++; } else if(suprisingNum > 0 && totalScore >= minSuprisingTotalScore){ qualifiedNum++; suprisingNum--; } } bw.write("Case #"); bw.write(Integer.toString(currentCase)); bw.write(": "); bw.write(Integer.toString(qualifiedNum)); bw.write('\n'); } br.close(); bw.close(); } }
0
1,188,953
A11759
A12052
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 googlecodejamqualifier; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * * @author Dean */ public class DancingWithGooglers { public static void main(String args[]) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(reader.readLine()); for (int i = 0; i < cases; i ++) { String line = reader.readLine().trim(); String split[] = line.split("[\\s]+"); int people = Integer.parseInt(split[0]); int suprising = Integer.parseInt(split[1]); int maxScore = Integer.parseInt(split[2]); int count = 0; for (int j = 3; j < split.length; j++) { double score = Double.parseDouble(split[j]); score = (score - maxScore)/2; if (score < 0) { continue; } score = score - maxScore; if (score >= -1) { count++; } else if (score >= -2) { if (suprising > 0) { suprising --; count++; } } } System.out.println("Case #" + (i+1) + ": " + count); } } }
0
1,188,954
A11759
A10389
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 sholay; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; /** * GoogleDancers */ public class GoogleDancers { public static String INPUT_FILE_NAME = "B-small-attempt0.in"; public static String OUTPUT_FILE_NAME = "B-small-attempt0.out"; class Player implements Comparable<Player> { int totalScore; int x; int y; int z; int thresholdScore; boolean isSurprise; boolean isMax; /** * @param totalScore * @param thresholdScore * @param x * @param y * @param z */ Player(int totalScore, int thresholdScore, int x, int y, int z) { this.totalScore = totalScore; this.thresholdScore = thresholdScore; this.x = x; this.y = y; this.z = z; isSurprise = (Math.abs(x - y) >= 2d || Math.abs(y - z) >= 2d || Math .abs(x - z) >= 2d); isMax = (x >= thresholdScore) || (y >= thresholdScore) || (z >= thresholdScore); } @Override public int compareTo(Player arg0) { return (isMax && !isSurprise) ? 1 : ((isMax && isSurprise) ? 0 : -1); } } // Map<Integer, java.util.List<Player>> map = new HashMap<Integer, java.util.List<Player>>(); /** * Read the input file, decode the input and write the output file * * @throws IOException */ public void solve() throws IOException { BufferedReader in = null; PrintWriter out = null; try { in = new BufferedReader(new FileReader(getFile(INPUT_FILE_NAME))); out = new PrintWriter(new FileWriter(OUTPUT_FILE_NAME)); String line = null; int lineNum = 0; int numTestCase = 0; int count = 0; while ((line = in.readLine()) != null) { if (lineNum >= 0) { if (lineNum == 0) { numTestCase = Integer.parseInt(line); } else { count++; if (count <= numTestCase) { int solution = getMaxBestResult(line); out.write("Case #" + count + ": " + solution); if (count != numTestCase) { out.write("\n"); } } else { break; } } } lineNum++; } } catch (Exception ex) { System.out.println("Program failed :" + ex.getMessage()); } finally { in.close(); out.close(); } } /** * @param line * @return */ private int getMaxBestResult(String line) { map.clear(); String[] lineArray = line.split(" "); int totalPlayers = Integer.parseInt(lineArray[0]); if (totalPlayers > 0) { int surprise = Integer.parseInt(lineArray[1]); int threshold = Integer.parseInt(lineArray[2]); for (int i = 0; i < totalPlayers; i++) { List<Player> players = getPossiblePlayers(surprise, threshold, Integer.parseInt(lineArray[3 + i])); map.put(i, players); } return findMaxBest(surprise, map); } return 0; } /** * @param surprise * @param map * @return */ private int findMaxBest(int surprise, Map<Integer, List<Player>> map) { int maxBest = 0; Set<Integer> players = map.keySet(); for (Integer player : players) { List<Player> possibility = map.get(player); Player p = getPlayer(surprise, possibility); if (p != null) { if (p.isMax) { maxBest++; } if (p.isSurprise) { surprise--; } } } return maxBest; } /** * @param surprise * @param possibility * @return */ private Player getPlayer(int surprise, List<Player> possibility) { Player pp = null; Collections.sort(possibility,Collections.reverseOrder()); for (Player p : possibility) { if (p.isMax && !p.isSurprise) { pp = p; break; } } if (pp == null) { for (Player p : possibility) { if (p.isMax && p.isSurprise && surprise > 0) { pp = p; break; } } } if (pp == null) { for (Player p : possibility) { if (!p.isSurprise && surprise <= 0) { pp = p; break; } } } if (pp == null) { for (Player p : possibility) { if (!p.isSurprise) { pp = p; break; } } } return pp; } /** * @param surprise * @param threshold * @param i * @return */ private List<Player> getPossiblePlayers(int surprise, int threshold, int totalScore) { List<Player> players = new ArrayList<Player>(); // if ((totalScore) % 3 == 0) { int div = (totalScore) / 3; if(div>=0) { players.add(new Player(totalScore, threshold, div, div, div)); } } // if ((totalScore - 1) % 3 == 0) { int div = (totalScore - 1) / 3; if(div>=0){ players.add(new Player(totalScore, threshold, div, div, div + 1)); } } // if ((totalScore - 2) % 3 == 0) { int div = (totalScore - 2) / 3; if(div>=0) { players.add(new Player(totalScore, threshold, div, div + 1, div + 1)); players.add(new Player(totalScore, threshold, div, div, div + 2)); } } // if ((totalScore - 3) % 3 == 0) { int div = (totalScore - 3) / 3; if(div>=0) { players.add(new Player(totalScore, threshold, div, div + 1, div + 2)); } } // if ((totalScore - 4) % 3 == 0) { int div = (totalScore - 4) / 3; if(div>=0) { players.add(new Player(totalScore, threshold, div, div + 2, div + 2)); } } return players; } /** * @param fileName * @return */ public static File getFile(String fileName) { return new File(fileName); } /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { GoogleDancers googleDancers = new GoogleDancers(); googleDancers.solve(); } }
0
1,188,955
A11759
A11706
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 javaapplication2; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.*; /** * * @author fawad */ public class codejam2 { static char arr[]={'a',98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122}; static char res[] = {'y','h','e','s','o','c','v','x','d','u','i','g','l','b','k','r','z','t','n','w','j','p','f','m','a','q'}; static int ar[] = {0, 1, 1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9, 9, 10,10,10}; static int arsur[] ={-1,-1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,-1,-1}; public static void main(String args[]){ try{ FileReader fr = new FileReader("B-small-attempt0.in"); //FileReader fr = new FileReader("New.txt"); BufferedReader br = new BufferedReader(fr); int size = Integer.parseInt(br.readLine()); for(int i=0;i<size;i++){ String str = br.readLine(); String strarray[] = str.split(" "); int N = Integer.parseInt(strarray[0]); int S = Integer.parseInt(strarray[1]); int P = Integer.parseInt(strarray[2]); //System.out.println(N + " " + S + " " + P + " "); int arrayint[] = new int[N]; for(int j=0;j<N;j++){ arrayint[j] = Integer.parseInt(strarray[j+3]); //System.out.println(arrayint[j] + " SUM" ); } Arrays.sort(arrayint); int result = 0; for(int j1=0;j1<N;j1++){ if(arrayint[j1]>1 && arrayint[j1]<29){ if(S>0){ if(arsur[arrayint[j1]] >= P){ S--; result++; }else if(ar[arrayint[j1]] >= P){ result++; } }else if(ar[arrayint[j1]] >= P){ result++; } }else{ if( ar[arrayint[j1]] >= P){ result++; } } } System.out.println("Case #"+(i+1)+": "+result); } br.close(); fr.close(); }catch(IOException ex){ ex.printStackTrace(); } //System.out.println(arr[25]+""); } }
0
1,188,956
A11759
A11058
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 rab1 { public static void main(String[] aesdfwer) { Scanner sc= new Scanner (System.in); int t=sc.nextInt(); int o; int n,s,p,pt; int a,r; for(int c=1;c<=t;c++) { n=sc.nextInt(); s=sc.nextInt(); p=sc.nextInt(); o=0; for(int i=0;i<n;i++) { pt=sc.nextInt(); r=pt%3; a=pt/3; if(a>=p) { o++; } else if(r==0) { if(a+1>=p && a>0 && s>0) { o++; s--; //System.out.println(pt+" kasus spesial! sisa "+s); } } else if(r==1) { if(a+1>=p) { o++; } } else { if(a+1>=p) { o++; } else if(a+2>=p && s>0) { o++; s--; //System.out.println(pt+" kasus spesial! sisa "+s); } } //System.out.println(pt+" "+r+" "+a+" "+s+" "+p); } System.out.println("Case #"+c+": "+o); } } }
0
1,188,957
A11759
A11447
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.Arrays; import java.util.StringTokenizer; public class DanceScores { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader f = new BufferedReader(new FileReader("test.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("dance.out"))); int numberCases = Integer.parseInt(f.readLine()); String log; StringTokenizer st; int dancers; int bestResult; int surprisingTriples; int triplesThatSatisfy; for (int i = 1; i <= numberCases; i++) { log = "Case #" + i + ": "; st = new StringTokenizer(f.readLine()); dancers = Integer.parseInt(st.nextToken()); surprisingTriples = Integer.parseInt(st.nextToken()); bestResult = Integer.parseInt(st.nextToken());; triplesThatSatisfy = calculateNumTriples(dancers, surprisingTriples, bestResult, st); log += triplesThatSatisfy; out.println(log); } out.close(); System.exit(0); } private static int calculateNumTriples(int dan, int sur, int bes, StringTokenizer st) { int result = 0; int surprising = sur; int total; //deal with p = 0 and p = 1, as these cases are special if (bes == 0) { return dan; } else if (bes == 1) { while (st.hasMoreTokens()) { if ((Integer.parseInt(st.nextToken())) != 0) { result++; } } return result; } else { while (st.hasMoreTokens()) { total = Integer.parseInt(st.nextToken()); if (total >= 3*bes - 2) { result++; } else if ((3*bes - 4 <= total) && (total <= 3*bes - 3)) { if (surprising > 0) { surprising--; result++; } } } return result; } } }
0
1,188,958
A11759
A12575
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; public abstract class JamProblem { int caseCount; int lastLine; abstract String solveCase(JamCase jamCase); abstract JamCase parseCase(List<String> file, int line); List<String> loadFile() throws IOException { FileReader inputStream = new FileReader("C:\\projekt\\codejam\\src\\input.txt"); BufferedReader reader = new BufferedReader(inputStream); List<String> list = new ArrayList<String>(); while (true) { String line = reader.readLine(); if (line == null) { break; } list.add(line); } return list; } void go() throws IOException { List<String> file = loadFile(); parseFirstLine(file); FileWriter writer = new FileWriter("C:\\projekt\\codejam\\src\\otput.txt"); for (int c=0; c< caseCount; c++) { JamCase casee= parseCase(file, lastLine); lastLine += casee.lineCount; String s = solveCase(casee); writer.write("Case #" + (c+1) +": " + s + "\n"); } writer.close(); } void parseFirstLine(List<String> file) { int[] firstLine = JamUtil.parseIntList(file.get(0), 1); this.caseCount = firstLine[0]; lastLine = 1; } }
0
1,188,959
A11759
A10479
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.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.Scanner; public class Main { public static void main(String[] args) { try { Scanner in = new Scanner(new FileReader("in.txt")); PrintWriter out = new PrintWriter(new FileWriter("out.txt"), true); int t = in.nextInt(); for (int i = 1; i <= t; i++) { int res = 0; int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int tt[] = new int[n]; for (int j = 0; j < n; j++) { tt[j] = in.nextInt(); } if (p == 0) { res = n; } else { int min = 3 * p - 2; for (int j = 0; j < n; j++) { if (min <= tt[j]) res++; } int ttt[] = new int[n - res]; int itr = 0; for (int j = 0; j < n; j++) { if (min > tt[j]) ttt[itr++] = tt[j]; } int minCrazy = 3 * p - 5; int ress = 0; for (int j = 0; j < itr; j++) { if (minCrazy <= ttt[j] && ttt[j] != 0) ress++; } if (ress <= s) { res += ress; } else { res += s; } } out.println("Case #" + i + ": " + res); } } catch (Exception e) { e.printStackTrace(); } } }
0
1,188,960
A11759
A10752
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.FileReader; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.HashMap; public class DancingGooglers { /** * @param args */ public static void main(String[] args) { try { File inf = new File("/home/jeyram/Downloads/"+"B-small-attempt0.in"); File of = new File("/home/jeyram/Downloads/"+"rl-dg-output.in"); FileInputStream in = new FileInputStream(inf); FileOutputStream out = new FileOutputStream(of); // 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) { System.out.println (strLine); int itrs= Integer.parseInt(strLine); int count=0; //#test cases while (count < itrs) { if ((strLine = br.readLine()) != null){ // input str String[] inst = strLine.split(" "); //number of googlers int N = Integer.parseInt(inst[0]); //number of surprises atleast ==2 int S = Integer.parseInt(inst[1]); //result of atleast p int p = Integer.parseInt(inst[2]); //max no of googlers with p int y=0; //scores list int[] ti = new int[inst.length-3]; int j=0; for(int i=3;i<inst.length;i++){ ti[j] = Integer.parseInt(inst[i]); int q = (ti[j]>0)?ti[j]/3:0; int r = (ti[j]>0)?ti[j] % 3:0; if(q==0&& r==0){ if(q>=p){ y++; } }else //eliminate surprise count //divis by 3 r 0 //2 strat one sur :n,n,n | n+1,n-1,n (sur) if (r==0){ //regular strat if(q>=p){ y++; }else{ if(S>0){//surprise strat if(((q+1)>=p) || (q>=p) || ((q-1)>=p)){ y++;S--; } } } } //divis by 3 r 1 //2 strat one sur :n,n,n+1 | n+1,n-1,n+1 (sur) else if(r==1){ //regular strat if(((q+1)>=p) || (q>=p)){ y++; } else { if(S>0){//surprise strat if(((q+1)>=p) || ((q-1)>=p)){ y++;S--; } } } } //divis by 3 r 2 //2 strat one sur :n+1,n+1,n |n+2,n,n (sur) else if(r==2){ //regular strat if(((q+1)>=p) || (q>=p)){ y++; } else { if(S>0){//surprise strat if(((q+2)>=p) || ((q)>=p)){ y++;S--; } } } } j++; } System.out.println("output string"+y); //write as Case #1: 2 3 BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); bw.write("Case #"+(count+1)+": "+y); bw.newLine(); bw.flush(); } count++; } } //Close the input stream in.close(); out.close(); }catch (Exception e) { e.printStackTrace(); } finally{ } } }
0
1,188,961
A11759
A10183
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.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; public class fileHandler { FileInputStream input; FileOutputStream output; BufferedReader buf; public fileHandler(String in, String out) { try { input = new FileInputStream(in); output = new FileOutputStream(out); buf = new BufferedReader(new InputStreamReader(input)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String readLineFromInput(){ String str = null; try { str = buf.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return str; } public int readCase(){ int i = -1; String str = null; try { str = buf.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } i = Integer.parseInt(str); return i; } public int[] readIntegers(){ int temp[]; String str = null; try { str = buf.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String split[] = str.split(" "); temp = new int[split.length]; for(int i=0;i<split.length;i++){ temp[i] = Integer.parseInt(split[i]); } return temp; } public void writeToOutput(String str){ byte buff[] = str.getBytes(); try { output.write(buff); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
1,188,962
A11759
A11139
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()); } } }
/** * DancingWithTheGooglers.java * * Either use command line or first argument must be path of input file. */ import java.io.File; import java.io.FileNotFoundException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; /** * @author bsanghvi */ public class DancingWithTheGooglers { private static final Map<Integer, Integer> scopesMap = new HashMap<Integer, Integer>(); private static final Map<Integer, Integer> surprisingScoresMap = new HashMap<Integer, Integer>(); static { scopesMap.put(30, 10); // 10, 10, 10 scopesMap.put(29, 10); // 10, 10, 9 scopesMap.put(28, 10); // 10, 9, 9 surprisingScoresMap.put(28, 10); // 10, 10, 8 scopesMap.put(27, 9); // 9, 9, 9 surprisingScoresMap.put(27, 10); // 10, 9, 8 scopesMap.put(26, 9); // 9, 9, 8 surprisingScoresMap.put(26, 10); // 10, 8, 8 scopesMap.put(25, 9); // 9, 8, 8 surprisingScoresMap.put(25, 9); // 9, 9, 7 scopesMap.put(24, 8); // 8, 8, 8 surprisingScoresMap.put(24, 9); // 9, 8, 7 scopesMap.put(23, 8); // 8, 8, 7 surprisingScoresMap.put(23, 9); // 9, 7, 7 scopesMap.put(22, 8); // 8, 7, 7 surprisingScoresMap.put(22, 8); // 8, 8, 6 scopesMap.put(21, 7); // 7, 7, 7 surprisingScoresMap.put(21, 8); // 8, 7, 6 scopesMap.put(20, 7); // 7, 7, 6 surprisingScoresMap.put(20, 8); // 8, 6, 6 scopesMap.put(19, 7); // 7, 6, 6 surprisingScoresMap.put(19, 7); // 7, 7, 5 scopesMap.put(18, 6); // 6, 6, 6 surprisingScoresMap.put(18, 7); // 7, 6, 5 scopesMap.put(17, 6); // 6, 6, 5 surprisingScoresMap.put(17, 7); // 7, 5, 5 scopesMap.put(16, 6); // 6, 5, 5 surprisingScoresMap.put(16, 6); // 6, 6, 4 scopesMap.put(15, 5); // 5, 5, 5 surprisingScoresMap.put(15, 6); // 6, 5, 4 scopesMap.put(14, 5); // 5, 5, 4 surprisingScoresMap.put(14, 6); // 6, 4, 4 scopesMap.put(13, 5); // 5, 4, 4 surprisingScoresMap.put(13, 5); // 5, 5, 3 scopesMap.put(12, 4); // 4, 4, 4 surprisingScoresMap.put(12, 5); // 5, 4, 3 scopesMap.put(11, 4); // 4, 4, 3 surprisingScoresMap.put(11, 5); // 5, 3, 3 scopesMap.put(10, 4); // 4, 3, 3 surprisingScoresMap.put(10, 4); // 4, 4, 2 scopesMap.put(9, 3); // 3, 3, 3 surprisingScoresMap.put(9, 4); // 4, 3, 2 scopesMap.put(8, 3); // 3, 3, 2 surprisingScoresMap.put(8, 4); // 4, 2, 2 scopesMap.put(7, 3); // 3, 2, 2 surprisingScoresMap.put(7, 3); // 3, 3, 2 scopesMap.put(6, 2); // 2, 2, 2 surprisingScoresMap.put(6, 3); // 3, 2, 1 scopesMap.put(5, 2); // 2, 2, 1 surprisingScoresMap.put(5, 3); // 3, 1, 1 scopesMap.put(4, 2); // 2, 1, 1 surprisingScoresMap.put(4, 2); // 2, 2, 0 scopesMap.put(3, 1); // 1, 1, 1 surprisingScoresMap.put(3, 2); // 2, 1, 0 scopesMap.put(2, 1); // 1, 1, 0 surprisingScoresMap.put(2, 2); // 2, 0, 0 scopesMap.put(1, 1); // 1, 0, 0 scopesMap.put(0, 0); // 0, 0, 0 } /** * The main method. * * @param args the arguments */ public static void main(final String[] args) { try { final Scanner in; if (args.length >= 1) { in = new Scanner(new File(args[0])); } else { in = new Scanner(System.in); } final int T = in.nextInt(); for (int test = 1; test <= T; test++) { final int result = processCase(in); System.out.println("Case #" + test + ": " + result); } } catch (final FileNotFoundException e) { e.printStackTrace(); } } private static int processCase(final Scanner in) { int result = 0; final int N = in.nextInt(); // number of Googlers int S = in.nextInt(); // number of surprising triplets of scores final int p = in.nextInt(); // best result final int[] t = new int[N]; for (int i = 0; i < t.length; i++) { t[i] = in.nextInt(); } for (final int ti : t) { if (scopesMap.containsKey(ti) && scopesMap.get(ti) >= p) { ++result; } else if (S > 0 && surprisingScoresMap.containsKey(ti) && surprisingScoresMap.get(ti) >= p) { ++result; --S; } } return result; } }
0
1,188,963
A11759
A11861
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 googleJam; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class GoogleDancers { public static void main(String[] args) { Scanner scan = null; try { scan = new Scanner(new File(args[0])); } catch (FileNotFoundException e) { System.err.println("File not found!"); return; } if (!scan.hasNext()) { System.err.println("Nothing in File!"); return; } int testCases = Integer.parseInt(scan.nextLine()); String[] line; String str; int theFabulousGoogleDancers; int soManySurprises; int whoIsBetterThanMe; int itsAStretch; int noSurpriseNeeded; int iAmBetterThanYou; int canReachWithSurprise; int number = 1; int combined; while (scan.hasNext()) { System.out.print("Case #" + number + ": "); iAmBetterThanYou = 0; itsAStretch = 0; str = scan.nextLine(); line = str.split(" "); theFabulousGoogleDancers = Integer.parseInt(line[0]); soManySurprises = Integer.parseInt(line[1]); whoIsBetterThanMe = Integer.parseInt(line[2]); noSurpriseNeeded = (whoIsBetterThanMe + (whoIsBetterThanMe-1) + (whoIsBetterThanMe-1)); canReachWithSurprise = (whoIsBetterThanMe + (whoIsBetterThanMe-2) + (whoIsBetterThanMe - 2)); if (whoIsBetterThanMe == 1) { noSurpriseNeeded = 1; canReachWithSurprise = 1; } if (whoIsBetterThanMe == 0) { noSurpriseNeeded = 0; canReachWithSurprise = 0; } for (int score = 3; score < line.length; score++) { if ((Integer.parseInt(line[score])) >= canReachWithSurprise && Integer.parseInt(line[score]) < noSurpriseNeeded) { itsAStretch++; } else if (Integer.parseInt(line[score]) >= noSurpriseNeeded) { iAmBetterThanYou++; } } if (itsAStretch <= soManySurprises) { combined = iAmBetterThanYou + itsAStretch; } else { combined = iAmBetterThanYou + soManySurprises; } System.out.print(combined); if(scan.hasNext()) { System.out.println(); } number++; } } }
0
1,188,964
A11759
A11634
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 codejam12; import java.io.*; import java.util.StringTokenizer; /** * * @author Mohamed Ibrahim (MIM) */ public class Problem_B { public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new FileReader("B-small-attempt4.in")); PrintWriter w = new PrintWriter(new BufferedWriter(new FileWriter("B-small-attempt4.out"))); int nCases = Integer.parseInt(r.readLine()); for (Integer k = 1; k <= nCases; k++) { int ret=0; w.print("Case #" + k + ": "); String line=r.readLine(); StringTokenizer st = new StringTokenizer(line); int n= Integer.parseInt(st.nextToken()); int more= Integer.parseInt(st.nextToken()); int p= Integer.parseInt(st.nextToken()); for (int i = 0; i <n; i++) { int cur= Integer.parseInt(st.nextToken()); int div=cur/3; int rem=cur-div*3; if(p==0){ ret=n; break; } if(cur==0)continue; if(div>=p)ret++; else{ if(p-div==1 && rem>0)ret++; else if(p-div==1 && more>0){ ret++; more--; } else if(p-div==2 && rem==2 && more>0){ ret++; more--; } /* else if(p-div==2 && more>0 && rem>0){ ret++; more--; }*/ } } w.println(ret); } w.close(); } }
0
1,188,965
A11759
A11767
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.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class ProblemB_Qual_2012 implements Runnable{ BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException{ in = new BufferedReader(new FileReader("B-small-attempt0.in")); out = new PrintWriter("output.txt"); } String readString() throws IOException{ while(!tok.hasMoreTokens()){ try{ tok = new StringTokenizer(in.readLine()); }catch (Exception e){ return null; } } return tok.nextToken(); } int readInt() throws IOException{ return Integer.parseInt(readString()); } long readLong() throws IOException{ return Long.parseLong(readString()); } double readDouble() throws IOException{ return Double.parseDouble(readString()); } public static void main(String[] args){ new Thread(null, new ProblemB_Qual_2012(), "", 256 * (1L << 20)).start(); } long timeBegin, timeEnd; void time(){ timeEnd = System.currentTimeMillis(); System.err.println("Time = " + (timeEnd - timeBegin)); } long memoryTotal, memoryFree; void memory(){ memoryFree = Runtime.getRuntime().freeMemory(); System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB"); } void debug(Object... objects){ if (DEBUG){ for (Object o: objects){ System.err.println(o.toString()); } } } public void run(){ try{ timeBegin = System.currentTimeMillis(); memoryTotal = Runtime.getRuntime().freeMemory(); init(); solve(); out.close(); time(); memory(); }catch (Exception e){ e.printStackTrace(System.err); System.exit(-1); } } boolean DEBUG = false; void solve() throws IOException{ int[] a = new int[3]; int t = readInt(); for (int it = 1; it <= t; it++){ out.print("Case #" + it + ": "); int count = 0; int n = readInt(); int s = readInt(); int p = readInt(); int[] b = new int[n]; for (int i = 0; i < n; i++){ b[i] = readInt(); } Arrays.sort(b); boolean[] used = new boolean[n]; for (int i = 0; i < n; i++){ int x = b[i]; for (int j = 0; j < 3; j++){ a[j] = x / 3; } x %= 3; for (int j = 2; x > 0; j--, x--){ a[j]++; } if (a[2] >= p){ count++; continue; } if (a[2] == a[1]){ if (s > 0 && a[2] == p - 1 && a[1] > 0 && a[2] < 10){ used[i] = true; s--; count++; } } } if (s > 0){ for (int i = 0; i < n && s > 0; i++){ if (used[i]) continue; int x = b[i]; for (int j = 0; j < 3; j++){ a[j] = x / 3; } x %= 3; for (int j = 2; x > 0; j--, x--){ a[j]++; } if (a[2] == a[1]){ if (a[2] < 10 && a[1] > 0){ used[i] = true; s--; } }else if (a[1] == a[0]){ if (a[1] < 10 && a[0] > 0){ used[i] = true; s--; } } } } if (s > 0){ System.err.println("AHTUNG!!!!! TEST #" + it); } out.println(count); } } }
0
1,188,966
A11759
A12231
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 { private static Scanner in = new Scanner(System.in); private static void solve(int no) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int ans = 0; for (int i = 0; i < N; i++) { int sum = in.nextInt(); int avr = sum / 3; int rem = sum % 3; switch (rem) { case 0: if (avr >= p) { ans++; } else if (S > 0 && avr > 0 && avr + 1 >= p) { ans++; S--; } break; case 1: if (avr + 1 >= p) { ans++; } break; case 2: if (avr + 1 >= p) { ans++; } else if (S > 0 && avr + 2 >= p) { ans++; S--; } break; } } System.out.printf("Case #%d: %d%n", no, ans); } public static void main(String[] args) { int T = in.nextInt(); for (int i = 0; i < T; i++) { solve(i + 1); } } }
0
1,188,967
A11759
A12511
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 main; import java.io.*; import java.util.Scanner; public class Main { static File problemFile = new File(System.getProperty("user.home") + "/Projects/java/CodeJam/DancingWithTheGooglers/B-small-attempt2.in"); static File solutionFile = new File(System.getProperty("user.home") + "/Projects/java/CodeJam/DancingWithTheGooglers/B-small-attempt2.out"); public static void main (String[] args) { Solver s = new Solver(); try { Scanner input = new Scanner(new FileInputStream(problemFile)); BufferedWriter outWriter = new BufferedWriter(new FileWriter(solutionFile)); s.createSolution(input, outWriter); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }
0
1,188,968
A11759
A13026
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.StringTokenizer; public class Dancing { private static int[] data; public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new FileReader("A-small-practice.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("A-small-practice.out"))); StringTokenizer st = new StringTokenizer(f.readLine()); int tests = Integer.parseInt(st.nextToken()); for (int t = 1; t <= tests; t++){ out.printf("Case #%d:", t); st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); data = new int[n]; for (int i = 0; i < n; i++){ data[i] = Integer.parseInt(st.nextToken()); } out.printf(" %d\n", fun1(n, s, p)); } out.close(); System.exit(0); } private static int fun1(int n, int s, int p){ int count = 0; int s_ = s; for (int i = 0; i < n; i++){ int avg = data[i] / 3; if (data[i] % 3 == 0){ if(avg >= p) { count ++; } else{ if((s_ > 0) && (avg + 1 >= p) && (avg - 1 >=0)){ count ++; s_--; } } } else if(data[i] % 3 == 1){ if(avg + 1 >= p){ count++; } } else if(data[i] % 3 == 2){ if(avg + 1 >= p){ count ++; } else if((s_ > 0) && (avg + 2 >= p)){ count++; s_--; } } } return count; } }
0
1,188,969
A11759
A10423
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 BinaryPower { public static int binpow (int a, int n) { int r = 1; while (n > 0) if (n % 2 == 0) { a *= a; n /= 2; } else { r *= a; --n; } return r; } public static long binpow (long a, int n) { long r = 1; while (n > 0) if (n % 2 == 0) { a *= a; n /= 2; } else { r *= a; --n; } return r; } public static double binpow (double a, int n) { double r = 1; while (n > 0) if (n % 2 == 0) { a *= a; n /= 2; } else { r *= a; --n; } return r; } }
0
1,188,970
A11759
A12457
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 KNIGHT0X300 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s=new Scanner(System.in); int t=s.nextInt(); for(int i=0;i<t;i++) { int tot=0; int N=s.nextInt(); int S=s.nextInt(); int p=s.nextInt(); int A=0; for(int j=0;j<N;j++) { A=s.nextInt(); // System.out.print(" "+A); if(p>=2) { if(S>0) { if((A==(3*p-4))||(A==(3*p-3))) { tot++; S--; } } if(A>=3*p-2) tot++; } if(p==0) { tot++; } if(p==1) { if(A>=1) {//System.out.println("sdk"); tot++;} }} System.out.println("Case #"+(i+1)+": "+tot); } } }
0
1,188,971
A11759
A11104
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.nos.gcj; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.util.Calendar; import java.util.StringTokenizer; public class GCJ_Q_02 { static final String path = "F:/GCJ/GCJ_Qalification_02/Small_1"; // static final String path = "F:/GCJ/GCJ_Qalification_02/Large"; class TestCase { int N; int S; int p; int[] t; } public TestCase readTestCase(BufferedReader br) throws Exception { TestCase tc = new TestCase(); String line = br.readLine(); StringTokenizer st = new StringTokenizer(line); tc.N = Integer.valueOf(st.nextToken()); tc.S = Integer.valueOf(st.nextToken()); tc.p = Integer.valueOf(st.nextToken()); tc.t = new int[tc.N]; for (int i=0; i<tc.N; i++) tc.t[i] = Integer.valueOf(st.nextToken()); return tc; } public void writeTestResult(BufferedWriter bw, TestCase tc) throws Exception { int total = 0; for (int i=0; i<tc.N; i++) { if (tc.t[i] == 0 ) { if (tc.p == 0) total++; } else if ( tc.t[i] >= (3*tc.p-2) ) total++; else if ((tc.t[i] >= (3*tc.p - 4)) && (tc.S > 0)) { tc.S--; total++; } } bw.write(""+total); } public void solve() throws Exception { BufferedReader br = new BufferedReader(new FileReader(path+"/input.in")); BufferedWriter bw = new BufferedWriter(new FileWriter(path+"/output.out")); int testCases = new Integer(br.readLine()); for (int i=0; i<testCases; i++) { System.out.print("Test case "+(i+1)+": "); long time = Calendar.getInstance().getTimeInMillis(); TestCase testCase = readTestCase(br); System.out.print(" read in "+(Calendar.getInstance().getTimeInMillis()-time)+"ms, "); time = Calendar.getInstance().getTimeInMillis(); bw.write("Case #"+(i+1)+": "); writeTestResult(bw, testCase); bw.write("\n"); System.out.println("solved in "+(Calendar.getInstance().getTimeInMillis()-time)+"ms"); } bw.flush(); bw.close(); br.close(); } public static void main(String[] args) throws Exception { GCJ_Q_02 jam = new GCJ_Q_02(); jam.solve(); } }
0
1,188,972
A11759
A11740
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.util.ArrayList; import java.util.List; public class DancingWithTheGooglers { /** * @param args */ public static void main(String[] args) { //List<String> inputList = FileIO.readFile("B-small-practice.in"); List<String> inputList = FileIO.readFile("B-small-attempt0.in"); List<String> outputList = new ArrayList<String>(); int caseNo = 1 ; int testCaseCount = Integer.parseInt(inputList.get(0)); while (caseNo <= testCaseCount) { Scores s = new Scores(inputList.get(caseNo)); outputList.add("Case #" +caseNo +": " +s.getMaxNumberOfGooglerOverScore()); caseNo++; } //FileIO.writeFile("B-small-practice.out", outputList); FileIO.writeFile("B-small-attempt0.out", outputList); } }
0
1,188,973
A11759
A10482
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 Pair { public int max; public boolean surprise; public Pair(int max, boolean surprise) { this.max = max; this.surprise = surprise; } @Override public boolean equals(Object other) { if (!(other instanceof Pair)) { return false; } Pair pOther = (Pair) other; return (max == pOther.max && surprise == pOther.surprise); } @Override public String toString() { return max + " " + surprise; } @Override public int hashCode() { // Dirty implementation return 0; } }
0
1,188,974
A11759
A11531
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 googlecodejam2012; import java.io.FileNotFoundException; /** * * @author Pavlos */ public class ProblemB { public static void main(String[] args) throws FileNotFoundException { Read.OpenFile("B-small-attempt2.in"); Write.OpenFile("solB.txt"); int T = Read.readInt(); for (int zz = 1; zz <= T; zz++) { int N = Read.readInt(); int S = Read.readInt(); int p = Read.readInt(); int t[] = new int[N]; for (int i = 0; i < t.length; i++) { t[i] = Read.readInt(); } int counter = 0; for (int i = 0; i < t.length; i++) { if(t[i] >= p){ int temp = t[i] - 3*p; if(temp >= -2) counter++; else if(temp >= -4 && temp < -2 && S > 0) { counter++; S--; } } } //counter -= S; if(counter > 3) counter = 3; Write.WriteToFile(String.format("Case #%d: %d\n",zz, counter)); }//end zz Write.CloseFile(); } }
0
1,188,975
A11759
A13154
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.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { setStandardIO(); setFileIO("dancingwiththegooglers"); readLine(); int T = nextInt(); for (int t = 1; t <= T; ++t) { readLine(); int N = nextInt(); int S = nextInt(); int p = nextInt(); int tab[] = new int[N]; int ta[] = new int[N]; int tb[] = new int[N]; for (int i = 0; i < N; ++i) { tab[i] = nextInt(); switch (tab[i] % 3) { case 0: ta[i] = tab[i] / 3; tb[i] = (ta[i] == 0 ? ta[i] : ta[i] + 1); break; case 1: ta[i] = tab[i] / 3 + 1; tb[i] = ta[i]; break; case 2: ta[i] = tab[i] / 3 + 1; tb[i] = ta[i] + 1; break; } } int count = 0; for (int i = 0; i < N; ++i) if (ta[i] >= p) count++; for (int i = 0; i < N && S > 0; ++i) if (ta[i] < p && tb[i] >= p) { count++; S--; } println("Case #" + t + ": " + count); } flush(); } //~ ---------------------------------------------------------------------------------------------------------------- //~ - Auxiliary code ----------------------------------------------------------------------------------------------- //~ ---------------------------------------------------------------------------------------------------------------- static BufferedReader in; static PrintWriter out; static StringTokenizer st; private static void setStandardIO() { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); } private static void setFileIO(String fileName) throws FileNotFoundException, IOException { in = new BufferedReader(new FileReader(fileName + ".in")); out = new PrintWriter(new BufferedWriter(new FileWriter(fileName + ".out"))); } public static void readLine() throws IOException { st = new StringTokenizer(in.readLine()); } public static int nextInt() { return Integer.parseInt(st.nextToken()); } public static long nextLong() { return Long.parseLong(st.nextToken()); } public static String nextString() { return st.nextToken(); } public static List<String> nextStrings() { List<String> strings = new ArrayList<String>(); while (st.hasMoreTokens()) strings.add(st.nextToken()); return strings; } public static void flush() { out.flush(); } public static void println(Object object) { out.println(object); } public static void print(Object object) { out.print(object); } public static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } public static class Pair { public long x, y; public Pair(long x, long y) { this.x = x; this.y = y; } @Override public String toString() { return "Pair [x=" + x + ", y=" + y + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + (int) (x ^ (x >>> 32)); result = prime * result + (int) (y ^ (y >>> 32)); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Pair other = (Pair) obj; if (x != other.x) return false; if (y != other.y) return false; return true; } } }
0
1,188,976
A11759
A12126
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 Main { public static void main(String [] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for(int x=0; x<T; x++) { int N = in.nextInt(); //googlers int S = in.nextInt(); //surprising int p = in.nextInt(); //score to beat int direct = 0; int poss = 0; for(int i=0; i<N; i++) { int total = in.nextInt(); int m = total/3; int mod = total %3; if(mod >0) m++; if(m>=p) { direct++; continue; } else if(m<p-1) continue; //Time to use possibilities switch(mod) { case 0: if(m<10 && m>0) poss++; break; case 2: if(m<10) poss++; break; } } int result = (S>poss)? poss : S; result += direct; System.out.print("Case #" + String.valueOf(x+1) + ": "); System.out.println(result); } } }
0
1,188,977
A11759
A12939
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.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; public class Speak implements Runnable { BufferedReader in; BufferedWriter out; static String inputFile = ""; static String outputFile = ""; static { inputFile = Speak.class.getName() + ".in"; outputFile = Speak.class.getName() + ".out"; } public int iread() throws Exception { return Integer.parseInt(readword()); } public double dread() throws Exception { return Double.parseDouble(readword()); } public long lread() throws Exception { return Long.parseLong(readword()); } public String readword() throws Exception { int c = in.read(); while( c >= 0 && c <= ' ' ) { c = in.read(); } if( c < 0 ) return ""; StringBuilder bld = new StringBuilder(); while( c > ' ' ) { bld.append((char)c); c = in.read(); } return bld.toString(); } public void solve() throws Exception { int t = iread(); for (int i = 0; i < t; i++) { int r = 0; int n = iread(); int s = iread(); int p = iread(); //if (p == 0) { //r = n; //} else { int p3 = 3 * p; for (int j = 0; j < n; j++) { int score = iread(); if (score == 0) { continue; } else if (score >= p3 - 2) { r++; } else if (score >= p3 - 4 && s != 0) { r++; s--; } } //} if(p==0){ r=n; } out.write("Case #" + (i + 1) + ": " + r + "\n"); } } public void run() { try { in = new BufferedReader( new FileReader( inputFile )); out = new BufferedWriter( new FileWriter( outputFile )); // in = new BufferedReader( new InputStreamReader(System.in)); // out = new BufferedWriter( new OutputStreamWriter(System.out)); solve(); out.flush(); } catch( Exception e ) { e.printStackTrace(); } } public static void main(String[] args) { new Thread( new Speak()).start(); } }
0
1,188,978
A11759
A10669
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.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGoogle { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader in = new BufferedReader(new FileReader("./test2.txt")); FileWriter fstream = new FileWriter("./out2.txt"); BufferedWriter out = new BufferedWriter(fstream); String str,str2; int i = 0; DancingGoogle mydg = new DancingGoogle(); int numTestCase = Integer.parseInt(in.readLine()); while ((str = in.readLine()) != null) { str2=""; int numOK = 0; String[] toks; toks = str.split(" "); int numGoogles = Integer.parseInt(toks[0]); int numSP = Integer.parseInt(toks[1]); int criteria = Integer.parseInt(toks[2]); for(int j =3;j<toks.length;j++) { int temp = Integer.parseInt(toks[j])/3; int rm = Integer.parseInt(toks[j])%3; if(temp >= criteria) { numOK++; continue; } int diff = criteria - temp; if(rm > diff){ numOK++; continue; } else if( rm == 1 && diff == 1) { numOK++; continue; } else if(rm == 2 && diff == 2 && numSP > 0) { numOK++; numSP--; continue; } else if(rm < diff && diff ==1 && numSP > 0 && temp-diff >=0) { numOK++; numSP--; continue; } } str2 = "Case #" + (++i) + ": " + numOK + "\n"; out.append(str2); System.out.print(str2); } in.close(); out.close(); } }
0
1,188,979
A11759
A10696
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 nl.maartenvangrootel.googlecodejam.qualifiers.dancing; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.regex.Pattern; /** * Hello world! * */ public class DancingScores { private File file; private static Pattern pattern = Pattern.compile("[\\ ]"); public DancingScores(String filename) { if (filename == null) throw new IllegalArgumentException("filename should not be null"); file = new File(filename); if (!(file.exists() && file.isFile())) throw new IllegalArgumentException(String.format( "'%s' does not exist or is not a file.", filename)); } private BufferedReader getReader() { BufferedReader reader = null; try { FileReader stream = new FileReader(file); reader = new BufferedReader(stream); } catch (FileNotFoundException e) { e.printStackTrace(); } return reader; } public String calculateResult() { BufferedReader reader = getReader(); StringBuilder builder = new StringBuilder(); try { int T = Integer.parseInt(reader.readLine()); int i = 1; String line; while ((line = reader.readLine()) != null) { if (i > 1) { builder.append("\n"); } builder.append("Case #"); builder.append(i); builder.append(": "); builder.append(parseLine(line)); i++; } } catch (IOException e) { e.printStackTrace(); } return builder.toString(); } public static int parseLine(String line) { String[] input = pattern.split(line); int googlers = Integer.parseInt(input[0]); int maxSurprises = Integer.parseInt(input[1]); int bestResultGoal = Integer.parseInt(input[2]); int[] totalResults = new int[googlers]; int[] totalResultsMinusGoal = new int[googlers]; int surpriseOrNot = 0, not = 0, normal = 0, surpriseOrNormal = 0; for (int i = 0; i < googlers; i++) { // totalResults[i] = Integer.parseInt(input[i + 3]); // totalResultsMinusGoal[i] = totalResults[i] - bestResultGoal; int result = Integer.parseInt(input[i + 3]); int resultMinusGoal = result - bestResultGoal; if (resultMinusGoal < 0 || resultMinusGoal < (bestResultGoal - 2) * 2) { not++; } else if (resultMinusGoal < (bestResultGoal + (bestResultGoal - 2))) { surpriseOrNot++; } else if (resultMinusGoal == (bestResultGoal + (bestResultGoal - 2))) { surpriseOrNormal++; } else { normal++; } } int retVal = 0; if (surpriseOrNot == maxSurprises) { // exactly enough surpriseOrNot: all surpriseOrNormal are normal retVal = normal + surpriseOrNormal + surpriseOrNot; } else if (surpriseOrNot > maxSurprises) { // too many surpriseOrNot, all surpriseOrNormals are normal, some // surpriseOrNot are not. retVal = normal + surpriseOrNormal + maxSurprises; } else if (surpriseOrNot < maxSurprises) { // Too little surprisesOrNot, take them from surpriseOrNormal, the // rest is Normal. retVal = normal + surpriseOrNot + surpriseOrNormal; } return retVal; } public static void main(String[] args) { if (args.length > 0) { DancingScores starter = new DancingScores(args[0]); String result = starter.calculateResult(); System.out.println(result); } else { System.err.println("No arguments given."); } } }
0
1,188,980
A11759
A11990
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.FileReader; import java.io.PrintStream; public class ProblemB { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader("in.txt")); PrintStream out = System.out; out = new PrintStream("out.txt"); int T = Integer.parseInt(in.readLine()); for (int t = 0; t < T; t++) { String[] tok = in.readLine().split(" "); int N = Integer.parseInt(tok[0]); int S = Integer.parseInt(tok[1]); int p = Integer.parseInt(tok[2]); // BRUTE FORCE int ans = 0; for (int s1 = 0; s1 <= 10; s1++) for (int s2 = s1; s2 <= s1+2; s2++) for (int s3 = s2; s3 <= s1+2; s3++) for (int s4 = 0; s4 <= 10; s4++) for (int s5 = s4; s5 <= s4+2; s5++) for (int s6 = s5; s6 <= s4+2; s6++) for (int s7 = 0; s7 <= 10; s7++) for (int s8 = s7; s8 <= s7+2; s8++) for (int s9 = s8; s9 <= s7+2; s9++) { int p1 = Integer.parseInt(tok[3]); int p1s = (s1+2 == s3) ? 1 : 0; int p1t = (s3 >= p) ? 1 : 0; if (s1+s2+s3 != p1) continue; if (N > 1) { int p2 = Integer.parseInt(tok[4]); int p2s = (s4+2 == s6) ? 1 : 0; int p2t = (s6 >= p) ? 1 : 0; if (s4+s5+s6 != p2) continue; if (N > 2) { int p3 = Integer.parseInt(tok[5]); int p3s = (s7+2 == s9) ? 1 : 0; int p3t = (s9 >= p) ? 1 : 0; if (s7+s8+s9 != p3) continue; if (p1s+p2s+p3s != S) continue; if (p1t+p2t+p3t > ans) ans = p1t+p2t+p3t; } else { if (p1s+p2s != S) continue; if (p1t+p2t > ans) ans = p1t+p2t; } } else { if (p1s != S) continue; if (p1t > ans) ans = p1t; } } // int with = 0, without = 0, either = 0; // for (int i = 3; i < tok.length; i++) // { // int total = Integer.parseInt(tok[i]); // // if (total == 0) // { // if (p == 0) without++; // } // else if (total == 1) // { // if (p <= 1) without++; // } // else if (total < 29) // { // if (total >= 3*p-2) either++; // else if (total >= 3*p-4) with++; // } // else without++; // } // int ans = with + without + either; // if (with > S) ans = S + without + either; // else if (S > with + either) ans = 0; out.printf("Case #%d: %d\n", t+1, ans); } if (out != System.out) out.close(); } }
0
1,188,981
A11759
A13227
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.util.Scanner; public class surprising { public static int solve(String input) { String[] inputs = input.split(" "); int count = Integer.parseInt(inputs[0]); int surprises = Integer.parseInt(inputs[1]); int best = Integer.parseInt(inputs[2]); int[] scores = new int[inputs.length - 3]; for (int i = 3; i < inputs.length; i++) { scores[i-3] = Integer.parseInt(inputs[i]); } int bestCount = 0; int surprisesCount = 0; for (int i = 0; i < scores.length; i++) { int num = scores[i]; if (best == 0) bestCount++; else if (num == 0) continue; else if (isBest(num, best)) bestCount++; else if (isSuprising(num, best)) surprisesCount++; } return bestCount + Math.min(surprisesCount, surprises); } public static boolean isBest(int n, int best) { int start = n / 3; if (start >= best) return true; // have two remaining, and is only less by one. // We can get a non-surprising result this way int remain = n % 3; if (start == best - 1 && (remain == 2 || remain == 1)) return true; return false; } public static boolean isSuprising(int n, int best) { int start = n / 3; int remain = n % 3; if (start == best - 1 && remain == 0) return true; if (start == best - 2 && remain == 2) return true; return false; } public static void main(String[] args) { Scanner scanner = null; try { scanner = new Scanner(new File("A-small-attempt0.in")); }catch (Exception e){ System.out.println(e.getMessage()); } String c = scanner.nextLine(); int i = 1; while (scanner.hasNextLine()) { String input = scanner.nextLine(); System.out.println("Case #" + i + ": " + solve(input)); i++; } } }
0
1,188,982
A11759
A10458
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 SolutionDancingWithGooglers { static int[] notes; static int surprising; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); for(int i = 0; i < cases; i++){ int googlers = sc.nextInt(); surprising = sc.nextInt(); int p = sc.nextInt(); int counter = 0; for(int j = 0; j < googlers; j++){ int triplet = sc.nextInt(); int[] scores = new int[3]; scores[0] = triplet/3; triplet = triplet - triplet/3; scores[1] = triplet/2; triplet = triplet - triplet/2; scores[2] = triplet; counter = counter + verify(scores, surprising, p); } System.out.println("Case #" + (i+1) + ": " + counter); } } public static int verify(int[] v, int count, int comp){ //System.out.println("count: "+count); if(good(v, comp)){ return 1; }else if(count != 0 && (v[0] > 0 && v[2] < 10)){ if(v[0] != v[1] || v[2] != v[1] + 1){ v = mod(v); if(possible(v) && good(v, comp)){ surprising = count - 1; return 1; }else return 0; }else return 0; }else return 0; } public static boolean good(int[] v, int comp){ for(int i = 0; i < v.length; i++){ if(v[i] >= comp){ return true; } } return false; } public static boolean possible(int[] v){ if(Math.abs(v[0] - v[1]) > 2) return false; else if(Math.abs(v[1] - v[2]) > 2) return false; else if(Math.abs(v[2] - v[0]) > 2) return false; else return true; } public static int[] mod(int[] v){ if(v[0] == v[1] && v[1] == v[2]){ v[0] = v[0] - 1; v[2] = v[2] + 1; return v; }else{ v[1] = v[1] - 1; v[2] = v[2] + 1; return v; } } }
0
1,188,983
A11759
A12123
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.Vector; public class problemB { Vector<String> lines = new Vector<String>(); public static void main(String[] a) { problemB pb = new problemB(); pb.lines = pb.readfile("C:\\eclipse\\Ashish\\files\\B-small-attempt0.in"); int nooftestcases = Integer.parseInt(pb.lines.elementAt(0)); System.out.println(nooftestcases); Vector<String> outlines = new Vector<String>(); //int j=1; for (int i=1; i<=nooftestcases; i++) { String[] s = pb.lines.elementAt(i).split(" "); int go = Integer.parseInt(s[0]); int su = Integer.parseInt(s[1]); int ms = Integer.parseInt(s[2]); Vector<Integer> sc = new Vector<Integer>(); for (int j=0; j<go; j++) { //System.out.println(s[j+3]); sc.add(Integer.valueOf((s[j+3]))); //System.out.println(sc.elementAt(j)); } TestCaseB tc = new TestCaseB(go,su,ms,sc); int sol = pb.solveit(tc); String ol = "Case #" + i + ": " + sol; outlines.add(ol); } pb.writefile("C:\\eclipse\\Ashish\\files\\otestb.txt", outlines); } public int solveit(TestCaseB tc) { int howmany = 0; int remsurp = tc.surprises; for (int i=0; i<tc.googlers; i++) { double score = tc.scores.elementAt(i).doubleValue(); double sd = score / 3; System.out.println("Score:" + score + " " + sd); if (tc.minscore - sd <= 0 || (tc.minscore - sd < 1 && tc.minscore - sd > 0)) { System.out.println("Yes"); howmany++; continue; } if (tc.minscore - sd > 1.5) { System.out.println("No"); continue; } if (remsurp > 0 && sd !=0 ) { System.out.println("finally"); howmany++; remsurp--; } else { System.out.println("Hard luck"); } } return howmany; } public void writefile(String name, Vector<String> l) { try{ // Create file FileWriter fstream = new FileWriter(name); BufferedWriter out = new BufferedWriter(fstream); for (int i=0; i<l.size(); i++) { out.write((l.elementAt(i) + System.getProperty("line.separator"))); } //Close the output stream out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } public Vector<String> readfile(String fp) { Vector<String> lines = new Vector<String>(); try { FileReader fr = new FileReader(fp); BufferedReader br = new BufferedReader(fr); String s; while((s = br.readLine()) != null) { //System.out.println(s); lines.addElement(s); } fr.close(); } catch (Exception e) { System.out.println(e); } return lines; } }
0
1,188,984
A11759
A12488
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; public class Main { // static Scanner in; static int next() throws Exception {return in.nextInt();}; static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;} static PrintWriter out; static String NAME = "b"; public static void main(String[] args) throws Exception { // in = new Scanner(new File(NAME + ".in")); out = new PrintWriter(new File(NAME + ".out")); in = new StreamTokenizer(new BufferedReader(new FileReader(new File(NAME + ".in")))); int tests = next(); int inf = 1000000; for (int test = 1; test <= tests; test++) { int n = next(); int s = next(); int p = next(); int[] t = new int[n]; for (int i = 0; i < n; i++) t[i] = next(); int[][] max = new int[n + 1][n + 1]; for (int[] mm : max) Arrays.fill(mm, -inf); max[0][0] = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (t[i] <= (p - 1) * 3) max[i + 1][j] = Math.max(max[i + 1][j], max[i][j]); if (2 <= t[i] && t[i] <= (p - 1) * 3 - 2) max[i + 1][j + 1] = Math.max(max[i + 1][j + 1], max[i][j]); if (p + 2*Math.max(p - 2, 0) <= t[i] && t[i] <= 28) max[i + 1][j + 1] = Math.max(max[i + 1][j + 1], max[i][j] + 1); if (3*p - 2 <= t[i]) max[i + 1][j] = Math.max(max[i + 1][j], max[i][j] + 1); } out.print("Case #" + test + ": "); out.println(max[n][s]); } out.close(); } }
0
1,188,985
A11759
A12830
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package google.codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; public class Main { private static boolean debug = false; public static void main(String [] args){ if(args!=null && args.length==2){ FileInputStream fstream = null; try { fstream = new FileInputStream(args[0]); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; File file = new File(args[1]); FileWriter fstreamOut = new FileWriter(file.getAbsolutePath()); BufferedWriter out = new BufferedWriter(fstreamOut); int lineNum = Integer.parseInt(br.readLine()); GoogleSolver solver = new DanceGoogler(); //GooglereseSolver.calcualteMapping(); for(int i=0 ; i<lineNum; i++){ strLine = br.readLine(); String resultStr = solver.solve(strLine); if(debug){ System.out.println (strLine + "->" + resultStr); }else{ String output = "Case #"+(i+1) +": " + resultStr; System.out.println (output); out.write(output+"\n"); } } out.close(); in.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
0
1,188,986
A11759
A11956
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 cj1 { public static void main(String[] args) { Scanner s = new Scanner(System.in); int T = s.nextInt(); for (int i = 1; i<=T; i++) { int N = s.nextInt(); int S = s.nextInt(); int p = s.nextInt(); int nc=0; int nawt=0; int nbwt=0; int naw=0; int nbw=0; int delta=0; for (int j = 1; j<=N; j++) { int ti = s.nextInt(); if (ti==0) { if(ti==p) { nbw++; nbwt++; } continue; } if((ti-1)%3==0) { if ((ti+2)/3>=p) nc++; } if(ti%3==0){ if(ti/3>=p) { nbw++; nbwt++; } else if((ti+3)/3>=p) nbw++; } if((ti+1)%3==0) { if ((ti+1)/3>=p) { naw++; nawt++; } else if ((ti+4)/3>=p) naw++; } } if(S<=(naw+nbw-nawt-nbwt)) delta=S; else delta=naw+nbw-nawt-nbwt; int max = nc + nawt + nbwt + delta; System.out.println("Case #" + i + ": "+ max); } } }
0
1,188,987
A11759
A11586
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 mishe { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int cnt = scan.nextInt(); for(int c=1 ; c<=cnt ; c++) { int[] nums = new int[scan.nextInt()]; int sup = scan.nextInt(); int max = scan.nextInt(); int MINSUP = max+2*((max>=2)?(max-2):0),MINNSUP = max+2*((max>=1)?(max-1):0),res = 0; for(int i=0 ; i<nums.length ; i++) nums[i] = scan.nextInt(); for(int i=0 ; i<nums.length ; i++) { if(nums[i]<MINSUP) continue; if(nums[i]>=MINSUP && nums[i]<MINNSUP) { if(sup>0) res++; sup--; } else if(nums[i]>=MINNSUP) res++; } System.out.println("Case #"+c+": "+res); } } }
0
1,188,988
A11759
A12053
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.lang.reflect.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Googlers { public static void main(String[] args) { try{ File dance = new File("C:\\Users\\Moeen\\Documents\\0 ECLIPSE\\IO Folder\\Input\\B-small-attempt0.in"); FileWriter outFile = new FileWriter("C:\\Users\\Moeen\\Documents\\0 ECLIPSE\\IO Folder\\Output\\B-small-attempt0.out"); PrintWriter dancePrint = new PrintWriter(outFile); Scanner scan = new Scanner(dance); String inputString = new String(); ArrayList<Integer> numbersArray = new ArrayList<Integer>(); inputString = scan.nextLine(); int totalNoCases = Integer.parseInt(inputString); System.out.println("Total Number of Cases: " + totalNoCases); for (int caseNo = 1; caseNo <= totalNoCases; caseNo++){ System.out.println("Case #" + caseNo + ": "); dancePrint.print("Case #" + caseNo + ": "); inputString = scan.nextLine(); int startIndex = 0; for (int itemCounter = 0; itemCounter < inputString.length(); itemCounter++){ if (inputString.charAt(itemCounter) == ' '){ numbersArray.add(Integer.parseInt(inputString.substring(startIndex, itemCounter))); startIndex = (itemCounter +1); } } numbersArray.add(Integer.parseInt(inputString.substring(startIndex))); int nGooglers = numbersArray.get(0); int sSurprising = numbersArray.get(1); int pBestResult = numbersArray.get(2); int bestCounter = 0; numbersArray.remove(0); numbersArray.remove(0); numbersArray.remove(0); int [] tripArray = new int[3]; for (int scores = 0; scores < nGooglers; scores++){ //System.out.println(numbersArray.get(scores)); int tripScores = numbersArray.get(scores)/3; tripArray[0] = tripScores; tripArray[1] = tripScores; tripArray[2] = tripScores; int remainder = (numbersArray.get(scores) - (tripScores*3)); if (remainder > 0){ for (int i = 0; i < remainder; i++){ tripArray[i]++; } } Arrays.sort(tripArray); if (tripArray[2] >= pBestResult){ bestCounter++; } else if( sSurprising != 0 && tripArray[2] != 0){ if(tripArray[2] +1 >= pBestResult){ bestCounter++; sSurprising--; } } } System.out.println(bestCounter); dancePrint.println(bestCounter); numbersArray.clear(); } scan.close(); dancePrint.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e1){ System.out.println("Error" + e1); } } }
0
1,188,989
A11759
A10168
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.io.Reader; import java.io.Writer; import java.util.Arrays; import java.util.HashSet; import java.util.Iterator; import java.util.Set; public class DancingWithTheGooglers { public static void main(String[] args) { if (args.length != 2) { System.out.println("Usage: java DancingWithTheGooglers <input-file> <output-file>"); System.exit(0); } try { DancingGooglerScoreProcessor processor = new DancingGooglerScoreProcessor(new FileReader(args[0]), new FileWriter(args[1])); processor.process(); } catch (Exception e) { System.out.println("Sorry, there was a fatal error:"); e.printStackTrace(); System.exit(0); } } } class DancingGooglerScoreProcessor { private final BufferedReader reader; private final PrintWriter writer; public DancingGooglerScoreProcessor(Reader in, Writer out) throws IOException { reader = new BufferedReader(in); writer = new PrintWriter(out); } public void process() throws IOException { String line = reader.readLine(); int numTests = Integer.parseInt(line); for (int i = 0; i < numTests; i++) { line = reader.readLine(); writer.printf("Case #%d: %d", i + 1, processLine(line)); writer.println(); } writer.flush(); writer.close(); reader.close(); } private int processLine(String line) { String[] tokens = line.split(" "); int[] scores = new int[Integer.parseInt(tokens[0])]; int S = Integer.parseInt(tokens[1]); int p = Integer.parseInt(tokens[2]); for (int i = 0; i < scores.length; i++) { scores[i] = Integer.parseInt(tokens[3+i]); } int numSurprises = 0; int n = 0; for (int score : scores) { Set<Triplet> triplets = getPossibleTriplets(score); removeTripletsThatWillNeverHappen(triplets); if (hasBestResultOrBetterNoSurprise(p, triplets)) { n++; } else { if (numSurprises < S && hasBestResultOrBetterSurprising(p, triplets)) { n++; numSurprises++; } } } return n; } private void removeTripletsThatWillNeverHappen(Set<Triplet> triplets) { for (Iterator<Triplet> itr = triplets.iterator(); itr.hasNext();) { Triplet t = itr.next(); if (t.willNeverHappen()) { itr.remove(); } } } private boolean hasBestResultOrBetterNoSurprise(int bestResult, Set<Triplet> triplets) { return hasBestResultOrBetter(bestResult, triplets, false); } private boolean hasBestResultOrBetterSurprising(int bestResult, Set<Triplet> triplets) { return hasBestResultOrBetter(bestResult, triplets, true); } private boolean hasBestResultOrBetter(int bestResult, Set<Triplet> triplets, boolean surprisingAllowed) { for (Triplet t : triplets) { if (t.getBestResult() >= bestResult) { if (t.isSurprising() && !surprisingAllowed) { continue; } return true; } } return false; } private Set<Triplet> getPossibleTriplets(int totalScore) { Set<Triplet> possibleTriplets = new HashSet<Triplet>(); for (int a = 0; a <= 10; a++) { for (int b = 0; b <= 10; b++) { for (int c = 0; c <= 10; c++) { if ((a + b + c) == totalScore) { possibleTriplets.add(new Triplet(a, b, c)); } } } } return possibleTriplets; } } class Triplet { private int[] scores = new int[3]; private boolean surprising = false; private boolean neverHappen = false; public Triplet(int a, int b, int c) { scores[0] = a; scores[1] = b; scores[2] = c; Arrays.sort(scores); int diff1 = scores[2] - scores[0]; int diff2 = scores[2] - scores[1]; int diff3 = scores[1] - scores[0]; surprising = (diff1 > 1) || (diff2 > 1) || (diff3 > 1); neverHappen = (diff1 > 2) || (diff2 > 2) || (diff3 > 2); } public int getBestResult() { return scores[2]; //since the array is sorted in ascending order } public boolean isSurprising() { return surprising; } public boolean willNeverHappen() { return neverHappen; } public boolean equals(Object t) { if (t == null) { return false; } if (!(t instanceof Triplet)) { return false; } Triplet that = (Triplet)t; return Arrays.equals(scores, that.scores); } public int hashCode() { return Arrays.hashCode(scores); } public String toString() { StringBuffer sb = new StringBuffer("["); sb.append(scores[0]); sb.append(","); sb.append(scores[1]); sb.append(","); sb.append(scores[2]); sb.append("]"); if (isSurprising()) { sb.append("*"); } return sb.toString(); } }
0
1,188,990
A11759
A11923
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; public class Main { public static Map<Integer, Integer> mapMax=Collections.synchronizedMap( new HashMap<Integer, Integer>()); public static Map<Integer, Integer> mapSurprisingMax=Collections.synchronizedMap( new HashMap<Integer, Integer>()); /** * */ public static double getFactor( int n){ double nFactor=( double) 1; for( int i=1; i<=n; i++) nFactor*=i; return nFactor; } /** * */ public static double getCombinations( int nData, int nItems){ return getFactor( nData)/ ( getFactor( nData- nItems)* getFactor( nItems)); } /** * */ /**@class Combination * */ public class Combination{ public Integer lastElement=0; public Set<Integer> setItems=Collections.synchronizedSet( new HashSet<Integer>()); /***/ public Combination(){} public Combination( Combination src){ this.lastElement=src.lastElement; this.setItems.addAll( src.setItems); } public void addItem( Integer item){ this.lastElement=item; this.setItems.add( this.lastElement); }} /**@class Combinator * */ public class Combinator{ public Integer[] rItems; /**@param nItems * */ public Combinator( int nItems){ this.rItems=new Integer[ nItems]; for( int i=0; i!=this.rItems.length; i++) this.rItems[ i]=i; } /**@param nSubitems * */ public double countCombinations( int nSubitems){ return Main.getCombinations( this.rItems.length, nSubitems); } /**@ * */ private Set<Combination> _getCombinations( Set<Combination> srcCombinations, int nSubitems){ Set<Combination> setCombinations=Collections.synchronizedSet( new HashSet<Combination>()); Iterator<Combination> iter=srcCombinations.iterator(); while( iter.hasNext()){ Combination srcCombination=iter.next(); if( srcCombination.setItems.size()==nSubitems){ setCombinations.add( srcCombination); }else{ Set<Combination> setSubitems=Collections.synchronizedSet( new HashSet<Combination>()); for( int i=0; i!=this.rItems.length; i++){ Combination combination=new Combination( srcCombination); if( this.rItems[ i]> combination.lastElement){ combination.addItem( this.rItems[ i]); setSubitems.add( combination); }} setCombinations.addAll( this._getCombinations( setSubitems, nSubitems)); }} return setCombinations; } /**@param nSubitems * */ public Set<Combination> getCombinations( int nSubitems){ Set<Combination> setCombinations=Collections.synchronizedSet( new HashSet<Combination>()); double nCombinations=this.countCombinations( nSubitems); if( nCombinations>0){ for( int i=0; i!=this.rItems.length; i++){ Combination combination=new Combination(); combination.addItem( this.rItems[ i]); setCombinations.add( combination); } return this._getCombinations( setCombinations, nSubitems); } return setCombinations; }} /** * */ public class TestCase{ public Integer id, n, s, p; public Integer iResult=0; public Integer[] rPoints; /***/ public TestCase( Integer id, Integer n, Integer s, Integer p, Integer[] rPoints){ this.id=id; this.n=n; this.s=s; this.p=p; this.rPoints=Arrays.copyOf( rPoints, rPoints.length); } /***/ public void doSolution(){ this.iResult=0; if( this.s==0){ for( int i=0; i!=this.rPoints.length; i++){ if( Main.mapMax.get( this.rPoints[ i])>=this.p) this.iResult++; } }else{ /***/ Combinator combinator=new Combinator( this.n); Set<Combination> setCombinations=combinator.getCombinations( this.s); Iterator<Combination> iterCombination=setCombinations.iterator(); while( iterCombination.hasNext()){ Combination combination=iterCombination.next(); this.iResult=Math.max( this.iResult, this.doCombination( combination)); }}} public Integer doCombination( Combination combination){ Integer iResult=0; for( int i=0; i!=this.rPoints.length; i++){ Integer max=( combination.setItems.contains( i))? Main.mapSurprisingMax.get( this.rPoints[ i]): Main.mapMax.get( this.rPoints[ i]); if( max>=this.p) iResult++; } return iResult; } } public TestCase createTestCase( Integer id, Integer n, Integer s, Integer p, Integer[] rPoints){ return new TestCase( id, n, s, p, rPoints); } /** * @param args */ public static void main(String[] args) { try { Main m=new Main(); LineNumberReader reader=new LineNumberReader( new FileReader( new File( args[ 0].trim()))); PrintWriter printer=new PrintWriter( new FileWriter( args[ 1].trim())); /** ScoreMaps */ for( int i0=0; i0<=10; i0++){ for( int i1=0; i1<=10; i1++){ for( int i2=0; i2<=10; i2++){ Integer maxScore=Math.max( i0, Math.max( i1, i2)); if( ( Math.abs( i0- i1)<= 2) && ( Math.abs( i0- i2)<= 2) && ( Math.abs( i1- i2)<= 2)){ Integer nSum=i0+ i1+ i2; // Not surprising score. if( !(( Math.abs( i0- i1)==2) || ( Math.abs( i0- i2)==2) || ( Math.abs( i1- i2)==2))){ if( !Main.mapMax.containsKey( nSum)){ Main.mapMax.put( nSum, maxScore); } Main.mapMax.put( nSum, Math.max( Main.mapMax.get( nSum), maxScore)); } // Surprising Score. if( !Main.mapSurprisingMax.containsKey( nSum)){ Main.mapSurprisingMax.put( nSum, maxScore); } Main.mapSurprisingMax.put( nSum, Math.max( Main.mapSurprisingMax.get( nSum), maxScore)); }}}} /***/ int nTestCases=Integer.valueOf( reader.readLine().trim()); for( int n=0; n!=nTestCases; n++){ String str[]=reader.readLine().split( " "); Integer[] rPoints=new Integer[ str.length- 3]; for( int i=3; i!=str.length; i++) rPoints[ i- 3]=Integer.valueOf( str[ i].trim()); TestCase testCase=m.createTestCase( n+ 1, Integer.valueOf( str[ 0].trim()), Integer.valueOf( str[ 1].trim()), Integer.valueOf( str[ 2].trim()), rPoints); testCase.doSolution(); printer.println( "Case #"+ testCase.id+": "+ testCase.iResult); System.out.println( "Case #"+ testCase.id+": "+ testCase.iResult); } printer.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}}
0
1,188,991
A11759
A11654
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.util.ArrayList; /** * * @author jim */ public class Input { private final String[] header; private final String[] data; public Input(ArrayList<String> lines, int header) { int size = lines.size(); this.header = new String[header]; this.data = new String[size - header]; for (int i = 0; i < size; i++) { String line = lines.get(i); if (i < header) this.header[i] = line; else this.data[i - header] = line; } } public String[] getHeader() { return header; } public String[] getData() { return data; } }
0
1,188,992
A11759
A12277
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; /** * Created by IntelliJ IDEA. * User: Leonid * Date: 4/14/12 * Time: 2:41 PM * Dancing With Googlers solution */ public class DancingWithGooglers { public static void main(String[] args) { FilesManager fileManager = FilesManager.getFilesManager(); while (fileManager != null) { produceSolution(fileManager); fileManager = FilesManager.getFilesManager(); } } private static void produceSolution(FilesManager filesManager) { FileCommunicationManager fileComManager = new FileCommunicationManager(filesManager); List<String> input = fileComManager.convertInputToStrings(); List<InputInfo> parsedInput = CaseInterpreter.parseInput(input); List<String> output = new ArrayList<String>(); for (int i = 0; i < parsedInput.size(); i++) { OutputInfo outputInfo = solve(parsedInput.get(i)); output.add(CaseInterpreter.composeOutputLine(outputInfo, i + 1)); } fileComManager.convertStringsToOutput(output); } private static OutputInfo solve(InputInfo inputInfo) { OutputInfo outputInfo = new OutputInfo(); int surpriseThreshold = inputInfo.p * 3 - 4; int regularThreshold = inputInfo.p * 3 - 2; int surpriseCounter = 0; int regularCounter = 0; for (int totalResult : inputInfo.results) { if (totalResult >= regularThreshold) { regularCounter++; } else if (totalResult >= surpriseThreshold && totalResult!=0) { surpriseCounter++; } } outputInfo.result = regularCounter + (surpriseCounter > inputInfo.s ? inputInfo.s : surpriseCounter); return outputInfo; } private static class InputInfo { int n, s, p; int[] results; } private static class OutputInfo { int result; public String toString() { return Integer.toString(result); } } private static class CaseInterpreter { private static final int CASE_NUMBER_OF_LINES = 1; public static List<InputInfo> parseInput(List<String> input) { List<InputInfo> parsedInput = new ArrayList<InputInfo>(); for (int i = 0; i < input.size(); i += CASE_NUMBER_OF_LINES) { parsedInput.add(parseCase(input.subList(i, i + CASE_NUMBER_OF_LINES))); } return parsedInput; } private static InputInfo parseCase(List<String> caseLines) { InputInfo inputInfo = new InputInfo(); List<Integer> ints = strToInts(caseLines.get(0)); inputInfo.n = ints.get(0); inputInfo.s = ints.get(1); inputInfo.p = ints.get(2); inputInfo.results = new int[inputInfo.n]; for (int i = 0; i < inputInfo.n; i++) { inputInfo.results[i] = ints.get(i + 3); } return inputInfo; } public static String composeOutputLine(OutputInfo output, int caseNumber) { String outputString = "Case #" + caseNumber + ": " + output.toString(); return outputString; } private static List<Integer> strToInts(String str) { List<Integer> ints = new ArrayList<Integer>(); String[] strs = str.split(" "); for (String s : strs) { ints.add(Integer.parseInt(s)); } return ints; } } private static class FilesManager { File inputFile; File outputFile; private static List<String> inputFiles; private static int inputFilesIt = 0; static { File f = new File("."); inputFiles = getInputFiles(f.list()); } private static List<String> getInputFiles(String[] fileNames) { List<String> inputFileNames = new ArrayList<String>(); for (String fileName : fileNames) { String[] splitFileName = fileName.split("\\."); if (splitFileName.length == 2) { if (splitFileName[1].equals("IN") || splitFileName[1].equals("In") || splitFileName[1].equals("in")) { inputFileNames.add(fileName); } } } return inputFileNames; } private static String generateOutputFileName(String inputFileName) { String[] stlitFileName = inputFileName.split("\\."); return stlitFileName[0] + "-output.txt"; } FilesManager(String inputFileName, String outputFileName) { inputFile = new File(inputFileName); assert (inputFile.exists()); outputFile = new File(outputFileName); try { outputFile.createNewFile(); } catch (IOException ex) { System.out.println("Exception while trying to create an output file"); } } public static FilesManager getFilesManager() { if (inputFilesIt >= inputFiles.size()) { return null; } String inputFileName = inputFiles.get(inputFilesIt++); String outputFileName = generateOutputFileName(inputFileName); return new FilesManager(inputFileName, outputFileName); } File getInputFile() { return inputFile; } File getOutputFile() { return outputFile; } } private static class FileCommunicationManager { File inputFile; File outputFile; FileCommunicationManager(FilesManager filesManager) { inputFile = filesManager.getInputFile(); outputFile = filesManager.getOutputFile(); } List<String> convertInputToStrings() { List<String> linesList = new ArrayList<String>(); try { FileReader fr = new FileReader(inputFile); BufferedReader bufReader = new BufferedReader(fr); int numOfCases = Integer.parseInt(bufReader.readLine()); for (int i = 0; i < numOfCases; i++) { linesList.add(bufReader.readLine()); } } catch (IOException e) { System.out.println("Error reading from the file"); } return linesList; } void convertStringsToOutput(List<String> linesList) { BufferedWriter bufWriter = null; try { bufWriter = new BufferedWriter(new FileWriter(outputFile)); for (String line : linesList) { bufWriter.write(line); bufWriter.newLine(); } } catch (IOException e) { System.out.println("Error reading from the file"); } finally { //Close the BufferedWriter try { if (bufWriter != null) { bufWriter.flush(); bufWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } } }
0
1,188,993
A11759
A11877
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 dancers; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.util.Arrays; public class DancerEvaluation { private final int numberOfGooglers; private int surpriseCount; private final int bestScore; private final int[] lstOfPoints; public DancerEvaluation(int numberOfGooglers, int surpriseCount, int bestScore, int[] lstOfPoints) { this.numberOfGooglers = numberOfGooglers; this.surpriseCount = surpriseCount; this.bestScore = bestScore; this.lstOfPoints = lstOfPoints; } public int solve() { int countOfTotalDancers = 0; for (int i = 0; i < lstOfPoints.length; i++) { int avg_point = lstOfPoints[i]/3; int x = avg_point; int y = avg_point; int z = avg_point; int leftOver = lstOfPoints[i] % 3; switch (leftOver) { case 0: if(avg_point + 1 == bestScore && surpriseCount > 0 && avg_point > 0){ z = z + 1; x = x - 1; surpriseCount--; } break; case 1: z = z + 1; break; case 2: if(surpriseCount > 0 && (z + 2) <= 10){ z = z + 2; surpriseCount--; }else { z = z+1; y = y+1; } break; } if(Math.max(Math.max(x, y), z) >= bestScore){ countOfTotalDancers++; } } return countOfTotalDancers; } public static void main(String[] args) throws Exception{ BufferedReader reader = new BufferedReader(new FileReader(new File("C:\\Users\\maheshsa\\Desktop\\input.txt"))); int numOfTestCases = Integer.parseInt(reader.readLine()); FileWriter fw = new FileWriter(new File("C:\\Users\\maheshsa\\Desktop\\output.txt")); for (int i = 1; i <= numOfTestCases; i++) { String[] inputAsString = reader.readLine().split(" "); int[] input = new int[inputAsString.length]; for (int j = 0; j < inputAsString.length; j++) { input[j] = Integer.parseInt(inputAsString[j]); } int numberOfDancers = input[0]; int surpriseCount = input[1]; int bestScore = input[2]; int[] scores = Arrays.copyOfRange(input, 3, input.length); fw.append("Case #" + i + ": " + new DancerEvaluation(numberOfDancers, surpriseCount, bestScore, scores).solve() + "\n"); } fw.flush(); reader.close(); fw.close(); } }
0
1,188,994
A11759
A12007
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package test.qual; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import com.utility.FileReader; import com.utility.FileWriterUtility; public class SpeakInTongues { public static void main(String[] args) throws IOException { BufferedReader inputBufReader = FileReader.getBufferedReader("sample.txt"); BufferedReader br = FileReader.getBufferedReader("A-small-attempt1.in"); BufferedWriter bw = FileWriterUtility.getBufferedWriter("output.txt"); Map<Character, Character> wordMap = getWordMap(inputBufReader); wordMap.put('y', 'a'); wordMap.put('e', 'o'); wordMap.put('z', 'q'); if (wordMap.keySet().size() == 25) { List<Character> alphabets1 = new ArrayList<Character>(); List<Character> alphabets2 = new ArrayList<Character>(); for (int i = 0; i < 26; i++) { alphabets1.add((char) ('a'+i)); alphabets2.add((char) ('a'+i)); } alphabets1.removeAll(wordMap.keySet()); alphabets2.removeAll(wordMap.values()); wordMap.put(alphabets1.get(0), alphabets2.get(0)); } int n = Integer.valueOf(br.readLine()); for (int i = 0; i < n; i++) { String input = br.readLine(); char[] chars = input.toCharArray(); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Case #" + (i+1) + ": "); for (int j = 0; j < chars.length; j++) { if (chars[j] == ' ') { stringBuilder.append(' '); } else if (wordMap.get(chars[j]) != null) { stringBuilder.append(wordMap.get(chars[j])); } else { stringBuilder.append(chars[j]); } } bw.write(stringBuilder.toString()); bw.newLine(); } bw.close(); } private static Map<Character,Character> getWordMap(BufferedReader inputBufReader) throws IOException { List<Character> input = new ArrayList<Character>(); List<Character> output= new ArrayList<Character>(); for (int i = 0; i < 3; i++) { String[] strArray = inputBufReader.readLine().split(" "); for (int j = 0; j < strArray.length; j++) { char[] temp = strArray[j].toCharArray(); for (int k = 0; k < temp.length; k++) { input.add(temp[k]); } } } for (int i = 0; i < 3; i++) { String[] strArray = inputBufReader.readLine().split(" "); for (int j = 0; j < strArray.length; j++) { char[] temp = strArray[j].toCharArray(); for (int k = 0; k < temp.length; k++) { output.add(temp[k]); } } } if (input.size() != output.size()) { throw new RuntimeException("Invalid word mapping"); } Map<Character, Character> wordMapping = new HashMap<Character, Character>(); for (int i = 0; i < input.size(); i++) { wordMapping.put(input.get(i), output.get(i)); } return wordMapping; } // List<Character> alphabets1 = new ArrayList<Character>(); // List<Character> alphabets2 = new ArrayList<Character>(); // for (int i = 0; i < 26; i++) { // alphabets1.add((char) ('a'+i)); // alphabets2.add((char) ('a'+i)); // } // // System.out.println(wordMapping.keySet().size()); // alphabets1.removeAll(wordMapping.keySet()); // alphabets2.removeAll(wordMapping.values()); // System.out.println(); // System.out.println('z' - 'a'); }
0
1,188,995
A11759
A10237
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; import java.text.*; public class Main implements Runnable{ /** * @param args */ private StringTokenizer stReader; private BufferedReader bufReader; private PrintWriter out; public static void main(String[] args) { // TODO Auto-generated method stub (new Main()).run(); } @Override public void run() { // TODO Auto-generated method stub bufReader = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); stReader = null; Solves(); out.flush(); } public String ReadLine() { String result = null; try { result = bufReader.readLine(); } catch (IOException e) { } return result; } public String NextString(){ if (stReader == null || !stReader.hasMoreTokens()){ stReader = new StringTokenizer(ReadLine(),"\n\r "); } return stReader.nextToken(); } public int NextInt(){ return Integer.parseInt(NextString()); } public long NextLong(){ return Long.parseLong(NextString()); } public double NextDouble(){ return Double.parseDouble(NextString()); } void Solves(){ int n = NextInt(); for(int i =0; i < n; i++){ out.print("Case #" +(i + 1) + ": "); Solve(); out.println(); //out.flush(); } out.flush(); } void Solve(){ int N = NextInt(); int S = NextInt(); int p = NextInt(); int mas[] = new int[N]; int result = 0; for(int i =0; i < N; i++){ int val = NextInt(); if (val < p) continue; int n = val /3; int k = val % 3; if (n >= p || (k > 0 && n + 1 >= p)) result++; else { if ((k == 2 && n + 2 >= p && S > 0) || (k == 0 && n + 1 >= p && S > 0)) { result++; S--; } } } out.print(result); } }
0
1,188,996
A11759
A12846
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.common; import java.util.ArrayList; import java.util.List; /** * * @author Lance Chen */ public class CodeHelper { private static String FILE_ROOT = "D:/workspace/googlecodejam/meta"; public static List<List<String>> loadInputsExcludes(String fileName) { List<List<String>> result = new ArrayList<List<String>>(); List<String> lines = FileUtil.readLines(FILE_ROOT + fileName); int index = 0; for (String line : lines) { if (index == 0) { index++; continue; } if (index % 2 == 1) { index++; continue; } List<String> dataList = new ArrayList<String>(); String[] dataArray = line.split("\\s+"); for (String data : dataArray) { if (data.trim().length() > 0) { dataList.add(data); } } result.add(dataList); index++; } return result; } public static List<List<String>> loadInputs(String fileName) { List<List<String>> result = new ArrayList<List<String>>(); List<String> lines = FileUtil.readLines(FILE_ROOT + fileName); for (String line : lines) { List<String> dataList = new ArrayList<String>(); String[] dataArray = line.split("\\s+"); for (String data : dataArray) { if (data.trim().length() > 0) { dataList.add(data); } } result.add(dataList); } return result; } public static List<String> loadInputLines(String fileName) { return FileUtil.readLines(FILE_ROOT + fileName); } public static void writeOutputs(String fileName, List<String> lines) { FileUtil.writeLines(FILE_ROOT + fileName, lines); } }
0
1,188,997
A11759
A12075
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.io.Closeable; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class Output implements Closeable { private static String lineSeparator = System.getProperty("line.separator"); private FileWriter writer; private Output(File file) { try { writer = new FileWriter(file); } catch (IOException e) { throw new TechnicalException(e); } } public static Output open(File file) { System.out.println("======== " + file); return new Output(file); } public void writeLine(String text) { System.out.println(text); try { writer.write(text); writer.write(lineSeparator); } catch (IOException e) { throw new TechnicalException(e); } } public void write(String text) { System.out.print(text); try { writer.write(text); } catch (IOException e) { throw new TechnicalException(e); } } public void writeLine(Object... text) { try { for (Object s : text) { System.out.print(s); writer.write(s.toString()); } System.out.println(); writer.write(lineSeparator); } catch (IOException e) { throw new TechnicalException(e); } } public void write(Object... text) { try { for (Object s : text) { System.out.print(s); writer.write(s.toString()); } } catch (IOException e) { throw new TechnicalException(e); } } public void close() { System.out.println("================ closed"); try { writer.close(); } catch (IOException e) { throw new TechnicalException(e); } } }
0
1,188,998
A11759
A10112
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.Scanner; public class DancinWithGooglers { public static void main(String[] args) { try { Scanner input = new Scanner(new File("input.txt")); PrintStream output = new PrintStream(new FileOutputStream("output.txt")); solveTask(input, output); } catch (FileNotFoundException e) { System.out.println("input.txt not found"); } catch (IOException e) { e.printStackTrace(); } } private static void solveTask(Scanner input, PrintStream output) { int testsCount = input.nextInt(); for (int test=1; test<=testsCount; test++) { int dancersCount = input.nextInt(); int surprises = input.nextInt(); int bestResult = input.nextInt(); int scoreNeeded = bestResult*3-2; int gotResultAnywayCount = 0; int gotResultConditionallyCount = 0; for (int i=0; i<dancersCount; i++) { int score = input.nextInt(); if (score >= scoreNeeded) { gotResultAnywayCount++; } else if (score > 1 && score < 29 && score >= scoreNeeded-2) { gotResultConditionallyCount++; } } int total = gotResultAnywayCount + Math.min(gotResultConditionallyCount, surprises); System.out.print("Case #"+test+": "); System.out.println(total); output.print("Case #"+test+": "); output.println(total); } } }
0
1,188,999