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
A12852
A12076
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.renoux.gael.codejam.utils; public class TechnicalException extends RuntimeException { private static final long serialVersionUID = 1L; public TechnicalException() { super(); } public TechnicalException(String message, Throwable cause) { super(message, cause); } public TechnicalException(String message) { super(message); } public TechnicalException(Throwable cause) { super(cause); } }
0
500
A12852
A10295
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; import java.math.*; public class Main implements Runnable { static Scanner scanner; static BufferedReader input; static PrintWriter pw; public static void main(String[] args) throws Exception { new Thread(new Main()).start(); } public void run() { try { input = new BufferedReader(new FileReader("input.txt")); scanner = new Scanner(input); pw = new PrintWriter(new File("output.txt")); solve(); pw.close(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } public void solve() throws Exception { int T = scanner.nextInt(); for(int t = 0; t < T; t++) { int N = scanner.nextInt(); // the number of Googlers int S = scanner.nextInt(); // the number of surprising triplets of scores int P = scanner.nextInt(); // Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? int [] ti = new int[N]; // the total points of the Googlers. for(int i = 0; i < N; i++){ ti[i]=scanner.nextInt(); } //--- judge int r, s; int ans = 0; int cand = 0; for(int i = 0; i < N; i++){ r = ti[i]/3; s = ti[i]%3; if ( s == 0 ) { if ( r >= P ) { ans++; } else if ( r+1 >= P && r-1 >=0 ) { cand++; } } else if ( s == 1 ) { if ( r+1 >= P ) { ans++; } } else { if ( r+1 >= P ) { ans++; } else if ( r+2 >= P ) { cand++; } } } ans = ans + Math.min (cand, S); pw.println("Case #" + (t+1) + ": " + ans); } } }
0
501
A12852
A11548
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; import java.util.ArrayList; public class googler{ public static void main(String[] args) throws IOException{ Scanner fileScan = new Scanner(new File("infile.in")); Writer out = new OutputStreamWriter(new FileOutputStream("output.txt")); fileScan.nextLine(); int i = 0; ArrayList<Integer> totals = new ArrayList<Integer>(); while(fileScan.hasNext()){ i++; int count = 0; totals.clear(); String line = fileScan.nextLine(); Scanner lineScan = new Scanner(line); int n = lineScan.nextInt(); int s = lineScan.nextInt(); int p = lineScan.nextInt(); while(lineScan.hasNext()){ totals.add(lineScan.nextInt()); } if (p == 0){ count = totals.size(); } else if (p == 1){ for(int temp: totals){ if (temp > 0){ count++; } } } else{ int sureTotal = 3 * p -2; int surprisingTotal = 3 * p - 4; int surprise = 0; for (int temp: totals){ if (temp >= sureTotal){ count++; } else if (temp >= surprisingTotal){ surprise++; } } count += ((s < surprise)? s: surprise); } out.write("Case #" + i + ": " + count + "\n"); } out.close(); } }
0
502
A12852
A11840
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; /** * * @author Daniel Sheng */ public class Dancing { private final static int NUM_JUDGES = 3; /** * @param args the command line arguments */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int lns = Integer.parseInt(in.nextLine()); for(int ln = 0; ln < lns; ln++) { String[] tokens = in.nextLine().split("\\s+"); int numDancers = Integer.parseInt(tokens[0]), numSurprising = Integer.parseInt(tokens[1]), targetBestScore = Integer.parseInt(tokens[2]); int result = 0; for(int i = 0; i < numDancers; i++) { int score = Integer.parseInt(tokens[i + 3]); if(score >= targetBestScore * NUM_JUDGES - 2) result++; else if(score >= targetBestScore * NUM_JUDGES - 4 && numSurprising > 0 && targetBestScore - 2 >= 0) { result++; numSurprising--; } } System.out.println("Case #" + (ln + 1) + ": " + result); } } }
0
503
A12852
A12402
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; import java.io.*; public class problem2 { private final Scanner sc; private static final boolean debug = true; static void debug(Object ... objects) { if(debug) System.err.println(Arrays.toString(objects)); } problem2() { sc = new Scanner(new BufferedInputStream(System.in)); } public static void main(String [] args) { (new problem2()).solve(); } void solve() { int T = sc.nextInt(); int cs = 0; while(cs < T) { cs++; int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int ans = 0; for(int i=0;i<n;i++) { int x = sc.nextInt(); int maxVal = (x+2)/3; if(maxVal>=p) { ans++; continue; } int m = x%3; if(m == 1) continue; if(maxVal == p-1 && s>0) { if(maxVal+1<=10&&maxVal-1>=0) { ans++; s--; } } } System.out.println("Case #" + cs+ ": "+ ans); } } }
0
504
A12852
A12786
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; class Dancing { public static void main(String args[]) throws IOException { Scanner in = new Scanner(new File("dance.txt")); PrintWriter fw = new PrintWriter(new FileWriter(new File("dance.out"))); int cases = in.nextInt(); for (int c = 1; c <= cases; c++) { int N = in.nextInt(); // number of googlers int S = in.nextInt(); // number of surprising triplets int p = in.nextInt(); // best result ArrayList<Integer> scores = new ArrayList<Integer>(); for (int n = 0; n < N; n++) { int googler = in.nextInt(); scores.add(googler); } Collections.sort(scores); int pass = 0; for (int i = 0; i < scores.size(); i++) { int score = scores.get(i); int mod = score % 3; int max = score / 3; int low = max; if (mod > 0) { max++; } if (max >= p) { pass++; continue; } if (S > 0) { if (mod % 2 == 0) { if(mod == 0 && low == 0){ continue; } max++; if (max >= p) { pass++; S--; continue; } } } }// for loop String fwout = "Case #" + c + ": " + pass; fw.println(fwout); } fw.close(); } }
0
505
A12852
A12349
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/** * User: avokin * Date: 4/14/12 */ public class ProblemB { private static int solve(int n, int s, int p, int[] t) { int result = 0; for (int i = 0; i < n; i++) { if (t[i] % 3 == 0) { int a = t[i] / 3; if (a >= p) { result++; } else { if (a > 0 && a + 1 == p && s > 0) { s--; result++; } } } else if (t[i] % 3 == 1) { int a = t[i] / 3 + 1; if (a >= p) { result++; } } else { int a = t[i] / 3 + 1; if (a >= p) { result++; } else { if (a + 1 == p && s > 0) { s--; result++; } } } } return result; } public static void main(String[] args) { String input = "100\n" + "3 1 5 15 13 11\n" + "3 0 8 23 22 21\n" + "2 2 10 18 3\n" + "1 0 0 28\n" + "1 0 8 21\n" + "2 0 0 28 4\n" + "1 0 7 17\n" + "2 0 10 26 12\n" + "3 0 4 11 8 8\n" + "2 2 3 14 25\n" + "3 0 10 30 30 30\n" + "1 0 0 4\n" + "3 1 4 8 9 4\n" + "1 0 8 12\n" + "2 2 9 3 11\n" + "3 0 6 13 15 20\n" + "3 1 7 19 26 9\n" + "1 0 6 15\n" + "3 1 4 9 8 9\n" + "1 0 3 6\n" + "3 0 4 11 28 8\n" + "2 0 4 11 9\n" + "1 0 5 12\n" + "1 0 4 25\n" + "1 0 3 5\n" + "1 0 3 21\n" + "2 0 0 30 30\n" + "2 1 4 8 8\n" + "1 0 7 19\n" + "3 3 8 14 19 20\n" + "1 1 9 22\n" + "1 0 9 24\n" + "3 0 5 11 12 1\n" + "3 3 5 25 7 16\n" + "2 0 7 17 18\n" + "3 2 4 2 2 12\n" + "3 3 5 2 12 27\n" + "3 0 1 16 4 17\n" + "1 0 7 4\n" + "1 0 5 11\n" + "3 1 7 12 25 9\n" + "3 3 5 3 4 12\n" + "1 0 3 1\n" + "1 0 1 0\n" + "3 0 9 18 19 30\n" + "3 0 6 15 29 26\n" + "2 0 9 7 4\n" + "1 0 6 5\n" + "3 0 8 28 21 21\n" + "2 2 7 9 10\n" + "1 0 4 8\n" + "1 0 10 26\n" + "2 2 4 2 17\n" + "3 0 10 0 0 26\n" + "1 0 10 15\n" + "2 0 4 30 8\n" + "3 0 2 4 22 27\n" + "1 1 8 25\n" + "3 2 7 29 2 27\n" + "2 0 2 22 25\n" + "3 0 4 9 30 9\n" + "2 0 3 5 6\n" + "2 0 3 30 30\n" + "2 0 1 0 0\n" + "3 0 4 24 3 17\n" + "3 3 0 14 16 4\n" + "2 0 6 27 16\n" + "2 1 10 16 24\n" + "1 0 4 27\n" + "1 1 4 10\n" + "2 1 1 3 17\n" + "1 0 8 21\n" + "3 0 9 23 22 24\n" + "1 0 9 2\n" + "3 0 1 25 2 29\n" + "3 0 7 17 18 17\n" + "3 0 6 3 14 13\n" + "1 0 10 6\n" + "3 2 9 23 24 23\n" + "2 1 3 5 5\n" + "3 2 1 23 0 11\n" + "2 2 3 18 10\n" + "2 1 8 25 21\n" + "2 1 9 7 23\n" + "1 1 0 19\n" + "1 0 8 20\n" + "3 1 6 10 15 15\n" + "3 1 0 8 4 1\n" + "2 2 6 8 20\n" + "3 0 9 22 21 12\n" + "3 3 0 11 11 2\n" + "1 1 10 19\n" + "2 2 0 4 3\n" + "1 0 8 20\n" + "3 1 8 20 16 21\n" + "2 0 10 26 27\n" + "3 0 0 0 0 0\n" + "1 1 8 14\n" + "2 1 10 26 27\n" + "1 1 6 12\n"; String[] lines = input.split("\n"); int T = Integer.parseInt(lines[0]); for (int i = 1; i <= T; i++) { String line = lines[i]; String[] items = line.split(" "); int n = Integer.parseInt(items[0]); int s = Integer.parseInt(items[1]); int p = Integer.parseInt(items[2]); int[] t = new int[n]; for (int j = 0; j < n; j++) { t[j] = Integer.parseInt(items[3 + j]); } int solution = solve(n, s, p, t); System.out.println("Case #" + i + ": " + solution); } } }
0
506
A12852
A10609
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.InputStreamReader; /** * * @author andy */ public class DancingWithGooglers { public static void main(String[] args) throws Exception { //char sd = '1'; //int[] sdf = new int[ 10 ]; //System.out.println( Math.ceil( 17 / 3.0 ) ); String map = "yhesocvxduiglbkrztnwjpfmaq"; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String s = in.readLine(); int numTestCases = Integer.parseInt(s); for( int testCase = 1 ; testCase <= numTestCases ; testCase ++ ) { String strCase = in.readLine(); String[] arrCase = strCase.split(" "); int count = 0; int numDancers = Integer.parseInt( arrCase[ 0 ] ); int numSurprises = Integer.parseInt( arrCase[ 1 ] ); int cutoff = Integer.parseInt( arrCase[ 2 ] ); for( int i = 0 ; i < numDancers ; i ++ ) { int score = Integer.parseInt(arrCase[ i + 3 ]); int modThree = score % 3; int divThree = score / 3; if( modThree > 0 ) divThree ++; if( divThree >= cutoff ) { count ++; }else if( numSurprises > 0 && (modThree == 0 || modThree == 2) && divThree > 1 && divThree + 1 >= cutoff) { numSurprises --; count ++; } } System.out.println("Case #" + testCase + ": " + count); } } }
0
507
A12852
A12021
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package codejam; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintWriter; /** * * @author Vale */ public class DancingWithGooglers { public static void main(String[] args){ String inputFile="/Users/Vale/Desktop/CodeJam/B-small-attempt4.in"; String outputFile="/Users/Vale/Desktop/CodeJam/B-small-output4.txt"; String[] lines=readAllLinesOfFile(inputFile); int numberOfCases=Integer.parseInt(lines[0]); String[] result=new String[numberOfCases]; for (int i = 1; i <= numberOfCases; i++) { String currentLine=lines[i]; int numberOfGooglers=Integer.parseInt(currentLine.substring(0, currentLine.indexOf(" "))); int start=currentLine.indexOf(" ")+1; int surprisingTriplets=Integer.parseInt(currentLine.substring(start, currentLine.indexOf(" ", start))); start=currentLine.indexOf(" ", start)+1; int valueOfP=Integer.parseInt(currentLine.substring(start, currentLine.indexOf(" ", start))); start=currentLine.indexOf(" ", start)+1; String totalPointsString=currentLine.substring(start); int[] totalPoints=getIntArrayFromSpaceSeperatedString(totalPointsString, numberOfGooglers); java.util.Arrays.sort(totalPoints); int resultValue=0; for (int j = totalPoints.length-1; j >=0 ; j--){ if(valueOfP==1){ if(totalPoints[j]>0){ resultValue++; } } else if(totalPoints[j]>3*valueOfP-3){ resultValue++; } else if(totalPoints[j]>3*valueOfP-5 && surprisingTriplets>0){ resultValue++; surprisingTriplets--; } } result[i-1]="Case #"+i+": "+resultValue; } writeLinesToFile(outputFile, result); } public static String[] readAllLinesOfFile(String file) { try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(file); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line String[] result = new String[1000000]; int index = 0; while ((strLine = br.readLine()) != null) { result[index++] = strLine; } //Close the input stream in.close(); String[] newResult = java.util.Arrays.copyOf(result, index); return newResult; } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); return new String[]{}; } } public static void writeLinesToFile(String filename, String[] linesToWrite) { try { PrintWriter pw = new PrintWriter(new FileWriter(filename)); for (int i = 0; i < linesToWrite.length; i++) { pw.println(linesToWrite[i]); } pw.flush(); pw.close(); } catch (Exception e) { throw new RuntimeException("Writing File \"" + filename + "\" Failed!"); } } public static int[] getIntArrayFromSpaceSeperatedString(String numbers, int numberOfInts){ numbers=numbers.trim(); int[] result= new int[numberOfInts]; int start=0; int end=numbers.indexOf(" "); for(int i=0; i<numberOfInts; i++){ if(end!=-1){ result[i]=Integer.parseInt(numbers.substring(start, end)); start=end+1; end=numbers.indexOf(" ", start); } else{ result[i]=Integer.parseInt(numbers.substring(start)); } } return result; } }
0
508
A12852
A12059
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class main { /** * @param args */ public static void main(String[] args) { try { System.setOut(new PrintStream(new File("B-small-attempt0.out"))); Scanner sc = new Scanner(new File("B-small-attempt0.in")); int T = sc.nextInt(); sc.nextLine(); for (int tc = 1; tc<=T; tc++) { int y = 0, y2 = 0; int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); for (int i = 0; i<N; i++) { int t = sc.nextInt(); if(t/3>=p || (t/3==p-1 && t%3>0)) { y++; } else if((t/3==p-1 && t%3==0) || (t/3==p-2 && t%3==2)) { if(S>0 && t>=2 && t<=28) { y++; S--; } } } System.out.format("Case #%d: %d%n", tc, y); } } catch (FileNotFoundException e) { e.printStackTrace(); } } }
0
509
A12852
A11939
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package dancingWithGooglers; public class BestResult { public int result(String input)throws Exception { String[] array= input.split(" "); int noOfGooglers = Integer.parseInt(array[0]); int surprising = Integer.parseInt(array[1]); int p = Integer.parseInt(array[2]); int x; int[] listOfBestResults = new int[noOfGooglers]; int count = 0; for(int i=3;i<array.length;i++) { x = Integer.parseInt(array[i]); if(canItBeBestResult(x, p)) { listOfBestResults[count] = x; count++; } } int bestResultCount = 0; for(int i=0;i<count;i++) { if(listOfBestResults[i]%3 == 2) { if(listOfBestResults[i]/3>=p) { System.out.println("list of best result w/o surprising " + listOfBestResults[i]); bestResultCount++; } else if((listOfBestResults[i]/3) + 2>=p && (listOfBestResults[i]/3) + 1>=p) { System.out.println("list of best result w/o surprising " + listOfBestResults[i]); bestResultCount++; } else if((listOfBestResults[i]/3) + 2>=p && surprising!=0) { System.out.println("list of best result surprising " + listOfBestResults[i]); bestResultCount++; surprising--; } } else if(listOfBestResults[i]%3 == 1 ) { if(listOfBestResults[i]/3>=p) { System.out.println("list of best result w/o surprising " + listOfBestResults[i]); bestResultCount++; } else if((listOfBestResults[i]/3) + 1>=p) { System.out.println("list of best result w/o surprising " + listOfBestResults[i]); bestResultCount++; } else if((listOfBestResults[i]/3) + 1>=p && surprising!=0) { System.out.println("list of best result surprising " + listOfBestResults[i]); bestResultCount++; surprising--; } } else if( listOfBestResults[i]%3 == 0 ) { if(listOfBestResults[i]/3>=p) { System.out.println("list of best result w/o surprising " + listOfBestResults[i]); bestResultCount++; } else if((listOfBestResults[i]/3) + 1>=p && surprising!=0) { System.out.println("list of best result surprising " + listOfBestResults[i]); bestResultCount++; surprising--; } } } return bestResultCount; } public boolean canItBeBestResult(int x, int p) { if(p==0) { return true; } if( x%3 == 2 && ((x/3)+2) >= p) { return true; } else if( x%3 == 1 && ((x/3)+1) >= p) { return true; } else if( x%3 == 0 && ((x/3)+1)>=p && x!=0) { return true; } return false; } }
0
510
A12852
A13010
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class QualificationRoundB { public static void main(String[] args) throws IOException { String inFile = args[0]; String outFile = inFile.replaceAll("\\.in$", ".out"); Scanner scanner = new Scanner(new FileInputStream(inFile)); int cases = scanner.nextInt(); FileWriter fileWriter = new FileWriter(outFile); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); for(int c = 1; c <= cases; c++){ bufferedWriter.write(String.format("Case #%d: ", c)); int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int t[] = new int[N]; for(int n = 0; n < N; n++) t[n] = scanner.nextInt(); int count = 0; int midTop = 3*p - 3; int midBot = 3*p - 4; for(int n = 0; n < N; n++){ switch(p){ case 0: case 1: if(t[n] >= p) count++; break; default: if(t[n] > midTop){ count++; } else if(t[n] >= midBot && S > 0){ S--; count++; } } } System.out.println(String.format("%d", count)); bufferedWriter.write(String.format("%d\n", count)); } bufferedWriter.close(); fileWriter.close(); } }
0
511
A12852
A10392
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package gcj2012.qual; import gcj2010.round2.*; import gcj2009.*; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.PrintWriter; import java.util.Scanner; /** * * @author scbit */ public class P2 { /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { new P2().run(); } PrintWriter pw; void run() throws Exception{ File infile=new File("B-small-attempt0.in"); String outfile="result"; pw=new PrintWriter(outfile); int T=0; //BufferedReader br=new BufferedReader(new FileReader(infile)); //N=Integer.parseInt(br.readLine()); Scanner sc=new Scanner(infile); T=sc.nextInt(); for(int case_i=1;case_i<=T;case_i++) { int result = 0; int N=sc.nextInt(); int S=sc.nextInt(); int p=sc.nextInt(); int[] ti=new int[N]; for(int i=0;i<N;i++){ ti[i]=sc.nextInt(); } int threshold1=3*p-2; int threshold2=3*p-4; if(p==0) threshold1=0; if(p<=1) threshold2=100000; for(int i=0;i<N;i++){ if(ti[i]>=threshold1) result++; else if(ti[i]>=threshold2){ if(S>0){ S--; result++; } } } pw.printf("Case #%d: %d\n", case_i,result); System.out.printf("Case #%d: %d\n", case_i,result); } pw.close(); } }
0
512
A12852
A13136
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class B { static Scanner s; /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub s = new Scanner(new File("a.txt")); int T = s.nextInt(); for(int a=1;a<=T;a++) { int N = s.nextInt(); int S = s.nextInt(); int p = s.nextInt(); int res = 0; for (int i=0;i<N;i++) { int v = s.nextInt(); if (v<p) continue; if (p==0) res++; else if (v/p >= 3) res++; else if ((v+2)/p>=3) { res++; } else if (S!=0 && (v+4)/p>=3) { res++; S--; } } if (s.hasNext()) s.nextLine(); System.out.println("Case #"+a+": "+res); } s.close(); } }
0
513
A12852
A10436
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
public class codejam { public static void main(String argv[]) throws Exception{ DancingWiththeGooglers dancingWiththeGooglers=new DancingWiththeGooglers(); dancingWiththeGooglers.start(); } }
0
514
A12852
A10723
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package quiz.number05; import java.io.*; import java.util.Arrays; /** * @author Keesun Baik */ public class KeesunDancingTest { public static void main(String[] args) throws IOException { KeesunDancingTest dancing = new KeesunDancingTest(); BufferedReader in = new BufferedReader(new FileReader("/workspace/telepathy/test/quiz/number05/B-small-attempt0.in")); String s; int lineNum = 0; int problemNum = 0; String answer = ""; while ((s = in.readLine()) != null) { if (s.isEmpty()) { return; } if (lineNum == 0) { problemNum = Integer.parseInt(s); } else { answer += "Case #" + lineNum + ": " + dancing.figureP(s) + "\n"; } lineNum++; } in.close(); System.out.println(answer); BufferedWriter out = new BufferedWriter(new FileWriter("/workspace/telepathy/test/quiz/number05/B-small-attempt0.out")); out.write(answer); out.close(); } private int figureP(String s) { String[] inputs = s.split(" "); int people = Integer.parseInt(inputs[0]); int surprise = Integer.parseInt(inputs[1]); int minScore = Integer.parseInt(inputs[2]); String[] scoreStrings = Arrays.copyOfRange(inputs, 3, inputs.length); int[] scores = new int[scoreStrings.length]; for (int i = 0; i < scoreStrings.length; i++) { scores[i] = Integer.parseInt(scoreStrings[i]); } int cases = 0; for (int score : scores) { int base = score / 3; System.out.println("score: " + score); System.out.println("base: " + base); System.out.println("minScore: " + minScore); System.out.println("surprise: " + surprise); switch (score % 3) { case 0: { System.out.println("0"); if (base >= minScore) { cases++; } else if (surprise > 0 && base > 0 && base + 1 >= minScore) { cases++; surprise--; } break; } case 1: { System.out.println("1"); if (base >= minScore || base + 1 >= minScore) { cases++; } else if (surprise > 0 && base + 1 >= minScore) { cases++; surprise--; } break; } case 2: { System.out.println("2"); if (base + 1 >= minScore || base >= minScore) { cases++; } else if (surprise > 0 && base + 2 >= minScore) { cases++; surprise--; } break; } } } System.out.println("people: " + people); System.out.println("remain surprise: " + surprise); return cases; } }
0
515
A12852
A11596
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package quals; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class DancingWithTheGooglers { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(reader.readLine()); for (int i=1; i<=T; i++) { String line = reader.readLine(); StringTokenizer tok = new StringTokenizer(line); int N = Integer.parseInt(tok.nextToken()); int S = Integer.parseInt(tok.nextToken()); int p = Integer.parseInt(tok.nextToken()); int most = 0; while (tok.hasMoreTokens()) { int sum = Integer.parseInt(tok.nextToken()); if (sum >= p*3-2) most++; else if (sum >= p*3-4 && S>0 && p>1) { most++; S--; } } System.out.printf("Case #%d: %d\n", i, most); } } }
0
516
A12852
A13014
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package googleCodeJam; import java.io.*; import java.util.*; public class ThirdExercise { /** * @param args */ public static void main(String[] args) { try{ FileInputStream fstream = new FileInputStream("B-small-attempt7.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fstream2 = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream2); String strLine; int j=0; strLine = br.readLine(); while ((strLine = br.readLine()) != null) { String[] st = strLine.split(" "); ArrayList<Integer> temp = new ArrayList<>(); int i =0; for (i=3;i<st.length;i++) temp.add(Integer.parseInt(st[i])); int nr = 0; int nr_s = 0; int n = Integer.parseInt(st[0]); int s = Integer.parseInt(st[1]); int p = Integer.parseInt(st[2]); for (Integer tmp: temp) if (Math.ceil(((double)tmp)/3.0)>=p) nr++; else if (Math.ceil(((double)tmp)/3.0)>=p-1 && ((double)tmp)/3.0-0.5>=0) nr_s++; nr+=((s>nr_s)?nr_s:s); //shkrimi i rezultatit out.write("Case #"+(++j)+": "+nr+" \n"); } in.close(); out.close(); } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
517
A12852
A10817
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * Problem B. Dancing With the Googlers */ /** * @author zdenda * */ public class Main { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); in.nextLine(); for (int i = 1; i <= t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); List<Integer> ti = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { ti.add(in.nextInt()); } //in.nextLine(); int result = compute(s, p, ti); System.out.println("Case #"+ i + ": " + result); } } /** * computes the maximum number of Googlers that could have had a best result of at least p * * @param s - the number of surprising triplets of scores * @param p * @param ti - the total points of the Googlers * @return the maximum number of Googlers that could have had a best result of at least p */ public static int compute(int s, int p, List<Integer> ti) { // limit for not surprising int nsLimit = p + 2 * (Math.max(0, (p-1))); // limit for surprising int sLimit = p + 2 * (Math.max(0, (p-2))); // not surprising counter int nsCount = 0; // surprising counter int sCount = 0; for (Integer score : ti) { if(score >= nsLimit) { ++nsCount; // if it's over not surprising limit } else if (score >= sLimit) { ++sCount; // if it's at over surprising limit, but under not surprising limit } } // max number of surprising scores is S, so we take the smaller number sCount = Math.min(s, sCount); return nsCount + sCount; } }
0
518
A12852
A12013
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.Set; class Case1 extends Question{ public Case1(String in, String out) { super(in, out); } class Unit{ int c; int i; ArrayList<Integer> items; ArrayList<Integer> items_old; public Unit(int c,int i,ArrayList<Integer> items){ this.c=c; this.i=i; this.items=items; items_old=new ArrayList<Integer>(); items_old.addAll(items); } public String solve(){ int st=0; int ed=items.size()-1; Collections.sort(items); while(true){ int small=items.get(st); int large=items.get(ed); int sum=small+large; if(sum>c) ed--; else if(sum<c) st++; else break; } boolean small_found=false; boolean large_found=false; ArrayList<Integer> rr=new ArrayList<Integer>(); for(int k=0;k<items.size();k++){ if(!small_found&&items_old.get(k)==items.get(st)){ rr.add(k+1); }else if(!large_found&&items_old.get(k)==items.get(ed)){ rr.add(k+1); } } return rr.get(0)+" "+rr.get(1); } } public void solve(){ ArrayList<Unit> units=new ArrayList<Unit>(); ArrayList<String> rst=new ArrayList<String>(); int n=pInt(0); int i=1; while(i<data.size()){ int c=pInt(i++); int i_n=pInt(i++); ArrayList<Integer> arr=splitInt(i++," "); units.add(new Unit(c,i,arr)); } for(int j=0;j<units.size();j++){ String r="Case #"+(j+1)+": "+units.get(j).solve(); rst.add(r); } try { write(file_out,rst); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class Case2 extends Question{ Map<Character,Integer> rate=new HashMap<Character,Integer>(); Map<Character,Character> change=new HashMap<Character,Character>(); public Case2(String in, String out) { super(in, out); } public void solve(){ ArrayList<String> graph=new ArrayList<String>(); ArrayList<String> rst=new ArrayList<String>(); change.put('a','y'); change.put('b','h'); change.put('c','e'); change.put('d','s'); change.put('e','o'); change.put('f','c'); change.put('g','v'); change.put('h','x'); change.put('i','d'); change.put('j','u'); change.put('k','i'); change.put('l','g'); change.put('m','l'); change.put('n','b'); change.put('o','k'); change.put('p','r'); change.put('q','z'); change.put('r','t'); change.put('s','n'); change.put('t','w'); change.put('u','j'); change.put('v','p'); change.put('w','f'); change.put('x','m'); change.put('y','a'); change.put('z','q'); int count=0; for(String s:data){ String n=""; for(int i=0;i<s.length();i++){ char c=s.charAt(i); if(rate.containsKey(c)){ rate.put(c,rate.get(c)+1); }else{ rate.put(c,1); } if(change.containsKey(c)){ c=change.get(c); } n=n+c; } if(count!=0) rst.add("Case #"+count+": "+n); count++; } Map<String,Integer> word_map=new HashMap<String,Integer>(); for(String s:data){ ArrayList<String> words=splitString(s," "); for(String w:words){ if(word_map.containsKey(w)){ word_map.put(w,word_map.get(w)+1); }else{ word_map.put(w,1); } } } Set<String> key_word=word_map.keySet(); for(String w:key_word){ if(word_map.get(w)>2){ if(w.length()<=2) System.out.println(w+":"+word_map.get(w)); } } for(String w:key_word){ if(word_map.get(w)>2){ if(w.length()==3) System.out.println(w+":"+word_map.get(w)); } } for(String w:key_word){ if(word_map.get(w)>2){ if(w.length()==4) System.out.println(w+":"+word_map.get(w)); } } Set<Character> keys=rate.keySet(); for(char key='a';key<='z';key++){ System.out.println(key+":"+rate.get(key)); } try { write(file_out,rst); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class Dancer extends Question{ public Dancer(String in, String out) { super(in, out); // TODO Auto-generated constructor stub } public void solve(){ try { data=read(file_in); } catch (IOException e) { e.printStackTrace(); } int cases=pInt(0); data.remove(0); ArrayList<String> rst=new ArrayList<String>(); int count=1; for(String s:data){ ArrayList<Integer> arr=splitInt(s," "); int num=arr.remove(0); int sp=arr.remove(0); int cut=arr.remove(0); int cut_normal=cut*3-2; int cut_sp=cut==1?1:cut*3-4; int besters=0; for(int i:arr){ if(i>=cut_normal) besters++; else if(i>=cut_sp){ if(sp>0){ besters++; sp--; } } } String add="Case #"+count+": "+besters; rst.add(add); count++; } try { write(file_out,rst); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } class Question{ String file_in; String file_out; ArrayList<String> data; public Question(String in,String out){ file_in=in; file_out=out; try { data=read(file_in); } catch (IOException e) { e.printStackTrace(); } } public void solve(){} public int pInt(int index){ return Integer.parseInt(data.get(index)); } public int pInt(String s){ return Integer.parseInt(s); } public ArrayList<String> splitString(String s,String sep){ ArrayList<String> arr=new ArrayList<String>(); String[] ss=s.split(sep); for(int i=0;i<ss.length;i++){ arr.add(ss[i]); } return arr; } public ArrayList<Integer> splitInt(String s,String sep){ ArrayList<Integer> arr=new ArrayList<Integer>(); String[] ss=s.split(sep); for(int i=0;i<ss.length;i++){ arr.add(Integer.parseInt(ss[i])); } return arr; } public ArrayList<String> splitString(int index,String sep){ return splitString(data.get(index), sep); } public ArrayList<Integer> splitInt(int index,String sep){ return splitInt(data.get(index), sep); } public ArrayList<String> read(String filename) throws IOException{ ArrayList<String> arr=new ArrayList<String>(); BufferedReader br=null; br=new BufferedReader(new FileReader(filename)); String l=null; while((l=br.readLine())!=null){ arr.add(l); } br.close(); return arr; } public void write(String filename,ArrayList<String> data) throws IOException{ PrintWriter pw=new PrintWriter(filename); for(String s:data){ pw.println(s); } pw.close(); } } public class Test { public static void main(String[] args){ Question a=new Dancer("B-small-attempt0.in","rst.txt"); a.solve(); } }
0
519
A12852
A10797
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedInputStream; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.util.HashMap; import java.util.Map; public class main { /** * @param args */ @SuppressWarnings("deprecation") public static void main(String[] args) { long now = System.currentTimeMillis(); // TODO Auto-generated method stub File file = new File("./input.txt"); FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; try { fis = new FileInputStream(file); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); int testCaseCount = Integer.parseInt(dis.readLine()), testCase; for(testCase = 0; testCase < testCaseCount; testCase ++) { String[] line = dis.readLine().split(" "); int N = Integer.parseInt(line[0]) , S = Integer.parseInt(line[1]) , p = Integer.parseInt(line[2]) , i; int[] g = new int[N]; for(i = 0; i < N; i ++) { g[i] = Integer.parseInt(line[i+3]); } // Program int found = 0, similar = p + ( 2 * (p-1)), surprise = p + (2 * (p-2)); if(similar < 0) { if(p > 0 ) { similar = 1; } else { similar = 0; } } if(surprise < 0) { if(p > 0 ) { surprise = 1; } else { surprise = 0; } } for(i = 0; i < N; i ++) { // Not surprising if(g[i] >= similar) { found ++; } else if(g[i] >= surprise && S > 0) { found ++; S --; } } System.out.println("Case #" + (testCase + 1) + ": " + found); } fis.close(); bis.close(); dis.close(); } catch(Exception e) { e.printStackTrace(); } } }
0
520
A12852
A11098
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class DancingWithTheGooglers { /** * @param args */ public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new FileReader( "C:\\bInput.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter( "C:\\bOutput.txt")); String strLine; strLine = br.readLine(); int size = Integer.parseInt(strLine); for (int i = 1; i <= size; i++) { String[] s = br.readLine().split(" "); int N = Integer.parseInt(s[0]); int S = Integer.parseInt(s[1]); int p = Integer.parseInt(s[2]); int[] totals = new int[N]; for(int j=0;j<N;j++){ totals[j] = Integer.parseInt(s[3+j]); } int res = FindMaximumBests(totals,N,S,p); bw.write("Case #" + i + ": " + res); bw.newLine(); } bw.close(); br.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } private static int FindMaximumBests(int[] totals, int N, int S, int p) { int aboveP = 0; int potentialAboveP = 0; for (int i = 0; i<N; i++){ if (totals[i]%3==0){ if(totals[i]/3>=p) aboveP++; else if (totals[i]/3==(p-1)){ if (totals[i]/3==0)//special exception when 0 can't get lower... continue; potentialAboveP++; } } else if (totals[i]%3==2){ if((totals[i]/3+1)>=p) aboveP++; else if ((totals[i]/3+1)==(p-1)) potentialAboveP++; } else{ if((totals[i]/3+1)>=p) aboveP++; } } return aboveP + Math.min(S, potentialAboveP); } }
0
521
A12852
A10369
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class Utils { public static int readIntegerLine(Scanner sc) { String s = readStringLine(sc); return Integer.parseInt(s); } public static String readStringLine(Scanner sc) { return sc.nextLine(); } public static int readInteger(Scanner sc) { return sc.nextInt(); } }
0
522
A12852
A13228
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package info.stephenn.codejam2012.qualify; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; public class B { public static void main(String[] args){ Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); for(int caseX=1; caseX <= cases; caseX+=1){ int nGoogles = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); List<Integer> gTot = new ArrayList<Integer>(); for (int i = 0; i < nGoogles; i++){ gTot.add(sc.nextInt()); } int y = doit(gTot, s,p); System.out.println("Case #"+caseX+": "+y); } } public static int doit(List<Integer> gTot, int s, int p){ Collections.sort(gTot); int y=0; for (int i=0; i < gTot.size(); i++){ if (greatestNonSurprising(gTot.get(i)) < p){ if (s > 0){ if (greatestSurprising(gTot.get(i)) >= p){ y +=1; s -=1; } } } else { y += ((gTot.size()) - (i)); break; } } return y; } public static int greatestSurprising(int gTot){ int x = gTot / 3; if ((gTot %3) == 0 && gTot > 2 ) x +=1; if ((gTot % 3) == 1) x+=1; else if ((gTot % 3) == 2) x+=2; return x; } public static int greatestNonSurprising(int gTot){ int x = gTot/3; if ((gTot % 3) > 0) x+=1; if (x > 10){ //shouldnt happen, . return 10; } else{ return x; } } }
0
523
A12852
A10819
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class B { public static void main(String[] argv){ Scanner in = new Scanner (System.in); int T=in.nextInt(); for(int i=0; i<T; i++){ int N=in.nextInt();int Surp=in.nextInt();int p=in.nextInt(); int[] NS=new int[N];int[] S=new int[N]; for(int k=0; k<N; k++){ int t=in.nextInt(); if(t==0){ NS[k]=0; S[k]=0; } else if(t%3==0){ NS[k]=t/3; S[k]=t/3+1; } else if(t%3==1){ NS[k]=(t-1)/3+1; S[k]=NS[k]; } else{ NS[k]=(t-2)/3+1; S[k]=(t-2)/3+2; } } //prT(NS); prT(S); int Rep=0; int ind=0; while(Surp>0 & ind<N){ if(S[ind]==p & NS[ind]==p-1){ Rep++; S[ind]=-1; NS[ind]=-1; Surp--; } ind++; } ind =0; while(Surp>0 & ind<N){ if(S[ind]>=p ){ Rep++; NS[ind]=-1; Surp--; } ind++; } for(int k=0; k<N; k++){ if(NS[k]>=p) Rep++; } System.out.println("Case #"+(i+1)+": "+Rep); //System.out.println(); } } public static void prT(int[] t){ System.out.println(); for(int x:t) System.out.print(x+" "); } }
0
524
A12852
A11101
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package main; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.LinkedList; import java.util.List; import java.util.StringTokenizer; public class QualificationB { public static void main(String[] args) throws IOException { String sampleIn = "input/b_sample.in"; String sampleOut = "output/b_sample.out"; String smallIn = "input/B-small-attempt0.in"; String smallOut = "output/B-small-attempt0.out"; String inFile = smallIn; String outFile = smallOut; FileWriter fstream = new FileWriter(outFile); BufferedWriter out = new BufferedWriter(fstream); int ncase = 0; for(TestCase tc : loadCodeLines(inFile)) { int withoutSurprises = 0; int withSurprises = 0; for (int s : tc.scores) { if (canMakeWithoutSurprise(tc.p, s)) { withoutSurprises++; } else if (canMakeWithSurprise(tc.p, s)) { withSurprises++; } } ncase++; System.out.println("Case #" + ncase + ": " + (withoutSurprises + Math.min(tc.s, withSurprises))); out.write("Case #" + ncase + ": " + (withoutSurprises + Math.min(tc.s, withSurprises)) + "\n"); //System.out.println("n=" + tc.n + " s=" + tc.s + " p=" + tc.p + " scores=" + tc.scores.toArray()); } out.close(); } private static boolean canMakeWithoutSurprise(int p, int score) { int rem = score - p; if (rem < 0) return false; int lower = rem / 2; return lower >= Math.max(p-1, 0); } public static boolean canMakeWithSurprise(int p, int score) { int rem = score - p; if (rem < 0) return false; int lower = rem / 2; return lower >= Math.max(p-2, 0); } public static List<TestCase> loadCodeLines(String filename){ List<TestCase> cases = new LinkedList<TestCase>(); try{ BufferedReader reader = new BufferedReader(new FileReader(filename)); String tString = reader.readLine(); int t = Integer.parseInt(tString); for(int i=0; i<t; i++){ StringTokenizer tokenizer = new StringTokenizer(reader.readLine()); int n = Integer.parseInt(tokenizer.nextToken(" ")); int s = Integer.parseInt(tokenizer.nextToken(" ")); int p = Integer.parseInt(tokenizer.nextToken(" ")); List<Integer> scores = new LinkedList<Integer>(); while(tokenizer.hasMoreTokens()) { int score = Integer.parseInt(tokenizer.nextToken(" \n")); scores.add(score); } cases.add(new TestCase(n,s,p,scores)); } } catch(Exception e){ e.printStackTrace(); throw new RuntimeException("can't load " + filename + "!"); } return cases; } private static class TestCase { public int n, s, p; public List<Integer> scores; public TestCase(int n, int s, int p, List<Integer> scores) { this.n = n; this.s = s; this.p = p; this.scores = scores; } } }
0
525
A12852
A13082
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Dance { public static void main(String[] args) throws FileNotFoundException{ Scanner scan = new Scanner (new File("C:\\Users\\kffong\\Desktop\\JAVA_workspace\\DanceGoogler\\input.txt")); // Scanner scan = new Scanner(new File("C:\\Users\\kffong\\Desktop\\JAVA_workspace\\DanceGoogler\\input.txt")); // System.out.print(scan.nextLine()); int numberOfCase = scan.nextInt(); scan.nextLine(); for(int k=0 ; k<numberOfCase; k++){ int N = scan.nextInt(); int surprise = scan.nextInt(); int p = scan.nextInt(); int total[] = new int[N]; int result = 0; int possibleIncrease = 0; for ( int i = 0 ; i < N ; i++){ total[i]=scan.nextInt(); } for(int i = 0 ; i<N ; i++){ int best; if (total[i]%3==0){ best=total[i]/3; } else{ best=total[i]/3 + 1; } if(best>=p){ result++; } else if(best==p-1 && total[i]%3!=1 &&total[i]!=0){ possibleIncrease++; } } // System.out.println("possibleIncrease="+possibleIncrease+" ;result="+result); if (possibleIncrease<=surprise){ result = result+possibleIncrease; } else{ result = result+surprise; } System.out.println("Case #"+(k+1)+": "+result); //System.out.println("===================="); if(scan.hasNextLine()){ scan.nextLine(); } } } }
0
526
A12852
A11362
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package br.ufmg.dcc.codejam.problemas; import java.io.FileNotFoundException; import java.io.IOException; import br.ufmg.dcc.codejam.util.ArquivoEscrita; import br.ufmg.dcc.codejam.util.ArquivoLeitura; /** * Solution for Problem B (Dancing With the Googlers) of Google Code Jam 2012 * @author Marcio * */ public class ProblemB { /** * Number of test cases */ private int m_numTestCases; /** * Input file */ private ArquivoLeitura m_inputFile; /** * Output file */ private ArquivoEscrita m_outputFile; /** * Constructor * @param p_inputFile The input file for the problem * @param p_outputFile The output file for the problem */ public ProblemB(ArquivoLeitura p_inputFile, ArquivoEscrita p_outputFile) { m_inputFile = p_inputFile; m_outputFile = p_outputFile; m_numTestCases = Integer.parseInt(p_inputFile.lerLinha()); } /** * Main method * @param p_args Program arguments. Argument 0 is the input file name and argument 1 is the output file name */ public static void main(String[] p_args) { ArquivoLeitura v_inputFile = null; ArquivoEscrita v_outputFile = null; try { v_inputFile = new ArquivoLeitura(p_args[0]); v_outputFile = new ArquivoEscrita(p_args[1]); ProblemB v_problemB = new ProblemB(v_inputFile, v_outputFile); v_problemB.solve(); } catch (FileNotFoundException v_exception) { System.out.println("File not found!"); v_exception.printStackTrace(); } catch (IOException v_exception) { System.out.println("IO error!"); v_exception.printStackTrace(); } finally { if(v_inputFile != null) { v_inputFile.fechar(); } if(v_outputFile != null) { v_outputFile.fechar(); } } } /** * Solves the problem */ private void solve() { for(int v_numTestCase = 1; v_numTestCase <= m_numTestCases; v_numTestCase++) { solveTestCase(v_numTestCase, m_inputFile.lerLinha()); } } /** * Solves a test case * @param p_numTestCase Number of the test case * @param p_inputLine Input line of the test case */ private void solveTestCase(int p_numTestCase, String p_inputLine) { m_outputFile.escrever("Case #" + p_numTestCase + ": "); String[] v_data = p_inputLine.split(" "); @SuppressWarnings("unused") int v_numGooglers = Integer.parseInt(v_data[0]); int v_numSurprises = Integer.parseInt(v_data[1]); int v_bestResult = Integer.parseInt(v_data[2]); int v_answer = 0; int v_minScoreWithoutSurprises = 0; int v_minScoreWithSurprises = 0; if(v_bestResult == 0) { v_minScoreWithoutSurprises = 0; v_minScoreWithSurprises = 0; } else if(v_bestResult == 1) { v_minScoreWithoutSurprises = 1; v_minScoreWithSurprises = 1; } else { v_minScoreWithoutSurprises = (3*v_bestResult) - 2; v_minScoreWithSurprises = v_minScoreWithoutSurprises - 2; } for(int i = 3; i < v_data.length; i++) { int v_totalPoints = Integer.parseInt(v_data[i]); if(v_totalPoints >= v_minScoreWithoutSurprises) { v_answer++; } else if(v_numSurprises > 0 && v_totalPoints >= v_minScoreWithSurprises) { v_answer++; v_numSurprises--; } } m_outputFile.escrever(String.valueOf(v_answer)); if(p_numTestCase != m_numTestCases) { m_outputFile.escreverLinha(""); } } }
0
527
A12852
A12969
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package mgg.utils; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * @author manolo * @date 13/04/12 */ public class StringUtils { public static List<Integer> stringWithIntegersToList(String str, int numItems, String delim){ ArrayList<Integer> list = new ArrayList<Integer>(); StringTokenizer tokenizer = new StringTokenizer(str, delim); if (tokenizer.countTokens() != numItems){ throw new RuntimeException("EXCEPTION: The string \"" + str + "\" has more tokens (" + tokenizer.countTokens() + ") than you said (" + numItems + ")"); } for (int i = 0; i < numItems; i++) { list.add(Integer.parseInt(tokenizer.nextToken())); } return list; } public static List<Integer> stringWithIntegersToList(String str, String delim){ ArrayList<Integer> list = new ArrayList<Integer>(); StringTokenizer tokenizer = new StringTokenizer(str, delim); int numOfTokens = tokenizer.countTokens(); for (int i = 0; i < numOfTokens; i++) { list.add(Integer.parseInt(tokenizer.nextToken())); } return list; } public static List<String> stringWithStringsToList(String str, int numItems, String delim){ ArrayList<String> list = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(str, delim); if (tokenizer.countTokens() != numItems){ throw new RuntimeException("EXCEPTION: The string \"" + str + "\" has more tokens (" + tokenizer.countTokens() + ") than you said (" + numItems + ")"); } for (int i = 0; i < numItems; i++) { list.add(tokenizer.nextToken()); } return list; } public static List<String> stringWithStringsToList(String str, String delim){ //System.out.println("String: " + str); ArrayList<String> list = new ArrayList<String>(); StringTokenizer tokenizer = new StringTokenizer(str, delim); //System.out.println("tokenizer.countTokens() = " + tokenizer.countTokens()); int numOfTokens = tokenizer.countTokens(); for (int i = 0; i < numOfTokens; i++) { list.add(tokenizer.nextToken()); } return list; } public static List<Character> allCharactersToList(String str) { System.out.println("String: " + str); ArrayList<Character> list = new ArrayList<Character>(); for (int i = 0; i < str.length(); i++) { list.add(str.charAt(i)); } System.out.println("List of characters: " + list); return list; } }
0
528
A12852
A12658
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class codejam2 { static class triplet { int a, b, c; int maxdiff; public triplet(int pa, int pb, int pc) { a = pa; b = pb; c = pc; maxdiff = maxdiff(); if (pa < 0 || pb < 0 || pc < 0) maxdiff = 3; } public boolean isSurprising() { return Math.abs(a-b) == 2 || Math.abs(a-c) == 2 || Math.abs(b-c) == 2; } public int maxdiff() { return Math.max(Math.abs(a-c), Math.max(Math.abs(a-b), Math.abs(b-c))); } } public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new FileReader("B-small-attempt0.in")); int T; T = Integer.parseInt(f.readLine()); StringTokenizer t; for (int q = 0; q < T; q++) { int N, S, p; triplet[] ts; boolean[] sat; t = new StringTokenizer(f.readLine()); N = Integer.parseInt(t.nextToken()); S = Integer.parseInt(t.nextToken()); p = Integer.parseInt(t.nextToken()); ts = new triplet[N]; sat = new boolean[N]; int surpcount = 0; for (int i = 0; i < N; i++) { int n = Integer.parseInt(t.nextToken()); int diff = n - (3 * (n/3)); if (diff == 0 || diff == 1) { ts[i] = new triplet(n/3, n/3, n/3 + diff); } if (diff == 2) { ts[i] = new triplet(n/3, n/3+1, n/3+1); } } for (int i = 0; i < N; i++) { if (ts[i].c >= p) { sat[i] = true; continue; } triplet newtrip = new triplet(ts[i].a, ts[i].b-1, ts[i].c+1); if (newtrip.maxdiff == 1 && (newtrip.c >= p)) { sat[i] = true; continue; } if (surpcount >= S) continue; if (newtrip.maxdiff == 2 && (newtrip.c >= p)) { sat[i] = true; surpcount++; continue; } triplet newnewtrip = new triplet(ts[i].a - 1, ts[i].b-1, ts[i].c+2); if (newnewtrip.maxdiff == 2 && (newtrip.c >= p)) { sat[i] = true; continue; } } int tot = 0; for (int i = 0; i < N; i++) { if (sat[i]) { tot++; } } System.out.println("Case #" + (q+1) + ": " + tot); } } }
0
529
A12852
A11105
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.StringTokenizer; public class GoogleDancers { public Triplet findAddFactors(int n) { int m = n / 3; if (m==0) return new Triplet(m,m,m); int add = n % m; int nums[] = { m, m, m }; while (add != 0) { nums[add]++; add--; } return new Triplet(nums); } public Triplet findSurprisingFactors(int n) { int m = n / 3; if (m==0) return new Triplet(m,m,m); int mod = n % m; if (mod == 2) return new Triplet(m, m, m + 2); else if (mod == 1) return new Triplet(m + 1, m + 1, m - 1); else return new Triplet(m - 1, m, m + 1); } public int findMaxAboveP(ArrayList<Triplet> scores, ArrayList<Triplet> surps, int surprises, int p) { int total = 0; int size = scores.size(); for (int i=0; i<size; i++) { Triplet curr = scores.get(i); if (curr.getHighest() >= p) { total++; }else if (surps.get(i).getHighest() >= p && surprises!=0 && surps.get(i).getHighest() <= 10) { total++; surprises--; } } return total; } public static void main(String[] args) { GoogleDancers driver = new GoogleDancers(); File input = new File("B-small-attempt1.in"); if (!input.canRead()) { System.out.println("Cannot read from file!"); System.exit(1); } ArrayList<Triplet> scores = new ArrayList<Triplet>(); ArrayList<Triplet> surprising = new ArrayList<Triplet>(); try { BufferedReader reader = new BufferedReader(new FileReader(input)); int count = 1; String line; reader.readLine(); //get rid of first line while ((line = reader.readLine()) != null && !line.isEmpty()) { scores.clear(); surprising.clear(); StringTokenizer tokenizer = new StringTokenizer(line, " "); int numGooglers = Integer.parseInt(tokenizer.nextToken()); int surprises = Integer.parseInt(tokenizer.nextToken()); int p = Integer.parseInt(tokenizer.nextToken()); while (tokenizer.hasMoreTokens()) { String token = tokenizer.nextToken(); //System.out.println("parsed " + token); scores.add(driver.findAddFactors(Integer.parseInt(token))); surprising.add(driver.findSurprisingFactors(Integer.parseInt(token))); } System.out.println("Case #" + count+": " + driver.findMaxAboveP(scores, surprising, surprises, p)); count++; } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private class Triplet { int one, two, three, highest; // Three scores public Triplet(int[] nums) { this.one = nums[0]; this.two = nums[1]; this.three = nums[2]; if (one >= two) highest = one; else highest = two; if (highest < three) highest = three; } public Triplet(int one, int two, int three) { this.one = one; this.two = two; this.three = three; if (one >= two) highest = one; else highest = two; if (highest < three) highest = three; } public String toString() { return one + ", " + two + ", " + three + "\n"; } public int getHighest() { return highest; } } }
0
530
A12852
A11690
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; /** * * @author Izhari Ishak Aksa */ public class ProblemB { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int t = 1; t <= T; t++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int ret = 0; for (int i = 0; i < n; i++) { int a = sc.nextInt(); int b = a / 3; int c = a % 3; if (b >= p) { ret++; } else if (b + 1 >= p && c >= 1) { ret++; } else if (b + 2 >= p && c >= 2 && s > 0) { ret++; s--; } else if (b + 1 >= p && s > 0 && b > 1) { ret++; s--; } } System.out.println("Case #" + t + ": " + ret); } } }
0
531
A12852
A12484
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.Scanner; /** * * @author leonardo */ public class Dance { static boolean canBeSurprising(int x1, int x2, int x3) { if (x1 > 10 || x2 > 10 || x3 > 10) return false ; return (Math.abs(x1 -x2) >= 2) || (Math.abs(x1 -x3) >= 2) || (Math.abs(x2 -x3) >= 2) ; } /*static boolean canBeSurprising(int r, int x, int p) { boolean[] res = new boolean[2] ; if (r == 0) { return canBeSurprising(x, x, x) || canBeSurprising(x-1, x+1, x) ; } else if (r == 1) { return canBeSurprising(x+1, x, x, p, res) || canBeSurprising(x+1, x+1, x-1) ; } else { canBeSurprising(x+2, x, x, p, res); canBeSurprising(x, x+1, x+1, p, res) ; } return (! res[0] && res[1]) ? 1 : 0; }*/ public static void main(String[] args) { Scanner scanner = new Scanner(System.in) ; int inputSize = Integer.parseInt(scanner.nextLine()) ; for(int i = 1; i <= inputSize; i++) { String[] numbers = scanner.nextLine().split(" ") ; int n = Integer.parseInt(numbers[0]) ; int s = Integer.parseInt(numbers[1]) ; int p = Integer.parseInt(numbers[2]) ; int count = 0 ; for(int googler = 0; googler < n; googler++) { int score = Integer.parseInt(numbers[googler + 3]) ; int r = score % 3 ; int x = score / 3 ; if (r == 0) { // possible maxs: x and x + 1 if (x >= p) count++ ; else if ((score > 0) && s > 0 && (x + 1) >= p) { s-- ; count++ ; } } // r == 1 -> max = x + 1 else if (r == 1 && (x + 1 >= p)) count++ ; else { // possible maxs: x + 1 and x + 2 if ((x + 1) >= p) count++ ; else if ((x+2 <= 10) && (x+2 >= p) && (s > 0)) { count++ ; s-- ; } } } System.out.println("Case #" + i + ": " + count) ; } } }
0
532
A12852
A10200
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.bakes; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; public class C { public static void main(String[] args) { C park = new C(); park.calculate(); } private long lcm(long a, long b) { return (a*b)/gcd(a,b); } public static long gcd(long i1, long i2) { // using Euclid's algorithm long a=i1, b=i2, temp; while (b!=0) { temp=b; b=a%temp; a=temp; } return a; } private void calculate() { BufferedReader in; String strLine1; String strLine2; String strLine3; PrintWriter out; try { in = new BufferedReader(new FileReader("B-small-attempt0.in")); in.readLine(); FileWriter outFile = new FileWriter("output.txt"); out = new PrintWriter(outFile); int n = 0; while ((strLine1 = in.readLine()) != null) { n++; String[] data = strLine1.split(" "); int N = Integer.parseInt(data[0]); int s = Integer.parseInt(data[1]); int p = Integer.parseInt(data[2]); int count = 0; for (int i = 3; i < 3 + N; i++) { int d = Integer.parseInt(data[i]); if ((d - 3*p) >= -2) { count++; } else if ((d-3*p) >= -4 && s >0 && d >=2) { count++; s--; } } String result = "Case #"+n+": "+count; out.println(result); System.out.println(result); } out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
533
A12852
A11055
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class PB { public static void main(String[] args) throws FileNotFoundException { if (args.length != 1) { System.exit(1); } File inFile = new File(args[0]); Scanner sc = new Scanner(inFile); int T = sc.nextInt(); try (PrintWriter out = new PrintWriter("out.txt")) { for (int i = 0; i < T; i++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int[] t = new int[N]; for (int j = 0; j < N; j++) { t[j] = sc.nextInt(); } int[][] scores = new int[N][3]; for (int j = 0; j < N; j++) { scores[j][0] = t[j] / 3; scores[j][1] = (t[j] - scores[j][0]) / 2; scores[j][2] = t[j] - scores[j][0] - scores[j][1]; } int count = 0; for (int j = 0; j < N; j++) { boolean isSurprise = false; if (scores[j][2] - scores[j][0] == 2) { S--; isSurprise = true; } if (scores[j][2] >= p) { count++; } else { if (S > 0 && !isSurprise && (p - scores[j][2]) == 1 && scores[j][1] > 0) { S--; scores[j][1]--; scores[j][2]++; count++; } } } out.println("Case #" + (i + 1) + ": " + count); } } System.out.println("Completed"); } }
0
534
A12852
A11708
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class problemB { public static void main(String[] args) { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try { int cases = Integer.parseInt(br.readLine()); for (int i = 1; i <= cases; i++) { String[] tokens = br.readLine().split(" "); int persons = Integer.parseInt(tokens[0]); int surprises = Integer.parseInt(tokens[1]); int bestResult = Integer.parseInt(tokens[2]); int lowestVal = bestResult - 2; if (lowestVal < 0) { lowestVal = 0; } int surpriseThreshold = (bestResult + (lowestVal*2)); int normalThreshold = ((bestResult*2) + (lowestVal)); int total = 0; for (int j = 0; j < persons; j ++) { if (Integer.parseInt(tokens[3+j]) >= normalThreshold ) { total++; } else if ((Integer.parseInt(tokens[3+j]) >= surpriseThreshold) && (surprises > 0)) { total++; surprises--; } } System.out.println("Case #" + i + ": " + total); } } catch (IOException e) { System.out.println("Error!"); System.exit(1); } } }
0
535
A12852
A12770
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class QualB { /** * @param args */ public static void main(String[] args)throws Exception { Scanner sc = new Scanner(new File("E:/inp.txt")); PrintWriter pr = new PrintWriter(new File("E:/out.txt")); int tc=sc.nextInt(); int cnt=0; for(int i=1;i<=tc;i++){ int n=sc.nextInt(); int sup=sc.nextInt(); int p=sc.nextInt(); cnt=0; for(int j=1;j<=n;j++){ int pt=sc.nextInt(); if(pt==0){ if(p==0)cnt++; } else if(pt!=0 && pt%3==0){ int t=pt/3; if(p<=t){ cnt++; } else if (sup>=1 && p-t==1){ cnt++; sup--; } } else if(pt!=0 && pt%3!=0){ int t=pt/3; if(p<=t+1){ cnt++; } else if (sup>=1 && p-t==2){ cnt++; sup--; } } } pr.printf("Case #%d: %d%n", i,cnt); } sc.close(); pr.close(); } }
0
536
A12852
A11166
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codezam.util; import java.io.File; import java.io.FileReader; import java.io.LineNumberReader; public class InputFile { private File file; FileReader freader; LineNumberReader lnreader; public void setFile(String filename) { try { file = new File(filename); freader = new FileReader(file); lnreader = new LineNumberReader(freader); } catch (Exception e) { e.printStackTrace(); } } public String readLine() { String line = null; try { line = lnreader.readLine(); //System.out.println("Line: " + lnreader.getLineNumber() + ": " + line); if (line==null) { close(); } } catch (Exception e) { e.printStackTrace(); } return line; } private void close() { try { freader.close(); lnreader.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
537
A12852
A11060
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class DancingGoogler{ public static void main(String[] args){ Scanner scanner = new Scanner(System.in); scanner.nextLine(); int count = 1; while(scanner.hasNextLine()){ String[] tokens = scanner.nextLine().split(" "); int numContestants = Integer.parseInt(tokens[0]); int numSuprises = Integer.parseInt(tokens[1]); int minScore = Integer.parseInt(tokens[2]); int[] scores = new int[numContestants]; for(int i = 0; i < scores.length; ++i){ scores[i] = Integer.parseInt(tokens[i + 3]); } DancingGoogler d = new DancingGoogler(numSuprises, minScore, scores); System.out.println("Case #" + count + ": " + d.getNumGooglersWithMinScore()); ++count; } } public DancingGoogler(int numSuprises, int minScore, int[] scores){ this.numSuprises = numSuprises; this.minScore = minScore; this.scores = scores; } public int getNumGooglersWithMinScore(){ int count = 0; for(int score : scores){ if(score == 0){ if(minScore == 0){ ++count; } continue; } if(score == 29){ ++count; continue; } if(score % 3 == 0){ int av = score / 3; if(av >= minScore){ ++count; }else{ if(numSuprises > 0 && av >= minScore -1){ ++count; --numSuprises; } } continue; } int av = score / 3; int av1 = (score / 3) + 1; int diffav = score - av * 3; int diffav1 = av1 * 3 - score; if(numSuprises > 0){ if(diffav == 2){ if(av1 >= minScore){ ++count; continue; }else{ if(av >= minScore || score - av*2 >= minScore){ ++count; --numSuprises; continue; } } }else{ if(av >= minScore || score -av * 2 >= minScore){ ++count; continue; } if(av1 >= minScore){ ++count; --numSuprises; continue; } } }else{ if(diffav == 2){ if(av1 >= minScore){ ++count; continue; } }else{ if(av >= minScore || score - av*2 >= minScore){ ++count; continue; } } } } return count; } private int numContestants; private int numSuprises; private int minScore; private int[] scores; }
0
538
A12852
A10184
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam; import java.util.ArrayList; import codejam.fileHandler; public class SpeakingInTongues { /** * @param args */ public static void main(String[] args) { fileHandler file = new fileHandler("input.in", "output.in"); int noOfCase = file.readCase(); char abcd[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' }; char replacement[] = { 'y', 'n', 'f', 'i', 'c', 'w', 'l', 'b', 'k', 'u', 'o', 'm', 'x', 's', 'e', 'v', 'z', 'p', 'd', 'r', 'j', 'g', 't', 'h', 'a', 'q' }; ArrayList<Character> arrayList = new ArrayList<Character>(); for(int i=0;i<replacement.length;i++){ arrayList.add(replacement[i]); } String string; String outputString; for (int i = 1; i <= noOfCase; i++) { string = file.readLineFromInput(); outputString = "Case #" + i + ": "; for(int j=0;j<string.length();j++){ if(string.charAt(j) == ' '){ outputString += " "; } else{ int k = arrayList.indexOf(string.charAt(j)); outputString += abcd[k]; } } outputString += "\n"; file.writeToOutput(outputString); } } }
0
539
A12852
A11367
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package fun.codeslam.dancers; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader( System.in)); Integer testCaseCount = Integer.parseInt(reader.readLine()); for (Integer testCaseNumber = 1; testCaseNumber <= testCaseCount; testCaseNumber++) { System.out.append("Case #" + testCaseNumber + ": "); System.out.append(new Result(new TestCase(reader.readLine())).toString()); System.out.append('\n'); } } }
0
540
A12852
A11176
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package leider.ken; import java.io.IOException; import java.util.Map; import java.util.concurrent.Callable; /** * * @author ken */ interface Parser { Map<Integer, Callable<String>> parse(String fileName) throws IOException; }
0
541
A12852
A11444
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.util.Scanner; public class Dancers { public static void main(String[] args) throws FileNotFoundException { FileInputStream file = new FileInputStream("C:\\Users\\Taghi\\Downloads\\B-small-attempt0.in"); DataInputStream in2 = new DataInputStream(file); Scanner in=new Scanner(new InputStreamReader(in2)); int numberOfTests=in.nextInt(); int[] results=new int[numberOfTests]; for (int i=0;i<numberOfTests;i++) { int counter=0; int numberOfGooglers=in.nextInt(); int N=in.nextInt(); int p=in.nextInt(); int j=0; while (j < numberOfGooglers) { int score=in.nextInt(); if (score < (3*p - 4)||score<p) {} else if (score <= (3*p - 3)) { if (N > 0) { counter++; N--; } } else { counter++; } j++; } results[i]=counter; } for (int i=0;i<numberOfTests;i++) { System.out.println("Case #"+(i+1)+": "+results[i]); } } }
0
542
A12852
A11583
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.lang.Integer; import java.util.ArrayList; class jam1a { public static void main(String[] args) { BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); try { String s = bufferRead.readLine(); int testCases=Integer.parseInt(s); ArrayList<String> sars = new ArrayList<String>(); for(int i=0; i< testCases; i++){ s = bufferRead.readLine(); sars.add(s); } System.out.println("\n"); for(int j=0; j<sars.size(); j++){ String [] split=sars.get(j).split(" "); int googlers=Integer.parseInt(split[0]); int surprises=Integer.parseInt(split[1]); int p=Integer.parseInt(split[2]); ArrayList<Integer> nums = new ArrayList<Integer>(); for(int i=3; i<split.length; i++){ nums.add(Integer.parseInt(split[i])); } System.out.println("Case #"+(j+1)+": " + atLeast(googlers, surprises,p,nums)); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static int atLeast(int googlers, int surprises, int p, ArrayList<Integer> numbers){ if(p==0) return numbers.size(); int ret=0; for (int i=0; i<numbers.size(); i++){ float tempNum=numbers.get(i); if(tempNum==0 && p>0 ) continue; float avg=(float)tempNum/3; float tempRem=tempNum-p; boolean okNoSuprise=false; if(tempRem%2==0){ int tempVal=(int) (tempRem/2); if((tempVal+1)>=p) { okNoSuprise=true; } }else{ int tempForDiv=(int) (tempRem-1); int val1=(int) (tempForDiv/2); if((val1+1)>=p){ okNoSuprise=true; } } if((avg)>=p) ret++; else if(okNoSuprise) ret++; else if( surprises > 0){ if(tempRem%2==0){ int tempVal=(int) (tempRem/2); if((tempVal+2)>=p) { ret++; surprises--; } }else{ int tempForDiv=(int) (tempRem-1); int val1=(int) (tempForDiv/2); int val2=val1+1; if((val1+2)>=p){ ret++; surprises--; } } } } return ret; } }
0
543
A12852
A10316
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package ProblemB; 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 Common { static String filename="C:\\eclipse-jee-indigo-SR2-win32\\eclipse\\projects\\goole codejam 2012\\Qualification\\src\\ProblemB\\B-small-attempt0.in"; static BufferedReader br; static String output; public static void main (String[] args) throws NumberFormatException, IOException{ br = new BufferedReader(new FileReader(filename)); BufferedWriter bw = new BufferedWriter(new FileWriter("C:\\eclipse-jee-indigo-SR2-win32\\eclipse\\projects\\goole codejam 2012\\Qualification\\src\\ProblemB\\output.txt")); int n; n = Integer.parseInt(br.readLine()); String[] splitArr; int[] input; for (int i=1;i<=n;++i){ splitArr=br.readLine().split(" "); input= new int [splitArr.length]; for (int j=0; j< splitArr.length;++j){ input[j] = Integer.parseInt(splitArr[j]); } bw.append("Case #"+i+": "+process(input)+"\n"); bw.flush(); } bw.close(); } static int process (int[] input){ int result=0; int explicitSurprisesFound=0; int limit=input[2]*3-4, surpriseLimit=limit+2; boolean notException = 1 != input[2]; for (int i=3;i<input.length;++i){ if (limit <= input[i]){ if (limit <=input[i] && surpriseLimit > input[i]){ if(notException){ if(explicitSurprisesFound < input[1]){ ++explicitSurprisesFound; ++result; } } }else { ++ result; } } } return result; } }
0
544
A12852
A10635
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.PrintWriter; import java.util.Scanner; /** * * @author yilianz */ public class DancingGoogler{ /** * @param args the command line arguments */ public static void main(String[] args) throws Exception{ // Read file Scanner inFile = new Scanner(new File("file.in")); PrintWriter outFile = new PrintWriter(new File("out.file")); int caseN =inFile.nextInt(); // TODO code application logic here for(int i = 1; i<caseN+1; i++){ int N = inFile.nextInt(); int S = inFile.nextInt(); int P = inFile.nextInt(); int MaxP = 0; //Read the total point for(int j = 0; j<N; j++){ int ti = inFile.nextInt(); if (ti >= 3*P-2) { MaxP++; } else if( ti >= 3*P - 4){ if (S>0 &&P!=1){ S--; MaxP++; } } } System.out.println("Case #"+i+": "+MaxP); outFile.println("Case #"+i+": "+MaxP); } //close the file inFile.close(); outFile.close(); } }
0
545
A12852
A10119
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; /** * Date: 14/4/12 * Time: 10:43 AM */ public class ProblemB { public static void main(String[] args) throws IOException { ArrayList<String> al = GoogleFileStream.getInput(); ArrayList<String> ret = new ArrayList<String>(); for( String i : al ) ret.add( solution( i ) ); GoogleFileStream.setOutput(ret); } /* HashMap help = new HashMap() { { // no surprise - surprise. put( 30, [10,false] ); // 10, 10, 10 put( 29, [10,false] ); // 10, 10, 9 put( 28, [10,false] ); // 10, 9, 9 put( 27, [9,10] ); // 9, 9, 9 - 10, 9, 8 put( 26, [9,9] ); // 9, 9, 8 - 10, 8, 8 put( 25, [9,9] ); // 9, 8, 8 - put( 24, [8,9]) // 8, 8, 8 - 9, 8, 7 put( 23, [8,9]) // 8, 8, 7 - 9, 7, 7 put( 22, [8,9]) // 8, 7, 7 - put( 21, [8,9]) // 7, 7, 7 - 8, 7, 6 put( 20, [8,9]) // 7, 7, 6 - 8, 6, 6 put( 19, [8,9]) // 7, 6, 6 - put( 18, [8,9]) // 6, 6, 6 - 7, 6, 5 put( 17, [8,9]) // 6, 6, 5 - 7, 5, 5 put( 16, [8,9]) // 6, 5, 5 - put( 15, [8,9]) // 5, 5, 5 - 6, 5, 4 put( 14, [8,9]) // 5, 5, 4 - 6, 4, 4 put( 13, [8,9]) // 5, 4, 4 - put( 12, [8,9]) // 4, 4, 4 - 5, 4, 3 put( 11, [8,9]) // 4, 4, 3 - 5, 3, 3 put( 10, [8,9]) // 4, 3, 3 - put( 9, [8,9]) // 3, 3, 3 - 4, 3, 2 put( 8, [8,9]) // 3, 3, 2 - 4, 2, 2 put( 7, [8,9]) // 3, 2, 2 - put( 6, [8,9]) // 2, 2, 2 - 3, 2, 1 put( 5, [8,9]) // 2, 2, 1 - 3, 1, 1 put( 4, [8,9]) // 2, 1, 1 - put( 3, [8,9]) // 1, 1, 1 - 2, 1, 0 put( 2, [8,9]) // 1, 1, 0 - 2, 0, 0 put( 1, [8,9]) // 1, 0, 0 - put( 0, [8,9]) // 0, 0, 0 - } }; */ static int minScore( int score, boolean surprise ) { int minScore = (score + 2) / 3; if( score > 1 && score < 28 && surprise && score % 3 != 1 ) minScore++; return minScore; } private static String solution(String i) { ArrayList<String> input = new ArrayList<String>(Arrays.asList(i.split(" "))); //int numOfGooglers = Integer.valueOf( input.get(0) ); int numOfSurprisingTriplets = Integer.valueOf( input.get(1) ); int minScore = Integer.parseInt( input.get(2) ); ArrayList<Integer> scores = new ArrayList<Integer>(); for( String s : input.subList(3, input.size()) ) scores.add( Integer.valueOf(s) ); Collections.sort(scores); ArrayList<Integer> ret = new ArrayList<Integer>(); for( int score : scores ) ret.add(minScore(score, false)); for( int ix = 0; ix < ret.size(); ix++ ) if( ret.get(ix).equals( minScore - 1 ) && ret.get(ix) != minScore(scores.get(ix), true) && numOfSurprisingTriplets > 0 ) { numOfSurprisingTriplets--; ret.set(ix, ret.get(ix)+1); } int count = 0; for( int sc : ret ) if( sc >= minScore ) count++; return String.valueOf(count); } }
0
546
A12852
A11514
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
//import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class jammo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner scanner = new Scanner(new File("input.txt")); //FileWriter fstream = new FileWriter("output.txt"); //BufferedWriter out = new BufferedWriter(fstream); PrintWriter out = new PrintWriter(new FileWriter("output.txt")); int inputSet,partC,surpC,minDM,curTot,noSurp,surpCo,total; inputSet = scanner.nextInt(); for(int i=1; i<=inputSet; i++) { partC = scanner.nextInt(); surpC = scanner.nextInt(); minDM = scanner.nextInt(); noSurp = 0; surpCo = 0; for(int j=0; j<partC; j++) { curTot = scanner.nextInt(); if(minDM==1 && curTot>=1) noSurp++; else if(curTot>=3*minDM-2) noSurp++; else if(curTot>=3*minDM-4) surpCo++; } total = noSurp + Math.min(surpC,surpCo); out.println("Case #"+i+": "+total); System.out.print("Case #"+i+": "+total+"\n"); } out.close(); return; } }
0
547
A12852
A10286
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package Problem2; 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; class FileReader{ public static ArrayList<String> Parsefile(String filename){ String chaine=""; String fichier =filename; try{ InputStream ips=new FileInputStream(fichier); InputStreamReader ipsr=new InputStreamReader(ips); BufferedReader br=new BufferedReader(ipsr); String ligne; int j=0; ArrayList<String> ArS_lines = new ArrayList<String>(); while ((ligne=br.readLine())!=null){ System.out.println(ligne); if (j>=1) ArS_lines.add(ligne); j++; } br.close(); return ArS_lines; } catch (Exception e){ return null; } } public static void writeconfig(String destinationfilename , ArrayList<String> ArS) { try { FileWriter fw = new FileWriter (destinationfilename); BufferedWriter bw = new BufferedWriter (fw); PrintWriter fichierSortie = new PrintWriter (bw); int i; int n = ArS.size(); for (i=0;i<n;i++){ fichierSortie.println("Case #"+(i+1)+":" + " "+ ArS.get(i)); } fichierSortie.close(); } catch (Exception e){ System.out.println(e.toString()); } } public static void writeconfig(String destinationfilename , int[] ArS) { try { FileWriter fw = new FileWriter (destinationfilename); BufferedWriter bw = new BufferedWriter (fw); PrintWriter fichierSortie = new PrintWriter (bw); int i; int n = ArS.length; for (i=0;i<n;i++){ fichierSortie.println("Case #"+(i+1)+":" + " "+ ArS[i]); } fichierSortie.close(); } catch (Exception e){ System.out.println(e.toString()); } } }
0
548
A12852
A11551
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class Dancing { public static int isPossible(int p, int t){ // -1 -> not possible // 0 -> possible // 1 -> possible but surprising int a = (t-p)/2; int b = t-p-a; if((t/3)>=p){ return 0; } if(a<0 || b<0){ return -1; } if(Math.abs(p-a)<=2 && Math.abs(p-b)<=2 && Math.abs(p-b)<=2) { if(Math.abs(p-a)==2 || Math.abs(p-b)==2 || Math.abs(p-b)==2){ return 1; } return 0; } return -1; } 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 t[] = new int[N]; int count=0; for(int j=0; j<N; j++){ t[j] = sc.nextInt(); switch(isPossible(p,t[j])){ case 0: count++; break; case 1: if(S!=0){ count++; S--; } } } System.out.print("Case #" + (i + 1) + ": "+count ); System.out.println(); } } }
0
549
A12852
A12283
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.brootdev.gcj2012.common; import java.io.*; public class Data { public final BufferedReader in; public final PrintWriter out; public Data(String inFile, String outFile) throws IOException { in = new BufferedReader(new FileReader(inFile)); out = new PrintWriter(new BufferedWriter(new FileWriter(outFile))); } public long readLongLine() throws IOException { return DataUtils.readLongLine(in); } public long[] readLongsArrayLine() throws IOException { return DataUtils.readLongsArrayLine(in); } public void writeCaseHeader(long case_) { DataUtils.writeCaseHeader(out, case_); } }
0
550
A12852
A13113
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* PROG: ProbB 2012 Google CodeJam Qualification Round Problem B */ import java.io.*; import java.util.*; public class Prob1B{ public static void main(String [] args) throws IOException { //long start = System.currentTimeMillis(); BufferedReader f = new BufferedReader(new FileReader("Prob1B.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("Prob1B.txt"))); int[] normal = {0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; int[] suprising = {0,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10,10,10}; int N = Integer.parseInt(f.readLine()); for(int i = 0; i < N; i++){ int countn = 0; int counts = 0; String[] input = (f.readLine()).split(" "); int M = Integer.parseInt(input[0]); int S = Integer.parseInt(input[1]); int P = Integer.parseInt(input[2]); for(int j = 0; j < M; j++){ int x = Integer.parseInt(input[3+j]); //System.out.println(x + " " + normal[x] + " " + suprising[x]); if(normal[x] >= P) countn++; else if(suprising[x] >= P) counts++; } int ans = countn + Math.min(counts, S); out.println("Case #" + (i+1) + ": " + ans); } //long end = System.currentTimeMillis(); //System.out.println(end - start); out.close(); } }
0
551
A12852
A10811
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class CodeJam2 { public static void main(String[] args) { Scanner input=new Scanner(System.in); int types=input.nextInt(); for(int i=0;i<types;i++) { int count1=0,count2=0; int n=input.nextInt(); int array2[]=new int[n]; int surprise=input.nextInt(); int p=input.nextInt(); for(int j=0;j<n;j++) { array2[j]=input.nextInt(); } int array1[][]=new int[n][3]; for(int j=0;j<n;j++) { array1[j][0]=array2[j]/3; int t=array2[j]-array1[j][0]; int c1=t/2; int c2=t-c1; if(array2[j]!=0) { if(c1-c2==0) { if(p-c1==1) { if(count1<surprise) { count1++; count2++; array1[j][1]=c1--; array1[j][2]=c2++; } else { array1[j][1]=c1; array1[j][2]=c2; } } else if (p-c1==0) { array1[j][2]=c2; ++count2; array1[j][1]=c1; } else if(p-c1>1) { array1[j][1]=c1; array1[j][2]=c2; } else if(p-c1<0) { array1[j][2]=c2; ++count2; array1[j][1]=c1; } } else if((c2-c1)==1) { if(p<=c2) { array1[j][2]=c2; ++count2; array1[j][1]=c1; } else { array1[j][2]=c2; array1[j][1]=c1; } } } else{ if(p==0) { ++count2; } } } System.out.println("Case #"+(i+1)+": " +count2); } } }
0
552
A12852
A11063
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class triplets { public static void main(String[] args) throws IOException { BufferedReader reader=new BufferedReader(new InputStreamReader(System.in)); //copy test data into standard input int num=Integer.parseInt(reader.readLine()); for(int i=1;i<=num;i++){ StringTokenizer st=new StringTokenizer(reader.readLine()); System.out.print("Case #"+i+": "); int n=Integer.parseInt(st.nextToken()); int s=Integer.parseInt(st.nextToken()); int p=Integer.parseInt(st.nextToken()); int over=0;//number automatically over int surp=0; //number over if surprising for(int j=0;j<n;j++){ int score=Integer.parseInt(st.nextToken()); int share=score/3; if(score==0){ if(p==0){ over++; } }else if(score%3==0){ if(share>=p){ over++; }else if(share+1>=p){ surp++; } }else if(score%3==1){ if(share+1>=p){ over++; } }else if(score%3==2){ if(share+1>=p){ over++; }else if(share+2>=p){ surp++; } } } if(surp>s){ over+=s; }else{ over+=surp; } System.out.println(over); } } }
0
553
A12852
A10851
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package GoogleCodeJam.ed2012; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class QualificationB2012 { private String inputFile; private String outputFile; private BufferedReader reader = null; private BufferedWriter writer = null; /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { QualificationB2012 qualificationB2012 = new QualificationB2012("QualificationB2012.in", "QualificationB2012.out"); qualificationB2012.run(); } private void run() throws Exception { openFiles(); solve(); closeFiles(); } private void solve() throws Exception { int tests = Integer.valueOf(reader.readLine()); for (int test=1; test<=tests; test++) { String[] line = reader.readLine().split(" "); int n = Integer.valueOf(line[0]); int s = Integer.valueOf(line[1]); int p = Integer.valueOf(line[2]); int maxNoteContestants = 0; for (int i=0; i<n; i++) { int points = Integer.valueOf(line[3+i]); if (haveNormalNoteOverP(points,p)) { maxNoteContestants++; } else if ((s>0) && haveSurprisingNoteOverP(points,p)) { s--; maxNoteContestants++; } } writer.write("Case #"+test+": "+maxNoteContestants+"\n"); } } private boolean haveSurprisingNoteOverP(int points, int p) { int note = points / 3; int modulo = points % 3; if ((modulo == 0) && (note+1<=10) && (note-1>=0) && (note+1>=p)) { return true; } else if ((modulo == 2) && (note+2 <= 10) && ( note+2>=p)) { return true; } return false; } private boolean haveNormalNoteOverP(int points, int p) { int note = points / 3; int modulo = points % 3; if (((modulo == 0) && (note>=p)) || ((modulo>0) && (note+1>=p))) { return true; } return false; } public QualificationB2012(String inputFile, String outputFile) { this.inputFile = inputFile; this.outputFile = outputFile; } private void closeFiles() { try { reader.close(); writer.close(); } catch (Exception e) { throw new RuntimeException(); } } private void openFiles() { try { reader = new BufferedReader(new FileReader(inputFile)); writer = new BufferedWriter(new FileWriter(outputFile)); } catch (Exception e) { throw new RuntimeException("File initialization failed"); } } }
0
554
A12852
A11378
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class B { public static void main(String[] args) { B b = new B(); b.solve(); } public void solve() { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int ii = 1; ii <= t; ++ii) { int num = in.nextInt(); int surprising = in.nextInt(); int points = in.nextInt(); int[][] bests = new int[num][2]; //[i][0] best, not surprising. [i][1], best, surprising for(int i = 0; i < num; ++i) { int score = in.nextInt(); if(score <= 1) { bests[i][0] = score; bests[i][1] = score; } else if(score % 3 == 0) { bests[i][0] = score/3; bests[i][1] = bests[i][0] + 1; } else if(score % 3 == 1) { bests[i][0] = score/3 + 1; bests[i][1] = bests[i][0]; } else { bests[i][0] = score/3 + 1; bests[i][1] = bests[i][0] + 1; } //System.out.printf("With a total of %d, best non: %d, best with: %d\n", score, bests[i][0], bests[i][1]); } int total = 0; for(int i = 0; i < num; ++i) { //check all not suprising stuffs if(bests[i][0] >= points) { ++total; bests[i][1] = -1; } } for(int i = 0; i < num && surprising > 0; ++i) { if(bests[i][1] >= points) { ++total; --surprising; } } System.out.printf("Case #%d: %d\n", ii, total); } } }
0
555
A12852
A10277
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package qualifs; public class Gcj2012 { public static void main(String[] args) { final B problem = new B("B-sample"); problem.run(); } }
0
556
A12852
A12046
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; public class qualb{ public static void main(String[] args){ qualb.solve(); } private static void solve(){ String fileName = "B-small-attempt0.in"; String outputFileName = fileName; if(outputFileName.contains(".")){ outputFileName = outputFileName.substring(0,outputFileName.indexOf(".")); } outputFileName = outputFileName+".out"; File file = new File(fileName); try { FileWriter fstream = new FileWriter(outputFileName,true); BufferedWriter out = new BufferedWriter(fstream); BufferedReader reader = new BufferedReader(new FileReader(file)); //Number of cases String text = reader.readLine(); int NoCases = Integer.parseInt(text); for(int caseNo=0;caseNo<NoCases;caseNo++){ //Case line text = reader.readLine(); String[] caseLine = text.split(" "); //No of googlers int NoGooglers = Integer.parseInt(caseLine[0]); //No of supprising scores int NoSupprising = Integer.parseInt(caseLine[1]); //Score in question int p = Integer.parseInt(caseLine[2]); int minScoreUnSupprising = p*3-2; if(minScoreUnSupprising<=0) minScoreUnSupprising = p; int minScoreSupprising = p*3-4; if(minScoreSupprising<=0) minScoreSupprising = p; int NoGooglersUnSupprising = 0; int NoGooglersSupprising = 0; for(int Googler=0;Googler<NoGooglers;Googler++){ int GooglerScore = Integer.parseInt(caseLine[3+Googler]); if(GooglerScore>=minScoreUnSupprising){ NoGooglersUnSupprising++; } else if(GooglerScore>=minScoreSupprising){ NoGooglersSupprising++; } } if(NoGooglersSupprising>NoSupprising) NoGooglersSupprising = NoSupprising; System.out.println("Case #"+(caseNo+1)+": "+(NoGooglersUnSupprising+NoGooglersSupprising)); out.write("Case #"+(caseNo+1)+": "+(NoGooglersUnSupprising+NoGooglersSupprising)); out.newLine(); } out.close(); } catch (Exception e) { System.out.println(e); } } }
0
557
A12852
A10608
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
///REMOVE ALL OUTPUT AND USE STRINGTOKENIZER! /* ID: mfranzs1 LANG: JAVA TASK: DancingWithTheGooglers */ import java.io.*; import java.util.*; public class DancingWithTheGooglers { static BufferedReader f; public static void main (String [] args) throws IOException { long unixTime = System.currentTimeMillis(); // Use BufferedReader rather than RandomAccessFile; it's much faster f = new BufferedReader(new FileReader("DancingWithTheGooglers.in")); // input file name goes above PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("DancingWithTheGooglers.out"))); int lines=Integer.parseInt(f.readLine()); for(int i=0;i<lines;i++){ StringTokenizer st = new StringTokenizer(f.readLine()," "); int bestOfAtLeastP=0; int numGooglers=Integer.parseInt(st.nextToken()); int suprising=Integer.parseInt(st.nextToken()); int p=Integer.parseInt(st.nextToken()); int suprisingLeft=suprising; for(int g=0;g<numGooglers;g++){ int total = Integer.parseInt(st.nextToken()); System.out.println(total+" "+Math.ceil(total/3D)+" "+p+" "+((total-p)/2D)); if(Math.ceil(total/3D)>=p){ bestOfAtLeastP++; }else{ //Has to be suprising if(total>=p){ if(suprisingLeft>0){ if((total-p)/2D>=p-2){ suprisingLeft--; bestOfAtLeastP++; } } } } } System.out.println("Case #"+(i+1)+": "+bestOfAtLeastP); out.println("Case #"+(i+1)+": "+bestOfAtLeastP); } out.close(); // close the output file System.out.println("Time elapsed (ms): "+(System.currentTimeMillis()-unixTime)); System.exit(0); // don't omit this! } }
0
558
A12852
A10532
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.googlerese.file; public class GooglersBean { private int numGooglers; private int surprising; private int result; private int[] scores = new int[100]; public int getNumGooglers() { return numGooglers; } public int getSurprising() { return surprising; } public int getResult() { return result; } public int[] getScores() { return scores; } public void setNumGooglers( int numGooglers ) { this.numGooglers = numGooglers; } public void setSurprising( int surprising ) { this.surprising = surprising; } public void setResult( int result ) { this.result = result; } public void setScores( int[] scores ) { this.scores = scores; } public void addScore( int index, int score ) { scores[index] = score; } }
0
559
A12852
A11537
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.List; import java.util.Map; import java.util.regex.Pattern; import com.google.common.collect.Lists; import com.google.common.collect.Maps; public class main { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new FileReader("B-small-attempt1.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt")); Pattern pat = Pattern.compile(" "); String firstLine = (br.readLine()); Integer numLines = new Integer(firstLine); Integer i; for(i=1;i<=numLines;i++){ Integer res=0; bw.write("Case #"+i+": "); String line = (br.readLine()).trim(); String [] st= pat.split(line); List<Integer> scores = Lists.newArrayList(); for(Integer j=3;j<st.length;j++){ scores.add(new Integer(st[j])); } res=solve(new Integer(st[1]),new Integer(st[2]),scores); bw.write(res.toString()); bw.newLine(); } bw.close(); } public static Integer solve(Integer numS,Integer p,List<Integer> scores){ Integer res=0; for(Integer e:scores){ Double aver= new Double(e)/3; Boolean r=false; if(aver>=p){ res++; }else{ Integer max=0; if(aver!=0.0){ if(aver>=(Math.floor(aver)+0.25)){ max= (int) (Math.floor(aver)+1); if(max>=p){ res++; r=true; } } if(numS!=0&&!r){ if(aver>=(Math.floor(aver)+0.50)){ max= (int) (Math.floor(aver)+2); }else{ max= (int) (Math.floor(aver)+1); } if(max>=p){ res++; numS--; } } } } } return res; } }
0
560
A12852
A10215
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; import java.io.*; class probB { public static void main(String[] args) throws IOException { Scanner input = new Scanner(new File("probB.in")); PrintWriter output = new PrintWriter(new File("probB.txt")); int lines = input.nextInt(); for (int onl = 0; onl<lines; onl++) { int googlers = input.nextInt(); int sur = input.nextInt(); int p = input.nextInt(); int[] scores = new int[googlers]; int ssf = 0; //Surprising so far int res = 0; for (int i=0; i<googlers; i++) { scores[i] = input.nextInt(); } for (int cur : scores) { if (cur%3 == 0) { //Split evenly if (cur/3 >= p) { res++; System.out.println(cur + " Even"); continue; } if (cur/3 + 1 >= p && cur > 1) { res++; ssf++; System.out.println(cur + " Even + 1"); continue; } } else if (cur%3 == 1) { if (cur/3 + 1 >= p && cur > 1) { res++; System.out.println(cur + " R1"); continue; } } else { if (cur/3 + 1 >= p && cur > 1) { res++; System.out.println(cur + " R2"); continue; } if (cur/3 + 2 >= p && cur >= 2) { res++; ssf++; System.out.println(cur + " R2 S"); continue; } } } System.out.println(ssf + " " + sur); if (ssf > sur) res -= (ssf - sur); output.println("Case #" + (onl+1) + ": " + res); System.out.println(onl+2 + "------"); } output.close(); } }
0
561
A12852
A11108
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/** * $Id$ * $Author$ * $Date$ * Copyright (c) 2011 Amazon.com, Inc. All rights reserved. * * Owner: softlines-amazon-dev@ */ package com.coding.codejam; 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; /** * @author madhava * */ public class B { private static final int MAX_SCORE = 10; private static final int MIN_SCORE = 0; private static final int MAX_DIFFERENCE = 2; private static int[][] dp = new int[100][101]; static { } /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(final String[] args) throws NumberFormatException, IOException { String inputFileName = args[0]; BufferedReader reader = new BufferedReader(new FileReader(inputFileName)); String outputFileName = inputFileName + "_output"; BufferedWriter writer = new BufferedWriter(new FileWriter(outputFileName)); int noOfTestCases = getInteger(reader); int loopCounter = 1; while (noOfTestCases-- != 0) { initialize(); List<Integer> input = getArray(reader); int noOfGooglers = input.get(0); int noOfSurprisingTriplets = input.get(1); int bestResult = input.get(2); List<Integer> scores = new ArrayList<Integer>(noOfGooglers); for (int i = 0; i < noOfGooglers; i++) { scores.add(input.get(i + 3)); } int result = maxNoOfGooglers(scores, 0, noOfSurprisingTriplets, bestResult); writer.write("Case #" + loopCounter + ": " + result + "\n"); System.out.println("Case #" + loopCounter + ": " + result); loopCounter++; } writer.close(); } /** * */ private static void initialize() { for (int i = 0; i < dp.length; i++) { for (int j = 0; j < dp[i].length; j++) { dp[i][j] = -1; } } } /** * @param scores * @param index * @param noOfSurprisingTriplets * @param bestResult * @return */ private static int maxNoOfGooglers(final List<Integer> scores, final int index, final int noOfSurprisingTriplets, final int bestResult) { if (noOfSurprisingTriplets < 0) { return -(scores.size() + 1); } if (index == scores.size()) { return noOfSurprisingTriplets == 0 ? 0 : -(scores.size() + 1); } int result = dp[index][noOfSurprisingTriplets]; if (result != -1) { return result; } else { result = 0; for (int maxScore = MAX_SCORE; maxScore >= MIN_SCORE; maxScore--) { for (int i = 0; i <= MAX_DIFFERENCE; i++) { int secondMaxScore = maxScore - i; int thirdMaxScore = scores.get(index) - secondMaxScore - maxScore; if ((thirdMaxScore > secondMaxScore) || (thirdMaxScore < 0) || (maxScore - thirdMaxScore > MAX_DIFFERENCE)) { continue; } result = Math.max( maxNoOfGooglers(scores, index + 1, noOfSurprisingTriplets - isTripletSuprising(maxScore, thirdMaxScore), bestResult) + toInteger(maxScore >= bestResult), result); } } dp[index][noOfSurprisingTriplets] = result; return result; } } /** * @param b * @return */ private static int toInteger(final boolean b) { if (b) { return 1; } else { return 0; } } /** * @param maxScore * @param thirdMaxScore * @return */ private static Integer isTripletSuprising(final int maxScore, final int thirdMaxScore) { return toInteger(maxScore - thirdMaxScore == MAX_DIFFERENCE); } /** * @param reader * @return * @throws IOException * @throws NumberFormatException */ private static int getInteger(final BufferedReader reader) throws NumberFormatException, IOException { return Integer.parseInt(reader.readLine()); } private static List<Integer> getArray(final BufferedReader reader) throws IOException { String[] line = reader.readLine().split(" "); List<Integer> numbers = new ArrayList<Integer>(); for (String input : line) { numbers.add(Integer.parseInt(input)); } return numbers; } }
0
562
A12852
A10069
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam; import java.io.*; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class B { static String str = "C:\\carl\\fileB.txt"; static String text = ""; static int N, S, P,T; static int[][] list; public static void main(String[] args) { try { int caser = 1; int count = 0; File file = new File(str); BufferedReader br = new BufferedReader(new FileReader(file)); PrintWriter outer = new PrintWriter(new FileWriter("C:\\carl\\outB.txt")); while((text = br.readLine()) != null) { StringTokenizer st = new StringTokenizer(text); if(count == 0) { T = Integer.parseInt(st.nextToken()); System.out.println(T); count++; } else { /* each subsequent line */ N = Integer.parseInt(st.nextToken()); list = new int[N][3]; S = Integer.parseInt(st.nextToken()); P = Integer.parseInt(st.nextToken()); //System.out.println(N + " :: " + S + " :: " + P); int c = 0; while(st.hasMoreTokens()) { float temp = Float.parseFloat(st.nextToken()); //double a = temp/3.0; list[c][0] = Math.round(temp/3.0f); list[c][1] = Math.round(temp/3.0f); list[c][2] = (int)(temp - (2 * Math.round(temp/3.0f))); //System.out.println(temp + " :: " + list[c][0] + " " + list[c][1] + " " + list[c][2]); c++; } /* calculations */ int counter = 0; for(int[] i : list) { if(i[0] >= P || i[1] >= P || i[2] >= P) { counter++; } else { if(S > 0 ) { double a = (i[0]+i[1]+i[2]) - P; //System.out.println("a : " + a); double b = a/2.0; if((P - b) <= 2 && a > 0) { //System.out.println("special " + S + " : " + (P - b) + " :: pass"); counter++; S--; } else { //System.out.println("special " + S + " : " + (P - b) + " :: fail"); } } } } //System.out.println(""); outer.println("Case #" + count + ": " + counter); count++; //caser++; } } outer.close(); } catch(IOException ex) { System.out.println("Error with IO you foooool"); } catch(Exception ex) { System.out.println("Generic Error. Noob."); ex.printStackTrace(); } } }
0
563
A12852
A10088
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; import java.util.StringTokenizer; class roundtwo { public static void main(String[] args) { String text = ""; if( args.length > 0) { text = args[0]; } else { try { FileInputStream fos = new FileInputStream( "text2.txt"); Scanner scanner = new Scanner(new FileInputStream("text2.txt")); try { while (scanner.hasNextLine()){ text += scanner.nextLine() + "\n"; } } finally{ scanner.close(); } try { fos.read(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } StringTokenizer st = new StringTokenizer(text, "[\r\n]+", false); int cases = Integer.parseInt(st.nextToken()); for (int x=1; x<= cases; x++) { StringTokenizer st2 = new StringTokenizer(st.nextToken(), "[ ]+", false); int number = Integer.parseInt(st2.nextToken()); int suprise = Integer.parseInt(st2.nextToken()); int score_target = Integer.parseInt(st2.nextToken()); int[] data = new int[30]; for( int i = 0; i < 30; i++){ data[i] = 0; } int for_sure = 0; int mabey = 0; for( int i = 0; i < number; i++){ int current = Integer.parseInt(st2.nextToken()); int base = current / 3; if( base >= score_target) { for_sure++; } if( base == (score_target - 1)) { int remainder = current % 3; if( remainder > 0) {for_sure++;} else if( base != 0){mabey++;} } if( base == (score_target - 2)) { int remainder = current % 3; if( remainder == 2) {mabey++;} } } int number_possible = for_sure; if( suprise >= mabey) { number_possible += mabey; } else { number_possible += suprise; } System.out.println( "Case #" + x + ": " + number_possible); } } }
0
564
A12852
A12789
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class tr { public static void main(String args[])throws FileNotFoundException,IOException { RandomAccessFile in=new RandomAccessFile("B-small-attempt3.in","r"); FileOutputStream out= new FileOutputStream("out.txt"); int o=Integer.parseInt(in.readLine()); int j=0; int res[]=new int[o]; String str[]=new String[o+1]; while((str[j]=in.readLine())!=null) { String []cas=str[j].split(" "); int no=Integer.parseInt(cas[0]); int sur=Integer.parseInt(cas[1]); int min=Integer.parseInt(cas[2]); int da[]=new int[no]; int mark[]=new int[no]; int [][]trip=new int[no][3]; int cursur=0; String map; String []mchar=new String[3]; for(int i=0;i<no;i++) { da[i]=Integer.parseInt(cas[3+i]);} da=setnos(da,no); for(int i=0;i<no;i++) { mark[i]=0; if(da[i]==1||da[i]==29||da[i]==30||da[i]==0||cursur==sur||check(da[i],min)==false) { map=normalsplit(da[i]); mchar=map.split(" "); trip[i][0]=Integer.parseInt(mchar[0]); trip[i][1]=Integer.parseInt(mchar[1]); trip[i][2]=Integer.parseInt(mchar[2]); System.out.println(trip[i][0]+" "+trip[i][1]+" "+trip[i][2]); } else { mark[i]=1; map=sursplit(da[i]); mchar=map.split(" "); trip[i][0]=Integer.parseInt(mchar[0]); trip[i][1]=Integer.parseInt(mchar[1]); trip[i][2]=Integer.parseInt(mchar[2]); cursur++; System.out.println(trip[i][0]+" "+trip[i][1]+" "+trip[i][2]); } } for(int i=0;i<no;i++) { if((mark[i]==0)&&(da[i]!=1||da[i]!=29||da[i]!=30)) cursur++; } for(int i=0;i<no;i++) { for(int k=0;k<3;k++) { if(trip[i][k]>=min) { res[j]++; break; } } } if(cursur<sur)res[j]=0; j++; } for(int i=0;i<o;i++) { out.write(("Case #"+(i+1)+": "+res[i]+"\n").getBytes()); } } static int []setnos(int []da,int no) { int temp; for(int i=0;i<no;i++) { for(int j=i+1;j<no;j++) { if(da[i]>da[j]) { temp=da[i]; da[i]=da[j]; da[j]=temp; } } } return da; } static boolean check(int d,int min) { String map; String []mchar=new String[3]; map=sursplit(d); mchar=map.split(" "); int a=Integer.parseInt(mchar[0]); int b=Integer.parseInt(mchar[1]); int c=Integer.parseInt(mchar[2]); if(a>=min||b>=min||c>=min)return true; return false; } static String normalsplit(int da) { switch(da) { case 0:return 0+" "+0+" "+0; case 1:return 1+" "+0+" "+0; case 2:return 1+" "+1+" "+0; case 3:return 1+" "+1+" "+1; case 4:return 2+" "+1+" "+1; case 5:return 2+" "+2+" "+1; case 6:return 2+" "+2+" "+2; case 7:return 2+" "+2+" "+3; case 8:return 2+" "+3+" "+3; case 9:return 3+" "+3+" "+3; case 10:return 3+" "+3+" "+4; case 11:return 3+" "+4+" "+4; case 12:return 4+" "+4+" "+4; case 13:return 4+" "+4+" "+5; case 14:return 4+" "+5+" "+5; case 15:return 5+" "+5+" "+5; case 16:return 5+" "+5+" "+6; case 17:return 5+" "+6+" "+6; case 18:return 6+" "+6+" "+6; case 19:return 6+" "+6+" "+7; case 20:return 6+" "+7+" "+7; case 21:return 7+" "+7+" "+7; case 22:return 7+" "+7+" "+8; case 23:return 7+" "+8+" "+8; case 24:return 8+" "+8+" "+8; case 25:return 8+" "+8+" "+9; case 26:return 8+" "+9+" "+9; case 27:return 9+" "+9+" "+9; case 28:return 9+" "+9+" "+10; case 29:return 9+" "+10+" "+10; case 30:return 10+" "+10+" "+10; } return ""; } static String sursplit(int da) { switch(da) { case 2:return 2+" "+0+" "+0; case 3:return 2+" "+1+" "+0; case 4:return 2+" "+2+" "+0; case 5:return 2+" "+2+" "+1; case 6:return 1+" "+2+" "+3; case 7:return 1+" "+3+" "+3; case 8:return 2+" "+2+" "+4; case 9:return 3+" "+2+" "+4; case 10:return 2+" "+4+" "+4; case 11:return 3+" "+3+" "+5; case 12:return 4+" "+3+" "+5; case 13:return 3+" "+5+" "+5; case 14:return 4+" "+4+" "+6; case 15:return 5+" "+4+" "+6; case 16:return 4+" "+6+" "+6; case 17:return 5+" "+5+" "+7; case 18:return 6+" "+5+" "+7; case 19:return 5+" "+7+" "+7; case 20:return 6+" "+6+" "+8; case 21:return 7+" "+6+" "+8; case 22:return 6+" "+8+" "+8; case 23:return 7+" "+7+" "+9; case 24:return 8+" "+7+" "+9; case 25:return 7+" "+9+" "+9; case 26:return 8+" "+8+" "+10; case 27:return 9+" "+8+" "+10; case 28:return 8+" "+10+" "+10; } return ""; } }
0
565
A12852
A11324
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; public class Evans2012B { private final String _PROBLEM_NO = "201201B"; private final String _FILE_DIRECTORY = "K:/Dropbox/workspace/codejam/" + _PROBLEM_NO + "/"; private final String _FILE_PATH = _FILE_DIRECTORY + "B-small-attempt0"; public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); new Evans2012B().execute(); } public void execute() { BufferedReader br = null; PrintWriter pw = null; try { br = new BufferedReader(new FileReader(_FILE_PATH + ".in")); pw = new PrintWriter(_FILE_PATH + ".out"); //main int caseno = Integer.parseInt(br.readLine()); for (int count = 1; count <= caseno; count++) { pw.print("Case #" + count + ": "); System.out.print("Case #" + count + ": "); String line = br.readLine(); String[] splits = line.split(" "); int N = Integer.parseInt(splits[0]); int S = Integer.parseInt(splits[1]); int P = Integer.parseInt(splits[2]); int r = 0; for(int j=0;j<N;j++) { int tt = Integer.parseInt(splits[3 +j]); if(tt==0) { if(P==0) r++; continue; } int t = tt - P*3; if(t >= -2) { r++; } else if(S > 0 && ((t == -3) || (t == -4))) { r++;S--; } } pw.print(r); System.out.print(r); pw.print("\n"); System.out.print("\n"); } //end br.close(); pw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if(pw != null) pw.close(); } catch(Exception e) {} try { if(br != null) br.close(); } catch(Exception e) {} } } }
0
566
A12852
A12214
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class QualiB { static void sop(String str) { System.out.println(str); } static void sop1(String str) { System.out.print(str); } public static void main(String args[]) { long tstart = System.currentTimeMillis(); if(args.length < 1) { System.out.println("You have not given input file!"); System.exit(0); } File f1 = null; Scanner sc = null; try { f1 = new File(args[0]); sc = new Scanner(f1); } catch(Exception e) { System.out.println("Error opening the input file " + e); } /* int nCases, i, j, k, m, n; sc.next(); sc.nextInt(); sc.nextLine(); sc.nextDouble(); */ int nCases, i, j, k, m, n; nCases = sc.nextInt(); // sc.nextLine(); for(i=1; i<=nCases; ++i) { int nDancers = sc.nextInt(); int nSurprising = sc.nextInt(); int best = sc.nextInt(); int totpts[] = new int[nDancers]; for(j=0; j<nDancers; j++) totpts[j] = sc.nextInt(); int ans = 0; if(best == 0) ans = nDancers; else if(best == 1) { for(j=0; j<nDancers; j++) if(totpts[j] > 0) ans++; } else { for(j=0; j<nDancers; j++) { if(nSurprising <= 0) break; if(totpts[j] == 3*best-4 || totpts[j] == 3*best-3) { totpts[j] = 3*best-2; nSurprising--; } } for(j=0; j<nDancers; j++) if(totpts[j] >= 3*best-2 ) ans++; } sop("Case #" + i + ": " + ans); } long tend = System.currentTimeMillis(); System.err.println("Time taken: " + (tend - tstart)/1000.0 + " seconds"); } // end of main() }
0
567
A12852
A12266
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.StringTokenizer; public class GoogleDancers{ public static void main(String[] args) throws Exception{ FileReader fr = new FileReader("C:\\Projects\\Learning\\src\\B-small-attempt1.in"); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter("C:\\Projects\\Learning\\src\\BLarge.txt"); int N = new Integer(br.readLine()); for (int cases = 1; cases <= N; cases++) { String str = br.readLine(); StringTokenizer st = new StringTokenizer(str); int numberParticipants = Integer.parseInt(st.nextToken()); int surprise = Integer.parseInt(st.nextToken()); int goodScore = Integer.parseInt(st.nextToken()); int a[] = new int[numberParticipants]; for(int i=0; i< numberParticipants; i++) { a[i] = Integer.parseInt(st.nextToken()); } int count = 0; int possibility = 0; int minToGetGoodScore = Math.max(((3 * goodScore) - 2), 1); System.out.println("minToGetGoodScore" + minToGetGoodScore); int surpriseRange = Math.max(((3* goodScore) - 4), 1); if (goodScore > 0 ) { for (int i = 0; i < numberParticipants; i++) { if (a[i] >= minToGetGoodScore) { count++; System.out.println("Count" + count); } else if (a[i] >= surpriseRange && a[i] < minToGetGoodScore) { possibility++; } }System.out.println("Count" + count); count = count + Math.min(possibility, surprise); System.out.println("Count" + count); } else { count = numberParticipants; } fw.write("Case #" + cases + ": " + count + "\n"); } fw.flush(); fw.close(); } }
0
568
A12852
A11434
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class B { static class State { boolean surprising, not; int max; State(boolean S, boolean n, int mx) { surprising = S; not = n; max = mx; } } private void solve() throws IOException { int T = nextInt(); while (T-- > 0) { int N = nextInt(); int S = nextInt(); int P = nextInt(); int[] a = new int[N]; State[] St = new State[N]; for (int i = 0; i < N; i++) a[i] = nextInt(); int res = 0; for (int i = 0; i < a.length; i++) { St[i] = new State(false, false, -1); for (int k1 = 0; k1 <= 10; k1++) { for (int k2 = 0; k2 <= 10; k2++) { for (int k3 = 0; k3 <= 10; k3++) { if (k1 + k2 + k3 == a[i]) { if (notValid(k1, k2, k3)) continue; if (surprise(k1, k2, k3)) { if (k1 >= P || k2 >= P || k3 >= P) { St[i].surprising = true; St[i].max = Math.max(St[i].max, Math.max(k1, Math.max(k2, k3))); } } else { if (k1 >= P || k2 >= P || k3 >= P) { St[i].not = true; St[i].max = Math.max(St[i].max, Math.max(k1, Math.max(k2, k3))); } } } } } } } boolean[] V = new boolean[N]; for (int i = 0; i < St.length && S > 0; i++) { if (St[i].surprising && !St[i].not) { res++; V[i] = true; S--; } } for (int i = 0; i < St.length && S > 0; i++) { if (!V[i] && St[i].surprising && St[i].not) { res++; V[i] = true; S--; } } for (int i = 0; i < St.length; i++) { if (!V[i] && St[i].not) { res++; } } pf(); pl(res); } } private boolean notValid(int k1, int k2, int k3) { if (Math.abs(k1 - k2) > 2 || Math.abs(k1 - k3) > 2 || Math.abs(k2 - k3) > 2) return true; return false; } private boolean surprise(int k1, int k2, int k3) { if (Math.abs(k1 - k2) == 2 || Math.abs(k1 - k3) == 2 || Math.abs(k2 - k3) == 2) return true; return false; } public static void main(String[] args) { new B().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader(new FileReader("B.in")); // reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; // writer = new PrintWriter(System.out); writer = new PrintWriter("B.out"); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } BigInteger nextBigInteger() throws IOException { return new BigInteger(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } void p(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.flush(); writer.print(objects[i]); writer.flush(); } } void pl(Object... objects) { p(objects); writer.flush(); writer.println(); writer.flush(); } int cc; void pf() { writer.printf("Case #%d: ", ++cc); writer.flush(); } }
0
569
A12852
A12004
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package dancing; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; 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.Arrays; import java.util.List; import java.util.StringTokenizer; public class DancingTestCase { private final int noOfDancers; private final int noOfSurprising; private final int minScore; private final List<Integer> scores; private final int result; DancingTestCase(int noOfDancers, int noOfSurprising, int minScore, List<Integer> scores) { if (scores.size() != noOfDancers) throw new IllegalArgumentException("Data mismatch"); if (noOfSurprising> noOfDancers) throw new IllegalArgumentException("too many surprises"); this.noOfDancers = noOfDancers; this.noOfSurprising = noOfSurprising; this.minScore = minScore; this.scores = scores; this.result = calculateResult(); } private int calculateResult() { int total=0; int grandTotal=0; int remainingSuprises = noOfSurprising; //needs to try all permutation of each dancer having the suprising flag //then return the bes for(int score : scores) { int div = score / 3; int next = score - div; int secondDiv = next /2; int remainder = next - secondDiv; //System.out.println("input "+score+" first:"+div+" second: "+secondDiv+" third:"+remainder); //assume these won't be more than 1 apart //remainder should be highest, div lowest //could decrement second div and increment reminder if we have a suprise left and smallest value only 1 less if (remainder<div) System.out.println("alarm1"); if (remainder<secondDiv) System.out.println("alarm2"); if (remainder== minScore -1 //missed by just 1 && remainingSuprises > 0 //could make this a suprising result && remainder < 10 //isn't already 10 (unlikly) && secondDiv > 0 //the second smallest isn't already at zero && ((remainder == div +1 && remainder==secondDiv)//we are currently only one apart from smallest //the second value is same as largest so could drop || (remainder == div && remainder ==secondDiv) )) //all values same { remainder++; remainingSuprises--; } int max = remainder; if (max >= minScore) total++; } if (total>grandTotal) grandTotal=total; return grandTotal; } public static void main(String[] args) { DancingTestCase dt = new DancingTestCase(3,1,5,new ArrayList<Integer>(Arrays.asList(15,13,11))); System.out.println("Result"+dt.getResult()); dt = new DancingTestCase(3,0,8,new ArrayList<Integer>(Arrays.asList(23,22,21))); System.out.println("Result"+dt.getResult()); dt = new DancingTestCase(2,1,1,new ArrayList<Integer>(Arrays.asList(8,0))); System.out.println("Result"+dt.getResult()); dt = new DancingTestCase(6,2,8,new ArrayList<Integer>(Arrays.asList(29,20,8,18,18,21))); System.out.println("Result"+dt.getResult()); if (args.length != 2) throw new IllegalArgumentException("No file specified"); List<String> data = new ArrayList<String>(); List<String> results = new ArrayList<String>(); try { FileInputStream fstream = new FileInputStream(args[0]); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { data.add(strLine); } in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } if (data.size() == 0) throw new IllegalArgumentException("No data in file"); int noTestCases = Integer.parseInt(data.get(0)); if (data.size() != noTestCases + 1) throw new IllegalArgumentException("Number of test cases is not " + noTestCases); for (int i = 1; i <= noTestCases; i++) { results.add("Case #" + i + ": " + parse(data.get(i))); } try { FileWriter fostream = new FileWriter(args[1]); BufferedWriter out = new BufferedWriter(fostream); for (int i =0;i<results.size();i++) { String s = results.get(i); out.write(s); if (i<results.size()-1) out.newLine(); } out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static int parse(String input) { StringTokenizer st = new StringTokenizer(input, " "); if (st.countTokens() <1) throw new IllegalArgumentException("No values found"); int noOfDancers = Integer.parseInt(st.nextToken()); if (st.countTokens() != 2 + noOfDancers) throw new IllegalArgumentException("Wrong no of values"); int noSuprises = Integer.parseInt(st.nextToken()); int minValue = Integer.parseInt(st.nextToken()); List<Integer> scores = new ArrayList<Integer>(); while (st.hasMoreTokens()) scores.add(Integer.parseInt(st.nextToken())); DancingTestCase dt = new DancingTestCase(noOfDancers,noSuprises,minValue,scores); // System.out.println("Result"+dt.getResult()); return dt.getResult(); } public int getResult() { return result; } }
0
570
A12852
A13205
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.codejam; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.HashMap; public class DancingWithTheGooglers { public static void main(String[] args) { try { FileInputStream fstream = new FileInputStream( "D:\\Softwares\\B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); FileOutputStream out = new FileOutputStream( "D:\\Softwares\\B-small-attempt0.out"); PrintStream p = new PrintStream(out); int lineNo = 1; while (in.available() != 0) { if (lineNo == 1) { cases(in.readLine(), in, p); } lineNo++; } in.close(); out.close(); } catch (Exception e) { e.printStackTrace(); } } private static void cases(String firstLine, DataInputStream in, PrintStream p) throws IOException { int casesNo = Integer.parseInt(firstLine); for (int i = 0; i < casesNo; i++) { p.print("Case #" + (i + 1) + ": "); String line = in.readLine(); googlers(line, p); } } private static void googlers(String line, PrintStream p) { String lines[] = line.split(" "); int suprises = Integer.parseInt(lines[1]); int reqP = Integer.parseInt(lines[2]); int result = 0; int number=0; int quo = 0; int rem = 0; for(int i = 3;i<lines.length;i++) { number =Integer.parseInt(lines[i]); if(number==0 && reqP==0) { result=result+1; continue; } if(number ==0 ) continue; quo = number/3; rem = number%3; rem = rem==0? 0 : 1; if(quo>=reqP || (rem+quo)>=reqP) { result=result+1; continue; } else { if(suprises>=1) { number +=2; quo = number/3; rem = number%3; rem = rem==0? 0 : 1; if(quo>=reqP || (rem+quo)>=reqP) { result=result+1; suprises=suprises-1; continue; } } } } p.println(result+""); } }
0
571
A12852
A11854
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithTheGooglers { private static Scanner scan; private static PrintWriter writer; private static File input = new File("B-small-attempt0.in"); private static File output = new File("B-small-attempt0.out"); public static void main(String[] args) throws Exception { scan = new Scanner(input); writer = new PrintWriter(output); int total = scan.nextInt(); int n, s, p, sum[]; for (int t = 1; t <= total; t++) { n = scan.nextInt();// googler's number s = scan.nextInt();// surprising p = scan.nextInt();// min_score sum = new int[n]; for (int i = 0; i < sum.length; i++) sum[i] = scan.nextInt(); int maximum = 0; for (int score : sum) { int part = score / 3; switch (score % 3) { case 0: if (part >= p) { maximum++; } else if (s > 0 && part > 0 && part + 1 >= p) { maximum++; s--; } break; case 1: if (part >= p || part + 1 >= p) { maximum++; } else if (s > 0 && part + 1 >= p) { maximum++; s--; } break; case 2: if (part + 1 >= p || part >= p) { maximum++; } else if (s > 0 && part + 2 >= p) { maximum++; s--; } break; } } println(String.format("Case #%d: %d", t, maximum)); } writer.flush(); } public static void println(String p) { System.out.println(p); writer.println(p); } }
0
572
A12852
A10499
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.*; import java.util.HashMap; import java.util.Iterator; import java.util.Map; /** * * @author Sagar */ public class Dancing_With_the_Googlers { Map m; int no_of_test_cases = 0; StringBuffer [] sb; Integer []output ; String inputfile = ""; String outputfile = ""; Integer [][] input ; int no_of_digits = 0; public void setInputOutput(String input, String output) { inputfile = input; outputfile = output; } public void readFile() { String line=""; boolean firstTime = true; int i = 0; try { FileReader filename = new FileReader(inputfile); BufferedReader reader = new BufferedReader(filename); while((line=reader.readLine()) !=null) { if(firstTime) { firstTime = false; no_of_test_cases = Integer.parseInt(line); System.out.println("testcases:"+no_of_test_cases); output = new Integer[no_of_test_cases]; for (int s = 0;s<no_of_test_cases;s++) output[s]= new Integer(0); sb = new StringBuffer[no_of_test_cases]; for(int j=0;j<no_of_test_cases;j++) sb[j] = new StringBuffer(); } else { sb[i++].append(line); } } /* for(int k=0;k<no_of_test_cases;k++) { System.out.println(input[k][0] + " " + input[k][1] ); } */ } catch(IOException e) { System.out.println("Input File not found"); } } public void processFile() { int p=0, special_cases=0,no_of_inputs=0; String [] tokens; for (int i=0;i<no_of_test_cases;i++) { System.out.println(sb[i].toString()); tokens = sb[i].toString().split(" "); //System.out.println("Tokens"+tokens[0]+ " " +tokens[1]+ " " +tokens[2]); no_of_inputs = Integer.parseInt(tokens[0]); special_cases = Integer.parseInt(tokens[1]); p = Integer.parseInt(tokens[2]); for(int j = 0;j<no_of_inputs;j++) { int number = Integer.parseInt(tokens[j+3]); int result =0; if(number !=0 ||(number==0 && special_cases==0)) { if(number%3==0) { result = (number /3); if(result>=p) output[i]=output[i]+1; else { if((p-result)==1 && special_cases>0) { output[i]=output[i]+1; special_cases--; } } } else if(number%3==1) { result = (number/3); if(result >=p || result+1 >=p) output[i]=output[i]+1; else if((p-result+1)==1 && special_cases>0) { output[i]=output[i]+1; special_cases--; } } else if(number%3==2) { result = (number/3); if(result >=p || result+1 >=p) { output[i]=output[i]+1; } else if (result+2>=p &&special_cases>0) { output[i]=output[i]+1; special_cases--; } else if((p-result+1)==1 && special_cases>0) { output[i]=output[i]+1; special_cases--; } } } } //System.out.println("OutPut"+i+ +output[i]); } } public void displayOutput() { try { // Create file FileWriter fstream = new FileWriter(outputfile); BufferedWriter out = new BufferedWriter(fstream); for(int i=0;i<no_of_test_cases;i++) { out.write("Case #"+(i+1)+": "); out.write(output[i].toString()); out.newLine(); } //Close the output stream out.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.toString()); } } public static void main(String []args) { Dancing_With_the_Googlers obj = new Dancing_With_the_Googlers(); obj.setInputOutput("C:\\Users\\Sagar\\Desktop\\myWork\\B-small-attempt0.in", "C:\\Users\\Sagar\\Desktop\\myWork\\output4.txt"); obj.readFile(); obj.processFile(); obj.displayOutput(); } }
0
573
A12852
A10318
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam.qual2012; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; public class B { public int count(int target, int surprise, int[] scores) { int a = target; int b = target - 1; int c = target - 2; if (b < 0) b = 0; if (c < 0) c = 0; int good = a + b + b; int goodWSurprize = a + c + c; int count = 0; for (int i : scores) { if (i >= good) { count++; } else if (i >= goodWSurprize && surprise > 0) { count++; surprise--; } } return count; } public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintStream out = new PrintStream(new BufferedOutputStream(System.out)); String line = in.readLine(); int testCases = Integer.parseInt(line); B b = new B(); // Read in all test cases for (int testCase = 1; testCase <= testCases; testCase++) { line = in.readLine(); String[] data = line.split(" "); int target = Integer.parseInt(data[2]); int surprise = Integer.parseInt(data[1]); int[] scores = new int[data.length - 3]; for (int i = 3; i < data.length; i++) { scores[i - 3] = Integer.parseInt(data[i]); } out.println("Case #" + testCase + ": " + b.count(target, surprise, scores)); } out.flush(); } }
0
574
A12852
A13050
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package Q2; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Main { private static BufferedReader input; private static BufferedWriter output; public Main(String inputSetName) throws Exception { if(getClass().getResource(".") == null){ System.err.println("Switch constructors man"); System.exit(-1); } String path = getClass().getResource(".").getPath(); System.out.println(path); input = new BufferedReader(new FileReader(path+inputSetName+".in")); output = new BufferedWriter(new FileWriter(path+inputSetName+".out")); } public Main(String[] args) throws Exception{ input = new BufferedReader(new FileReader(args[0])); output = new BufferedWriter(new FileWriter(args[1])); } public void run(Solver model, boolean resultNewLine) throws Exception{ int cases = Integer.parseInt(input.readLine()); model.setInput(input); for(int i=1;i<=cases;i++){ System.out.println("Working on case "+i+"..."); String $ = model.solve(); if(resultNewLine) outputln("Case #"+i+":"); else output("Case #"+i+": "); outputln($); System.out.println("Case "+i+" finished! Result: "+$); } input.close(); output.close(); } public static void outputln(String s){ try { output.write(s); output.newLine(); } catch (IOException e) { e.printStackTrace(); } } public static void output(String s){ try { output.write(s); } catch (IOException e) { e.printStackTrace(); } } }
0
575
A12852
A10949
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/** * Write a description of class solver here. * * @author (your name) * @version (a version number or a date) */ public class solver { public int solve(int nog,int nos,int p,int t[]) { int[] aux=new int[2*nog]; int i=0,count=0; for(i=0;i<nog;i++) { if(t[i]==0) { aux[i]=0; aux[nog+i]=-1; } else if(t[i]==1) { aux[i]=1; aux[nog+i]=-1; } else if(t[i]==29) { aux[i]=10; aux[nog+i]=-10; } else if(t[i]==30) { aux[i]=10; aux[nog+i]=-10; } else if(t[i]%3==0) { aux[i]=t[i]/3; aux[nog+i]=t[i]/3+1; } else if(t[i]%3==1) { aux[i]=t[i]/3+1; aux[nog+i]=-1; } else { aux[i]=t[i]/3+1; aux[nog+i]=t[i]/3+2; } } for(i=0;i<nog;i++) { if(aux[i]>=p) { count++; aux[nog+i]=-1; } } for(i=0;i<nog;i++) { if(nos==0) break; else if(aux[i+nog]>=p) { nos-=1; count++; } } return count; } }
0
576
A12852
A10255
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; /** * Google Code Jam 2012 * * @author 7henick */ public class ProblemB { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); sc.nextLine(); for (int i = 0; i < T; i++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int result = 0; for (int j = 0; j < N; j++) { int g = sc.nextInt(); int min = g / 3; int best = g - min * 2; if (best - min == 0) { if (best >= p) { result++; } else { if (best + 1 >= p && min - 1 >= 0 && S > 0) { result++; S--; } } } else if (best - min == 1) { if (best >= p) { result++; } } else if (best - min == 2) { if (best - 1 >= p) { result++; } else { if (best >= p && S > 0) { result++; S--; } } } else { throw new Exception(); } } System.out.println("Case #" + (i + 1) + ": " + result); sc.nextLine(); } } }
0
577
A12852
A12320
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package br.com.atama.google.jam.dancing; public enum Context { INSTANCE; private int numSurprises; private int threshold; public int getNumSurprises() { return numSurprises; } public void setNumSurprises(int numSurprises) { this.numSurprises = numSurprises; } public int getThreshold() { return threshold; } public void setThreshold(int threshold) { this.threshold = threshold; } }
0
578
A12852
A11308
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package google_code_jam; import java.io.FileInputStream; import java.io.IOException; import java.util.Scanner; public class Dancing { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new FileInputStream("data/dancers.txt")); try { // Read the number of tests int numTests = 0; int answer = 0; String testLine; if (scanner.hasNextLine()) numTests = Integer.valueOf(scanner.nextLine()); for (int i=1; i<=numTests; i++) { if (scanner.hasNextLine()) { testLine = scanner.nextLine(); answer = getAnswer(testLine); System.out.println("Case #" + i + ": " + answer); } } } finally { scanner.close(); } } private static int getAnswer(String testLine) { //System.out.println("The updateCounts was called with " + testLine); int numDancers = 0; int numSurprises = 0; int scoreToReach = 0; int sumScores = 0; String[] parts = testLine.split(" "); numDancers = Integer.valueOf(parts[0]); numSurprises = Integer.valueOf(parts[1]); scoreToReach = Integer.valueOf(parts[2]); if (scoreToReach <= 0) { return numDancers; } int answer = 0; for (int j=0; j<numDancers; j++) { sumScores = Integer.valueOf(parts[j+3]); if (canBeNormal(sumScores, scoreToReach)) { answer++; } else if (numSurprises > 0 && canBeSurprise(sumScores, scoreToReach)) { answer++; numSurprises--; } else { // Didn't quality, do nothing } } return answer; } private static boolean canBeSurprise(int sumScores, int scoreToReach) { if (sumScores == 0) return false; if (sumScores >= 3 * (scoreToReach - 2) + 2) return true; else return false; } private static boolean canBeNormal(int sumScores, int scoreToReach) { return sumScores > 3 * (scoreToReach - 1); } }
0
579
A12852
A12930
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package google.loader; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.List; public class ChallengeLoader { private List<Challenge> challenges; private final ChallengeReader reader; public ChallengeLoader(ChallengeReader reader){ this.reader = reader; } public List<Challenge> load(String aPath){ try{ String input = readFileAsString(aPath); readChallenges(input); return challenges; } catch(Exception e){ throw new RuntimeException(e); } } private String readFileAsString(String filePath) throws java.io.IOException{ byte[] buffer = new byte[(int) new File(filePath).length()]; BufferedInputStream f = null; try { f = new BufferedInputStream(new FileInputStream(filePath)); f.read(buffer); } finally { if (f != null) try { f.close(); } catch (IOException ignored) { } } return new String(buffer); } private void readChallenges(String input) { String delimiter; if(input.indexOf("\r\n")>0){ delimiter="\r\n"; }else{ delimiter="\n"; } String[] lines = input.split(delimiter); challenges = reader.createChallenges(lines); } public String getResult() { StringBuffer res = new StringBuffer(); for(Challenge challenge : challenges){ res.append(challenge.getResult()); } return res.toString(); } }
0
580
A12852
A13047
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package Q2; import java.io.BufferedReader; import java.io.IOException; abstract public class Solver { protected BufferedReader input; protected final String nl = System.getProperty("line.separator"); abstract public String solve() throws Exception; protected String readLine(){ try { return input.readLine(); } catch (IOException e) { e.printStackTrace(); System.exit(-1); } return null; } protected Long[] splitLineL(String line){ return splitLineL(line, " "); } protected Long[] splitLineL(String line, String delim){ String[] split = line.split(delim); Long[] $ = new Long[split.length]; for(int i=0;i<split.length;i++){ $[i] = Long.parseLong(split[i]); } return $; } protected Integer[] splitLine(String line){ return splitLine(line, " "); } protected Integer[] splitLine(String line, String delim){ String[] split = line.split(delim); Integer[] $ = new Integer[split.length]; for(int i=0;i<split.length;i++){ $[i] = Integer.parseInt(split[i]); } return $; } public void setInput(BufferedReader input) { this.input = input; } <T> void printArr(T[] arr){ for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); } } <T> void printArr(T[][] arr){ for(int i=0;i<arr.length;i++){ for(int j=0;j<arr[i].length;j++){ System.out.print(arr[i][j]+" "); } System.out.println(); } } }
0
581
A12852
A10990
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; public class MaxDancers { public static void main(String[] args)throws IOException { String fichierentree= "/home/marwen/Téléchargements/B-small-attempt0.in"; String fichiersortie= "/home/marwen/Bureau/output.in"; BufferedWriter wr= new BufferedWriter(new FileWriter(fichiersortie)); DataInputStream rd= new DataInputStream(new FileInputStream(fichierentree)); //Reading number of cases String ligne = rd.readLine(); int cases = Integer.valueOf(ligne); int k; for (k=1;k<=cases;k++) { //Reading ligne by ligne ligne = rd.readLine(); ligne=ligne+" "; // Reading length of the table and filling in it with numbers int taille = Integer.valueOf(ligne.substring(0, ligne.indexOf(" "))); int [] T1= new int [3+taille]; T1[0]=taille; int i,val; for (i=1;i<3+taille;i++) { ligne=ligne+" "; ligne = ligne.substring(ligne.indexOf(" ") + 1); val = Integer.valueOf(ligne.substring(0, ligne.indexOf(" "))); T1[i]=val; } // End of Reading table from ligne //Solving the problem for each Line int s,p,nb,l; s=T1[1]; p=T1[2]; nb=0; l=T1.length; for(i=3;i<l;i++) { if (T1[i]>=p) { if (T1[i]>=3*p-2) {nb++;} else {if ((T1[i]>=3*p-3)||(T1[i]>=3*p-4)){if (s>0){nb++;s--;}}} } } //Writing into the output file before moving to the next Line wr.write("Case #"+k+": "+nb); wr.newLine(); } wr.close(); rd.close(); } }
0
582
A12852
A11232
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam2012.qualified; 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 ProblemB { static BufferedReader buffReader = null; static BufferedWriter buffWriter = null; static FileReader fileReader = null; static FileWriter fileWriter = null; static String input_test = "/home/qimeng/problemB.test"; static String input_small = "/home/qimeng/B-small-attempt1.in"; static String input_large = "/home/qimeng/B-small-attempt1.out"; public static final void main(String[] args){ try { fileReader = new FileReader(input_small); buffReader = new BufferedReader(fileReader); fileWriter = new FileWriter("/home/qimeng/problemB.out"); buffWriter = new BufferedWriter(fileWriter); int total_size = Integer.parseInt(buffReader.readLine()); //iterate through every input line for(int i=1; i<=total_size; i++){ String[] str = buffReader.readLine().split(" "); int strLen = str.length; int T = Integer.parseInt(str[0]); int s = Integer.parseInt(str[1]); int p = Integer.parseInt(str[2]); int[] scores = new int[T]; int k = 0; for(int j=3; j<strLen; j++){ scores[k] = Integer.parseInt(str[j]); k++; } System.out.println("Case #" +i+": " + danceAlgorithm(s, p, scores)); buffWriter.write("Case #" +i+": " + danceAlgorithm(s, p, scores)); buffWriter.newLine(); buffWriter.flush(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { buffWriter.flush(); buffWriter.close(); buffReader.close(); fileReader.close(); fileWriter.close(); } catch (IOException e) { e.printStackTrace(); } } } private static int danceAlgorithm(int s, int p, int[] scores){ int result = 0; int i = 0; while(i < scores.length){ int score = scores[i]; if(score == 0 && p != 0){ i++; continue; } int avg = score / 3; int rem = scores[i] % 3; //System.out.println("p:"+ p +" avg: "+avg+" rem: "+rem); if(avg >= p){ result++; } else { if(rem == 0){ if(avg + 1 >= p) { if(s>0){ result++; s--; } } } else if(rem == 1){ if(avg + 1 >= p) { result++; } } else if(rem == 2){ if(avg + 2 >= p) { if(avg+1>=p){ result++;} else{ if(s>0){ result++; s--; } } } } } i++; } return result; } }
0
583
A12852
A12843
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.util.Arrays; public class B { BufferedReader in; BufferedWriter out; static String inputFile = "B.in"; static String outputFile = "B.out"; public String readWord() throws Exception { int c = in.read(); while (c>=0 && c<=' ') { c = in.read(); } if (c < 0) { return ""; } StringBuilder builder = new StringBuilder(); while( c > ' ' ) { builder.append((char)c); c = in.read(); } return builder.toString(); } public int nonsurpMax(int totalP) { int result = totalP/3; if (totalP - result*3 > 0) result++; return result; } public void solve() throws Exception { int cases = Integer.parseInt(readWord()); for (int i = 0; i<cases; i++) { StringBuilder builder = new StringBuilder(); builder.append("Case #" + (i+1) + ": "); int count = 0; int N = Integer.parseInt(readWord()); int S = Integer.parseInt(readWord()); int p = Integer.parseInt(readWord()); for (int j = 0; j<N; j++) { int t = Integer.parseInt(readWord()); int max = nonsurpMax(t); if (max >= p) count++; if ((max<10) && (max > 0) && (max == p-1) && (S>0)) { count++; S--; } } builder.append("" + count); if (i < cases-1) builder.append("\n"); out.write(builder.toString()); } } public static void main(String[] args) { B start = new B(); start.run(); } public void run() { try { in = new BufferedReader(new FileReader(inputFile)); out = new BufferedWriter(new FileWriter(outputFile)); solve(); out.flush(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
584
A12852
A13049
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package Q2; public class ChooseCalc { private long[][] chooseCache; public ChooseCalc(int cacheSize, boolean readyCache) { chooseCache = new long[cacheSize][cacheSize]; for(int i=0;i<cacheSize;i++){ for(int j=0;j<cacheSize;j++){ chooseCache[i][j] = readyCache ? perm(i, j) : -1; } } } public static long perm(int n, int k){ if(n < k) return 0; long $=1; for(int i=n;i>Math.max(k, n-k);i--){ $ *= i; } for(int i=1;i<=Math.min(k, n-k);i++){ $ /= i; } return $; } public long choose(int k, int n) { if(chooseCache[n][k] == -1) chooseCache[n][k] = perm(n, k); return chooseCache[n][k]; } public long cached(int k, int n){ return chooseCache[n][k]; } public long choosewithRep(int k, int n){ return choose(k, n)*(n-k); } }
0
585
A12852
A11538
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; import java.io.*; public class DanceGooglers{ public static void main(String[] args){ try{ FileReader fin = new FileReader(args[0]); BufferedReader txtFile = new BufferedReader(fin); //FileWriter fout = new FileWriter(args[1]); //BufferedWriter out = new BufferedWriter(fout); String line = null; line = txtFile.readLine(); int T = Integer.parseInt(line); //System.out.println(T); for(int i = 0; i < T; i ++){ line = txtFile.readLine(); StringTokenizer st = new StringTokenizer(line, " "); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int[] ts = new int[N]; for(int i1 = 0; i1 < N; i1 ++) ts[i1] = Integer.parseInt(st.nextToken()); int[][] notSurp = new int[N][3]; int[][] surp = new int[N][3]; boolean[] outOfRange = new boolean[N]; for(int i1 = 0; i1 < N; i1 ++){ int num = ts[i1]; if(num % 3 == 0){ notSurp[i1][0] = num/3; notSurp[i1][1] = num/3; notSurp[i1][2] = num/3; surp[i1][0] = num/3-1; surp[i1][1] = num/3; surp[i1][2] = num/3+1; if(surp[i1][0] < 0 || surp[i1][2] > 10) outOfRange[i1] = true; else outOfRange[i1] = false; } if(num % 3 == 1){ notSurp[i1][0] = num/3; notSurp[i1][1] = num/3; notSurp[i1][2] = num/3+1; surp[i1][0] = num/3-1; surp[i1][1] = num/3+1; surp[i1][2] = num/3+1; if(surp[i1][0] < 0 || surp[i1][2] > 10) outOfRange[i1] = true; else outOfRange[i1] = false; } if(num % 3 == 2){ notSurp[i1][0] = num/3; notSurp[i1][1] = num/3+1; notSurp[i1][2] = num/3+1; surp[i1][0] = num/3; surp[i1][1] = num/3; surp[i1][2] = num/3+2; if(surp[i1][2] > 10) outOfRange[i1] = true; else outOfRange[i1] = false; } }//for(int i1 = 0; i1 < N; i1 ++) int result = 0; for(int i1 = 0; i1 < N-1; i1 ++){ for(int i2 = i1 + 1; i2 < N; i2 ++){ if(surp[i1][2] > surp[i2][2]){ int tmp = surp[i1][0]; surp[i1][0] = surp[i2][0]; surp[i2][0] = tmp; tmp = surp[i1][1]; surp[i1][1] = surp[i2][1]; surp[i2][1] = tmp; tmp = surp[i1][2]; surp[i1][2] = surp[i2][2]; surp[i2][2] = tmp; tmp = notSurp[i1][0]; notSurp[i1][0] = notSurp[i2][0]; notSurp[i2][0] = tmp; tmp = notSurp[i1][1]; notSurp[i1][1] = notSurp[i2][1]; notSurp[i2][1] = tmp; tmp = notSurp[i1][2]; notSurp[i1][2] = notSurp[i2][2]; notSurp[i2][2] = tmp; boolean tmp2 = outOfRange[i1]; outOfRange[i1] = outOfRange[i2]; outOfRange[i2] = tmp2; } }//for }//for /*for(int i1 = 0; i1 < N; i1 ++){ System.out.println(surp[i1][0]+" "+surp[i1][1]+" "+surp[i1][2]); System.out.println(notSurp[i1][0]+" "+notSurp[i1][1]+" "+notSurp[i1][2]); }*/ int k = 1; for(int i1 = N-1; i1 >= 0; i1 --){ if(k <= S && surp[i1][2] >= p && notSurp[i1][2] < p && outOfRange[i1] == false){ result ++; k ++; } else if(notSurp[i1][2] >= p){ result ++; } } System.out.println("Case #"+Integer.toString(i+1)+": "+Integer.toString(result)); }//for(int i = 0; i < T; i ++) }//try catch(IOException e) { e.printStackTrace(); } } }
0
586
A12852
A11138
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Dance { public static void main(String[] args) throws FileNotFoundException { File file = new File("input.in"); Scanner in = new Scanner(file); int cases = in.nextInt(); for (int i = 0; i < cases; i++) { int N = in.nextInt(); //googlers int S = in.nextInt(); //surprising scores int p = in.nextInt(); int [] scores = new int[N]; for (int j = 0; j < scores.length; j++) { scores[j] = in.nextInt(); } int max = 0; for (int j = 0; j < scores.length; j++) { if (scores[j] >= (3*p-2)) { max++; } else if (scores[j] >= (3*p-4) && S > 0 && !((3*p-4) <= 0) ) { max++; S--; } } System.out.println("Case #"+ (i+1) + ": " + max); } } }
0
587
A12852
A12169
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; public class Dancing { public static void main(String args[]) throws IOException{ // Setup the input File f1 = new File("B-small-attempt0.in"); Scanner s1 = new Scanner(f1); // setup the output: PrintWriter out = new PrintWriter(new FileWriter("output.out")); // getting the number of test cases and getting rid of the line int testCases = Integer.parseInt(s1.nextLine()); //System.out.println(testCases); // setting up some vars int googlers; int surprising; int testMax; ArrayList<Integer> scores = new ArrayList<Integer>(); int j = 0; int resultNum; int surprisingLeft; // Loop over the lines while(s1.hasNextLine()){ scores.clear(); resultNum = 0; j++; googlers = s1.nextInt(); surprising = s1.nextInt(); surprisingLeft = surprising; testMax = s1.nextInt(); for (int i = 0; i <googlers;i++){ scores.add(s1.nextInt()); } //System.out.println("Line "+j+" Googlers: " + googlers + " surprising: "+surprising+" testMax: " + testMax); // loop over all the googlers for (int k = 0; k<googlers;k++){ //System.out.println(k); //int minScore = (testMax-1)+(testMax-1)+(testMax-1); //System.out.println(minScore); if (scores.get(k)>((testMax-1)+(testMax-1)+(testMax-1))){ resultNum++; } else if (surprisingLeft != 0 && scores.get(k)!=0){ if (scores.get(k)>=testMax+testMax-2+testMax-2){ resultNum++; surprisingLeft--; } } } out.println("Case #"+j+": "+resultNum); } // close the scanner s1.close(); out.close(); } }
0
588
A12852
A11895
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.google.codejam; import com.google.codejam.util.CodeJamInputFile; import com.google.codejam.util.CodeJamOutputFile; public class Dancer { /** * @param args */ public static void main(String[] args) { CodeJamInputFile f = new CodeJamInputFile("in/B-small-attempt0.in"); CodeJamOutputFile fo = new CodeJamOutputFile("out/B-small-attempt0.out"); for(int c = 0; c < f.getCases(); c++){ int count = 0; String line = f.getLine(); String[] tokens = line.split(" "); int goog = Integer.valueOf(tokens[0]); int surp = Integer.valueOf(tokens[1]); int best = Integer.valueOf(tokens[2]); for(int g = 3; g < (goog + 3); g++){ int tot = Integer.valueOf(tokens[g]); System.out.print(tot + " - "); if(tot > ((best * 3) - 3)){ count++; continue; } if((surp > 0) && (tot > ((best * 3) - 5)) && (tot > 2)){ count++; surp--; } } System.out.println(count + ""); fo.writeCase(c, count + ""); } f.close(); fo.close(); } }
0
589
A12852
A11833
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.Reader; public class ProB { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub File infile = new File("B-small-attempt1.in"); File outfile = new File("out.txt"); int []scores = new int[222]; BufferedReader reader = null; BufferedWriter writer = null; try{ reader = new BufferedReader(new FileReader(infile)); writer = new BufferedWriter(new FileWriter(outfile)); String ss = reader.readLine(); String out; String []nums; int t = Integer.parseInt(ss),i,j,res; int n,s,p,temp,rest; for(i=1;i<=t;i++){ out = "Case #" + i + ": "; ss = reader.readLine(); nums = ss.split(" "); n = Integer.parseInt(nums[0]); s = Integer.parseInt(nums[1]); p = Integer.parseInt(nums[2]); for(j=3;j<3+n;j++){ scores[j-3] = Integer.parseInt(nums[j]); } sort(scores,n); res = 0; for(j=0;j<n;j++){ temp = scores[j] /3; rest = scores[j] - temp * 3; if(rest > 0) temp++; if(temp >= p) res++; else{ if(rest == 2 && s > 0 && temp + 1 >= p){ s--; res++; } if(rest == 0 && s > 0 && temp > 0 && temp + 1 >= p){ s--; res++; } } } out += res; writer.write(out); writer.newLine(); } reader.close(); writer.close(); }catch(Exception e){ e.printStackTrace(); } } private static void sort(int []scores,int n) { int i,j,t,s; for(i=0;i<n;i++){ t = i; s = scores[i]; for(j=i+1;j<n;j++){ if(scores[j] > s){ s = scores[j]; t = j; } } s = scores[i]; scores[i] = scores[t]; scores[t] = s; } } }
0
590
A12852
A12124
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Vector; public class TestCaseB { public int googlers; public int surprises; public int minscore; public Vector<Integer> scores; public TestCaseB(int g, int s, int m, Vector<Integer> sc) { googlers = g; surprises = s; minscore = m; scores = sc; System.out.println("tc: " + g + " " + s + " " + m + " " + scores); } }
0
591
A12852
A12514
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class Dancing { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int z=1; z<=t; z++) { StringTokenizer st = new StringTokenizer(br.readLine()," "); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int ans = 0; int temp = 0; int[] a = new int[n]; for(int i=0; i<n; i++) { a[i] = Integer.parseInt(st.nextToken()); if(a[i]>(3*p-3)) ans++; if(a[i]==(3*p-3)||a[i]==(3*p-4)) temp++; } if(temp>s) temp = s; if(p==1) temp = 0; System.out.println("Case #"+z+": "+(ans+temp)); } } }
0
592
A12852
A12028
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Created with IntelliJ IDEA. * User: andraz * Date: 14.4.12 * Time: 13:25 * To change this template use File | Settings | File Templates. */ public class Dancing { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int rep=0; rep<t; rep++) { String line[] = br.readLine().split(" "); int n = Integer.parseInt(line[0]); int s = Integer.parseInt(line[1]); int p = Integer.parseInt(line[2]); int count = 0; for(int i=0; i< n; i++) { int total = Integer.parseInt(line[3+i]); if(total>=3*p - 2) { count++; } else if ((total >= 3*p - 4) && (total>=p) && (s>0)) { count++; s--; } } System.out.printf("Case #%d: %d\n", rep+1, count); } } }
0
593
A12852
A12243
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws Exception{ char problem = 'B'; boolean smallCase = true; boolean practice = false; BufferedReader br = new BufferedReader(new FileReader(problem + "-" + (smallCase ? "small" : "large") + (practice ? "-practice" : "") + ".in")); PrintWriter out = new PrintWriter(new FileWriter(problem + "-" + (smallCase ? "small" : "large") + (practice ? "-practice" : "") + ".out")); int t = Integer.parseInt(br.readLine()); for(int i = 1; i <= t; i++) { out.println("Case #" + i + ": " + solve(br.readLine())); } out.close(); System.exit(0); } public static int solve(String in) { Scanner sc = new Scanner(in); int numPeople = sc.nextInt(); int numSurprize = sc.nextInt(); int target = sc.nextInt(); int output = 0; for(; numPeople > 0; numPeople--) { int cur = sc.nextInt(); if(cur >= target * 3 - 2) output ++; else if(target != 1 && numSurprize > 0 && cur >= target * 3 - 4) { output ++; numSurprize --; } } return output; } }
0
594
A12852
A10711
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class problem2 { void main() { solve(); } void solve() { try { FileInputStream fstream = new FileInputStream("pr2_input.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fout = new FileWriter("output.txt"); BufferedWriter out = new BufferedWriter(fout); int iCases = Integer.parseInt(br.readLine()); for (int iStep = 0; iStep < iCases; iStep++) { String strLine = br.readLine(); String[] numbers = strLine.split(" "); int N = Integer.valueOf(numbers[0]).intValue(); int S = Integer.valueOf(numbers[1]).intValue(); int P = Integer.valueOf(numbers[2]).intValue(); List<Integer> notes = new ArrayList<Integer>(); for (int jStep = 0; jStep < N; jStep++) { notes.add(Integer.valueOf(numbers[jStep + 3]).intValue()); } //< Calcculate notes int iNormalMinNote = P * 3 - 2; int iSurpriseMinNote = P * 3 - 4; Collections.sort(notes); int iGooglers = 0; for (int jStep = 0; jStep < notes.size(); jStep++) { if (S > 0) { if (notes.get(jStep) >= iSurpriseMinNote) { if (notes.get(jStep) >= 2) { S--; iGooglers++; } } } else { if (notes.get(jStep) >= iNormalMinNote) { iGooglers++; } } } if (iStep != (iCases - 1)) { out.write(String.format("Case #%d: %d\n", iStep + 1, iGooglers)); } else { out.write(String.format("Case #%d: %d", iStep + 1, iGooglers)); } } out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
595
A12852
A10838
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package be.mokarea.gcj.googledancers; import be.mokarea.gcj.common.TestCase; public class GoogleDancerTestCase extends TestCase { private final int numberOfGooglers; private final int numberOfSurprisingTripletsOfScores; private final int scoreLowerBoundary; private final int[] scores; protected GoogleDancerTestCase(int caseNumber, int numberOfGooglers, int numberOfSurprisingTripletsOfScores, int scoreLowerBoundary, int[] scores) { super(caseNumber); this.numberOfGooglers = numberOfGooglers; this.numberOfSurprisingTripletsOfScores = numberOfSurprisingTripletsOfScores; this.scoreLowerBoundary = scoreLowerBoundary; this.scores = scores; } public int getNumberOfGooglers() { return numberOfGooglers; } public int getMaxNumberOfSurprisingTripletsOfScores() { return numberOfSurprisingTripletsOfScores; } public int getScoreLowerBoundary() { return scoreLowerBoundary; } public int[] getScores() { return scores; } }
0
596
A12852
A11322
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.util.ArrayList; import java.util.Scanner; public class Main { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("input.txt")); BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt")); int N = scanner.nextInt(); for (int i = 1; i <= N; i++) { int n = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); ArrayList<Integer> e = new ArrayList<Integer>(); for (int j = 0; j < n; j++) e.add(scanner.nextInt()); Solver solver = new Solver(s, p, e); writer.append("Case #" + i + ": " + solver.solve()); writer.newLine(); } writer.close(); scanner.close(); } }
0
597
A12852
A13203
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Googler implements Runnable { int[] isSuprisingMaxScore = new int[31]; int[] isNotSuprisingMaxScore = new int[31]; boolean[] canSuprising = new boolean[31]; private void solve() throws IOException { // long time = System.currentTimeMillis(); int test = nextInt(); Arrays.fill(canSuprising, true); canSuprising[0] = false; canSuprising[1] = false; for (int i = 4; i <= 30 ; i += 3) canSuprising[i] = false; int maxScore = 2; for (int i = 2; i <= 30; i += 3) { for (int j = i ; j <= Math.min(i + 2, 30); j++) isSuprisingMaxScore[j] = maxScore; maxScore++; } maxScore = 1; for (int i = 1; i <= 30; i += 3) { for (int j = i ; j <= Math.min(i + 2, 30); j++) isNotSuprisingMaxScore[j] = maxScore; maxScore++; } for (int i = 1; i <= test; i++) { solveTest(i); } writer.close(); // writer.println("Running time: " + (System.currentTimeMillis() - // time)); } private void solveTest(int test) throws IOException { // TODO Auto-generated method stub int n = nextInt(); int s = nextInt(); int p = nextInt(); int[] scores = new int[n+1]; for (int i = 1; i <= n; i++) scores[i] = nextInt(); int result = 0; for (int i = 1; i <= n; i++) { if (isNotSuprisingMaxScore[scores[i]] >= p) { result++; continue; } if (isSuprisingMaxScore[scores[i]] >= p && s >= 1) { result++; s--; } } writer.write("Case #" + test + ": " + result + "\n"); } public static void main(String[] args) { new Googler().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; String fileName = "Googler"; public void run() { try { reader = new BufferedReader(new FileReader(fileName + ".in")); tokenizer = null; writer = new PrintWriter(new FileWriter(fileName + ".out")); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } }
0
598
A12852
A12623
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class goog { static int surprise; public static void main (String [] args) throws Exception { BufferedReader f = new BufferedReader(new FileReader("goog.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("goog.out"))); int N = Integer.parseInt(f.readLine()); for(int i = 0; i<N; i++){ String s = f.readLine(); StringTokenizer st = new StringTokenizer(s); int[] hi = new int[Integer.parseInt(st.nextToken())]; surprise = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); for(int j = 0; j<hi.length; j++) hi[j] = Integer.parseInt(st.nextToken()); Arrays.sort(hi); int count = 0; for(int j = hi.length-1; j>=0; j--) if(could(hi[j], p)) count++; out.println("Case #"+(i+1)+": "+count); } out.close(); System.exit(0); } public static boolean could(int i, int greq){ int[] t = new int[]{Math.max(0, greq-1), Math.max(0, greq-1), greq}; int sum = 0; for(int e:t) sum+=e; if(sum<=i) return true; if(surprise>0){ surprise--; t = new int[]{Math.max(0, greq-2), Math.max(0, greq-2), greq}; sum = 0; for(int e:t) sum+=e; if(sum<=i) return true; } return false; // if(i>=3*(greq-1)+1) // return true; // if(greq == 2){ // if(greq<2) // return false; // if(surprise>0) // { // surprise--; // return true; // } // return false; // } // if(i<Math.max(greq, 3*(greq-2)+2)) // return false; // if(surprise>0) // { // surprise--; // return true; // } // return false; } }
0
599