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
A10901
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 Main2 { public static void main(String argsp[]) throws FileNotFoundException{ Scanner in = new Scanner(new FileReader("input.in")); PrintWriter out = new PrintWriter("output.txt"); int T = 0; String S1 = in.nextLine() ; T = Integer.parseInt(S1); for(int i=0;i<T;i++) { S1 = in.nextLine(); out.print("Case #"+ (i+1) +": "); int space = S1.indexOf(" "); int N = Integer.parseInt(S1.substring(0, space)); S1 = S1.substring(space+1); space = S1.indexOf(" "); int S = Integer.parseInt(S1.substring(0, space)); S1 = S1.substring(space+1); space = S1.indexOf(" "); int p = Integer.parseInt(S1.substring(0, space)); int a[] = new int[N]; for(int j=0;j<N-1;j++) { S1 = S1.substring(space+1); space = S1.indexOf(" "); a[j] = Integer.parseInt(S1.substring(0, space)); } a[N-1] = Integer.parseInt(S1.substring(space+1)); int checker = 0; if (p>1) checker = 3*p - 4; else checker = 0; int great = 0; int surprise = 0; for(int k=0;k<N;k++) { if(a[k]>=checker) great++; if((a[k]==checker || a[k] == checker+1) && p>1) surprise++; if(p==1 && a[k] == 0) great--; } // System.out.println(great+ " " + surprise); int answer = 0; if((S-surprise)<=0) answer = great+S-surprise; else answer = great; out.println(answer); } out.close(); } }
0
1,189,800
A11759
A12459
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 qualifier; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Map; import java.util.Scanner; public class TB { private Map<Character, Character> translate = null; public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); try { File file = new File("src/qualifier/B-small-attempt0.in"); String a = file.getAbsolutePath(); in = new Scanner(file); out = new PrintWriter(new File("src/qualifier/B-small-attempt0.out")); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } TB worker = new TB(); int n = in.nextInt(); for (int i=1; i<=n; i++) { int k = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int[] scores = new int[k]; for (int j=0;j<k;j++) { scores[j] = in.nextInt(); } out.println("Case #" + i + ": " + worker.maxGs(k,p,s,scores)); } out.flush(); } public int maxGs(int k, int p, int s, int[] scores) { int res = 0; int subres = 0; int acceptable = 3*p-4; if (p == 1) acceptable = 1; for (int i=0; i<k; i++) if (scores[i]>=3*p-2) res++; else if (scores[i]>=acceptable) subres++; res += Math.min(subres, s); return res; } }
0
1,189,801
A11759
A11790
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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; import java.util.Vector; class dancing { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter( "output.txt"))); StringTokenizer st = new StringTokenizer(f.readLine()); int cases = Integer.parseInt(st.nextToken()); for (int k = 1; k < cases; k++) { st = new StringTokenizer(f.readLine()); int memSum = Integer.parseInt(st.nextToken()); int surprising = Integer.parseInt(st.nextToken()); int level = Integer.parseInt(st.nextToken()); int[] scores = new int[memSum]; for (int i = 0; i < memSum; i++) { scores[i] = Integer.parseInt(st.nextToken()); } int max = getMax(memSum, surprising, level, scores); out.println("Case #" + k + ": " + max); // output result } st = new StringTokenizer(f.readLine()); int memSum = Integer.parseInt(st.nextToken()); int surprising = Integer.parseInt(st.nextToken()); int level = Integer.parseInt(st.nextToken()); int[] scores = new int[memSum]; for (int i = 0; i < memSum; i++) { scores[i] = Integer.parseInt(st.nextToken()); } int max = getMax(memSum, surprising, level, scores); out.print("Case #" + cases + ": " + max); // output result out.close(); // close the output file System.exit(0); // don't omit this! } public static int getMax(int _memSum, int _surprising, int _level, int[] _scores) { int[] scores = _scores; int memSum = _memSum; int surprising = _surprising; int level = _level; int max = 0; int certainStart = level * 3 - 2; int certainEnd = 30; int maybeStart = level * 3 - 4; int maybeEnd = level * 3 + 4; if(certainStart < 0) { certainStart = level; } if(maybeStart < 0) { maybeStart = level; } for (int i = 0; i < scores.length; i++) { if (scores[i] <= certainEnd && scores[i] >= certainStart) { max++; } else { if (surprising > 0) { if (scores[i] <= maybeEnd && scores[i] >= maybeStart) { max++; surprising--; } } } } return max; } }
0
1,189,802
A11759
A11263
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; import java.util.Collections; public class DancingWithGooglers { public static void main(String[] args) throws IOException{ FileReader inf = new FileReader("data/B-small.in"); BufferedReader in = new BufferedReader(inf); FileWriter outf = new FileWriter("result/B-small.out"); BufferedWriter out = new BufferedWriter(outf); int numCases = Integer.parseInt(in.readLine()); int numGoogler = 0; int numSuprising = 0; int p = 0; int maxResult = 0; for(int index = 1; index <=numCases; index++) { /*Begin to get data*/ String line = in.readLine(); String []tokens = line.split(" "); numGoogler = Integer.parseInt(tokens[0]); numSuprising = Integer.parseInt(tokens[1]); p = Integer.parseInt(tokens[2]); Integer [] scores = new Integer[numGoogler]; int k = 0; maxResult = 0; for(int i = 3; i < tokens.length; i++) { scores[k++] = Integer.parseInt(tokens[i]); } /*End of getting data*/ /*Reverse the order*/ Arrays.sort(scores, Collections.reverseOrder()); for(int i = 0; i < scores.length;i++) { if(scores[i] >= 3*p) { maxResult++; } else if(scores[i] < p) { continue; } else if((scores[i]>=(3*p - 2)) && (scores[i]<= (3*p -1))) { maxResult++; } else if((scores[i]>=(3*p - 4)) && (3*p - 4) > 0) { if(numSuprising > 0) { maxResult ++; numSuprising--; } } else { continue; } } System.out.println("Case #"+index+": "+maxResult); out.write("Case #"+index+": "+" "+maxResult); out.newLine(); out.flush(); } } }
0
1,189,803
A11759
A11934
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.sam.googlecodejam.speakingtoungue; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import com.sam.googlecodejam.helper.InputReader; /** * This class generates the mapping based on the samples that have been provided. * @author Saifuddin Merchant * */ public class TranslatorMapping { public Map<String, String> iAvalableLines = new HashMap<>(); public Map<Character, Character> iLetterMapping = new TreeMap<>(); public TranslatorMapping() { iAvalableLines.put("ejp mysljylc kd kxveddknmc re jsicpdrysi", "our language is impossible to understand"); iAvalableLines.put("rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd", "there are twenty six factorial possibilities"); iAvalableLines.put("de kr kd eoya kw aej tysr re ujdr lkgc jv", "so it is okay if you want to just give up"); } public void mapLetters() { for(Entry<String , String> lineEntry: iAvalableLines.entrySet()) { String keyLine = lineEntry.getKey(); String keyValue = lineEntry.getValue(); int index=0; for(Character keyChar:keyLine.toCharArray()) { iLetterMapping.put(keyChar, keyValue.charAt(index++)); } } iLetterMapping.put('z', 'q');//add the missing mappings iLetterMapping.put('q', 'z');//add the missing mappings //System.out.println(iLetterMapping.size()); //System.out.println(iLetterMapping); } public void translate(String pInput) { for(Character translateChar:pInput.toCharArray()) { System.out.print(iLetterMapping.get(translateChar)); } } public static void main(String[] args) { TranslatorMapping mapping = new TranslatorMapping(); mapping.mapLetters(); InputReader reader = new InputReader("c://input.in"); reader.readNextLine(); //read the line number off - we don't need it String lineRead = null; int i=1; while((lineRead=reader.readNextLine())!=null ) { System.out.print("Case #"+i+": "); i++; mapping.translate(lineRead); System.out.println(); } } }
0
1,189,804
A11759
A10852
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.Locale; import java.util.StringTokenizer; public class GCJ2012QualB { int maxNS[] = new int[31]; int maxS[] = new int[31]; public void run() throws IOException { for (int s = 0; s <= 30; ++s) { maxNS[s] = maxS[s] = -1; } for (int a = 0; a <= 10; ++a) { for (int b = 0; b <= a; ++b) { for (int c = 0; c <= b; ++c) { if (a - c <= 1) { maxNS[a + b + c] = Math.max(maxNS[a + b + c], a); } else if (a - c <= 2) { maxS[a + b + c] = Math.max(maxS[a + b + c], a); } } } } int T = nextInt(); for (int i = 1; i <= T; ++i) { out.println("Case #" + i + ": " + solve()); } } private int solve() throws IOException { int N = nextInt(); int S = nextInt(); int p = nextInt(); int na = 0; int nns = 0; int ns = 0; int nn = 0; for (int i = 0; i < N; ++i) { int t = nextInt(); if (maxNS[t] >= p && maxS[t] >= p) { ++na; } else if (maxNS[t] >= p) { ++nns; } else if (maxS[t] >= p) { ++ns; } else { ++nn; } } assert S <= N; assert na + nns + ns + nn == N; if (ns >= S) { return na + nns + S; } else if (na + ns + nn >= S) { return na + nns + ns; } else { return na + nns + ns - (S - (na + ns + nn)); } } public static BufferedReader in; public static PrintStream out; public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); String className = GCJ2012QualB.class.getSimpleName(); char lastChar = className.charAt(className.length() - 1); System.setIn(new FileInputStream(lastChar + ".in")); System.setOut(new PrintStream(lastChar + ".out")); in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintStream(new BufferedOutputStream(System.out)); new GCJ2012QualB().run(); out.close(); } public static StringTokenizer tokenizer; public static String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(in.readLine()); } return tokenizer.nextToken(); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static long nextLong() throws IOException { return Long.parseLong(nextToken()); } public static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
0
1,189,805
A11759
A11154
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.FileOutputStream; import java.io.FileReader; import java.io.PrintWriter; public class DancingWiththeGooglers { private static tripletOfScore[] triples; private static void iniciarEscenario() { triples=new tripletOfScore[31]; triples[0]=new tripletOfScore(0, 0, 0); triples[1]=new tripletOfScore(1, 0, 0); triples[2]=new tripletOfScore(1,1,0,2,0,0); triples[3]=new tripletOfScore(1,1,1,2,1,0); triples[4]=new tripletOfScore(2,1,1,2,2,0); triples[5]=new tripletOfScore(2,2,1,3,1,1); triples[6]=new tripletOfScore(2,2,2,3,2,1); triples[7]=new tripletOfScore(3,2,2,3,3,1); triples[8]=new tripletOfScore(3,3,2,4,2,2); triples[9]=new tripletOfScore(3,3,3,4,3,2); triples[10]=new tripletOfScore(4,3,3,4,4,2); triples[11]=new tripletOfScore(4,4,3,5,3,3); triples[12]=new tripletOfScore(4,4,4,5,4,3); triples[13]=new tripletOfScore(5,4,4,5,5,3); triples[14]=new tripletOfScore(5,5,4,6,4,4); triples[15]=new tripletOfScore(5,5,5,6,5,4); triples[16]=new tripletOfScore(6,5,5,6,6,4); triples[17]=new tripletOfScore(6,6,5,7,5,5); triples[18]=new tripletOfScore(6,6,6,7,6,5); triples[19]=new tripletOfScore(7,6,6,7,7,5); triples[20]=new tripletOfScore(7,7,6,8,6,6); triples[21]=new tripletOfScore(7,7,7,8,7,6); triples[22]=new tripletOfScore(8,7,7,8,8,6); triples[23]=new tripletOfScore(8,8,7,9,7,7); triples[24]=new tripletOfScore(8,8,8,9,8,7); triples[25]=new tripletOfScore(9,8,8,9,9,7); triples[26]=new tripletOfScore(9,9,8,10,8,8); triples[27]=new tripletOfScore(9,9,9,10,9,8); triples[28]=new tripletOfScore(10,9,9,10,10,8); triples[29]=new tripletOfScore(10,10,9); triples[30]=new tripletOfScore(10,10,10); } public static void main(String[] args) { iniciarEscenario(); try { FileOutputStream fos=new FileOutputStream(new File("data/outB.txt")); BufferedReader br=new BufferedReader(new FileReader("data/B-small-attempt0.in")); PrintWriter pw=new PrintWriter(fos); String a=br.readLine(); System.out.println("Ignore"+a); int contadorCasos=1; while((a=br.readLine())!=null) { String parte[]=a.split(" "); int googlers=Integer.parseInt(parte[0]); int sps=Integer.parseInt(parte[1]); int numeroMayor=Integer.parseInt(parte[2]); int contador=0; for(int i=0;i<googlers;i++){ int puntajeActual=Integer.parseInt(parte[3+i]); tripletOfScore temporal=triples[puntajeActual]; if(temporal.existeAlgunValorMayorPrimero(numeroMayor)){ contador++; } else{ if(sps>0) { if(temporal.existeAlgunValorMayorSegundo(numeroMayor)) { contador++; sps--; } } } } pw.println("Case #"+contadorCasos+": "+contador); contadorCasos++; } pw.close(); } catch (Exception e) {e.printStackTrace();} } } class tripletOfScore{ private int puntajeUno; private int puntajeDos; private int puntajeTres; private int segundoPuntajeUno; private int segundoPuntajeDos; private int segundoPuntajeTres; private int TIPO; public tripletOfScore(int a, int b, int c){ puntajeUno=a; puntajeDos=b; puntajeTres=c; TIPO=1; } public tripletOfScore(int a, int b, int c, int a2, int b2, int c2){ puntajeUno=a; puntajeDos=b; puntajeTres=c; segundoPuntajeUno=a2; segundoPuntajeDos=b2; segundoPuntajeTres=c2; TIPO=2; } public int getPuntajeUno() { return puntajeUno; } public int getPuntajeDos() { return puntajeDos; } public int getPuntajeTres() { return puntajeTres; } public int getSegundoPuntajeUno() { return segundoPuntajeUno; } public int getSegundoPuntajeDos() { return segundoPuntajeDos; } public int getSegundoPuntajeTres() { return segundoPuntajeTres; } public int getTipo() { return TIPO; } public boolean existeAlgunValorMayorPrimero(int num){ if(puntajeUno>=num||puntajeDos>=num||puntajeTres>=num){ return true; } else return false; } public boolean existeAlgunValorMayorSegundo(int num){ if(TIPO==1){ return false; } else{ if(segundoPuntajeUno>=num||segundoPuntajeDos>=num||segundoPuntajeTres>=num){ return true; } else return false; } } }
0
1,189,806
A11759
A10885
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int nCases = sc.nextInt(); for (int i = 1; i <= nCases; i++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int y = 0; for (int zz = 0; zz < n; zz++) { int cScore = sc.nextInt(); if (cScore >= (p * 3 - 2)) { y++; } else if (s > 0 && cScore != 0 && cScore >= (p * 3 - 4)) { y++; s--; } } System.out.println("Case #" + i + ": " + y); } } }
0
1,189,807
A11759
A12928
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.contest.B; import google.loader.Challenge; import google.problems.AbstractReader; public class BReader extends AbstractReader { @Override protected Challenge createChallenge(int number) { int theLine = getActualLine(); String[] lines = getLines(); BChallenge chal = new BChallenge(number, lines[theLine]); setActualLine(theLine+1); return chal; } }
0
1,189,808
A11759
A10621
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.Collection; import java.util.ArrayList; import java.util.Arrays; import java.lang.Integer; import java.io.*; import java.util.Scanner; public class DancingWithTheGooglers{ private long inversions = 0; public static void main(String[] args) throws FileNotFoundException{ String filename = args[0]; DancingWithTheGooglers countInversions = new DancingWithTheGooglers(); countInversions.readArray(filename); // list = countInversions.sortAndCount(list); // System.out.println(list); // System.out.println(countInversions.inversions); } private void readArray( String filename ) throws FileNotFoundException{ ArrayList<Integer> list = new ArrayList<Integer>(); File fFile = new File(filename); Scanner scanner = new Scanner(new FileReader(fFile)); try { BufferedWriter out = new BufferedWriter(new FileWriter("outfilename")); int k = Integer.valueOf(scanner.nextLine()); for (int j=1; j<=k; ++j){ String szoveg = scanner.nextLine(); Object[] szamok =szoveg.split("[^0-9]"); ArrayList szamlista = new ArrayList(Arrays.asList(szamok)); for (int i=0; i<szamlista.size(); ++i){ if (szamlista.get(i).equals("")){ szamlista.remove(i); i--; }else{ szamlista.set(i,Integer.valueOf((String)szamlista.get(i))); } } String mashogy = new String(); int o=0; int u=0; int N = ((Integer)(szamlista.get(0))); int S = ((Integer)(szamlista.get(1))); int p = ((Integer)(szamlista.get(2))); szamlista.remove(0); szamlista.remove(0); szamlista.remove(0); int w=4; if (p==1){ w=2; }else if (p==0){ w=0; } mashogy = mashogy.concat("Case #"); mashogy = mashogy.concat(((Integer)j).toString()); mashogy = mashogy.concat(": "); for (int i=0; i<szamlista.size(); ++i){ if (((Integer)(szamlista.get(i)))<(3*p-w)){ szamlista.remove(i); i--; }else if(((Integer)(szamlista.get(i)))>=(3*p-2)){ szamlista.remove(i); i--; o++; }else if(u<S){ szamlista.remove(i); i--; o++; u++; } } // String mashogy = (String)(szoveg.clone()); // System.out.println(szoveg); mashogy = mashogy.concat(((Integer)o).toString()); mashogy = mashogy.concat("\n"); System.out.println(mashogy); out.write(mashogy); } out.close(); } catch (IOException e) { } scanner.close(); return; } }
0
1,189,809
A11759
A10778
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 Triplet { private int total; public Triplet(int totalScore){ total = totalScore; } int getTotal() { return total; } boolean isSuprisable() { if (total < 2 || total > 28) { return false; } else { return true; } } int getBest(boolean suprising) { int extra = total%3; int mean = total/3; int result = -1; switch (extra) { case 0: if (suprising) { if (mean >= 1 && mean <= 9) { result = (mean+1); // m-1, m, m+1 } else { result = -1; } } else { result = mean; // m, m, m } break; case 1: if (suprising) { if (mean >= 1 && mean <= 9) { result = mean+1; // m-1, m+1, m+1 } else { result = -1; } } else { result = mean+1; // m, m, m+1 } break; case 2: if (suprising) { if (mean >= 0 && mean <= 8) { result = mean + 2; // m, m, m+2 } else { result = -1; } } else { result = mean + 1; // m, m+1, m+1 } default: break; } return result; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + total; return result; } }
0
1,189,810
A11759
A11234
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 googledance { public static void main (String [] args) throws IOException { BufferedReader f = new BufferedReader(new FileReader("googledance.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("googledance.out"))); int n = Integer.parseInt(f.readLine()); String[] scores = new String[n]; int[] answers = new int[n]; for(int i=0; i<n; i++){ scores[i] = f.readLine(); answers[i] = 0; } for(int i=0; i<n; i++){ StringTokenizer st = new StringTokenizer(scores[i]); int numgooglers = Integer.parseInt(st.nextToken()); int numsurprises = Integer.parseInt(st.nextToken()); int threshold = Integer.parseInt(st.nextToken()); Integer[] sumscores = new Integer[numgooglers]; int[][] breakdown = new int[numgooglers][3]; boolean[] succeeded = new boolean[numgooglers]; for(int j=0; j<numgooglers; j++){ sumscores[j] = Integer.parseInt(st.nextToken()); } Arrays.sort(sumscores, Collections.reverseOrder()); //sort DESCENDING for(int j=0; j<numgooglers; j++){ //System.out.println(); int psum = 0; for(int k=0; k<3; k++){ breakdown[j][k] = sumscores[j]/3; psum += sumscores[j]/3; } if (psum!=sumscores[j]){ int deviation = psum-sumscores[j]; for(int k=0; k<Math.abs(deviation); k++){ //Notice that there will be AT MOST 2 deviations! if(deviation > 0){ //balance out the deviations as closely as possible breakdown[j][k]--; } else{ breakdown[j][k]++; //good news, the breakdown is always sorted from inc->dec } } } /*for(int k=0; k<3; k++){ System.out.println(breakdown[j][k]); }*/ } for(int j=0; j<numgooglers; j++){ for(int k=0; k<3; k++){ if(!succeeded[j] && breakdown[j][k]>= threshold){ answers[i]++; succeeded[j] = true; break; } } } for(int j=0; j<numgooglers; j++){ if(!succeeded[j] && numsurprises>0){ if((breakdown[j][0]+2-breakdown[j][1] > 2) || (breakdown[j][0]+1>10) || (breakdown[j][1]-1<0)) //greater than 2 is an impossible surprise continue; breakdown[j][1]--; breakdown[j][0]++; numsurprises--; } } for(int j=0; j<numgooglers; j++){ for(int k=0; k<3; k++){ if(!succeeded[j] && breakdown[j][k] >= threshold){ answers[i]++; succeeded[j] = true; break; } } /*for(int k=0; k<3; k++){ System.out.println(breakdown[j][k]); }*/ } } for(int i=0; i<n; i++){ out.println("Case #" + (i+1) + ": " + answers[i]); } out.close(); System.exit(0); } }
0
1,189,811
A11759
A12061
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.File; import java.io.FileInputStream; import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; public class dancer { public static Scanner setFileIn(){ try{ Scanner input = new Scanner(new FileInputStream(new File ("test.txt"))); return input; }catch(Exception e){ return null; } } public static Scanner setSysIn(){ Scanner input = new Scanner(new BufferedInputStream(System.in)); return input; } public static int dancer(int n, int s, int p,Scanner input){ int ans = 0; int noSur = 3*p-2; int sur = 3*p-4; if (p==1){ noSur = 1; sur = 1; } if(p==0){ noSur = 0; sur = 0; } // //System.out.println(" "+s+" "+p); //System.out.println(" "+noSur+" "+sur); while(n>0){ int score = input.nextInt(); //System.out.print(" "+ score+" "); if (score>=noSur){ ans++; }else{ if ((score >= sur)&&(s>0)){ s--; ans++; } } n--; } return ans; } public static void main(String args[]){ Scanner input = setFileIn(); long counter = input.nextInt(); int ans = 0; int count = 1; while(count<=counter){ System.out.print("Case #"+count+": "); int n = input.nextInt(); int s = input.nextInt(); int p = input.nextInt(); ans = dancer(n,s,p,input); System.out.println(ans); count++; } } }
0
1,189,812
A11759
A11616
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.util.Scanner; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i=0;i<t;i++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int total = 0; for (int j=0;j<n;j++) { int score = sc.nextInt(); if (score >= 3 * p - 2) { total++; } else if (p >= 2 && score >= 3 * p - 4 && s > 0) { total++; s--; } } System.out.println("Case #" + (i + 1) + ": " + total); } } }
0
1,189,813
A11759
A11649
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package uk.co.epii.codejam.common; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; /** * * @author jim */ public class FileLoader { public FileLoader() { } public ArrayList<String> loadFile(String fileName) throws IOException { FileReader fr = new FileReader(fileName); BufferedReader br = new BufferedReader(fr); String in; ArrayList<String> lines = new ArrayList<String>(); while ((in = br.readLine()) != null) { lines.add(in); } return lines; } }
0
1,189,814
A11759
A10445
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 dancers { public static void main(String[] args) { ArrayList<HashSet<triple>> list = new ArrayList<HashSet<triple>>(); for (int i = 0; i <= 30; i++) { HashSet<triple> temp = new HashSet<triple>(); list.add(temp); } for (int i = 0; i <= 10; i++) for (int j = 0; j <= 10; j++) for (int k = 0; k <= 10; k++) { if (!((Math.abs(i - j) > 2) || (Math.abs(i - k) > 2) || (Math.abs(j - k) > 2))) { triple temp = new triple(i, j, k); HashSet<triple> temp2 = list.get(temp.total); boolean found = false; for (triple t : temp2) { if (t.theset.equals(temp.theset)) { found = true; break; } } if (!found) temp2.add(temp); list.set(temp.total, temp2); } } /* * //System.out.println(list); for (HashSet<triple> h : list) { * //System.out.println(h.size()); } */ try { FileReader fread = new FileReader(new File("B-small-attempt4.in")); BufferedReader br = new BufferedReader(fread); FileWriter fwrite = new FileWriter(new File("output.txt")); PrintWriter pw = new PrintWriter(fwrite); int cases = new Integer(br.readLine()); for (int i = 1; i <= cases; i++) { String line = br.readLine(); StringTokenizer st = new StringTokenizer(line); int googlers = new Integer(st.nextToken()); int s = new Integer(st.nextToken()); int p = new Integer(st.nextToken()); int[] googlerscores = new int[googlers]; for (int j = 0; j < googlers; j++) { googlerscores[j] = new Integer(st.nextToken()); } // for (int a : googlerscores) // System.out.println(a); int fors[] = new int[googlers]; int fornos[] = new int[googlers]; for (int j = 0; j < googlers; j++) { fors[j] = 0; fornos[j] = 0; } int counts = 0; int countnos = 0; for (int j = 0; j < googlers; j++) { HashSet<triple> scores = list.get(googlerscores[j]); for (triple s1 : scores) { // System.out.println(s1); if (s1.p >= p) { if (s1.state == 2) { fors[j] = s1.p; counts++; // //System.out.println("counts=" + counts); } else { fornos[j] = s1.p; countnos++; // //System.out.println("countnos=" + countnos); } } } } // System.out.println("s=" + s); for (int d : fors) { // System.out.print(d + ","); } // System.out.println(); for (int d : fornos) { // System.out.print(d + ","); } // System.out.println(); int count = 0; if ((s == 3) && (counts == 3)) count = 3; else if (s == 2) { if ((googlers == 2) && (counts == 2)) count = 2; else if ((googlers == 3) && (counts >= 2)) { int check = 0; if (fors[0] > 0 && fors[1] > 0) { check = 2; if (fornos[2] > 0) check = 3; } // 12 if (fors[1] > 0 && fors[2] > 0) { check = Math.max(check, 2); if (fornos[0] > 0) check = Math.max(check, 3); } // 23 if (fors[0] > 0 && fors[2] > 0) { check = Math.max(check, 2); if (fornos[1] > 0) check = Math.max(check, 3); } // 13 count = check; } } else if (s == 1) { if (counts >= 1) { if (googlers == 1) { count = 1; } else if (googlers == 2) { if (fors[0] > 0) { count = 1; if (fornos[1] > 0) count = 2; } if (fors[1] > 0) { count = Math.max(count, 1); if (fornos[0] > 0) count = Math.max(count, 2); } } else if (googlers == 3) { if (fors[0] > 0) { int check = 1; if (fornos[1] > 0) check++; if (fornos[2] > 0) check++; count = Math.max(count, check); } if (fors[1] > 0) { int check = 1; if (fornos[0] > 0) check++; if (fornos[2] > 0) check++; count = Math.max(count, check); } if (fors[2] > 0) { // System.out.println("in here"); int check = 1; if (fornos[0] > 0) check++; if (fornos[1] > 0) check++; count = Math.max(count, check); } } } } else { count = countnos; } pw.println("Case #" + i + ": " + count); // System.out.println("Case #" + i + ": " + count); } pw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
0
1,189,815
A11759
A10039
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class Main { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub Scanner reader = new Scanner(new File("B-small-attempt1.in")); PrintWriter writer = new PrintWriter(new File("output.txt")); int cases = reader.nextInt(); for (int i=0; i<cases; i++) { int N = reader.nextInt(); int S = reader.nextInt(); int P = reader.nextInt(); int[] G = new int[N]; int X = 0; int K = 0; for (int j=0; j<N; j++) { G[j] = reader.nextInt(); int score = G[j]; int base = (int) Math.ceil(G[j] /3); switch (score % 3) { case 0: if (base >= P) { X++; } else if (K < S && base > 0 && (base + 1) >= P) { K++; X++; } break; case 1: if (base >= P || (base + 1) >= P) { X++; } else if (K < S && (base + 1) >= P) { K++; X++; } break; case 2: if ((base + 1) >= P || base >= P) { X++; } else if (K < S && (base + 2) >= P) { K++; X++; } break; } } writer.println("Case #" + (i+1) + ": " + X); } System.out.println("done"); reader.close(); writer.close(); } }
0
1,189,816
A11759
A11994
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; public class Prob2 { public static void main(String[] args) throws NumberFormatException, IOException { String filePath = "C://Users//Apoorv//Downloads//B-small-attempt2.in"; // String filePath = "C://Users//Apoorv//Desktop//test1.txt"; BufferedReader br2 = new BufferedReader(new InputStreamReader( new DataInputStream(new FileInputStream(filePath)))); String str = null; long count = 0; Integer numCases = 0; numCases = Integer.parseInt(br2.readLine()); for (int curCase = 0; curCase < numCases; curCase++) { System.out.print("Case #" + (curCase + 1) + ": "); Integer answer=0; str = br2.readLine(); String[] tokens = str.split(" "); int numGoogle = Integer.parseInt(tokens[0]); int numCrazy = Integer.parseInt(tokens[1]); int minScore = Integer.parseInt(tokens[2]); int usedCrazy =0; for (int curTotal=0;curTotal<numGoogle;curTotal++){ int curScore = Integer.parseInt(tokens[3+curTotal]); double avgValue = (double)curScore/3.0; if(avgValue >= minScore) answer++; else if(avgValue > (minScore -1)) answer++; else if(usedCrazy < numCrazy && curScore>= minScore && curScore > (3*minScore-5)){ answer++; usedCrazy++; } } System.out.println(answer); } } }
0
1,189,817
A11759
A13221
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 SurprisingDancers { public static void main(String[] args) { BufferedReader br; BufferedWriter bw; int count; try { br = new BufferedReader(new FileReader(args[0])); bw = new BufferedWriter(new FileWriter(new File("output.txt"))); count = new Integer(br.readLine()); for(int i = 1; i <= count; i++) { try { bw.write("Case #" + i + ": "); Scanner intReader = new Scanner(br.readLine()); int numGooglers = intReader.nextInt(); int numSurprises = intReader.nextInt(); int p = intReader.nextInt(); int ans = 0; for(int j = 1; j <= numGooglers; j++) { int score = intReader.nextInt(); if((score/3) >= p) { ans++; } else { if(score % 3 == 0 && score > 0) { if((score/3 + 1) >= p) { if(numSurprises > 0) { numSurprises--; ans++; } } } if(score % 3 == 1) { if((score/3 + 1) >= p) { ans++; } } if(score % 3 == 2) { if((score/3 + 1) >= p) { ans++; } else if((score/3 + 2) >= p) { if(numSurprises > 0) { numSurprises--; ans++; } } } } } String stringAns = "" + ans; bw.write(stringAns); bw.newLine(); } catch(IOException e) { System.out.println("Error reading line."); } } br.close(); bw.close(); } catch(FileNotFoundException e) { System.out.println("File not found."); } catch(IOException e) { System.out.println("Error reading first line or creating output."); } } }
0
1,189,818
A11759
A11601
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.LinkedList; class firstgame21 { BufferedReader br; PrintWriter pw; String input; int totalpass; public firstgame21() { try { br = new BufferedReader(new FileReader("B-small-attempt0.in")); pw = new PrintWriter(new BufferedWriter(new FileWriter("output1.txt"))); input = br.readLine(); int count = Integer.parseInt(input); for (int x=1; x<= count; x++) { totalpass = 0; input = br.readLine(); String data[] = input.split(" "); int people = Integer.parseInt(data[0]); int extra = Integer.parseInt(data[1]); int min = Integer.parseInt(data[2]); for (int y = 0; y< people ; y++ ) { int p = Integer.parseInt(data[3+y]); int max; if (p%3==0) { max = p/3; //System.out.println("max1:"+max); if (max >= min) { totalpass++; } else if (max + 1 == min) { if (max == 0) { } else if (extra > 0) { totalpass++; extra-- ; } } } else if (p%3==1) { max = (p/3) + 1; //System.out.println("max2:"+max); if (max >= min) { totalpass++; } } else if (p%3==2) { max = (p/3) + 1; //System.out.println("max3:"+max); if (max >= min) { totalpass++; } else if (max+1 == min) { if (extra > 0) { totalpass++; extra-- ; } } } } System.out.println("Case #"+x+": "+totalpass); pw.println("Case #"+x+": "+totalpass); } // after end read pw.close(); } catch (IOException e) { System.out.println(e); } } public static void main(String[] args) { new firstgame21(); } }
0
1,189,819
A11759
A10804
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.Dancing; public class Combination { int[] list; boolean surprising; public Combination(int[] list, boolean surprising){ this.list = list; this.surprising = surprising; } public int[] getList(){ return list; } public boolean isSurprising(){ return surprising; } @Override public String toString(){ String s = ""; for (int i = 0; i<list.length;i++){ s += list[i] + " "; } s+= " " + this.surprising; return s; } }
0
1,189,820
A11759
A10725
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.*; public class main { static int numberPeriod(int n, int len) { if (len == 2 && n / 10 == n % 10) return 1; if (len == 4 && n % 100 == n / 100) return 2; if (len == 6 && n % 100 == n / 10000 && n % 100 == n / 100 % 100) return 2; if (len == 6 && n % 1000 == n / 1000) return 3; return len; } static int numberLength(int n) { int len = 0; while (n > 0) { n /= 10; len++; } return len; } main() throws FileNotFoundException { Scanner sc = new Scanner(new File("B-small-attempt0.in")); PrintWriter out = new PrintWriter("result.txt"); int tests = sc.nextInt(); for (int t = 1; t <= tests; t++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); Map<Integer, ArrayList<Decompose>> map = new TreeMap<>(); ArrayList<Integer> scores = new ArrayList<>(); for (int m = 0; m < n; m++) { int g = sc.nextInt(); scores.add(g); map.put(g, dec(g)); //out.println(dec(g).toString()); } int ww = 0; int w = 0; int cw = 0; for (int i = 0; i < n; i++) { if (isDecomposeThere(map.get(scores.get(i)), p, true) && isDecomposeThere(map.get(scores.get(i)), p, false)) { ww++; } else if (isDecomposeThere(map.get(scores.get(i)), p, true)) { w++; } else if (isDecomposeThere(map.get(scores.get(i)), p, false)) { cw++; } } if (w >= s) { out.printf("Case #%d: %d\n", t, s + cw + ww); } else { //s -= w; out.printf("Case #%d: %d\n", t, w + ww + cw); } } out.flush(); } public static void main(String[] args) throws FileNotFoundException { main m = new main(); } public boolean isDecomposeThere(ArrayList<Decompose> decomposes, int p, boolean surprise) { for (Decompose dec : decomposes) { if (dec.a >= p && dec.surprise == surprise) return true; } return false; } public ArrayList<Decompose> dec(int n) { ArrayList<Decompose> list = new ArrayList<>(); for (int i = 0; i <= 10; i++) { for (int j = 0; j <= i; j++) { for (int k = 0; k <= j; k++) { if (i - j <= 2 && j - k <= 2 && i - k <= 2 && i + j + k == n) { boolean surprise = (i - j == 2 || j - k == 2 || i - k == 2); list.add(new Decompose(i, j, k, surprise)); } } } } return list; } class Decompose { int a, b, c; boolean surprise; public Decompose(int a, int b, int c, boolean surprise) { this.a = a; this.b = b; this.c = c; this.surprise = surprise; } @Override public String toString() { return "" + a + " " + b + " " + c + " " + surprise; } } }
0
1,189,821
A11759
A11889
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.awt.Point; class Case{ long num1,Ngoogle,Special,p; int total; String result=""; public Case(File aFile) { try{ StringBuilder contents = new StringBuilder(); BufferedReader input = new BufferedReader(new FileReader(aFile)); String line = input.readLine(); num1 = Integer.valueOf(line).intValue(); int i=1; total=0; System.out.println("nmber of ttal cases"+ num1 +"testing"); while (i<=num1 && ( line = input.readLine()) != null) { StringTokenizer st = new StringTokenizer(line," "); Ngoogle=Integer.valueOf(st.nextToken()); // System.out.println("ngooge #"+ Ngoogle); Special=Integer.valueOf(st.nextToken()); // System.out.println("Special #"+ Special); p=Integer.valueOf(st.nextToken()); // System.out.println("p #"+ p); // use this for testing long normalP=p*3-2; long specialP=p*3-4; int ii=1; while (ii<=Ngoogle) { long temp=Integer.valueOf(st.nextToken()); // okay test the temp integer if(p==0) { total++; } else if(p==1) { if(temp>=1) total++; } else if(temp>=normalP) { total++; } else if(Special>0 && temp>=specialP) { total++; Special--; } ii++; } //System.out.println(result); // output total... or save to vector. // System.out.println("Case #"+ i +"total"+ total); oneCase(i, total); total=0; i++; } } catch (IOException ex){ ex.printStackTrace(); } } public String getResult (){ return result; } public void oneCase (int c, int total){ // System out Case #c: total System.out.println("Case #"+ c +":" +total); result+="Case #"+c+": "+total+System.getProperty("line.separator"); } } public class ReadWriteTextFile { static public String getContents(File aFile) { StringBuilder contents = new StringBuilder(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents.toString(); } static public void setContents(File aFile, String aContents) throws FileNotFoundException, IOException { if (aFile == null) { throw new IllegalArgumentException("File should not be null."); } if (!aFile.exists()) { throw new FileNotFoundException ("File does not exist: " + aFile); } if (!aFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + aFile); } if (!aFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + aFile); } Writer output = new BufferedWriter(new FileWriter(aFile)); try { output.write( aContents ); } finally { output.close(); } } public static void main (String... aArguments) throws IOException { File testFile = new File("B-small-attempt0.in"); File testFile2 = new File("result.txt"); Case allcases = new Case(testFile); setContents(testFile2, allcases.getResult()); } }
0
1,189,822
A11759
A13083
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 GooglerDance { public static void main(String[] args) { Scanner in = new Scanner(System.in); int size = in.nextInt(); int count = 0; while (count < size) { int maxNum = 0; int googlers = in.nextInt(); int[][] judges = new int[googlers][3]; int[] scores = new int[googlers]; boolean[] ishigher = new boolean[googlers]; int s = in.nextInt(); int p = in.nextInt(); for (int i = 0; i < scores.length; i++) {// getting scores scores[i] = in.nextInt(); } // computing scores for (int i = 0; i < scores.length; i++) { int ceil = scores[i] / 3; if ((scores[i] % 3) > 0) { ceil++; } if (ceil >= p) { ishigher[i] = true; maxNum++; } if ((3 * ceil) == scores[i]) { judges[i][0] = ceil; judges[i][1] = ceil; judges[i][2] = ceil; if (!ishigher[i] && (p - ceil) == 1 && s > 0 && (ceil - 1) > 0) { judges[i][0] = ceil + 1; judges[i][1] = ceil; judges[i][2] = ceil - 1; maxNum++; s--; } } else if ((3 * ceil) == (scores[i] + 1)) { judges[i][0] = ceil; judges[i][1] = ceil; judges[i][2] = ceil - 1; if (!ishigher[i] && (p - ceil) == 1 && s > 0 && (ceil - 1) > 0) { judges[i][0] = ceil + 1; judges[i][1] = ceil - 1; judges[i][2] = ceil - 1; maxNum++; s--; } } else if ((3 * ceil) == (scores[i] + 2)) { judges[i][0] = ceil; judges[i][1] = ceil - 1; judges[i][2] = ceil - 1; } else { System.out.println("Error in Algorithm"); } } System.out.format("Case #%d: %d\n", count + 1, maxNum); count++; } } }
0
1,189,823
A11759
A11964
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 gjc.googledancer; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; public class Solution { /** * @param args */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("B-small-attempt0.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("B-small-attempt0.txt")); int nTestCases = Integer.parseInt(br.readLine()); for (int i=0; i<nTestCases; i++) { String line = br.readLine(); StringTokenizer st = new StringTokenizer(line); int nDancer = Integer.parseInt(st.nextToken()); int nSurprise = Integer.parseInt(st.nextToken()); int threshold = Integer.parseInt(st.nextToken()); int result = 0; for (int j=0; j<nDancer; j++) { int totalValue = Integer.parseInt(st.nextToken()); int stdValue = 0, surpriseValue = 0; if (totalValue%3==0) { stdValue = totalValue/3; if (totalValue==0 || totalValue==30) { surpriseValue = stdValue; } else { surpriseValue = totalValue/3 + 1; } } else if (totalValue%3==1) { stdValue = totalValue/3 + 1; surpriseValue = totalValue/3 + 1; } else if (totalValue%3==2) { stdValue = totalValue/3+1; if (totalValue==29) { surpriseValue = stdValue; } else { surpriseValue = totalValue/3 + 2; } } if (stdValue>=threshold) { result++; } else if (surpriseValue>=threshold && nSurprise>0) { result++; nSurprise--; } } // Display the results. bw.write("Case #"+(i+1)+": "); bw.write(result+"\n"); } bw.close(); } }
0
1,189,824
A11759
A12489
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 Dancing { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); for (int C=1;C<=N;C++) { System.out.printf("Case #%d: ", C); int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int count = 0; for (int i=0;i<n;i++) { int score = sc.nextInt(); if (score/3>=p || (score/3==p-1 && score%3>0)) count ++; else if (((score/3==p-1) || (score/3==p-2 && score%3==2 && p-2>=0)) && s>0 && score/3-1>=0) { s--; count ++; } } System.out.println(count); } } }
0
1,189,825
A11759
A10024
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.HashSet; public class DancingWithTheGooglers { private static String inputFile = "C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Input.txt"; private static String outputFile = "C:\\PERSONAL-WORKSPACE\\GCJ-2012\\src\\input-output\\Output.txt"; public static void main(String[] args) { InputReader ir = new InputReader(inputFile); OutputWriter ow = new OutputWriter(outputFile); ArrayList<String> lines = ir.loadLines(); for(int i=1;i<lines.size();i++){ int count = 0; Long[] arrL = GCJUtils.getLongArray(lines.get(i).split(" ",lines.get(i).length())); long nst = arrL[1]; long score = arrL[2]; ArrayList<Long[]> al = new ArrayList<Long[]>(); for(int j=3;j<arrL.length;j++){ Long[] scoresArr = new Long[3]; long remainder = arrL[j]%3; long tmp = arrL[j]/3; scoresArr[0] = scoresArr[1] = scoresArr[2] = tmp; for(int k=0;k<remainder;k++){ scoresArr[k]++; } if(scoresArr[0] >=score || scoresArr[1] >=score ||scoresArr[2] >=score){ count++; }else if(remainder!=1 ){ al.add(scoresArr); } } for(int p=0;p<al.size();p++){ Long[] arrLL = al.get(p); if(nst==0)break; if(arrLL[0]!=0 && arrLL[0]==(score-1)){ count++;nst--; } } ow.writeCaseLine(count+""); } ow.flushAndClose(); } }
0
1,189,826
A11759
A12357
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class B { public String solve(int N, int S, int p, int[] t) { int cnt = 0; int p1 = Math.max(3*p-2, p); int p2 = Math.max(3*p-4, p); for (int i=0; i<N; i++) { if (t[i] >= p1) { cnt ++; } else if (t[i] >= p2) { if (S > 0) { S --; cnt ++; } } } return Integer.toString(cnt) + "\n"; } //////////////////////////////////////// // read input //////////////////////////////////////// public String runInput(BufferedReader br) throws IOException { String[] items = br.readLine().trim().split("\\s+"); int idx = 0; int N = Integer.parseInt(items[idx++]); int S = Integer.parseInt(items[idx++]); int p = Integer.parseInt(items[idx++]); int[] t = new int[N]; for (int i=0; i<N; i++) { t[i] = Integer.parseInt(items[idx++]); } return solve(N, S, p, t); } //////////////////////////////////////// // main //////////////////////////////////////// public static void main(String[] args) { B b = new B(); try { b.parseFile("B-sample"); b.parseFile("B-small-attempt0"); //b.parseFile("B-large"); } catch (IOException e) { e.printStackTrace(); } } //////////////////////////////////////// // library //////////////////////////////////////// public void parseFile(String filePrefix) throws IOException { String fileIn = filePrefix + ".in"; String fileOut = filePrefix + ".out"; BufferedReader br = new BufferedReader(new FileReader(fileIn)); BufferedWriter bw = new BufferedWriter(new FileWriter(fileOut)); int n = Integer.parseInt(br.readLine()); for (int i=1; i<=n; i++) { String ret = "Case #" + i + ": "; ret += runInput(br); System.out.print(ret); bw.write(ret); } br.close(); bw.close(); } }
0
1,189,827
A11759
A11535
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package gcj_b; /** * * @author kay */ public class Gcj_B { /** * @param args the command line arguments */ public static void main(String[] args) { Generate app = new Generate(); app.do_processing("G:/my.txt"); // TODO code application logic here } }
0
1,189,828
A11759
A12990
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class B { public static void main(String[] args) throws IOException { String filename = "B-small-attempt3"; String inname = filename + ".in"; String outname = filename + ".out"; Scanner sc = new Scanner(new File(inname)); PrintWriter out = new PrintWriter(new FileWriter(outname)); int N = sc.nextInt(); for (int t = 1; t <= N; t++) { int[] scores = new int[31]; int numGooglers = sc.nextInt(); int surprise = sc.nextInt(); int minPoints = sc.nextInt(); for (int i = 0; i < numGooglers; i++) { scores[sc.nextInt()]++; } int triple = minPoints * 3; int ans = 0; int p = 30; while (p >= 0) { scores[p]--; if (scores[p] >= 0) { if(p >= triple) { ans++; } else if(p >= triple - 2 && minPoints >= 1) { ans++; } else if(p >= triple - 4 && minPoints >= 2 && surprise > 0) { ans++; surprise--; } } else { p--; } } out.println("Case #" + t + ": " + ans); System.out.println("Case #" + t + ": " + ans); } out.close(); } }
0
1,189,829
A11759
A10827
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.InputStreamReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.StringTokenizer; public class B { private void run() throws IOException { // put your code here .. String read=in.readLine(); int testcases=Integer.parseInt(read); int number=1; while(testcases-->0){ StringTokenizer tokens=new StringTokenizer(in.readLine()); int answer=0; int N=Integer.parseInt(tokens.nextToken()); int S=Integer.parseInt(tokens.nextToken()); int P=Integer.parseInt(tokens.nextToken()); if(P==0){ writeln("Case #"+(number++)+": "+N); continue; } int mincount=P==1?1:3*(P-1)-1; for (int i = 0; i < N; i++) { int x=Integer.parseInt(tokens.nextToken()); if(x<mincount)continue; int divideX=x/3; int inc=1; if(x%3==0)inc=0; if((divideX+inc)>=P){ answer++; } else{ if(S<=0)continue; if((divideX+2)>=P){ answer++; S--; } } } writeln("Case #"+(number++)+": "+answer); } } private int nextInt() throws IOException { if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); return Integer.parseInt(input.nextToken()); } private long nextLong() throws IOException { if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); return Long.parseLong(input.nextToken()); } private double nextDouble() throws IOException { if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); return Double.parseDouble(input.nextToken()); } private String nextString() throws IOException { if (!input.hasMoreTokens())input=new StringTokenizer(in.readLine()); return input.nextToken(); } private void write(String output){ out.write(output); out.flush(); } private void writeln(String output){ out.write(output+"\n"); // out.flush(); } private void end() throws IOException{ in.close(); out.close(); System.exit(0); } private BufferedReader in; private PrintWriter out; private StringTokenizer input; public B() throws IOException { //Input Output for Console to be used for trying the test samples of the problem // in = new BufferedReader(new InputStreamReader(System.in)); // out = new PrintWriter(System.out); //------------------------------------------------------------------------- //Input Output for File to be used for solving the small and large test files in = new BufferedReader(new FileReader("B-small-attempt0.in")); out = new PrintWriter("output2.txt"); //------------------------------------------------------------------------- //Initialize Stringtokenizer input } public static void main(String[] args) throws Exception { //------------------------------------------------------------------------- //initializing... B sol = new B(); //------------------------------------------------------------------------- sol.run(); //------------------------------------------------------------------------- //closing up sol.end(); //-------------------------------------------------------------------------- } }
0
1,189,830
A11759
A12540
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(new FileReader("B-small-attempt0.in")); PrintWriter pw = new PrintWriter(new FileWriter("outputB0.txt")); int caseCount = sc.nextInt(); sc.nextLine(); for (int caseNum = 0; caseNum < caseCount; caseNum++) { //System.out.println(caseNum); int dancerCount = sc.nextInt(); int surprisingCount = sc.nextInt(); int p = sc.nextInt(); int pCount = 0; int sCount = 0; for (int dancerNum = 0; dancerNum < dancerCount; dancerNum++) { int score = sc.nextInt(); int d = checkScore(score, p); if (d == 1) pCount++; else if (d == 2) sCount++; } //System.out.println(pCount + " " + sCount + " " + surprisingCount); int count = pCount; if (sCount < surprisingCount) { count += sCount; } else { count += surprisingCount; } pw.write("Case #" + (caseNum + 1) + ": "); pw.write(count + "\n"); } pw.flush(); pw.close(); sc.close(); } private static int checkScore(int score, int p) { boolean sScore = false; 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 == score && (a >= p || b >= p || c >= p)) { int ab = Math.abs(a-b); int ac = Math.abs(a-c); int bc = Math.abs(b-c); if (ab < 2 && ac < 2 && bc < 2) { //System.out.println("P " + a + " " + b + " " + c); return 1; } else if (ab < 3 && ac < 3 && bc < 3) { //System.out.println("S " + a + " " + b + " " + c); sScore = true; } } } } } if(sScore == true) { return 2; } return 0; } }
0
1,189,831
A11759
A10754
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 ProblemB { public static void main(String[] args) { /* try { System.setIn(new FileInputStream("b-example.in")); } catch (Exception e) {} */ new ProblemB(); } public ProblemB() { Scanner input = new Scanner(System.in); int cases = input.nextInt(); for (int n = 0; n < cases; n++) { int total = input.nextInt(); int surprising = input.nextInt(); int limit = input.nextInt(); int[] score = new int[total]; for (int i = 0; i < total; i++) { score[i] = input.nextInt(); } int[][] triplet = new int[total][3]; int[] tripletMax = new int[total]; int[] tripletMin = new int[total]; for (int i = 0; i < total; i++) { int tempScore = score[i]; triplet[i][0] = tempScore / 3; tempScore -= triplet[i][0]; triplet[i][1] = tempScore / 2; tempScore -= triplet[i][1]; triplet[i][2] = tempScore; tripletMax[i] = Math.max(Math.max(triplet[i][0], triplet[i][1]), triplet[i][2]); tripletMin[i] = Math.min(Math.min(triplet[i][0], triplet[i][1]), triplet[i][2]); } int max = 0; int tempSurprising = surprising; List<Integer> secondPass = new ArrayList<Integer>(); for (int i = 0; i < total; i++) { secondPass.add(i); } for (int i = 0; i < total; i++) { if (tripletMax[i] >= limit) { max++; } else if ((score[i] >= 2) && (tempSurprising > 0)) { if (tripletMax[i] >= (limit - 1)) { if ((tripletMax[i] - tripletMin[i]) == 1) { if ((tripletMax[i] == triplet[i][0] && tripletMax[i] == triplet[i][1] && tripletMin[i] == triplet[i][2]) || (tripletMax[i] == triplet[i][0] && tripletMin[i] == triplet[i][1] && tripletMax[i] == triplet[i][2]) || (tripletMin[i] == triplet[i][0] && tripletMax[i] == triplet[i][1] && tripletMax[i] == triplet[i][2])) { max++; tempSurprising--; secondPass.remove(secondPass.indexOf(i)); } } else { if (triplet[i][0] == triplet[i][1] && triplet[i][1] == triplet[i][2]) { max++; tempSurprising--; secondPass.remove(secondPass.indexOf(i)); } } } } } if (tempSurprising > 0) { for (int i : secondPass) { if (tempSurprising > 0) { if ((tripletMax[i] >= limit) || (score[i] >= 2)) { tempSurprising--; } } } } System.out.println("Case #" + (n+1) + ": " + max); } } }
0
1,189,832
A11759
A10636
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package cj2012; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader buffer = new BufferedReader(new FileReader( "B-small-attempt0.in")); int t = Integer.parseInt(buffer.readLine()); for (int i = 0; i < t; i++) { String kase = buffer.readLine(); StringTokenizer tokenizer = new StringTokenizer(kase); int n = Integer.parseInt(tokenizer.nextToken()); int s = Integer.parseInt(tokenizer.nextToken()); int p = Integer.parseInt(tokenizer.nextToken()); int[] scores = new int[n]; for (int j = 0; j < scores.length; j++) { scores[j] = Integer.parseInt(tokenizer.nextToken()); } boolean done = false; int solution = 0, sdash = 0; int x = 0; for (int k = 0; k < n && !done; k++) { int make = make(scores[k], p); if (make == 0) x++; else if (make == 1 && s > sdash) { x++; sdash++; } } solution = x; System.out.printf("Case #%d: %d\n", (i + 1), solution); } } private static int make(int i, int p) { i -= p; if (i > 2 * p) return 0; if (i < 0) return -1; if (i > 2 * p - 3 && i < 2 * p + 3) return 0; if (i > 2 * p - 5 && i < 2 * p + 5) return 1; return -1; } }
0
1,189,833
A11759
A13053
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.InputStreamReader; public class B { void run() { try { BufferedReader bfd = new BufferedReader(new InputStreamReader( System.in)); int tc = Integer.parseInt(bfd.readLine()), i, j, k, s, p, goo[], surp[], res[], t, r, cnt; boolean[] taken; String[] sp; for(r=0; r<tc; ++r){ sp = bfd.readLine().split(" +"); s = Integer.parseInt(sp[1]); p = Integer.parseInt(sp[2]); goo = new int[sp.length-3]; for(i=0; i<goo.length; ++i) goo[i] = Integer.parseInt(sp[i+3]); surp = new int[goo.length]; res = new int[goo.length]; int min; for(t=0; t<goo.length; ++t){ min = (int)Math.floor(goo[t]/3)-1; if(min<0) min = 0; for(i=min; i<=goo[t]; ++i){ for(j=i; j<=i+2; ++j){ for(k=j; k<=j+2; ++k){ if(k-i<=2) if(i+j+k==goo[t] && Math.max(Math.max(i, j), k)>=p){ if(k-i==2){ ++surp[t]; } else if(k-i < 2) { ++res[t]; } } } } } } taken = new boolean[goo.length]; cnt = 0; for(i=0; i<goo.length; ++i){ if(s>0 && res[i]==0 && surp[i]==1){ taken[i] = true; --s; } } for(i=0; i<goo.length; ++i) if(res[i]==1 && !taken[i]) taken[i] = true; for(i=0; i<taken.length; ++i) if(taken[i]) ++cnt; System.out.print("Case #"+(r+1)+": "); System.out.print(cnt); System.out.println(); } } catch (Exception e) { } } public static void main(String[] args) { new B().run(); } }
0
1,189,834
A11759
A11640
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 exercicio.b; import java.awt.List; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class ExerciocioB { public static void main(String args[]) throws IOException { int[][] combinacoes = new int[1331][3]; for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 10; j++) { for (int k = 0; k <= 10; k++) { combinacoes[i * 121 + j * 11 + k][0] = i; combinacoes[i * 121 + j * 11 + k][1] = j; combinacoes[i * 121 + j * 11 + k][2] = k; } } } File fileInput = new File("src/exercicio/b/input.txt"); FileReader fileReaderInput = new FileReader(fileInput); BufferedReader leitorInput = new BufferedReader(fileReaderInput); String numeroLinhas = leitorInput.readLine(); Integer numero = new Integer(numeroLinhas); String linhaInput = null; for (int j = 0; j < numero; j++) { linhaInput = leitorInput.readLine(); String[] linha = linhaInput.split(" "); Integer numeroGoo = new Integer(linha[0]); Integer numeroSurp = new Integer(linha[1]); Integer minScore = new Integer(linha[2]); int[] pontos = new int[numeroGoo]; for(int b = 0; b< numeroGoo; b++){ pontos[b] = new Integer(linha[b+3]); } boolean[] semSurp = new boolean[numeroGoo]; boolean[] comSurp = new boolean[numeroGoo]; for (int k = 0; k < numeroGoo; k++) { comSurp[k] = false; semSurp[k]=false; for (int i = 0; i < combinacoes.length; i++) { if (Math.abs(combinacoes[i][0] - combinacoes[i][1]) <= 1 && Math.abs(combinacoes[i][0] - combinacoes[i][2]) <= 1 && Math.abs(combinacoes[i][1] - combinacoes[i][2]) <= 1 && (combinacoes[i][0] + combinacoes[i][1] + combinacoes[i][2]) == pontos[k] && (combinacoes[i][0] >= minScore || combinacoes[i][1] >= minScore || combinacoes[i][2] >= minScore)) { semSurp[k] = true; break; } } for (int i = 0; i < combinacoes.length; i++) { if (Math.abs(combinacoes[i][0] - combinacoes[i][1]) <= 2 && Math.abs(combinacoes[i][0] - combinacoes[i][2]) <= 2 && Math.abs(combinacoes[i][1] - combinacoes[i][2]) <= 2 && (combinacoes[i][0] + combinacoes[i][1] + combinacoes[i][2]) == pontos[k] && (combinacoes[i][0] >= minScore || combinacoes[i][1] >= minScore || combinacoes[i][2] >= minScore)) { comSurp[k] = true; break; } } } int contaMaior = 0; for(int a = 0; a < numeroGoo; a++){ if(semSurp[a] == true) contaMaior++; } for(int a = 0; a < numeroGoo; a++){ if(comSurp[a] == true && numeroSurp >0 && !semSurp[a]){ contaMaior++; numeroSurp--; } else if (numeroSurp == 0){ break; } } System.out.println("Case #" + (j + 1) + ": "+contaMaior); } } }
0
1,189,835
A11759
A12516
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 B { private class OutputDelegate { BufferedWriter out; private OutputDelegate(String fileName) { try { out = new BufferedWriter(new FileWriter(fileName)); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void writeLine(String output) { try { out.write(output); out.newLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private void close() { try { if (out != null) { out.close(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } private class InputDelegate { BufferedReader in; private InputDelegate(String fileName){ try { in = new BufferedReader(new FileReader(fileName)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private int[] readIntLine() { String line; String income[] = null; try { if ((line = in.readLine()) != null) { income = line.split(" "); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } int array[] = new int[income.length]; for (int i = 0; i < array.length; i++) { array[i] = (Integer.parseInt(income[i])); } return array; } private void close() { try { in.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } public void process(String[] args) { InputDelegate in = new InputDelegate(args[0]); OutputDelegate out = new OutputDelegate(args[1]); int cases = in.readIntLine()[0]; for (int i = 1; i <= cases; i++) { int[] line = in.readIntLine(); int contnum = line[0]; int surpr = line[1]; int p = line[2]; int[] contestants = new int[contnum]; for (int j = 3; j < line.length; j++) { contestants[j-3] = line[j]; } int[] triplets = new int[2]; triplets[0] = p*3-4; triplets[1] = p*3-3; int output = 0; for (int j = 0; j < contnum; j++) { if(contestants[j] == 0) { if(p == 0) { output++; continue; } else continue; } if(contestants[j] > triplets[1]) { output++; } else if(contestants[j] == triplets[0] || contestants[j] == triplets[1]) { if(surpr > 0) { surpr--; output++; } } } out.writeLine("Case #" + i + ": " + output); } in.close(); out.close(); } public static void main(String[] args) { B m = new B(); m.process(args); } }
0
1,189,836
A11759
A12949
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.text.DecimalFormat; import java.util.*; import static java.lang.Math.* ; import static java.util.Arrays.* ; public class B { public static void main(String[] args) throws FileNotFoundException { in = new Scanner(new InputStreamReader(new FileInputStream("b_in.txt"))); out = new PrintStream(new BufferedOutputStream(new FileOutputStream("b_out.txt"))); int n = in.nextInt() ; in.nextLine() ; int t = 1 ; while( n-- > 0) new B().solveProblem(t++); out.close(); } static Scanner in = new Scanner(new InputStreamReader(System.in)); static PrintStream out = new PrintStream(new BufferedOutputStream(System.out)); //static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public void solveProblem(int nr) { out.print("Case #" + nr + ": " ) ; int N = in.nextInt() ; int S = in.nextInt() ; int p = in.nextInt() ; int[] v = new int[N] ; for( int i = 0 ; i < N ; i++ ) v[i] = in.nextInt() ; int[] min_ns = new int[31] ; int[] min_s = new int[31] ; fill( min_s, -1 ); for( int i = 0 ; i <= 10 ; i++ ) for( int j = i ; j <= i + 2 && j <= 10 ; j++ ) for( int k = j ; k <= i + 2 && k <= 10 ; k++ ){ min_s[i+j+k] = max(min_s[i+j+k],k ) ; } for( int i = 0 ; i <= 10 ; i++ ) for( int j = i ; j <= i + 1 && j <= 10 ; j++ ) for( int k = j ; k <= i + 1 && k <= 10 ; k++ ){ min_ns[i+j+k] = max(min_ns[i+j+k],k ) ; } int t1 = 0 ; int t2 = 0 ; for( int a : v ){ if( min_ns[a] >= p ) t1++ ; else if( min_s[a] >= p ) t2++ ; } out.println(t1+min(t2,S)) ; System.err.println("Case #" + nr + " solved") ; } }
0
1,189,837
A11759
A10572
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 jam2; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.ArrayList; public class Test2 { public static void main(String argv[]){ Test2 tb = new Test2(); ArrayList<String> strin = tb.readFile("B-small-attempt0.in"); ArrayList<ArrayList<Integer>> intin = tb.getInt(strin); tb.printInt(intin); ArrayList<String> strout = new ArrayList<String>(); tb.computeDancer(intin, strout); tb.writeResult(strout, "outtest2_mall.txt"); } public void computeDancer(ArrayList<ArrayList<Integer>> intin, ArrayList<String> strout){ if(intin==null || strout==null || intin.size()==0) return; int nTest = intin.get(0).get(0); for(int i=1; i<=nTest; ++i){ int ndancer = intin.get(i).get(0); if(ndancer!=(intin.get(i).size()-3)){ System.out.println("dancer do not match!"); return; } int nsurprise = intin.get(i).get(1); int thresh = intin.get(i).get(2); final int tri =3; int ng = 0; //the googlers have score above threshold for(int j=3; j<intin.get(i).size(); ++j){ int score = intin.get(i).get(j); if(score > (tri*(thresh-1))){ ng++; }else if(score>(tri*(thresh-2)+1)){ int div = score/tri; int residule = score%tri; if(nsurprise > 0){ if(residule <=1 && div==0) continue; // ng++; nsurprise --; } } } //write out the results String line = "Case #"+i+": "+ng; System.out.println(line); strout.add(line); } } public void printInt(ArrayList<ArrayList<Integer>> intin){ if(intin==null ) return; for(ArrayList<Integer> arr:intin){ for(Integer i: arr){ System.out.print(i+","); } System.out.println(); } } public ArrayList<ArrayList<Integer>> getInt(ArrayList<String> strlist){ if(strlist == null) return null; ArrayList<ArrayList<Integer>> intlist = new ArrayList<ArrayList<Integer>>(); for(String s:strlist){ ArrayList<Integer> tarr = new ArrayList<Integer>(); String astr[] = s.split(" "); for(int i=0; i<astr.length; ++i){ int itemp = Integer.parseInt(astr[i]); tarr.add(itemp); } intlist.add(tarr); } return intlist; } public ArrayList<String> readFile(String inname){ if(inname == null) return null; ArrayList<String> arr = new ArrayList<String>(); try{ FileInputStream fstream = new FileInputStream(inname); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { arr.add(strLine); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } return arr; } public void writeResult(ArrayList<String> res, String fname){ if(res == null || res.size()==0) return; try{ FileWriter fstream = new FileWriter(fname); BufferedWriter out = new BufferedWriter(fstream); for(int i=0; i<res.size()-1;++i){ out.write(res.get(i)); out.newLine(); } out.write(res.get(res.size()-1)); out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
1,189,838
A11759
A13147
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Reverser { private static int getMaxNormalCase(int score) { return (int) Math.ceil((double) score / 3); } private static int getMaxSurprisingCase(int score) { if (score >= 2 && score <= 28) { return (int) Math.round((double) score / 3) + 1; } else { return 0; } } public static void main(String[] args) { BufferedReader br; try { br = new BufferedReader(new InputStreamReader(new DataInputStream( new FileInputStream("B-small-attempt3.in")))); FileOutputStream fos = new FileOutputStream("output3.txt", true); Integer inputSize = Integer.parseInt(br.readLine()); for (int i = 1; i <= inputSize; i++) { String line = br.readLine(); int tallerOrEqualCounter = 0; /* * 0 = N = amount of googlers 1 = S = number of surprisings 2 = * p = reference till end ... score of each googler */ String[] splittedLine = line.split(" "); int surprisingCounter = Integer.parseInt(splittedLine[1]); int referenceVal = Integer.parseInt(splittedLine[2]); for (int n = 0; n < Integer.parseInt(splittedLine[0]); n++) { int playerNScore = Integer.parseInt(splittedLine[3 + n]); if (getMaxNormalCase(playerNScore) >= referenceVal) { tallerOrEqualCounter++; } else if (surprisingCounter > 0 && getMaxSurprisingCase(playerNScore) >= referenceVal) { tallerOrEqualCounter++; surprisingCounter--; } } ArrayList<Integer> usedPlayers = new ArrayList<Integer>(); if (surprisingCounter > 0) { for (int n = 0; n < Integer.parseInt(splittedLine[0]); n++) { int playerNScore = Integer .parseInt(splittedLine[3 + n]); if (getMaxNormalCase(playerNScore) >= referenceVal && getMaxSurprisingCase(playerNScore) >= referenceVal) { surprisingCounter--; usedPlayers.add(n); } } } if (surprisingCounter > 0) { for (int n = 0; n < Integer.parseInt(splittedLine[0]); n++) { int playerNScore = Integer .parseInt(splittedLine[3 + n]); if (getMaxNormalCase(playerNScore) < referenceVal && getMaxNormalCase(playerNScore) < referenceVal) { surprisingCounter--; } } } if (surprisingCounter > 0) { for (int n = 0; n < Integer.parseInt(splittedLine[0]); n++) { int playerNScore = Integer .parseInt(splittedLine[3 + n]); if (getMaxNormalCase(playerNScore) >= referenceVal && !usedPlayers.contains(n) && playerNScore >= 2 && playerNScore <= 28) { tallerOrEqualCounter--; surprisingCounter--; } } } String output = "Case #" + i + ": " + tallerOrEqualCounter + "\n"; fos.write(output.getBytes()); } } catch (IOException e) { e.printStackTrace(); } } }
0
1,189,839
A11759
A11074
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package gcj2012; import java.io.FileInputStream; import java.io.PrintStream; import java.util.Scanner; public class B { public static void main(String[] args) throws Exception { new B().run(); } void run() throws Exception { Scanner in = new Scanner(System.in); in = new Scanner(new FileInputStream("B-small-attempt0.in")); PrintStream out = System.out; out = new PrintStream("B-small-attempt0.out"); int T = in.nextInt(); for (int x = 1; x <= T; x++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int t[] = new int[N]; for (int i = 0; i < t.length; i++) t[i] = in.nextInt(); out.printf("Case #%d: %d\n", x, countAtLeastP(t, p, S)); } } int countAtLeastP(int[] t, int p, int s) { int canN = 0; int canS = 0; for (int i : t) if (canAtLeastPNonSurprising(i, p)) canN++; else if (canAtLeastPSurprising(i, p)) canS++; return (canN ) + Math.min(canS, s); } // min total score with best ind score of p is p + (p-1) + (p-1) boolean canAtLeastPNonSurprising(int s, int p) { return s >= 3 * p - 2; } // min surp total score with best ind score of p is p + (p-2) + (p-2) boolean canAtLeastPSurprising(int s, int p) { if (s < 2) return false; return s >= 3 * p - 4; } }
0
1,189,840
A11759
A12486
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 round0; import java.io.BufferedReader; import java.io.FileReader; import java.io.PrintWriter; import java.util.Scanner; public class Dance { BufferedReader _in; PrintWriter _out; int _numTestCases; Input[] _inputs; public Dance(BufferedReader in) throws Exception { this._in = in; this._out = new PrintWriter("answers.out"); } public void calculate() throws Exception { this._inputs = readInputs(); for(int i=0; i < _inputs.length; i++) { processInput(_inputs[i], i+1); } _out.flush(); _out.close(); } private void processInput(Input input, int caseIndex) { int maxGP = 0; int surprisesAvailable = input.S; for(int i=0; i < input.N; i++) { int mp = input.tpts[i]/3; int modulo = input.tpts[i]%3; switch(modulo) { case 0: if(mp >= input.p) { maxGP++; } else if(mp+1 >= input.p && mp > 0 && surprisesAvailable > 0) { maxGP++; surprisesAvailable--; } break; case 1: if(mp+1 >= input.p) { maxGP++; } break; case 2: if(mp+1 >= input.p) { maxGP++; } else if(mp+2 >= input.p && surprisesAvailable > 0) { maxGP++; surprisesAvailable--; } break; default: //not needed } } _out.println("Case #" + caseIndex +": " + maxGP); } private Input[] readInputs() throws Exception { Scanner scanner = new Scanner(_in); _numTestCases = scanner.nextInt(); Input[] inputs = new Input[_numTestCases]; for(int i=0; i < _numTestCases; i++) { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int [] tpts = new int[N]; for(int j=0; j < N; j++) tpts[j] = scanner.nextInt(); inputs[i] = new Input(N, S, p, tpts); } return inputs; } public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader(args[0])); new Dance(in).calculate(); } private class Input { int N; int S; int p; int[] tpts; public Input(int N, int S, int p, int[] tpts) { this.N = N; this.S = S; this.p = p; this.tpts = tpts; } } }
0
1,189,841
A11759
A13130
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 codejam2 { public static void main(String args[])throws IOException { Scanner sc=new Scanner(new FileReader("C:\\Users\\chotu\\Desktop\\B-small-attempt3.in")); PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("C:\\Users\\chotu\\Desktop\\out.txt"))); int t=sc.nextInt(); int n,p,x,sur,nsur,s,c; for(int i=0;i<t;i++) { n=sc.nextInt(); s=sc.nextInt(); p=sc.nextInt(); c=n; for(int j=0;j<n;j++) { x=sc.nextInt(); sur=((x-2)/3)+2; nsur=((x+2)/3); if(x<2) { if(p>x) c--; } else if(x>=2&&x<=28) { if(sur<p && nsur<p) c--; else if(sur>=p && nsur<p) { if(s>0) { s--; } else c--; } } } out.println("Case #"+(i+1)+": "+c); c=0; sur=0;nsur=0; } out.flush(); } }
0
1,189,842
A11759
A10720
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
/* ID: codeKNIGHT LANG: JAVA TASK: */ import java.util.*; import java.math.*; import java.io.*; class dancingWithGooglers { public static void main(String args[])throws IOException { //Scanner in=new Scanner(System.in); Scanner in=new Scanner(new FileReader("C:\\Users\\Lokesh\\Desktop\\B-small-attempt0.in")); //PrintWriter out=new PrintWriter(System.out); //BufferedReader br=new BufferedReader(new FileReader("C:\\Users\\Lokesh\\Desktop\\input.in")); PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter("E:\\programss\\GCJ\\output.txt"))); int t=in.nextInt(),test,i,j,k; int s,p,n,total; for(test=1;test<=t;test++) { n=in.nextInt(); s=in.nextInt(); p=in.nextInt(); int max=n; int x=0,y=0; for(i=0;i<n;i++) { total=in.nextInt(); if(total>=2&&total<=28) { j=(total-2)/3+2; k=(total+2)/3; if(j<p&&k<p) max--; else if(j>=p&&k<p) { if(s>0) s--; else max--; } } else if(total<2) { if(p>total) max--; } } out.println("Case #"+test+": "+max); } out.flush(); System.exit(0); } }
0
1,189,843
A11759
A12190
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Scanner; class ProbB{ public static void main(String[] args) throws FileNotFoundException{ File in; File out; Scanner sc; PrintWriter pw; int T; in = new File("B2.in"); out = new File("B.out"); sc = new Scanner(in); pw = new PrintWriter(out); T = sc.nextInt(); sc.nextLine(); for(int j = 1; j<=T; j++){ int N = sc.nextInt(); int S = sc.nextInt(); int S2 = S; int p = sc.nextInt(); int ans = 0; for(int u = 1; u<=N; u++){ int a = sc.nextInt(); int e = isEligible(a, p); switch(e){ case 2: ans++; break; case 1: S--; ans++; break; } } if(S<0){ ans = ans + S; } pw.println("Case #" + j + ": " + ans); } pw.close(); } static int isEligible(int a, int p){ int lo = a/3; int me = (a - lo)/2; int hi = a - lo - me; if(hi>=p){ return 2; } if(hi==me && hi+1>=p && me != 0){ return 1; } else{ return 0; } } }
0
1,189,844
A11759
A12112
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 B { /** * @param args */ public static void main(String[] args) throws IOException { Scanner s = new Scanner(new FileReader(new File("B-small-attempt0.in"))); PrintWriter out = new PrintWriter(new File("B.out")); StringBuilder resultat =new StringBuilder(""); int T = s.nextInt(); for (int i = 0; i < T; i++) { int r=0; int N = s.nextInt(); int S = s.nextInt(); int P = s.nextInt(); int sr = S; int[] ti = new int[N]; for (int j = 0; j < N; j++) { ti[j] = s.nextInt(); if(ti[j]==0 && P>0) continue; if(ti[j]>=P*3-2) r++; else if(ti[j]>=P*3-4 && sr>0) { r++; sr--; } } if(i!=0) resultat.append("\n"); resultat.append("Case #"+(i+1)+": "+r); } out.print(resultat); out.close(); } }
0
1,189,845
A11759
A11323
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class Main { public static void main(String[] args) { InputStream in = System.in; PrintStream out = System.out; if (args.length > 0) { try { in = new FileInputStream(args[0]); } catch (FileNotFoundException e) { e.printStackTrace(); } } Scanner scanner = new Scanner(in); int cases = scanner.nextInt(); for (int i = 1; i <= cases; ++i) { int n = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); int good = 0; int surprising = 0; for (int j = 0; j < n; ++j) { int t,q,r; t = scanner.nextInt(); if (t > 0) { --t; r = t % 3; q = t / 3; if (q + 1 >= p) { ++good; } else if (r > 0 && q + 2 >= p) { ++surprising; } } else if (p == 0) { ++good; } } out.format("Case #%d: ",i); out.print(good + Math.min(s, surprising)); out.println(); } } }
0
1,189,846
A11759
A13112
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class Googlers { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String fichier ="C:\\result.txt"; int compteurlignes = 0; int nombreCas ; ArrayList<String> googlers = new ArrayList<String>(); ArrayList<String> results = new ArrayList<String>(); //lecture du fichier texte try { InputStream ips=new FileInputStream(fichier); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); String ligne; while ((ligne=br.readLine())!=null){ compteurlignes++; //System.out.println(ligne); if (compteurlignes ==1) { nombreCas = Integer.valueOf(ligne); } else { googlers.add(ligne); //System.out.println(ligne); } } br.close(); //traitement par ligne ArrayList<String> nombres = new ArrayList<String>(); for(int i = 0; i < googlers.size();i++) { ligne = googlers.get(i); //get numbers StringTokenizer st = new StringTokenizer(ligne, " "); while (st.hasMoreTokens()) { nombres.add(st.nextToken()); } int numberGooglers = Integer.parseInt(nombres.get(0)); int surprises = Integer.parseInt(nombres.get(1)); int chiffre = Integer.parseInt(nombres.get(2)); int value = 0; int totalNumber = chiffre *3; for(int x = 0; x < numberGooglers; x++) { int totalMark = Integer.parseInt(nombres.get(x+3)); if(totalNumber ==0) { value++; } else if(totalMark <= totalNumber+2 && totalMark >= totalNumber-2) { value++; } else if(totalMark == totalNumber-3 || totalMark == totalNumber-4) { if (surprises >0 && totalMark != 0) { surprises--; value++; } } else if(totalMark >= totalNumber+3) value++; } results.add(String.valueOf(value)); System.out.println("result : "+value); //clean arrayList nombres = new ArrayList<String>(); } } catch (Exception e) { System.out.println(e.toString()); } //écrire dans le fichier try { FileWriter fw = new FileWriter (fichier); BufferedWriter bw = new BufferedWriter (fw); PrintWriter fichierSortie = new PrintWriter (bw); for (int w =0; w<results.size();w++) { fichierSortie.println ("Case #"+(w+1)+": "+results.get(w)); } fichierSortie.close(); System.out.println("Le fichier " + fichier + " a été créé!"); } catch (Exception e) { System.out.println(e.toString()); } } }
0
1,189,847
A11759
A13111
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.math.BigInteger; import java.util.*; public class GB { String s = null; String[] sp = null; public void run() throws Exception{ BufferedReader br = new BufferedReader(new FileReader("B-small-attempt0.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("OUTPUT.txt")); s = br.readLine(); int T = Integer.parseInt(s); int t = 1; while(t <= T){ s = br.readLine(); sp = s.split(" "); int N = Integer.parseInt(sp[0]); int S = Integer.parseInt(sp[1]); int p = Integer.parseInt(sp[2]); int[] sco = new int[N]; for(int i = 0; i < N; i++){ sco[i] = Integer.parseInt(sp[i+3]); } int ans = 0; if(p == 0){ ans = N; } else if(p == 1){ for(int i = 0; i < sco.length; i++){ if(sco[i] > 0){ ans++; } } } else{ int ut = p * 3 - 2; int bt = p * 3 - 4; int bn = 0; for(int i = 0; i < sco.length; i++){ if(sco[i] >= ut){ ans++; } else if(sco[i] >= bt){ bn++; } } ans += Math.min(S, bn); } bw.write("Case #" + t + ": " + ans + "\n"); t++; } bw.close(); } public static void main(String[] args) throws Exception { GB b = new GB(); b.run(); } }
0
1,189,848
A11759
A10296
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package B; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; public class B { public static void main(String[] args) { B b = new B(); b.run(args[0], "result"); } public B() { } public void run(String inputFile, String outputFile) { String directory = this.getClass().getResource("").getPath() + "\\"; inputFile = directory + inputFile; outputFile = directory + outputFile; FileReader fileReader = null; BufferedReader bufferedReader = null; try { fileReader = new FileReader(inputFile); bufferedReader = new BufferedReader(fileReader); } catch (Exception e) { e.printStackTrace(); return; } if (bufferedReader != null) { int testCount = 0; try { testCount = Integer.parseInt(bufferedReader.readLine()); } catch (Exception e) { e.printStackTrace(); return; } StringBuilder builder = new StringBuilder(3400); for (int i = 1; i <= testCount; i++) { if (i > 1) { builder.append("\r\n"); } builder.append("Case #"); builder.append(i); builder.append(": "); String input = null; try { input = bufferedReader.readLine(); } catch (Exception e) { e.printStackTrace(); return; } String[] strs = input.split(" "); int length = strs.length; int[] ints = new int[length]; for (int j = 0; j < length; j++) { try { ints[j] = Integer.parseInt(strs[j]); } catch (Exception e) { } } int case1 = 0; int case2 = 0; int case3 = 0; int s = ints[1]; int p = ints[2]; int a = 3 * p - 4; int b = a + 2; if (a < 2) { a = 2; } if (b < 2) { b = 2; } for (int j = 3; j < length; j++) { int test = ints[j]; if (test >= a) { if (test > 28) { case3++; } else if (test >= b) { case1++; } else { case2++; } } else if (p == 1 && test >= 1) { case3++; } else if (p == 0) { case3++; } } if (case2 > s) { case2 = s; } builder.append(case1 + case2 + case3); } //System.out.println(builder.toString()); try { FileWriter writer = new FileWriter(outputFile); writer.append(builder.toString()); writer.flush(); writer.close(); } catch (Exception e) { e.printStackTrace(); return; } try { bufferedReader.close(); fileReader.close(); } catch (Exception e) { e.printStackTrace(); } } } }
0
1,189,849
A11759
A12543
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 problem1; import java.io.*; import java.util.IllegalFormatException; import java.util.regex.Matcher; import java.util.regex.Pattern; import javax.swing.JFileChooser; import javax.swing.JOptionPane; /** * TextIO provides a set of static methods for reading and writing text. By default, it reads * from standard input and writes to standard output, but it is possible to redirect the input * and output to files or to other input and output streams. When the standard input and output * streams are being used, the input methods will not produce an error; instead, the user is * repeatedly prompted for input until a legal input is entered. (If standard input has been * changed externally, as by file redirection on the command line, this is not a reasonable * behavior; to handle this case, TextIO will give up after 10 consecutive illegal inputs and * will throw an IllegalArgumentException.) For the most part, any other * error will be translated into an IllegalArguementException. * <p>For writing to standard output, the output methods in this class pretty much * duplicate the functionality of System.out, and System.out can be used interchangeably with them. * <p>This class does not use optimal Java programming practices. It is designed specifically to be easily * usable even by a beginning programmer who has not yet learned about objects and exceptions. Therefore, * everything is in a single source file that compiles into a single class file, all the methods are * static methods, and none of the methods throw exceptions that would require try...catch statements. * Also for this reason, all exceptions are converted into IllegalArgumentExceptions, even when this * exception type doesn't really make sense. * <p>This class requires Java 5.0 or higher. (A previous version of TextIO required only Java 1.1; * this version should work with any source code that used the previous version, but it has some new * features, including the type of formatted output that was introduced in Java 5 and the ability to * use files and streams.) */ public class TextIO { /* Modified November 2007 to empty the TextIO input buffer when switching from one * input source to another. This fixes a bug that allows input from the previous input * source to be read after the new source has been selected. */ /** * The value returned by the peek() method when the input is at end-of-file. * (The value of this constant is (char)0xFFFF.) */ public final static char EOF = (char)0xFFFF; /** * The value returned by the peek() method when the input is at end-of-line. * The value of this constant is the character '\n'. */ public final static char EOLN = '\n'; // The value returned by peek() when at end-of-line. /** * After this method is called, input will be read from standard input (as it * is in the default state). If a file or stream was previously the input source, that file * or stream is closed. */ public static void readStandardInput() { if (readingStandardInput) return; try { in.close(); } catch (Exception e) { } emptyBuffer(); // Added November 2007 in = standardInput; inputFileName = null; readingStandardInput = true; inputErrorCount = 0; } /** * After this method is called, input will be read from inputStream, provided it * is non-null. If inputStream is null, then this method has the same effect * as calling readStandardInput(); that is, future input will come from the * standard input stream. */ public static void readStream(InputStream inputStream) { if (inputStream == null) readStandardInput(); else readStream(new InputStreamReader(inputStream)); } /** * After this method is called, input will be read from inputStream, provided it * is non-null. If inputStream is null, then this method has the same effect * as calling readStandardInput(); that is, future input will come from the * standard input stream. */ public static void readStream(Reader inputStream) { if (inputStream == null) readStandardInput(); else { if ( inputStream instanceof BufferedReader) in = (BufferedReader)inputStream; else in = new BufferedReader(inputStream); emptyBuffer(); // Added November 2007 inputFileName = null; readingStandardInput = false; inputErrorCount = 0; } } /** * Opens a file with a specified name for input. If the file name is null, this has * the same effect as calling readStandardInput(); that is, input will be read from standard * input. If an * error occurs while trying to open the file, an exception of type IllegalArgumentException * is thrown, and the input source is not changed. If the file is opened * successfully, then after this method is called, all of the input routines will read * from the file, instead of from standard input. */ public static void readFile(String fileName) { if (fileName == null) // Go back to reading standard input readStandardInput(); else { BufferedReader newin; try { newin = new BufferedReader( new FileReader(fileName) ); } catch (Exception e) { throw new IllegalArgumentException("Can't open file \"" + fileName + "\" for input.\n" + "(Error :" + e + ")"); } if (! readingStandardInput) { // close current input stream try { in.close(); } catch (Exception e) { } } emptyBuffer(); // Added November 2007 in = newin; readingStandardInput = false; inputErrorCount = 0; inputFileName = fileName; } } /** * Puts a GUI file-selection dialog box on the screen in which the user can select * an input file. If the user cancels the dialog instead of selecting a file, it is * not considered an error, but the return value of the subroutine is false. * If the user does select a file, but there is an error while trying to open the * file, then an exception of type IllegalArgumentException is thrown. Finally, if * the user selects a file and it is successfully opened, then the return value of the * subroutine is true, and the input routines will read from the file, instead of * from standard input. If the user cancels, or if any error occurs, then the * previous input source is not changed. * <p>NOTE: Calling this method starts a GUI user interface thread, which can continue * to run even if the thread that runs the main program ends. If you use this method * in a non-GUI program, it might be necessary to call System.exit(0) at the end of the main() * routine to shut down the Java virtual machine completely. */ public static boolean readUserSelectedFile() { if (fileDialog == null) fileDialog = new JFileChooser(); fileDialog.setDialogTitle("Select File for Input"); int option = fileDialog.showOpenDialog(null); if (option != JFileChooser.APPROVE_OPTION) return false; File selectedFile = fileDialog.getSelectedFile(); BufferedReader newin; try { newin = new BufferedReader( new FileReader(selectedFile) ); } catch (Exception e) { throw new IllegalArgumentException("Can't open file \"" + selectedFile.getName() + "\" for input.\n" + "(Error :" + e + ")"); } if (!readingStandardInput) { // close current file try { in.close(); } catch (Exception e) { } } emptyBuffer(); // Added November 2007 in = newin; inputFileName = selectedFile.getName(); readingStandardInput = false; inputErrorCount = 0; return true; } /** * After this method is called, output will be written to standard output (as it * is in the default state). If a file or stream was previously open for output, it * will be closed. */ public static void writeStandardOutput() { if (writingStandardOutput) return; try { out.close(); } catch (Exception e) { } outputFileName = null; outputErrorCount = 0; out = standardOutput; writingStandardOutput = true; } /** * After this method is called, output will be sent to outputStream, provided it * is non-null. If outputStream is null, then this method has the same effect * as calling writeStandardOutput(); that is, future output will be sent to the * standard output stream. */ public static void writeStream(OutputStream outputStream) { if (outputStream == null) writeStandardOutput(); else writeStream(new PrintWriter(outputStream)); } /** * After this method is called, output will be sent to outputStream, provided it * is non-null. If outputStream is null, then this method has the same effect * as calling writeStandardOutput(); that is, future output will be sent to the * standard output stream. */ public static void writeStream(PrintWriter outputStream) { if (outputStream == null) writeStandardOutput(); else { out = outputStream; outputFileName = null; outputErrorCount = 0; writingStandardOutput = false; } } /** * Opens a file with a specified name for output. If the file name is null, this has * the same effect as calling writeStandardOutput(); that is, output will be sent to standard * output. If an * error occurs while trying to open the file, an exception of type IllegalArgumentException * is thrown. If the file is opened successfully, then after this method is called, * all of the output routines will write to the file, instead of to standard output. * If an error occurs, the output destination is not changed. * <p>NOTE: Calling this method starts a GUI user interface thread, which can continue * to run even if the thread that runs the main program ends. If you use this method * in a non-GUI program, it might be necessary to call System.exit(0) at the end of the main() * routine to shut down the Java virtual machine completely. */ public static void writeFile(String fileName) { if (fileName == null) // Go back to reading standard output writeStandardOutput(); else { PrintWriter newout; try { newout = new PrintWriter(new FileWriter(fileName)); } catch (Exception e) { throw new IllegalArgumentException("Can't open file \"" + fileName + "\" for output.\n" + "(Error :" + e + ")"); } if (!writingStandardOutput) { try { out.close(); } catch (Exception e) { } } out = newout; writingStandardOutput = false; outputFileName = fileName; outputErrorCount = 0; } } /** * Puts a GUI file-selection dialog box on the screen in which the user can select * an output file. If the user cancels the dialog instead of selecting a file, it is * not considered an error, but the return value of the subroutine is false. * If the user does select a file, but there is an error while trying to open the * file, then an exception of type IllegalArgumentException is thrown. Finally, if * the user selects a file and it is successfully opened, then the return value of the * subroutine is true, and the output routines will write to the file, instead of * to standard output. If the user cancels, or if an error occurs, then the current * output destination is not changed. */ public static boolean writeUserSelectedFile() { if (fileDialog == null) fileDialog = new JFileChooser(); fileDialog.setDialogTitle("Select File for Output"); File selectedFile; while (true) { int option = fileDialog.showSaveDialog(null); if (option != JFileChooser.APPROVE_OPTION) return false; // user canceled selectedFile = fileDialog.getSelectedFile(); if (selectedFile.exists()) { int response = JOptionPane.showConfirmDialog(null, "The file \"" + selectedFile.getName() + "\" already exists. Do you want to replace it?", "Replace existing file?", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if (response == JOptionPane.YES_OPTION) break; } else { break; } } PrintWriter newout; try { newout = new PrintWriter(new FileWriter(selectedFile)); } catch (Exception e) { throw new IllegalArgumentException("Can't open file \"" + selectedFile.getName() + "\" for output.\n" + "(Error :" + e + ")"); } if (!writingStandardOutput) { try { out.close(); } catch (Exception e) { } } out = newout; writingStandardOutput = false; outputFileName = selectedFile.getName(); outputErrorCount = 0; return true; } /** * If TextIO is currently reading from a file, then the return value is the name of the file. * If the class is reading from standard input or from a stream, then the return value is null. */ public static String getInputFileName() { return inputFileName; } /** * If TextIO is currently writing to a file, then the return value is the name of the file. * If the class is writing to standard output or to a stream, then the return value is null. */ public static String getOutputFileName() { return outputFileName; } // *************************** Output Methods ********************************* /** * Write a single value to the current output destination, using the default format * and no extra spaces. This method will handle any type of parameter, even one * whose type is one of the primitive types. */ public static void put(Object x) { out.print(x); out.flush(); if (out.checkError()) outputError("Error while writing output."); } /** * Write a single value to the current output destination, using the default format * and outputting at least minChars characters (with extra spaces added before the * output value if necessary). This method will handle any type of parameter, even one * whose type is one of the primitive types. * @param x The value to be output, which can be of any type. * @param minChars The minimum number of characters to use for the output. If x requires fewer * then this number of characters, then extra spaces are added to the front of x to bring * the total up to minChars. If minChars is less than or equal to zero, then x will be printed * in the minumum number of spaces possible. */ public static void put(Object x, int minChars) { if (minChars <= 0) out.print(x); else out.printf("%" + minChars + "s", x); out.flush(); if (out.checkError()) outputError("Error while writing output."); } /** * This is equivalent to put(x), followed by an end-of-line. */ public static void putln(Object x) { out.println(x); out.flush(); if (out.checkError()) outputError("Error while writing output."); } /** * This is equivalent to put(x,minChars), followed by an end-of-line. */ public static void putln(Object x, int minChars) { put(x,minChars); out.println(); out.flush(); if (out.checkError()) outputError("Error while writing output."); } /** * Write an end-of-line character to the current output destination. */ public static void putln() { out.println(); out.flush(); if (out.checkError()) outputError("Error while writing output."); } /** * Writes formatted output values to the current output destination. This method has the * same function as System.out.printf(); the details of formatted output are not discussed * here. The first parameter is a string that describes the format of the output. There * can be any number of additional parameters; these specify the values to be output and * can be of any type. This method will throw an IllegalArgumentException if the * format string is null or if the format string is illegal for the values that are being * output. */ public static void putf(String format, Object... items) { if (format == null) throw new IllegalArgumentException("Null format string in TextIO.putf() method."); try { out.printf(format,items); } catch (IllegalFormatException e) { throw new IllegalArgumentException("Illegal format string in TextIO.putf() method."); } out.flush(); if (out.checkError()) outputError("Error while writing output."); } // *************************** Input Methods ********************************* /** * Test whether the next character in the current input source is an end-of-line. Note that * this method does NOT skip whitespace before testing for end-of-line -- if you want to do * that, call skipBlanks() first. */ public static boolean eoln() { return peek() == '\n'; } /** * Test whether the next character in the current input source is an end-of-file. Note that * this method does NOT skip whitespace before testing for end-of-line -- if you want to do * that, call skipBlanks() or skipWhitespace() first. */ public static boolean eof() { return peek() == EOF; } /** * Reads the next character from the current input source. The character can be a whitespace * character; compare this to the getChar() method, which skips over whitespace and returns the * next non-whitespace character. An end-of-line is always returned as the character '\n', even * when the actual end-of-line in the input source is something else, such as '\r' or "\r\n". * This method will throw an IllegalArgumentException if the input is at end-of-file (which will * not ordinarily happen if reading from standard input). */ public static char getAnyChar() { return readChar(); } /** * Returns the next character in the current input source, without actually removing that * character from the input. The character can be a whitespace character and can be the * end-of-file character (specified by the constant TextIO.EOF).An end-of-line is always returned * as the character '\n', even when the actual end-of-line in the input source is something else, * such as '\r' or "\r\n". This method never causes an error. */ public static char peek() { return lookChar(); } /** * Skips over any whitespace characters, except for end-of-lines. After this method is called, * the next input character is either an end-of-line, an end-of-file, or a non-whitespace character. * This method never causes an error. (Ordinarily, end-of-file is not possible when reading from * standard input.) */ public static void skipBlanks() { char ch=lookChar(); while (ch != EOF && ch != '\n' && Character.isWhitespace(ch)) { readChar(); ch = lookChar(); } } /** * Skips over any whitespace characters, including for end-of-lines. After this method is called, * the next input character is either an end-of-file or a non-whitespace character. * This method never causes an error. (Ordinarily, end-of-file is not possible when reading from * standard input.) */ private static void skipWhitespace() { char ch=lookChar(); while (ch != EOF && Character.isWhitespace(ch)) { readChar(); if (ch == '\n' && readingStandardInput && writingStandardOutput) { out.print("? "); out.flush(); } ch = lookChar(); } } /** * Skips whitespace characters and then reads a value of type byte from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static byte getlnByte() { byte x=getByte(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type short from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static short getlnShort() { short x=getShort(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type int from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static int getlnInt() { int x=getInt(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type long from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static long getlnLong() { long x=getLong(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type float from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static float getlnFloat() { float x=getFloat(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type double from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static double getlnDouble() { double x=getDouble(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type char from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). Note that the value * that is returned will be a non-whitespace character; compare this with the getAnyChar() method. * When using standard IO, this will not produce an error. In other cases, an error can occur if * an end-of-file is encountered. */ public static char getlnChar() { char x=getChar(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads a value of type boolean from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. * <p>Legal inputs for a boolean input are: true, t, yes, y, 1, false, f, no, n, and 0; letters can be * either upper case or lower case. One "word" of input is read, using the getWord() method, and it * must be one of these; note that the "word" must be terminated by a whitespace character (or end-of-file). */ public static boolean getlnBoolean() { boolean x=getBoolean(); emptyBuffer(); return x; } /** * Skips whitespace characters and then reads one "word" from input, discarding the rest of * the current line of input (including the next end-of-line character, if any). A word is defined as * a sequence of non-whitespace characters (not just letters!). When using standard IO, * this will not produce an error. In other cases, an IllegalArgumentException will be thrown * if an end-of-file is encountered. */ public static String getlnWord() { String x=getWord(); emptyBuffer(); return x; } /** * This is identical to getln(). */ public static String getlnString() { return getln(); } /** * Reads all the characters from the current input source, up to the next end-of-line. The end-of-line * is read but is not included in the return value. Any other whitespace characters on the line are retained, * even if they occur at the start of input. The return value will be an empty string if there are no * no characters before the end-of-line. When using standard IO, this will not produce an error. * In other cases, an IllegalArgumentException will be thrown if an end-of-file is encountered. */ public static String getln() { StringBuffer s = new StringBuffer(100); char ch = readChar(); while (ch != '\n') { s.append(ch); ch = readChar(); } return s.toString(); } /** * Skips whitespace characters and then reads a value of type byte from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static byte getByte() { return (byte)readInteger(-128L,127L); } /** * Skips whitespace characters and then reads a value of type short from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static short getShort() { return (short)readInteger(-32768L,32767L); } /** * Skips whitespace characters and then reads a value of type int from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static int getInt() { return (int)readInteger(Integer.MIN_VALUE, Integer.MAX_VALUE); } /** * Skips whitespace characters and then reads a value of type long from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static long getLong() { return readInteger(Long.MIN_VALUE, Long.MAX_VALUE); } /** * Skips whitespace characters and then reads a single non-whitespace character from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error. In other cases, an IllegalArgumentException will be thrown if an end-of-file * is encountered. */ public static char getChar() { skipWhitespace(); return readChar(); } /** * Skips whitespace characters and then reads a value of type float from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static float getFloat() { float x = 0.0F; while (true) { String str = readRealString(); if (str == null) { errorMessage("Floating point number not found.", "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE); } else { try { x = Float.parseFloat(str); } catch (NumberFormatException e) { errorMessage("Illegal floating point input, " + str + ".", "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE); continue; } if (Float.isInfinite(x)) { errorMessage("Floating point input outside of legal range, " + str + ".", "Real number in the range " + (-Float.MAX_VALUE) + " to " + Float.MAX_VALUE); continue; } break; } } inputErrorCount = 0; return x; } /** * Skips whitespace characters and then reads a value of type double from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. */ public static double getDouble() { double x = 0.0; while (true) { String str = readRealString(); if (str == null) { errorMessage("Floating point number not found.", "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE); } else { try { x = Double.parseDouble(str); } catch (NumberFormatException e) { errorMessage("Illegal floating point input, " + str + ".", "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE); continue; } if (Double.isInfinite(x)) { errorMessage("Floating point input outside of legal range, " + str + ".", "Real number in the range " + (-Double.MAX_VALUE) + " to " + Double.MAX_VALUE); continue; } break; } } inputErrorCount = 0; return x; } /** * Skips whitespace characters and then reads one "word" from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. A word is defined as * a sequence of non-whitespace characters (not just letters!). When using standard IO, * this will not produce an error. In other cases, an IllegalArgumentException will be thrown * if an end-of-file is encountered. */ public static String getWord() { skipWhitespace(); StringBuffer str = new StringBuffer(50); char ch = lookChar(); while (ch == EOF || !Character.isWhitespace(ch)) { str.append(readChar()); ch = lookChar(); } return str.toString(); } /** * Skips whitespace characters and then reads a value of type boolean from input. Any additional characters on * the current line of input are retained, and will be read by the next input operation. When using standard IO, * this will not produce an error; the user will be prompted repeatedly for input until a legal value * is input. In other cases, an IllegalArgumentException will be thrown if a legal value is not found. * <p>Legal inputs for a boolean input are: true, t, yes, y, 1, false, f, no, n, and 0; letters can be * either upper case or lower case. One "word" of input is read, using the getWord() method, and it * must be one of these; note that the "word" must be terminated by a whitespace character (or end-of-file). */ public static boolean getBoolean() { boolean ans = false; while (true) { String s = getWord(); if ( s.equalsIgnoreCase("true") || s.equalsIgnoreCase("t") || s.equalsIgnoreCase("yes") || s.equalsIgnoreCase("y") || s.equals("1") ) { ans = true; break; } else if ( s.equalsIgnoreCase("false") || s.equalsIgnoreCase("f") || s.equalsIgnoreCase("no") || s.equalsIgnoreCase("n") || s.equals("0") ) { ans = false; break; } else errorMessage("Illegal boolean input value.", "one of: true, false, t, f, yes, no, y, n, 0, or 1"); } inputErrorCount = 0; return ans; } // ***************** Everything beyond this point is private implementation detail ******************* private static String inputFileName; // Name of file that is the current input source, or null if the source is not a file. private static String outputFileName; // Name of file that is the current output destination, or null if the destination is not a file. private static JFileChooser fileDialog; // Dialog used by readUserSelectedFile() and writeUserSelectedFile() private final static BufferedReader standardInput = new BufferedReader(new InputStreamReader(System.in)); // wraps standard input stream private final static PrintWriter standardOutput = new PrintWriter(System.out); // wraps standard output stream private static BufferedReader in = standardInput; // Stream that data is read from; the current input source. private static PrintWriter out = standardOutput; // Stream that data is written to; the current output destination. private static boolean readingStandardInput = true; private static boolean writingStandardOutput = true; private static int inputErrorCount; // Number of consecutive errors on standard input; reset to 0 when a successful read occurs. private static int outputErrorCount; // Number of errors on standard output since it was selected as the output destination. private static Matcher integerMatcher; // Used for reading integer numbers; created from the integer Regex Pattern. private static Matcher floatMatcher; // Used for reading floating point numbers; created from the floatRegex Pattern. private final static Pattern integerRegex = Pattern.compile("(\\+|-)?[0-9]+"); private final static Pattern floatRegex = Pattern.compile("(\\+|-)?(([0-9]+(\\.[0-9]*)?)|(\\.[0-9]+))((e|E)(\\+|-)?[0-9]+)?"); private static String buffer = null; // One line read from input. private static int pos = 0; // Position of next char in input line that has not yet been processed. private static String readRealString() { // read chars from input following syntax of real numbers skipWhitespace(); if (lookChar() == EOF) return null; if (floatMatcher == null) floatMatcher = floatRegex.matcher(buffer); floatMatcher.region(pos,buffer.length()); if (floatMatcher.lookingAt()) { String str = floatMatcher.group(); pos = floatMatcher.end(); return str; } else return null; } private static String readIntegerString() { // read chars from input following syntax of integers skipWhitespace(); if (lookChar() == EOF) return null; if (integerMatcher == null) integerMatcher = integerRegex.matcher(buffer); integerMatcher.region(pos,buffer.length()); if (integerMatcher.lookingAt()) { String str = integerMatcher.group(); pos = integerMatcher.end(); return str; } else return null; } private static long readInteger(long min, long max) { // read long integer, limited to specified range long x=0; while (true) { String s = readIntegerString(); if (s == null){ errorMessage("Integer value not found in input.", "Integer in the range " + min + " to " + max); } else { String str = s.toString(); try { x = Long.parseLong(str); } catch (NumberFormatException e) { errorMessage("Illegal integer input, " + str + ".", "Integer in the range " + min + " to " + max); continue; } if (x < min || x > max) { errorMessage("Integer input outside of legal range, " + str + ".", "Integer in the range " + min + " to " + max); continue; } break; } } inputErrorCount = 0; return x; } private static void errorMessage(String message, String expecting) { // Report error on input. if (readingStandardInput && writingStandardOutput) { // inform user of error and force user to re-enter. out.println(); out.print(" *** Error in input: " + message + "\n"); out.print(" *** Expecting: " + expecting + "\n"); out.print(" *** Discarding Input: "); if (lookChar() == '\n') out.print("(end-of-line)\n\n"); else { while (lookChar() != '\n') // Discard and echo remaining chars on the current line of input. out.print(readChar()); out.print("\n\n"); } out.print("Please re-enter: "); out.flush(); readChar(); // discard the end-of-line character inputErrorCount++; if (inputErrorCount >= 10) throw new IllegalArgumentException("Too many input consecutive input errors on standard input."); } else if (inputFileName != null) throw new IllegalArgumentException("Error while reading from file \"" + inputFileName + "\":\n" + message + "\nExpecting " + expecting); else throw new IllegalArgumentException("Error while reading from inptu stream:\n" + message + "\nExpecting " + expecting); } private static char lookChar() { // return next character from input if (buffer == null || pos > buffer.length()) fillBuffer(); if (buffer == null) return EOF; else if (pos == buffer.length()) return '\n'; else return buffer.charAt(pos); } private static char readChar() { // return and discard next character from input char ch = lookChar(); if (buffer == null) { if (readingStandardInput) throw new IllegalArgumentException("Attempt to read past end-of-file in standard input???"); else throw new IllegalArgumentException("Attempt to read past end-of-file in file \"" + inputFileName + "\"."); } pos++; return ch; } private static void fillBuffer() { // Wait for user to type a line and press return, try { buffer = in.readLine(); } catch (Exception e) { if (readingStandardInput) throw new IllegalArgumentException("Error while reading standard input???"); else if (inputFileName != null) throw new IllegalArgumentException("Error while attempting to read from file \"" + inputFileName + "\"."); else throw new IllegalArgumentException("Errow while attempting to read form an input stream."); } pos = 0; floatMatcher = null; integerMatcher = null; } private static void emptyBuffer() { // discard the rest of the current line of input buffer = null; } private static void outputError(String message) { // Report an error on output. if (writingStandardOutput) { System.err.println("Error occurred in TextIO while writing to standard output!!"); outputErrorCount++; if (outputErrorCount >= 10) { outputErrorCount = 0; throw new IllegalArgumentException("Too many errors while writing to standard output."); } } else if (outputFileName != null){ throw new IllegalArgumentException("Error occurred while writing to file \"" + outputFileName+ "\":\n " + message); } else { throw new IllegalArgumentException("Error occurred while writing to output stream:\n " + message); } } } // end of class TextIO
0
1,189,850
A11759
A11796
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 ex2; import java.util.Scanner; public class main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); for(int i = 0; i < n; i++) { int g = in.nextInt(); // participants int su = in.nextInt(); // anomalies int s = in.nextInt(); // note maximum int ctn = 0; for(int j = 0; j < g; j++) { int p = in.nextInt(); // score if(3*s <= p || 2*(s-1)+s <= p || (s-1) + 2*s <= p) ctn++; else if (su > 0 && p > 0 && ((s-2)+2*s <= p || 2*(s-2)+s <= p || (s-2)+(s-1)+s <= p)) { ctn++; su--;} } System.out.println("Case #"+(i+1)+": "+ctn); } } }
0
1,189,851
A11759
A10032
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 GoogleDancing { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new FileReader("B-small-attempt3.in.txt")); int T = Integer.parseInt(read.readLine()); for(int i = 1; i <= T; i++){ StringTokenizer st = new StringTokenizer(read.readLine()); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int P = Integer.parseInt(st.nextToken()); if(P == 0) { System.out.println("Case #" + i + ": " + N); continue; } int total = 0; for(int j = 0; j < N; j++) { int temp = Integer.parseInt(st.nextToken()); if(temp == 0) continue; int q = temp/3 + ((temp%3 == 0)? 0:1); if(P <= q) total++; else if(temp%3 != 1) { if(P <= q+1 && S > 0) { total++; S--; } } } System.out.println("Case #" + i + ": " + total); } } }
0
1,189,852
A11759
A12217
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 q2 { public static void main(String args[]) { Scanner obj = new Scanner(System.in); int T = obj.nextInt(); try { FileOutputStream out = new FileOutputStream("myfile.txt"); PrintStream p = new PrintStream(out); for (int i = 0; i < T; i++) { int N = obj.nextInt(); int S = obj.nextInt(); int pp = obj.nextInt(); int count2 = 0; int count4 = 0; for (int j = 0; j < N; j++) { int num = obj.nextInt(); if (num >= (3 * pp - 2)) { count2++;} else if(num ==0){ count2=count2; } else if (num >= (3 * pp - 4)) { count4++; } } System.out.println(count4); if (count4 > S) { count2 = count2 + S; } else { count2 = count2 + count4; } p.print("Case #" + (i+1) + ": " + count2); p.println(); } p.close(); } catch (Exception e) { System.err.println("Error writing to file"); } } }
0
1,189,853
A11759
A11039
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package fixjava; /** * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in * Java. * * <code> final HashSet<String> allNames = new HashSet<String>(); Lambda<Set<String>, Void> addAllIfNotNull = new Lambda<Set<String>, Void>() { public Void apply(Set<String> newNames) { if (allNames != null) allNames.addAll(newNames); return null; } }; allNames.add(cell.getName()); addAllIfNotNull.apply(cell.getValues("Main_name")); addAllIfNotNull.apply(cell.getValues("Other_name")); addAllIfNotNull.apply(cell.getValues("Tree_node")); addAllIfNotNull.apply(cell.getValues("Lineage_name")); * </code> */ public interface Lambda<P, V> { public V apply(P param); }
0
1,189,854
A11759
A12158
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) { bestResultForScores(); new DancingWithTheGooglers().go(); } public static int[] bestUnsurprisingResultForScore = new int[31]; public static int[] bestSurprisingResultForScore = new int[31]; public static int[] upgradeBySurprise = new int[31]; private static void bestResultForScores() { for (int a = 0; a <= 10; a++) for (int b = 0; b <= 10; b++) for (int c = 0; c <= 10; c++) { int bestResult = Math.max(a, Math.max(b, c)); int worstResult = Math.min(a, Math.min(b, c)); int spread = bestResult - worstResult; int totalScore = a + b + c; switch (spread) { case 0: case 1: if (bestResult > bestUnsurprisingResultForScore[totalScore]) bestUnsurprisingResultForScore[totalScore] = bestResult; break; case 2: if (bestResult > bestSurprisingResultForScore[totalScore]) bestSurprisingResultForScore[totalScore] = bestResult; } } for(int i = 0; i < 31; i++) { upgradeBySurprise[i] = Math.max(0, (bestSurprisingResultForScore[i] - bestUnsurprisingResultForScore[i])); } } private void go() { Scanner sc = new Scanner(System.in); int numTestCases = Integer.parseInt(sc.nextLine()); for (int caseNum = 1; caseNum <= numTestCases; caseNum++) { System.out.print("Case #" + caseNum + ": "); int numGooglers = sc.nextInt(); int numSurprisingTriplets = sc.nextInt(); int p = sc.nextInt(); int[] totalPoints = new int[numGooglers]; for (int i = 0; i < numGooglers; i++) { totalPoints[i] = sc.nextInt(); } int[] bestPossibleScores = new int[31]; for (int i = 0; i < numGooglers; i++) { bestPossibleScores[bestUnsurprisingResultForScore[totalPoints[i]]]++; } int sum = 0; for (int i = p; i < 31; i++) { sum += bestPossibleScores[i]; } for(int totalScore : totalPoints) { if(bestUnsurprisingResultForScore[totalScore] == p-1 && bestSurprisingResultForScore[totalScore] == p && numSurprisingTriplets > 0) { numSurprisingTriplets--; sum++; } } System.out.println(sum); } } }
0
1,189,855
A11759
A11907
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.*; /** * @author Seitaro Sakoda * */ public class DancingWithTheGooglers { public static void main(String[] args) throws Exception { DataReader dr = new DataReader(); int NoT = dr.readInt(); ArrayList<String> ans = new ArrayList<String>(); for(int not=0;not<NoT;not++){ int[] tmp = dr.readInts(); int[] t = new int[tmp.length-3]; System.arraycopy(tmp, 3, t, 0, t.length); ans.add("Case #"+(not+1)+": "+doit(tmp[0],tmp[1],tmp[2],t)); } dr.close(); DataWriter dw = new DataWriter(); for(int not=0;not<NoT;not++) dw.writeLine(ans.get(not)); dw.close(); } /** * @param c * @param data * @return */ private static int doit(int N, int S, int p, int[] t) { int[] ns = new int[t.length]; // the best score in not-surprising case int[] ss = new int[t.length]; // the best score in surprising case for(int i=0;i<t.length;i++){ switch(t[i]%3){ case 0: // 7 7 7 or 6 7 8 ns[i] = t[i]/3; if(t[i] == 30){ ss[i]=10; }else if(t[i] == 0){ ss[i]=0; }else{ ss[i] = (t[i]/3 + 1); } break; case 1: // 7 7 8 or 6 8 8 ns[i] = t[i]/3 + 1; ss[i] = t[i]/3 + 1; break; case 2: // 7 8 8 or 7 8 9 ns[i] = t[i]/3 + 1; ss[i] = t[i] == 29 ? 10 : (t[i]/3 + 2); break; default: break; } } int nc = 0; int sc = 0; for(int i=0;i<t.length;i++){ if(ns[i]>=p) nc++; if(ns[i]<p && ss[i]>=p) sc++; } return nc + (sc > S ? S : sc); } static class DataReader { public BufferedReader br; public DataReader(String filename) throws Exception { br = new BufferedReader(new FileReader(filename)); } public DataReader() throws Exception { this("data.in"); } private String readLine() throws Exception { return br.readLine(); } public int readInt() throws Exception { return Integer.parseInt(readLine()); } public int[] readInts() throws Exception { String[] tmp = readLine().split(" "); int[] ret = new int[tmp.length]; for(int i=0;i<tmp.length;i++) ret[i] = Integer.parseInt(tmp[i]); return ret; } public String readString() throws Exception { return readLine(); } public String[] readStrings() throws Exception { return readLine().split(" "); } public void close() throws Exception { br.close(); } } static class DataWriter { public BufferedWriter bw; public DataWriter(String filename) throws Exception { bw = new BufferedWriter(new FileWriter(filename)); } public DataWriter() throws Exception { this("data.out"); } public void writeLine(String line) throws Exception { bw.write(line); bw.newLine(); } public void close() throws Exception { bw.flush(); bw.close(); } } }
0
1,189,856
A11759
A10580
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.code.jam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.ListIterator; public class DancingWithTheGooglers { final static String fileNameIn = "B-small-attempt0.in"; final static String fileNameOut = "B-small-attempt0.out"; private static int solve(int S, int p, List<Integer> t) { int count = 0; for (int i = 0; i < t.size(); i++) { int bestResultNotSurprising = getBestResultNotSurprising(t.get(i)); int bestResultSurprising = getBestResultSurprising(t.get(i)); if (bestResultNotSurprising >= p) { count++; } else if (bestResultSurprising >= p && S > 0) { count++; S--; } } return count; } private static int getBestResultNotSurprising(int n) { return getBestResult(n, false); } private static int getBestResultSurprising(int n) { return getBestResult(n, true); } private static int getBestResult(int n, boolean surprising) { int average = (int) Math.floor(n / 3); int residue = n % 3; if (n == 0) return 0; if (surprising && residue == 0) return average + 1; if (surprising && residue == 1) return average + 1; if (surprising && residue == 2) return average + 2; if (!surprising && residue == 0) return average; if (!surprising && residue == 1) return average + 1; if (!surprising && residue == 2) return average + 1; return average; } public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader(fileNameIn)); BufferedWriter out = new BufferedWriter(new FileWriter(fileNameOut)); int testCases = Integer.parseInt(in.readLine()); for (int i = 0; i < testCases; i++) { String[] elements = in.readLine().split( new Character((char) 32).toString()); List<Integer> values = new ArrayList<Integer>(); for (String v : elements) { values.add(Integer.valueOf(v)); } ListIterator<Integer> iterator = values.listIterator(); int N = iterator.next(); int S = iterator.next(); int p = iterator.next(); List<Integer> t = values.subList(values.size() - N, values.size()); out.write(String.format("Case #%s: %s\n", i + 1, solve(S, p, t))); } in.close(); out.close(); } }
0
1,189,857
A11759
A12143
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package codejam; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; /** * * @author Aymen */ public class main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { int[] v = new int[1000]; int[] tabMin = new int[100]; String outputFile = System.getenv("USERPROFILE") + "\\Documents\\B-small.out"; String inputFile = System.getenv("USERPROFILE") + "\\Documents\\B-small.in"; //String outputFile = System.getenv("USERPROFILE") + "\\Documents\\output.txt"; //String inputFile = System.getenv("USERPROFILE") + "\\Documents\\input.txt"; BufferedWriter os = new BufferedWriter(new FileWriter(outputFile)); DataInputStream is = new DataInputStream(new FileInputStream(inputFile)); int T = Integer.valueOf(is.readLine()); System.out.println("T " + T); for (int i = 0; i < T; i++) { String list = is.readLine(); list += " "; int n = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); int s = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); int p = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); int valMin = 3 * p - 4; if (valMin < 0) s = 0; int number = 0; int surp = 0; for (int j = 0; j < s; j++) { tabMin[j] = 0; } for (int j = 0; j < n; j++) { int val = Integer.valueOf(list.substring(0, list.indexOf(" "))); if (val >= valMin){ if ((val == valMin) || (val == valMin + 1)){ surp += 1; if (surp <= s){ number += 1; } }else number += 1; } list = list.substring(list.indexOf(" ") + 1); } int m = i + 1; System.out.println("number " + number); os.write("Case #" + m + ": " + number); os.newLine(); System.out.println(""); } is.close(); os.close(); } }
0
1,189,858
A11759
A11421
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.math.*; import java.util.*; public class CodeJam { void runCase(int caseNum) throws IOException { int n = nextInt(); int s = nextInt(); int p = nextInt(); int ret = 0; Map<Integer, Boolean> nonSurprise = new HashMap<Integer, Boolean>(); Map<Integer, Boolean> surprise = new HashMap<Integer, Boolean>(); for (int i = 0; i <= 10; ++i) { for (int j = i; j <= Math.min(10, i + 2); ++j) { for (int k = Math.max(j, p); k <= Math.min(10, i + 2); ++k) { int sum = i + j + k; if (k - i == 2) surprise.put(sum, true); else nonSurprise.put(sum, true); } } } for (int i = 0; i < n; ++i) { int t = nextInt(); if (nonSurprise.containsKey(t)) { ++ret; } else if (s > 0 && surprise.containsKey(t)){ ++ret; --s; } } System.out.print(new StringBuilder().append("Case #").append(caseNum).append(": ").append(ret).toString()); System.out.println(); } public static void main(String[] args) throws IOException { System.setIn(new FileInputStream(new File( "input.txt"))); PrintStream ps = new PrintStream(new File( "output.txt")); System.setOut(ps); new CodeJam().runit(); ps.flush(); ps.close(); return; } BufferedReader in; private StringTokenizer st; PrintWriter out; String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } void runit() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); st = new StringTokenizer(""); int N = nextInt(); for (int i = 0; i < N; i++) { runCase(i + 1); } out.flush(); } }
0
1,189,859
A11759
A10269
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.gcj.parser; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Parser { private String inputFileDest; private FileInputStream fileInputStream; public Parser(String inputFileDest) { super(); this.inputFileDest = inputFileDest; try { fileInputStream = new FileInputStream(new File(inputFileDest)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public String getInputFileDest() { return inputFileDest; } public void setInputFileDest(String inputFileDest) { this.inputFileDest = inputFileDest; } public FileInputStream getFileInputStream() { return fileInputStream; } public void setFileInputStream(FileInputStream fileInputStream) { this.fileInputStream = fileInputStream; } @SuppressWarnings("unchecked") public ArrayList<Integer>[] toArray(){ Scanner scan = new Scanner(getFileInputStream()); // The first line must be an number Integer nbOfLines = new Integer(scan.nextLine()); ArrayList<Integer>[] parsedData = new ArrayList[nbOfLines]; int index = 0; while (scan.hasNextLine()){ String line = scan.nextLine(); String[] datas = line.split(" "); ArrayList<Integer> dataRow = new ArrayList<Integer>(); for (String data : datas){ dataRow.add(new Integer(data)); } parsedData[index] = dataRow; index++; } return parsedData; } }
0
1,189,860
A11759
A10438
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 ulohy; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Codejam_2 { static byte cases; static int[] googlers = new int[100]; static int[] supr_triplets = new int[100]; static int[][] total_scores = new int[100][100]; static int[][] max = new int[100][100]; static int[][] supr_max = new int[100][100]; static int[] treshold = new int[100]; static int[] result = new int[100]; public static void read_input() { Scanner s = null; try { s = new Scanner(new FileReader("./src/ulohy/B-small-attempt0.in")); } catch (FileNotFoundException e) { e.printStackTrace(); } cases = s.nextByte(); for (int i = 0; i < cases; i++) { googlers[i] = s.nextInt(); supr_triplets[i] = s.nextInt(); treshold[i] = s.nextInt(); for (int j = 0; j < googlers[i]; j++) { total_scores[i][j] = s.nextInt(); } } s.close(); } public static void write_output() { FileWriter outFile; try { outFile = new FileWriter("./src/ulohy/output"); PrintWriter out = new PrintWriter(outFile); for (int i = 1; i <= cases; i++) { out.println("Case #"+i+": "+result[i-1]); } out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String args[]) { read_input(); for (int i = 0; i < cases; i++) { for (int j = 0; j < googlers[i]; j++) { if (total_scores[i][j] > 0) { switch (total_scores[i][j] % 3) { case 0: max[i][j] = total_scores[i][j]/3; supr_max[i][j] = total_scores[i][j]/3 + 1; break; case 1: max[i][j] = total_scores[i][j]/3 + 1; supr_max[i][j] = total_scores[i][j]/3 + 1; break; case 2: max[i][j] = total_scores[i][j]/3 + 1; supr_max[i][j] = total_scores[i][j]/3 + 2; break; default: break; } } } for (int j = 0; j < googlers[i]; j++) { if (max[i][j] >= treshold[i]) { result[i]++; } else { if (supr_max[i][j] >= treshold[i] && supr_triplets[i] > 0) { result[i]++; supr_triplets[i]--; } } } } write_output(); } }
0
1,189,861
A11759
A11151
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package gcj; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.util.Scanner; /** * * @author Mervin.Lavin */ public class Gcj { public static void main (String[] args) throws Exception { doProb2( "B-small-attempt0.in", "output.txt" ); } private static void doProb2 ( String inputFileName, String outputFileName ) throws Exception { File inputFile = new File( inputFileName ); Scanner scanner = null; scanner = new Scanner( inputFile ); File outputFile = new File( outputFileName ); BufferedWriter output = new BufferedWriter( new FileWriter( outputFile ) ); int contestants, surpriseScores, minBestScore; int totalScore, aveScore, passedContestants; int testCases = scanner.nextInt(); for ( int caseNum = 1; caseNum <= testCases; caseNum++ ) { contestants = scanner.nextInt(); surpriseScores = scanner.nextInt(); minBestScore = scanner.nextInt(); passedContestants = 0; for ( int contestant = 0; contestant < contestants; contestant++ ) { totalScore = scanner.nextInt(); aveScore = totalScore / 3; switch ( totalScore % 3 ) { case 0: if ( aveScore >= minBestScore ) { passedContestants++; } else if ( ( surpriseScores > 0 ) && ( ( aveScore + 1 ) >= minBestScore ) && ( ( aveScore + 1 ) <= totalScore )) { passedContestants++; surpriseScores--; } break; case 1: if ( ( aveScore + 1 ) >= minBestScore ) { passedContestants++; } break; case 2: if ( ( aveScore + 1 ) >= minBestScore ) { passedContestants++; } else if ( ( surpriseScores > 0 ) && ( ( aveScore + 2 ) >= minBestScore ) && ( ( aveScore + 2 ) <= totalScore ) ) { passedContestants++; surpriseScores--; } break; } } output.append( "Case #" + caseNum + ": " + passedContestants ); output.newLine(); } scanner.close(); output.close(); } }
0
1,189,862
A11759
A11456
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 Test { public static void main(String[] args){ Scanner in = new Scanner(System.in); int T = in.nextInt(); for(int i = 1; i<=T; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int result = 0; for(int j = 0; j<n; j++){ int x = canAddUp(in.nextInt(), p); if(x == 0) { result++; } else if (x==1 && s > 0) { result++; s--; } } System.out.println("Case #"+i+": "+result); } } public static int canAddUp(int sum, int limit) { boolean flag = false; for(int i = 0; i<=sum; i++) { for(int j = 0; i+j <= sum; j++) { int k = sum-(i+j); int a = Math.abs(i-j); int b = Math.abs(i-k); int c = Math.abs(j-k); if(a > 2 || b > 2 || c> 2){ continue; } if (i>=limit || j>=limit || k>=limit) { if(a < 2 && b < 2 && c < 2) { return 0; }else{ flag = true; } } } } return (flag) ? 1 : 2; } }
0
1,189,863
A11759
A13020
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package com.google.codejam.googlers; /** * Class to represent each test case. * It will hold details like test case no, input to be operated and TestResult. * @author Sushant Deshpande * */ public class TestCase { /** * Variable to hold value for test case number. */ private int caseNo; /** * Variable to hold lower limit. */ private int noOfGooglers; /** * Variable to hold upper limit. */ private int noOfurprisingTriplets; /** * Variable to hold value of best result. */ private int bestResult; /** * Array to hold googlers score. */ private int [] scores; /** * Variable holding test case result. */ private TestResult output; /** * Constructor for creating TestCase with case no. * @param caseNo int * @param noOfGooglers int * @param surprisingTriplets int */ public TestCase(final int caseNo, final int noOfGooglers, final int surprisingTriplets, final int bestResult, final int [] scores) { this.caseNo = caseNo; this.noOfGooglers = noOfGooglers; this.noOfurprisingTriplets = surprisingTriplets; this.bestResult = bestResult; this.scores = scores; } /** * Settter method for TestResult. * @param output TestResult */ public final void setOutput(final TestResult output) { this.output = output; } public final int getNoOfurprisingTriplets() { return noOfurprisingTriplets; } public final int getNoOfGooglers() { return noOfGooglers; } /** * Getter method for best result. * @return int */ public final int getBestResult() { return bestResult; } /** * Method for getting scores. * @return int [] */ public final int[] getScores() { return scores; } /** * Method to format the test output for printing in the report. * @return String formatted output for the given input. */ public final String printTestResult() { StringBuilder resultBuilder = new StringBuilder("Case #"); resultBuilder.append(caseNo).append(": "); resultBuilder.append(output.getTestOutput()).append("\n"); return resultBuilder.toString(); } }
0
1,189,864
A11759
A11458
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.util.*; import java.io.*; public class Dancing { public static void main(String[] args) { try { Scanner scan = new Scanner(new File("Dancing.in")); int x = Integer.parseInt(scan.nextLine()); for(int y=0;y<x;y++) { String s=scan.nextLine(); System.out.println("Case #"+(y+1)+": " + convert(s)); } } catch(FileNotFoundException e) { System.out.println("File Not Found"); } } public static int convert(String t) { int a=0; int b=0; int c=0; int total=0; String[] ar=t.split("[ ]"); a=Integer.parseInt(ar[0]); b=Integer.parseInt(ar[1]); c=Integer.parseInt(ar[2]); for(int x=3;x<a+3;x++) { int temp=Integer.parseInt(ar[x]); if(temp>=3*c-2) total++; else if(temp>=3*c-4 && temp != 0) { if(b>0) { b--; total++; } } } return total; } }
0
1,189,865
A11759
A11896
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package com.google.codejam.util; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class CodeJamInputFile extends File { /** * */ private static final long serialVersionUID = 8294095294390757204L; private BufferedReader reader; private int cases; public CodeJamInputFile(String pathname) { super(pathname); try { this.setReader(); } catch (FileNotFoundException e) { } try { this.setCases(Integer.valueOf(this.getReader().readLine())); } catch (NumberFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private void setReader() throws FileNotFoundException { reader = new BufferedReader(new FileReader(this)); } public BufferedReader getReader() { return reader; } public void setCases(int cases) { this.cases = cases; } public int getCases() { return cases; } public void close() { try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public String getLine() { String line = ""; try { line = reader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return line; } }
0
1,189,866
A11759
A11817
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 googlecodejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; /** * * @author Wouter */ public class DancingWithTheGooglers { ArrayList<String> cases = new ArrayList<String>(); int makesit = 0; int needsSurp = 0; public DancingWithTheGooglers() { try { // Setup in/out System.setIn(new FileInputStream("C:\\GCJ\\B-small-attempt0.in")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\GCJ\\B-small-attempt0.out")); bw.flush(); int untill = Integer.parseInt(br.readLine()); for (int t = 1; t <= untill; t++) { String[] ins = br.readLine().split(" "); int n = Integer.parseInt(ins[0]); // number of googlers int s = Integer.parseInt(ins[1]); // number of surpirsing trips int p = Integer.parseInt(ins[2]); // min points int[] ti = new int[n]; for (int i = 3; i < n + 3; i++) { ti[i - 3] = Integer.parseInt(ins[i]); } for (int m = 0; m < ti.length; m++) { doMath(ti[m], p); } int ans = makesit; if (s < needsSurp) { ans += s; } else { ans += needsSurp; } String out = "Case #" + t + ": " + ans; cases.add(out); makesit = 0; needsSurp = 0; } for (String s : cases) { System.out.println(s); bw.write(s); bw.flush(); bw.newLine(); } } catch (IOException ex) { System.out.println("SOMETHING WENT WRONG"); } } public void doMath(int number, int p) { int start = 10; boolean done = false; while (true) { if (start + start + start == number) { if (start >= p) { makesit++; done = true; break; } break; } if (start + start + start - 1 == number) { if (start >= p) { makesit++; done = true; break; } break; } if (start + start - 1 + start - 1 == number) { if (start >= p) { makesit++; done = true; break; } break; } start--; } if (!done) { start = 10; while (true) { if (start == 1) { break; } if (start + (start - 1) + (start - 2) == number) { if (start >= p) { needsSurp++; break; } break; } if (start + (start - 2) + (start - 2) == number) { if (start >= p) { needsSurp++; break; } break; } start--; } } } public static void main(String[] args) { new DancingWithTheGooglers(); } }
0
1,189,867
A11759
A10525
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 Q2 { public static void main(String str[])throws IOException { FileReader fr=new FileReader("B-small-attempt0.in"); // FileReader fr=new FileReader("B-large.in"); BufferedReader br=new BufferedReader(fr); FileWriter fw=new FileWriter("output.txt"); BufferedWriter bw=new BufferedWriter(fw); PrintWriter pw=new PrintWriter(bw); int T=Integer.parseInt(br.readLine()); for(int i=1;i<=T;i++) { String s=br.readLine(); StringTokenizer st=new StringTokenizer(s); int N=Integer.parseInt(st.nextToken()); int S=Integer.parseInt(st.nextToken()); int p=Integer.parseInt(st.nextToken()); int Arr[][]=new int[N][4]; for(int j=0;j<N;j++) { int num=Integer.parseInt(st.nextToken()); int mod=num%3; Arr[j][0]=mod; Arr[j][3]=num; int n=num/3; if(mod==0) { Arr[j][2]=n; if(n>=p) Arr[j][1]=1; else Arr[j][1]=0; } else { Arr[j][2]=n+1; if(n+1>=p) Arr[j][1]=1; else Arr[j][1]=0; } } for(int j=0;j<N;j++) { if(S==0) break; if(Arr[j][1]==0 && (Arr[j][0]==0 || Arr[j][0]==2) && (Arr[j][2]+1)>=p && (Arr[j][2]+1)<=Arr[j][3]) { S--; Arr[j][1]=1; } } int sum=0; for(int j=0;j<N;j++) { sum+=Arr[j][1]; } pw.println("Case #"+i+": "+sum); } pw.close(); bw.close(); fw.close(); br.close(); fr.close(); } }
0
1,189,868
A11759
A10210
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 googlecodejam2012_qualification; /** * @author neil */ import java.io.*; import java.util.*; public class NewMain3 { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedReader in = new BufferedReader(new FileReader("C:\\Documents and Settings\\neil\\Desktop\\B-small-in.in")); BufferedWriter out = new BufferedWriter(new FileWriter("C:\\Documents and Settings\\neil\\Desktop\\B-small-output.txt")); PrintStream ps = new PrintStream(System.out,true); StringTokenizer st;//st = new StringTokenizer(in.readLine()," "); int count=0; int t = Integer.parseInt(in.readLine()); while(count++<t) { int score=0; st = new StringTokenizer(in.readLine()," "); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int a[] = new int[n]; for(int i=0;i<n;i++) { a[i] = Integer.parseInt(st.nextToken()); } boolean selected[] = new boolean[n]; //int b[] = new int[n]; for(int i=0;i<n;i++) { if(a[i]>=p) { if(a[i]%3==0) { if(a[i]/3>=p){ score++; selected[i] = true;} } else { if(a[i]/3+1>=p){ score++;selected[i] = true;} } } } for(int i=0;i<n;i++) { if(!selected[i]&&a[i]>=p) { if(s==0) break; if(a[i]%3==2) { if(a[i]/3+2>=p){ score++; s--; } } else { if(a[i]/3+1>=p){ score++; s--; } } } } ps.println("Case #"+count+": "+score); out.write("Case #"+count+": "+score+"\n"); out.flush(); } } }
0
1,189,869
A11759
A12919
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.solver; import google.loader.ChallengeLoader; import google.loader.ChallengeReader; import java.io.FileInputStream; import java.util.Properties; public class Solver implements ChallengeConstants{ private ChallengeReader reader; private String inputFileName; private String result; private final String path; public Solver(String aPath) { this.path = aPath; init(); solve(); writeResult(); } private void solve() { ChallengeLoader loader = new ChallengeLoader(reader); loader.load(inputFileName); result = loader.getResult(); } private void init() { try{ String propFileName = path+DELIMITER+CHALLENGE_DEFINITION; Properties properties = new Properties(); properties.load(new FileInputStream(propFileName)); inputFileName = path+DELIMITER+(String)properties.get("fileName"); String readerClassName = (String)properties.get("readerClassName"); reader = (ChallengeReader) Class.forName(readerClassName).newInstance(); } catch(Exception e){ throw new RuntimeException(e); } } public String getResult(){ return result; } public void writeResult(){ String result = getResult(); write(result); } private void write(String text) { ProblemPackageCreator.write(getResultFileName(), text); } private String getResultFileName() { return inputFileName+".result"; } public static void main(String[] args) { String problem = CHALLENGE_NAME; String path = BASE_DIR+DELIMITER+problem; Solver solver = new Solver(path); String result = solver.getResult(); System.out.println(result); } }
0
1,189,870
A11759
A11443
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.io.StreamTokenizer; public class B { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StreamTokenizer tokenizer = new StreamTokenizer(in); int tests; tokenizer.nextToken(); tests = (int)tokenizer.nval; int[] answers = new int[tests]; for (int i = 0;i < tests; ++i) { int N, S, p; tokenizer.nextToken(); N = (int)tokenizer.nval; tokenizer.nextToken(); S = (int)tokenizer.nval; tokenizer.nextToken(); p = (int)tokenizer.nval; int[] tscores = new int[N]; for (int j = 0;j < N; ++j) { tokenizer.nextToken(); tscores[j] = (int)tokenizer.nval; } int hugeScoresCount = 0; int greaterPCount = 0; for (int j = 0;j < N; ++j) { if (Math.ceil((double)tscores[j] / 3) >= p) { ++hugeScoresCount; } else { if (tscores[j] % 3 == 0 && tscores[j] / 3 >= p - 1 && tscores[j] != 0) { ++ greaterPCount; }else if (tscores[j] % 3 == 2 && tscores[j] / 3 >= p - 2) { ++ greaterPCount; } } } answers[i] = hugeScoresCount + Math.min(S, greaterPCount); } for (int j = 0;j < tests; ++j) { System.out.println("Case #" + (j + 1) + ": " + answers[j]); } } }
0
1,189,871
A11759
A12421
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.util.ArrayList; import java.util.Collections; import java.util.List; import reusable.CodeJamBase; public class DancingWithTheGooglers { public static void main(String[] args) { new CodeJamBase("B-small-attempt0") { @Override protected String solution() { int[] input = nextIntArray(); int googlers = input[0]; int suprisingTriplets = input[1]; int minBestResult = input[2]; int minTotal = Math.max(0, 3 * minBestResult - 2); // (a-1)+(a-1)+a int minTotalSuprising = Math.max(2, 3 * minBestResult - 4); // (a-2)+(a-2)+a int result = 0; List<Integer> googlerScores = new ArrayList<>(); for (int i = 3; i < googlers + 3; i++) { googlerScores.add(input[i]); } Collections.sort(googlerScores, Collections.reverseOrder()); for (int googlerScore : googlerScores) { if (googlerScore >= minTotal) { result++; } else if ((suprisingTriplets > 0) && (googlerScore >= minTotalSuprising)) { suprisingTriplets--; result++; } else { break; } } return String.valueOf(result); } }.run(); } }
0
1,189,872
A11759
A13105
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.contest; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.Vector; public class ProblemB { public static void main(String[]arg) { try { FileInputStream fInputStream = new FileInputStream(arg[0]); DataInputStream in = new DataInputStream(fInputStream); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String strLine; int i = 0; while ((strLine = reader.readLine()) != null) { if (i > 0) { String[] arrString = strLine.split(" "); System.out.println("Case #" + i + ": " + getResult(arrString)); } i++; } } catch (Exception e) { e.printStackTrace(); } } private static int getResult(String[] arrValues) { int result = 0; int numGooglers = Integer.parseInt(arrValues[0]); int numSurprise = Integer.parseInt(arrValues[1]); int numResult = Integer.parseInt(arrValues[2]); Vector vctScores = new Vector(); for (int i = 3; i < arrValues.length; i++) { int score = Integer.parseInt(arrValues[i]); vctScores.add(getSubScores(score)); } result = getBestResult(vctScores, numSurprise, numResult); return result; } private static Vector getSubScores(int value) { int score1 = value / 3; int score2 = value / 3; int score3 = value / 3; if (value % 3 == 1) score1++; else if (value % 3 == 2) { score1++; score2++; } Vector vctResult = new Vector(); vctResult.add(score1); vctResult.add(score2); vctResult.add(score3); return vctResult; } private static int getBestResult(Vector vct, int numSurp, int numScore) { int result = 0; for (int i = 0; i < vct.size(); i++) { Vector score = (Vector) vct.elementAt(i); int elem1 = (Integer) score.elementAt(0); int elem2 = (Integer) score.elementAt(1); int elem3 = (Integer) score.elementAt(2); if (numScore == 0) result++; else if (elem1 != 0) { if (((elem1 == numScore - 1 && numSurp > 0) && ((elem2 != elem3) || ((elem1 == elem2) && (elem2 == elem3))))) { numSurp--; result++; } else if (elem1 >= numScore) result++; } } return result; } }
0
1,189,873
A11759
A10270
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.gcj.parser; public class MaxPoints { public static int normal(int value){ int toReturn = 0; switch (value) { case 0 : toReturn = 0 ; break; case 1 : toReturn = 1 ; break; case 2 : toReturn = 1 ; break; case 3 : toReturn = 1 ; break; case 4 : toReturn = 2 ; break; case 5 : toReturn = 2 ; break; case 6 : toReturn = 2 ; break; case 7 : toReturn = 3 ; break; case 8 : toReturn = 3 ; break; case 9 : toReturn = 3 ; break; case 10 : toReturn = 4 ; break; case 11 : toReturn = 4 ; break; case 12 : toReturn = 4 ; break; case 13 : toReturn = 5 ; break; case 14 : toReturn = 5 ; break; case 15 : toReturn = 5 ; break; case 16 : toReturn = 6 ; break; case 17 : toReturn = 6 ; break; case 18 : toReturn = 6 ; break; case 19 : toReturn = 7 ; break; case 20 : toReturn = 7 ; break; case 21 : toReturn = 7 ; break; case 22 : toReturn = 8 ; break; case 23 : toReturn = 8 ; break; case 24 : toReturn = 8 ; break; case 25 : toReturn = 9 ; break; case 26 : toReturn = 9 ; break; case 27 : toReturn = 9 ; break; case 28 : toReturn = 10 ; break; case 29 : toReturn = 10 ; break; case 30 : toReturn = 10 ; break; } return toReturn; } public static int surprising(int value){ int toReturn = 0; switch (value) { case 0 : toReturn = 0 ; break; case 1 : toReturn = 1 ; break; case 2 : toReturn = 2 ; break; case 3 : toReturn = 2 ; break; case 4 : toReturn = 2 ; break; case 5 : toReturn = 3 ; break; case 6 : toReturn = 3 ; break; case 7 : toReturn = 3 ; break; case 8 : toReturn = 4 ; break; case 9 : toReturn = 4 ; break; case 10 : toReturn = 4 ; break; case 11 : toReturn = 5 ; break; case 12 : toReturn = 5 ; break; case 13 : toReturn = 5 ; break; case 14 : toReturn = 6 ; break; case 15 : toReturn = 6 ; break; case 16 : toReturn = 6 ; break; case 17 : toReturn = 7 ; break; case 18 : toReturn = 7 ; break; case 19 : toReturn = 7 ; break; case 20 : toReturn = 8 ; break; case 21 : toReturn = 8 ; break; case 22 : toReturn = 8 ; break; case 23 : toReturn = 9 ; break; case 24 : toReturn = 9 ; break; case 25 : toReturn = 9 ; break; case 26 : toReturn = 10 ; break; case 27 : toReturn = 10 ; break; case 28 : toReturn = 10 ; break; case 29 : toReturn = 10 ; break; case 30 : toReturn = 10 ; break; } return toReturn; } }
0
1,189,874
A11759
A11501
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 template; //standard libraries potentially used: //Apache commons http://http://commons.apache.org/ //Google Guava http://code.google.com/p/guava-libraries/ import java.util.ArrayList; public class Template { public static void main(String[] args) { //test(); //Utils.die("Done testing"); String folder = "C:\\Users\\Paul Thomson\\Documents\\CodeJam\\DancingWithTheGooglers\\"; Utils.logfile = folder + "log.txt"; String infile = folder + "small.in"; String outfile = infile.substring(0, infile.lastIndexOf(".")) + ".out"; ArrayList<TestCase> tcList = TestCaseIO.loadFromFile(infile); //ArrayList<TestCase> tcList = TestCaseIO.mockUp(); int numThreads = 1; if (numThreads == 1) { TestCaseSolver tcSolver = new TestCaseSolver(tcList, 1); tcSolver.run(); } else { //split into separate lists ArrayList<ArrayList<TestCase>> tcSubLists = new ArrayList<>(); for (int i = 0; i < numThreads; i++) { tcSubLists.add(new ArrayList<TestCase>()); } int i = 0; for (TestCase tc : tcList) { tcSubLists.get(i).add(tc); i++; if (i == numThreads) { i = 0; } } //run each sublist in its own thread ArrayList<Thread> threadList = new ArrayList<>(); int ref = 1; for (ArrayList<TestCase> tcl : tcSubLists) { TestCaseSolver tcs = new TestCaseSolver(tcl, ref); Thread h = new Thread(tcs); threadList.add(h); h.start(); ref++; } //wait for completion for (Thread h : threadList) { try { h.join(); } catch (InterruptedException ex) { Utils.die("InterruptedException waiting for threads"); } } } TestCaseIO.writeSolutions(tcList, outfile); double totalTime = 0; for (TestCase tc : tcList) { totalTime += tc.getTime(); } double avTime = totalTime / (double)tcList.size(); Utils.sout("Total compute time " + String.format("%.2f", totalTime) + " secs."); Utils.sout("Average compute time " + String.format("%.2f", avTime) + " secs."); Utils.sout("Done."); } public static void test() { } }
0
1,189,875
A11759
A10961
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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; import java.io.File; import java.io.FileWriter; import java.util.ArrayList; import java.util.Scanner; public class ProblemaB { static String caminho = "/home/mateus/"; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(new File(caminho + "entrada.txt")); FileWriter writer = new FileWriter(new File("/home/mateus/saida.txt"), false); int cases = sc.nextInt(); for (int i = 1; i <= cases; i++) { if (i == 3) { System.out.println(""); } int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int resposta = 0; ArrayList<Tripla> triplas = new ArrayList<Tripla>(); for (int j = 0; j < n; j++) { triplas.add(new Tripla(sc.nextInt())); } for (int w = triplas.size() - 1; w >= 0; w--) { if (triplas.get(w).maximaPontuacao() >= p) { resposta++; triplas.remove(w); } } for (int w = 0; w < triplas.size() && s > 0; w++) { if (triplas.get(w).maximaPontuacaoEspecial() >= p) { s--; resposta++; } } writer.append(criarCase(i, resposta + "")); } writer.flush(); writer.close(); } public static String criarCase(int i, String s) { return "Case #" + i + ": " + s + "\n"; } }
0
1,189,876
A11759
A12594
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.Collections; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner s = new Scanner(new File("input")); BufferedWriter w = new BufferedWriter(new FileWriter(new File("output"))); int cases = s.nextInt(); for (int i = 0; i < cases; i++) { s.nextLine(); int n = s.nextInt(); int surprising = s.nextInt(); int target = s.nextInt(); int answer = 0; if (target == 0) { answer = n; } else { int lowestBound = target * 3 - 4; ArrayList<Integer> l = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { int si = s.nextInt(); if (si >= lowestBound && si >= target) { l.add(si); } } Collections.sort(l); Collections.reverse(l); for (int si : l) { int roundedAverage = si / 3; int mod = si % 3; if (mod == 0) { if (roundedAverage >= target) { answer++; } else if (roundedAverage + 1 == target && surprising > 0) { answer++; if (--surprising == 0) { break; } } } else if (mod == 1) { answer++; } else { if (roundedAverage + 1 >= target) { answer++; } else if (roundedAverage + 2 >= target && surprising > 0) { answer++; if (--surprising == 0) { break; } } } } } w.write("Case #"); w.write(String.valueOf(i + 1)); w.write(": "); w.write(String.valueOf(answer)); w.write("\n"); } w.close(); } }
0
1,189,877
A11759
A11494
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package com.google.jam.eaque.stub; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class InputFileManager { private BufferedReader br; public InputFileManager(String filePath) throws NumberFormatException, IOException { br = new BufferedReader(new FileReader(filePath)); } public void close() throws IOException { br.close(); } public String readLine() throws IOException { return br.readLine(); } public long readLong() throws NumberFormatException, IOException { return Long.parseLong(br.readLine()); } public String[] readAndSplit() throws IOException { return br.readLine().split(" "); } }
0
1,189,878
A11759
A11357
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.*; import java.util.*; public class Dancing { class Case{ int surprises; int bestscore; int[] scores; int counter; public Case(int[] input){ this.surprises = input[1]; this.bestscore = input[2]; scores = new int[input[0]]; System.arraycopy(input, 3, this.scores, 0, scores.length); } public int getResult(){ for(int i=0; i<scores.length; i++){ //System.out.println(" Score "+scores[i]); if(bestscore == 0){ counter++; continue; } else if(bestscore != 0 && scores[i] / bestscore >= 3){ //System.out.println("success"); counter++; continue; } else if((scores[i] - bestscore) >= 0 && (scores[i] - bestscore) % 2 == 0){ if((scores[i] - bestscore)/2 == bestscore - 1){ //System.out.println("success"); counter++; continue; } else if(((scores[i] - bestscore)/2 == bestscore - 2) && (surprises > 0)){ //System.out.println("success"); counter++; surprises--; continue; } } else{ if(scores[i] - 2 * bestscore >= 0 && (scores[i] - 2 * bestscore) == bestscore - 1){ //System.out.println("success"); counter++; continue; } else if(scores[i] - (2 * bestscore) >= 0 && ((scores[i] - (2 * bestscore) + 3) == bestscore) && (surprises > 0)){ //System.out.println("success"); counter++; surprises--; continue; } } } return counter; } } public Dancing(String file){ BufferedReader in = null; PrintWriter out = null; try{ in = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file+"/input.txt")))); out = new PrintWriter(new BufferedWriter(new FileWriter(file+"/output.txt")), true); int caseId = 1; int result = 0; String line = null; Case c = null; in.readLine(); //no of cases while ((line = in.readLine()) != null) { c = new Case(getIntArray(line)); result = c.getResult(); System.out.println("Case #"+caseId+ ": "+result); out.println("Case #"+caseId+ ": "+result); caseId++; } } catch(Exception e){ e.printStackTrace(); } finally{ try{ out.close(); } catch(Exception ignored){} try{ in.close(); } catch(Exception ignored){} } } public String[] getStringArray(String str){ return str.split("\\s+"); } public int[] getIntArray(String str){ String[] sArray = getStringArray(str); int[] iArray = new int[sArray.length]; for(int i=0; i<sArray.length; i++){ iArray[i] = Integer.parseInt(sArray[i]); } return iArray; } public static void main(String args[]) throws Exception { Dancing obj = new Dancing(args[0]); } }
0
1,189,879
A11759
A12113
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class B { static int[][] memo; static int[] nums; static int p; public static void main(String[] args)throws IOException { Scanner br=new Scanner(new File("B-small-attempt0.in")); PrintWriter out=new PrintWriter(new File("b.out")); int cases=br.nextInt(); for(int c=1;c<=cases;c++) { int n=br.nextInt(),s=br.nextInt(); p=br.nextInt(); nums=new int[n]; for(int i=0;i<n;i++) nums[i]=br.nextInt(); memo=new int[n][s+1]; for(int[] a:memo) Arrays.fill(a,-1); out.printf("Case #%d: %d\n",c,go(0,s)); } out.close(); } public static int go(int index,int s) { if(index>=nums.length) return 0; if(memo[index][s]!=-1) return memo[index][s]; int best=0; for(int i=0;i<=10;i++) { int max=i; for(int j=0;j<=10;j++) { if(Math.abs(i-j)>2) continue; max=Math.max(i,j); thisone: for(int k=0;k<=10;k++) { int ret=0; if(Math.abs(i-k)>2||Math.abs(j-k)>2) continue; max=Math.max(max,k); int count=0; if(Math.abs(i-k)==2) count++; if(Math.abs(i-j)==2) count++; if(Math.abs(j-k)==2) count++; if(i+j+k==nums[index]) { boolean surp=(count>=1); if(surp&&s>0) { if(max>=p) ret++; ret+=go(index+1,s-1); } else if(!surp) { if(max>=p) ret++; ret+=go(index+1,s); } best=Math.max(best,ret); } else if(i+j+k>nums[index]) break thisone; } } } return memo[index][s]=best; } }
0
1,189,880
A11759
A11683
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 QuestionB extends Question{ private int N; private int S; private int p; private int[] dancers; public QuestionB(Result result, Counter counter) { super(result, counter); } @Override public void readInput(Scanner scanner) { N = scanner.nextInt(); S = scanner.nextInt(); p = scanner.nextInt(); dancers = new int[N]; for (int i = 0; i < N; i++) { dancers[i] = scanner.nextInt(); } } @Override public String solution() { int counter = 0; for (int i = 0; i < N; i++) { if (dancers[i]>=3*p-Math.min(2,dancers[i]*2)) counter++; else if (dancers[i]>=3*p-Math.min(4,dancers[i]*2) && S>0) { S--; counter++; } } return Integer.toString(counter); } }
0
1,189,881
A11759
A11385
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.teamg9.codejam; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Scanner; interface ISolver { public String evaluate(); } public abstract class Solver implements ISolver { protected Scanner in; public void solve() { in = new Scanner(System.in); _solve(System.out); } public void solve(File inFile) { String filename = inFile.getPath(); filename = filename.substring(0, filename.lastIndexOf('.')); File outFile = new File(filename + ".out"); try { in = new Scanner(inFile); _solve(new PrintStream(outFile)); } catch (FileNotFoundException e) { e.printStackTrace(); } } private void _solve(PrintStream out) { int count = in.nextInt(); in.nextLine(); for(int index = 0; index<count; index++) { out.append("Case #") .append(String.valueOf(index+1)) .append(": ") .append(evaluate()) .append("\n"); } } public String solve(String singleTest) { in = new Scanner(singleTest); return evaluate(); } }
0
1,189,882
A11759
A10605
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 assignments; import java.util.Scanner; import base.Assignment; public class AssignmentB implements Assignment { int bestResult; int numberOfGooglers; int numberOfSurprises; int[] test; @Override public String solve() { int minNeeded = 3*bestResult - 2; int minNeededWithSurprise = 3*bestResult - 4; int total = 0; for (int i : test) { if (i >= minNeeded) { total++; } else if (i >= minNeededWithSurprise && numberOfSurprises > 0 && bestResult > 1) { total++; numberOfSurprises--; } } return "" + total; } public static Assignment createFromScanner(Scanner scanner) { AssignmentB assignment = new AssignmentB(); assignment.numberOfGooglers = scanner.nextInt(); assignment.numberOfSurprises = scanner.nextInt(); assignment.bestResult = scanner.nextInt(); assignment.test = new int[assignment.numberOfGooglers]; for (int i = 0; i < assignment.numberOfGooglers; i++) { assignment.test[i] = scanner.nextInt(); } return assignment; } }
0
1,189,883
A11759
A11273
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.PrintWriter; public class ProblemaB { /** * @param args */ public static void main(String[] args)throws Exception { int couldHaveBeenQuantity = 0; int couldHaveBeenSurprinsinglyQuantity = 0; PrintWriter pw = new PrintWriter ("C:\\Users\\Rodrigo\\Downloads\\B-small-attempt0.out"); BufferedReader reader = new BufferedReader(new FileReader (new File ("C:\\Users\\Rodrigo\\Downloads\\B-small-attempt0.in"))); int cases = Integer.parseInt(reader.readLine()); for (int i = 1; i <= cases; i++){ couldHaveBeenQuantity = 0; couldHaveBeenSurprinsinglyQuantity = 0; String linha = reader.readLine(); String [] tokens = linha.split(" "); int N = Integer.parseInt(tokens[0]); int S = Integer.parseInt (tokens[1]); int p = Integer.parseInt (tokens[2]); for (int j = 3; j < tokens.length; j++){ int total = Integer.parseInt(tokens[j]); if (couldHaveBeenNormally(total, p)){ couldHaveBeenQuantity++; } else if (couldHavebeenSurprisingly(total, p)){ couldHaveBeenSurprinsinglyQuantity++; } } int allThatCould = couldHaveBeenQuantity + (couldHaveBeenSurprinsinglyQuantity <= S ? couldHaveBeenSurprinsinglyQuantity : S); System.out.println("Case #" + i + ": " + allThatCould); pw.println("Case #" + i + ": " + allThatCould); } pw.close(); } static boolean couldHaveBeenNormally (int total, int p){ //if (total < p) //return false; //if (total == p) //return false; switch (p){ case 10: if (total >= 28) return true; return false; case 9: if (total >= 25) return true; return false; case 8: if (total >= 22) return true; return false; case 7: if (total >= 19) return true; return false; case 6: if (total >= 16) return true; return false; case 5: if (total >= 13) return true; return false; case 4: if (total >= 10) return true; return false; case 3: if (total >= 7) return true; return false; case 2: if (total >= 4) return true; return false; case 1: if (total >= 1) return true; return false; default: return true; } } static boolean couldHavebeenSurprisingly (int total, int p){ //if (total < p) //return false; //if (total == p) //return false; switch (p){ case 10: if (total >= 26) return true; return false; case 9: if (total >= 23) return true; return false; case 8: if (total >= 20) return true; return false; case 7: if (total >= 17) return true; return false; case 6: if (total >= 14) return true; return false; case 5: if (total >= 11) return true; return false; case 4: if (total >= 8) return true; return false; case 3: if (total >= 5) return true; return false; case 2: if (total >=2) return true; return false; case 1: if (total >= 1) return true; return false; default: return true; } } }
0
1,189,884
A11759
A10327
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.dancing_with_the_googlers; import java.io.IOException; import java.util.ArrayList; import codejam.filestuff.FileStuff; public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { FileStuff fs = new FileStuff("B-small-attempt2.in","B-small.out","dancing_with_the_googlers"); ArrayList<String> input = new ArrayList<String>(); input = fs.ReadFromFile(); ArrayList<String> output = new ArrayList<String>(); int xCase = Integer.valueOf(input.get(0)); int xPointer = 1; for (int i=1;i<=xCase;i++) { String strOut = "Case #" + String.valueOf(i) + ":"; String strLine = input.get(xPointer); xPointer++; String[] arrLine = strLine.split(" "); int xN = Integer.valueOf(arrLine[0]); int xS = Integer.valueOf(arrLine[1]); int xp = Integer.valueOf(arrLine[2]); int xRes = 0; for (int a=0;a<xN;a++) { int xScore = Integer.valueOf(arrLine[a+3]); if (xScore != 0) { int xDiv = xScore; while (xDiv % 3 != 0) xDiv++; int xSub = xDiv - xScore; xDiv /= 3; if (xDiv >= xp) { xRes++; } else { if (xS > 0) { if (xSub < 2) xDiv++; if (xDiv >= xp) { xRes++; xS--; } } } } else { if (xp == 0) xRes++; } } strOut += " " + String.valueOf(xRes); output.add(strOut); } fs.WriteToFile(output); System.out.print("Done!!!"); } }
0
1,189,885
A11759
A12414
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 cg.y2012.QualQ2; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; public class Q2 { /** * @param args */ public static void main(String[] args) { int[] s = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; Map<Integer, List<int[]>> G = new HashMap<Integer, List<int[]>>(); for(int i:s){ for(int j:s){ for(int k:s){ if(Math.abs(i-j)< 2 && Math.abs(k-j)< 2 && Math.abs(i-k)< 2){ int sum = i+j+k; List<int[]> trips = G.get(sum); if(trips == null){ trips = new ArrayList<int[]>(); } trips.add(new int[]{i,j,k}); G.put(sum, trips); } } } } Map<Integer, List<int[]>> ST = new HashMap<Integer, List<int[]>>(); for(int i:s){ for(int j:s){ for(int k:s){ if((Math.abs(i-j)== 2 && Math.abs(k-j) < 2 && Math.abs(i-k) < 2) || (Math.abs(i-j)< 2 && Math.abs(k-j)== 2 && Math.abs(i-k)<2) || (Math.abs(i-j) < 2 && Math.abs(k-j) < 2 && Math.abs(i-k)== 2)){ int sum = i+j+k; List<int[]> trips = ST.get(sum); if(trips == null){ trips = new ArrayList<int[]>(); } trips.add(new int[]{i,j,k}); ST.put(sum, trips); } if((Math.abs(i-j)== 2 && (Math.abs(k-j) == 0 || Math.abs(i-k) == 0)) || (Math.abs(k-j)== 2 && (Math.abs(k-i) == 0 || Math.abs(i-j) == 0)) || (Math.abs(k-i)== 2 && (Math.abs(k-j) == 0 || Math.abs(i-j) == 0))){ int sum = i+j+k; List<int[]> trips = ST.get(sum); if(trips == null){ trips = new ArrayList<int[]>(); } trips.add(new int[]{i,j,k}); ST.put(sum, trips); } } } } for(Map.Entry<Integer, List<int[]>> k : G.entrySet()){ System.out.print(k.getKey()+" -- "); List<int[]> l = k.getValue(); for(int[] a : l){ System.out.print("{"); for(int x : a){ System.out.print(" "+x+", "); } System.out.print("}"); } System.out.println(""); } for(Map.Entry<Integer, List<int[]>> k : ST.entrySet()){ System.out.print(k.getKey()+" -- "); List<int[]> l = k.getValue(); for(int[] a : l){ System.out.print("{"); for(int x : a){ System.out.print(" "+x+", "); } System.out.print("}"); } System.out.println(""); } BufferedWriter out = null; try { String newLine = System.getProperty("line.separator"); out = new BufferedWriter(new FileWriter(args[0]+".output")); BufferedReader b = new BufferedReader(new FileReader(args[0])); int number_of_test_cases = Integer.parseInt(b.readLine().split(" ")[0]); for( int tc = 0; tc < number_of_test_cases; tc++) { int[] data = convertToInt(b.readLine()); int N = data[0]; int S = data[1]; int p = data[2]; int rScores[] = new int[N]; int j=0; for(int i=0;i < rScores.length;i++){ rScores[i] = -1; } int count = 0; for(int i=0;i<N;i++){ List<int[]> scores = G.get(data[3+i]); boolean found = false; if(scores != null){ for(int[] score : scores){ if(score[0] >=p ||score[1] >=p || score[2] >=p ){ count ++; found = true; break; } } if(!found){ rScores[j] =data[3+i]; j++; } } } for(int i=0;i < rScores.length && S > 0;i++){ if(rScores[i] == -1) break; List<int[]> scores = ST.get(rScores[i]); if(scores != null){ for(int[] score : scores){ if(score[0] >=p ||score[1] >=p || score[2] >=p ){ count ++; S--; break; } } } } out.write("Case #"+(tc+1)+": "+count+newLine); } } catch (IOException e) { System.out.println("Exception : "+e); } finally { if(out != null){ try { out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } } private static int[] convertToInt(String line){ String data[] = line.split(" "); int[] rtn = new int[data.length]; for(int i=0;i< data.length ;i++){ rtn[i]=Integer.parseInt(data[i].trim()); } return rtn; } }
0
1,189,886
A11759
A10488
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.File; import java.io.PrintWriter; import java.util.Scanner; /** * Created with IntelliJ IDEA. * User: vors * Date: 4/14/12 * Time: 6:40 PM * To change this template use File | Settings | File Templates. */ public class B { public static void main(String[] args) throws Exception { B b = new B(); b.go(); } private void go() throws Exception { Scanner in = new Scanner(new File("b.in")); PrintWriter out = new PrintWriter(new File("b.out")); int T = in.nextInt(); for (int cas=1; cas<=T; cas++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int[] t = new int[N]; int res = 0; for (int i=0; i<N; i++) { int x = t[i] = in.nextInt(); switch (x % 3) { case 0 : { if (x / 3 >= p) { res++; break; } if (x / 3 + 1 >= p && x / 3 > 0 && S > 0) { S--; res++; break; } break; } case 1 : { if (x / 3 + 1 >= p) { res++; break; } break; } case 2 : { if (x / 3 + 1 >= p) { res++; break; } if (x / 3 + 2 >= p && x / 3 > 0 && S > 0) { S--; res++; break; } break; } default: throw new RuntimeException("Unreachable " + x % 3); } } out.printf("Case #%d: %d\n", cas, res); } out.close(); } }
0
1,189,887
A11759
A11544
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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.codejam.qualification; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws IOException { String file = "B-small-attempt3"; Scanner sc = new Scanner(new FileReader(file + ".in")); PrintWriter pw = new PrintWriter(new FileWriter(file + ".out")); int T = new Integer(sc.nextLine()); for (int i = 1; i <= T; i++) { int result = 0; pw.print("Case #" + i + ": "); String line = sc.nextLine(); String[] numbers = line.split(" "); int N = new Integer(numbers[0]); int S = new Integer(numbers[1]); int P = new Integer(numbers[2]); for (int j = 0; j < N; j++) { int div = new Integer(numbers[j + 3]); if(div == 0 && P == 0) result++; if (div != 0) { div = div / 3; if (div >= P) { result++; } else { if ((P - div) == 1) { if ((new Integer(numbers[j + 3]) % 3) >= 1) { result++; } else if ((new Integer(numbers[j+3]) % 3) == 0 && S > 0) { result++; S--; } } else if ((P - div) == 2) { if ((new Integer(numbers[j + 3]) % 3) == 2 && S > 0) { result++; S--; } } } } } pw.println(result); } pw.flush(); pw.close(); sc.close(); } }
0
1,189,888
A11759
A12201
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 test { public static void main(String[] args) throws IOException { // Location of file to read functions aa = new functions(); File file = new File("input.txt"); Writer output = new BufferedWriter(new FileWriter("output.txt")); int i = 1; int answer = 0; String A = ""; String B = ""; int j = 0; int n = 0; int N = 0; int[] numbers = new int[100]; int l = 0,p = 0,s=0,k=0;; try { Scanner scanner = new Scanner(file); N = Integer.parseInt((String)scanner.nextLine()); while (scanner.hasNextLine()) { A = ""; B = ""; j = 0; l = 0; p = 0; s = 0; n = 0; String line = scanner.nextLine(); while(line.charAt(j) != ' '){ A = A + line.charAt(j); j++; } n = Integer.parseInt(A); j++; A = ""; for(k = 1; k <= n+1;k++){ while(line.charAt(j) != ' '){ A = A + line.charAt(j); j++; } if(k == 1) s = Integer.parseInt(A); else if(k == 2) p = Integer.parseInt(A); else numbers[l++] = Integer.parseInt(A); j++; A = ""; } while(j < line.length()){ B = B + line.charAt(j); j++; } numbers[l++] = Integer.parseInt(B); answer = aa.solve(numbers,p,s,n); if(i < N) output.write("Case #" + i +": "+ answer +"\n"); else output.write("Case #" + i +": "+ answer); i++; } scanner.close(); output.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
0
1,189,889
A11759
A11801
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 DancingGooglers { static String test = "4\n3 1 5 15 13 11\n3 0 8 23 22 21\n2 1 1 8 0\n6 2 8 29 20 8 18 18 21"; static String val = "100\n3 1 5 15 13 11\n3 0 8 23 22 21\n2 0 8 21 24\n3 0 6 15 15 14\n3 0 0 17 8 1\n2 1 9 20 26\n3 0 1 18 18 23\n3 0 9 5 23 24\n2 2 7 28 11\n3 0 5 13 5 30\n1 0 1 0\n3 0 8 7 17 21\n1 0 7 2\n1 1 4 7\n2 0 5 27 3\n3 0 9 24 5 23\n1 1 1 15\n1 0 10 27\n1 0 3 30\n2 2 6 28 12\n2 0 8 21 28\n3 1 8 30 3 5\n1 0 10 30\n3 3 6 5 13 22\n3 0 0 30 30 30\n1 0 8 20\n2 0 3 20 16\n3 1 2 3 9 2\n1 0 10 26\n3 0 6 14 8 14\n3 2 1 2 13 18\n1 1 2 22\n2 1 6 20 24\n3 1 10 26 0 27\n2 0 5 12 11\n3 3 5 22 17 12\n1 0 0 15\n2 0 6 23 14\n3 2 2 22 7 15\n3 2 1 24 0 11\n3 0 1 28 14 25\n2 2 6 15 20\n1 0 2 3\n2 0 8 21 20\n3 0 5 0 12 0\n3 0 5 25 25 7\n3 0 9 27 22 3\n2 1 4 11 15\n1 0 9 1\n2 1 9 8 27\n3 3 4 4 17 15\n2 0 1 3 18\n2 1 10 25 30\n1 0 1 13\n3 3 0 20 26 5\n3 2 10 4 9 18\n1 0 10 30\n3 1 4 9 9 9\n3 1 9 24 23 23\n3 2 10 9 12 4\n1 0 4 24\n2 1 10 30 23\n3 0 2 6 22 1\n2 0 10 21 2\n1 0 3 5\n1 1 0 26\n3 1 3 5 9 5\n3 0 4 8 8 9\n2 0 6 6 15\n2 2 2 15 9\n2 0 3 21 5\n2 1 7 27 28\n3 0 8 9 3 21\n3 1 3 6 5 30\n2 2 0 24 2\n2 0 10 2 15\n3 2 2 7 1 15\n1 0 4 8\n1 0 10 17\n1 0 10 23\n1 0 4 5\n1 0 8 12\n2 0 2 2 2\n3 0 4 8 6 4\n1 1 4 28\n2 2 1 9 10\n1 1 6 8\n1 1 2 21\n1 0 6 14\n3 1 10 30 28 4\n3 1 6 15 15 14\n2 0 7 10 17\n3 2 2 3 3 3\n2 0 7 17 17\n3 1 6 14 24 14\n2 2 0 18 26\n3 0 0 0 0 0\n3 0 3 5 5 0\n1 0 6 14\n2 1 6 14 14\n"; /** * @param args */ public static void main(String[] args) { String[][] cases = CaseReader.getCases(val, 1); for (int i = 0;i < cases.length;i++) { parseCase(i + 1, cases[i][0]); } } static void parseCase(int caseNum, String caseString) { String[] args = caseString.split(" "); int googleCount = Integer.parseInt(args[0]); int surprises = Integer.parseInt(args[1]); int lowest = Integer.parseInt(args[2]); int[] googleScores = new int[googleCount]; for (int i = 0;i < googleCount;i++) { googleScores[i] = Integer.parseInt(args[i + 3]); } int countAbove = getCasesWhereAbove(lowest, surprises, googleScores); System.out.println("Case #" + caseNum + ": " + countAbove); } static int getCasesWhereAbove(int minimum, int surpriseCount, int[] scores) { int count = 0, currentSurprises = 0; for (int i = 0;i < scores.length;i++) { if ((scores[i] + 2) / 3 >= minimum) { // This one naturally works, so it's fine. count++; } else if (scores[i] >= minimum && (scores[i] + 4) / 3 >= minimum && currentSurprises < surpriseCount) { count++; currentSurprises++; } } return count; } }
0
1,189,890
A11759
A12713
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 ProblemB { public static void main(String[] args) throws IOException { BufferedReader leer= new BufferedReader(new InputStreamReader(System.in)); int T=intS(leer.readLine()); for (int i = 1; i <= T; i++) { StringTokenizer st= new StringTokenizer(leer.readLine()); int N=intS(st.nextToken()); int S=intS(st.nextToken()); int p=intS(st.nextToken()); int[][] g= new int[N][3]; for (int j = 0; j < N; j++){ int v=intS(st.nextToken()); g[j][0]=v/3; g[j][1]=v%3; int score[]={g[j][0],g[j][0],g[j][0]}; if(g[j][1]>=1) score[0]++; if(g[j][1]==2) score[1]++; if(score[0]>=p) g[j][2]=2; else if(score[0]+1>=p && score[0]-score[1]==0 && score[0]!=0 ) g[j][2]=1; else g[j][2]=0; } int r=0; for (int j = 0; j < N; j++){ if(g[j][2]==1 && S>0){ g[j][2]=2; S--; } if(g[j][2]==2) r++; } System.out.println("Case #"+i+": "+r); } } static int intS(String s){ return Integer.parseInt(s); } }
0
1,189,891
A11759
A11046
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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; public class DirConsts { public static final String // INPUT_DIR = "/home/luke/Downloads", // OUTPUT_DIR = "/home/luke/Downloads/CodeJam"; }
0
1,189,892
A11759
A10953
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 at.jaki.codejam.qr2012.B; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class B { private static final String TEMPLATE = "Case #%d: %d"; private static final String IN = "B-small-attempt0.in"; private static final String OUT = "B-small-attempt0.out"; private static Scanner sc; private static PrintWriter pw; public static void main(String[] args) throws FileNotFoundException { sc = new Scanner(new File(IN)); pw = new PrintWriter(new File(OUT)); int tests = sc.nextInt(); for (int i = 1; i <= tests; i++) { resolve(i); } pw.flush(); pw.close(); } private static void resolve(int TT) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int[] scores = new int[n]; for (int i = 0; i < n; i++) { scores[i] = sc.nextInt(); } int total = 0; for (int i = 0; i < n; i++) { int q = scores[i] / 3; int r = scores[i] % 3; int best; if (r == 0) { best = q; } else { best = q + 1; } if (best >= p) { total++; continue; } if (best == p - 1) { if (s > 0 && r != 1 && scores[i] != 0) { total++; s--; continue; } } } pw.println(String.format(TEMPLATE, TT, total)); System.out.println(total); } } // 4---> 2 1 1 // 4*--> 2 2 0 // 5---> 2 2 1 // 5*--> 3 1 1 // 6---> 2 2 2 // 6*--> 3 2 1 // 7---> 3 2 2 // 7*--> 3 3 1
0
1,189,893
A11759
A11568
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 dancingwiththegooglers; import java.util.ArrayList; import java.util.List; public class TestCase { int numberOfGooglers; public int getNumberOfGooglers() { return numberOfGooglers; } public int getSurprisingScores() { return surprisingScores; } public int getBestResult() { return bestResult; } int surprisingScores; int bestResult; List<Integer> scores = null; public TestCase(int numberOfGooglers, int surprisingScores, int bestResult, List<Integer> scores){ this.numberOfGooglers = numberOfGooglers; this.surprisingScores = surprisingScores; this.bestResult = bestResult; this.scores = new ArrayList<Integer>(scores); } public int execute(){ int bestScorers = 0; for(int score : this.scores){ if(canItBeTheBestScorer(score, bestResult)) bestScorers++; } return bestScorers; } private boolean canItBeTheBestScorer(int score, int bestResult2) { if(score < bestResult2) return false; if(bestResult2 == 0) return true; if(bestResult2 == 1) if(score > 0) return true; else return false; if(score >= (bestResult2 * 3) - 2){ return true; }else if(score >= (bestResult2 * 3) - 4){ if(this.surprisingScores > 0){ this.surprisingScores--; return true; } return false; } return false; } }
0
1,189,894
A11759
A11482
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.StringTokenizer; public class Dancing { static int N, S, p; static int[] t; public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new FileReader("dancing.in")); int tc = Integer.parseInt(reader.readLine()); String line; StringTokenizer st; for (int c = 1; c <= tc; c++) { line = reader.readLine(); st = new StringTokenizer(line); N = Integer.parseInt(st.nextToken()); S = Integer.parseInt(st.nextToken()); p = Integer.parseInt(st.nextToken()); t = new int[N]; for (int i = 0; i < N; i++) { t[i] = Integer.parseInt(st.nextToken()); } System.out.println("Case #"+c+": "+solve()); } } static int solve(){ boolean[] puedeSolo = new boolean[N]; for (int i = 0; i < N; i++) { int k = t[i]/3; if (t[i]%3==0 && k>=p) puedeSolo[i]=true; if (t[i]%3!=0 && k+1>=p) puedeSolo[i]=true; } boolean[] puedeSorpresa= new boolean[N]; for (int i = 0; i < N; i++) { int k = t[i]/3; if (t[i]%3==2 && k+2>=p) puedeSorpresa[i]=true; if (t[i]>=2 && t[i]%3<2 && k+1>=p) puedeSorpresa[i]=true; } int cps = 0; for (int i = 0; i < N; i++) { if (puedeSolo[i]) cps++; } int cpsor = 0; for (int i = 0; i < N; i++) { if (!puedeSolo[i] && puedeSorpresa[i]) cpsor++; } return Math.min(cps+cpsor, cps + S); } }
0
1,189,895
A11759
A10478
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package year2012.DancingWiththeGooglers; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; final class DancingWiththeGooglers { /** * @param args * @throws IOException */ static class Triplet { public boolean ableMax = false; public boolean ableSurprising = true; public boolean beMaxMustSurprise = false; Triplet(int totalScore, int maxScore) { int mean = totalScore / 3; int remainder = totalScore % 3; if (totalScore == 29 || totalScore == 30) { ableMax = true; } else if (totalScore == 0 || totalScore == 1) { ableSurprising = false; if (maxScore <= totalScore) { ableMax = true; } else ableMax = false; } else if (mean >= maxScore) { ableMax = true; } else if (mean == (maxScore - 1)) { if (remainder == 2 || remainder == 1) ableMax = true; if (remainder == 0) beMaxMustSurprise = true; } else if (mean == (maxScore - 2)) { if (remainder == 2) beMaxMustSurprise = true; } } } public static void main(String[] args) throws IOException { String file = "B-small-attempt0"; Scanner sc = new Scanner(new FileReader(file + ".in")); PrintWriter pw = new PrintWriter(new FileWriter(file + ".out")); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int N = sc.nextInt(); int S = sc.nextInt(); // surprising int p = sc.nextInt(); int totalBeAlwaysMax = 0; int totalBeMaxMustSurprising = 0; int totalNotSurpriseAbleMax = 0; int result = 0; for (int i1 = 0; i1 < N; i1++) { Triplet temp = new Triplet(sc.nextInt(), p); if (temp.ableMax && temp.ableSurprising) totalBeAlwaysMax++; if (temp.beMaxMustSurprise == true) totalBeMaxMustSurprising++; if (!temp.ableSurprising && temp.ableMax) { totalNotSurpriseAbleMax++; } } if (S <= totalBeMaxMustSurprising) { result = totalBeAlwaysMax + S + totalNotSurpriseAbleMax ; } else { result = totalBeAlwaysMax + totalBeMaxMustSurprising + totalNotSurpriseAbleMax; } pw.println("Case #" + (i + 1) + ": " + result); // pw.println(); } pw.flush(); pw.close(); sc.close(); } }
0
1,189,896
A11759
A12751
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
package qualification; import java.util.ArrayList; import java.util.List; import loader.InputReader; import loader.OutPutWriter; public class GoogleDance { static String inputName = "B-small-attempt0.in"; /** * @param args */ public static void main(String[] args) { start(); } public static void start(){ InputReader reader = new InputReader(); reader.read(inputName); List<String> inputs = reader.getInputs(); List<String> outputs = new ArrayList<String>(); for(String in: inputs){ List<Integer> aLine = transfer(in); int out = process(aLine); outputs.add(new Integer(out).toString()); } OutPutWriter writer = new OutPutWriter(); writer.write("question2.out", outputs); } public static int process(List<Integer> aLine){ int res = 0; int number = aLine.get(0); int avaliableSup = aLine.get(1); int p = aLine.get(2); if(p == 0) return number; int standard = p*3; int mustSuccessCounter = 0; int needSup = 0; for(int i=3; i<aLine.size(); i++){ int t = aLine.get(i); if(t >= standard-2) mustSuccessCounter++; if((t == standard-3 || t == standard-4) && (standard-3>0))needSup++; } res = mustSuccessCounter + (Math.min(avaliableSup, needSup)); return res; } private static List<Integer> transfer(String s){ List<Integer> l = new ArrayList<Integer>(); String[] arrayString = s.split(" "); for(int i=0; i<arrayString.length; i++){ l.add(Integer.parseInt(arrayString[i])); } return l; } }
0
1,189,897
A11759
A10398
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new 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 dancinggooglers; import java.io.File; import java.util.Scanner; public class DanceScoreCalculator { public static void main(String[] args) { if(args.length <= 0 || args[0] == null) { System.out.println("You must enter a file to read"); System.out.println("Usage: blah <filename>"); System.exit(0); } File argFile = new File(args[0]); try { Scanner googleSpeakScanner = new Scanner(argFile); String firstLine = googleSpeakScanner.nextLine(); Integer linesToScan = new Integer(firstLine); for(int i = 1; i <= linesToScan; i++) { String googleDancerLine = googleSpeakScanner.nextLine(); DanceScoreCase danceCase = new DanceScoreCase(googleDancerLine); System.out.println(String.format("Case #%d: %d", i, danceCase.maxDancersThatCouldPass())); } } catch (Exception e) { e.printStackTrace(); } } }
0
1,189,898
A11759
A10451
import java.io.*; import java.util.*; public class Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class Problem2 { public static void main (String[] args) throws IOException { File file = new File("input.txt"); Scanner scan = null; try { scan = new Scanner(file); } catch (FileNotFoundException e) { e.printStackTrace(); } FileWriter fstream = null; try { fstream = new FileWriter("output.txt"); } catch (IOException e) { e.printStackTrace(); } BufferedWriter out = new BufferedWriter(fstream); int lineNumber; lineNumber = Integer.parseInt(scan.nextLine()); for (int i = 0; i < lineNumber; i++) { Scanner lineScan = new Scanner(scan.nextLine()); out.write("Case #" + (i + 1) + ": "); int n = lineScan.nextInt(); int s = lineScan.nextInt(); int p = lineScan.nextInt(); int[] scores = new int[n]; for (int j = 0; j < n; j++) { scores[j] = lineScan.nextInt(); } int total = 0; for (int j = 0; j < n; j++) { if (scores[j] == 0) { if (p == 0) { total ++; } continue; } if (scores[j]/3 >= p) { total++; } else if (scores[j]/3 == p-1) { if (scores[j]%3 >= 1) { total++; } else { if (s > 0) { s--; total++; } } } else if (scores[j]/3 == p-2) { if (scores[j]%3 >= 2) { if (s > 0) { s--; total++; } } } } out.write(total + " \n"); } out.close(); } }
0
1,189,899