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
A11888
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.io.IOException; import java.io.PrintWriter; /** * Apr 14, 2012  * @author parisel * GGJ - Qualification Round */ public class B { private static final int TEST= 0, SMALL= 1, LARGE= 2; private static final String[] infile= { "-test.in", "-small.in", "-large.in"}; private static final String[] outfile= {"-test.out", "-small.out", "-large.out"}; java.io.BufferedReader br; java.io.PrintWriter out; String[] tok; private String[] getTok() throws IOException {return br.readLine().split(" ");} private int getInt() throws IOException {return Integer.valueOf(br.readLine());} private int[] getInt(int N) throws IOException { int[] data= new int[N]; tok= br.readLine().split(" "); for (int i=0; i<N; i++) data[i]= Integer.valueOf(tok[i]); return data; } private int toInt(String s) { return Integer.valueOf(s); } int[] normalBestScore, surprisingBestScore; private void generateBestScores() { normalBestScore= new int[31]; surprisingBestScore= new int[31]; int i,j,k, sum, max; for (i=0; i<=10; i++) { for (j=0; j<=10; j++) { for (k=0; k<=10; k++) { sum= i+j+k; if (isValid(i, j, k)) { max= max(i,j,k); if (isSurpring(i, j, k)) { if (max>surprisingBestScore[sum]) surprisingBestScore[sum]= max; } else { if (max>normalBestScore[sum]) normalBestScore[sum]= max; } } } } } } private boolean isValid(int i, int j, int k) { return (Math.abs(i-j)<=2) && (Math.abs(i-k)<=2) && (Math.abs(j-k)<=2); } private boolean isSurpring(int i, int j, int k) { return (Math.abs(i-j)==2) || (Math.abs(i-k)==2) || (Math.abs(j-k)==2); } private int max(int i, int j, int k) { return Math.max(i, Math.max(j, k)); } int N, S, p; int[] t; private int answer() { int i, countNormal= 0, countSurprising= 0; for (i=0; i<N; i++) { if (normalBestScore[t[i]]>= p) ++countNormal; if (normalBestScore[t[i]]< p && surprisingBestScore[t[i]]>=p) ++countSurprising; } return countNormal + Math.min(S, countSurprising); } public void solve() throws IOException { int i,j,k; String s; int MODE= SMALL; br = new BufferedReader (new FileReader("B"+infile[MODE])); out = new PrintWriter(new BufferedWriter(new FileWriter("B"+outfile[MODE]))); generateBestScores(); int C= Integer.valueOf(br.readLine()); for (int c=1; c<=C; c++) { // read tok= getTok(); N= toInt(tok[0]); S= toInt(tok[1]); p= toInt(tok[2]); t= new int[N]; for (i=0; i<N; i++) t[i]= toInt(tok[3+i]); // output out.printf("Case #%d: %d\n", c, answer()); } out.close(); } public static void main(String[] args) throws IOException { new B().solve(); } }
0
400
A12852
A10995
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 DancingWiththeGooglers { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int T = Integer.parseInt(sc.nextLine()); int r[] = new int[T]; for (int i = 0; i < T; i++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); for (int j = 0; j < N; j++) { int total = sc.nextInt(); if (total >= p) { if ((p*3 - 2) <= total) { r[i]++; } else if ((p*3 - 4) <= total && S > 0) { S--; r[i]++; } } } } for (int i = 0; i < r.length; i++) { System.out.println("Case #" + (i + 1) + ": " + r[i]); } } }
0
401
A12852
A12765
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.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.Scanner; public class B { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub // bug eliminator Scanner in = new Scanner(new File("d:\\b.small.in"));// new Scanner(new // File("d:\\b.small.in")); // in = new Scanner(new File("d:\\Minimum Scalar Product-big.in")); int people, surp, max,cutter, dangers, certainty; int[] scores; int testCases = in.nextInt(); in.nextLine(); for (int cas = 1; cas <= testCases; cas++) { int ans = 0; people = in.nextInt(); scores = new int[people]; surp = in.nextInt(); max = in.nextInt(); cutter = max*3; for (int i = 0; i < people; i++) scores[i] = in.nextInt(); // in.nextLine();// eat linedelim dangers = 0; certainty = 0; for (int i = 0; i < people; i++) { if (scores[i] >= cutter - 2) { certainty++; } else if (scores [i] >= cutter - 4&&cutter - 4>=0) { dangers++; } } // System.out.println("m"+max+"c"+cutter+"c"+certainty+"d"+dangers+"s"+surp); ans = certainty; ans+= dangers > surp ? surp : dangers; System.out.printf("Case #%d: %d\n", cas, ans); } } }
0
402
A12852
A12454
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; /* 4 3 1 5 15 13 11 3 0 8 23 22 21 2 1 1 8 0 6 2 8 29 20 8 18 18 21 */ public class Problem { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int test = 1, numberOfTests, dancarinos, erros, notaCorte, notaAtual, resposta; numberOfTests = scanner.nextInt(); for( int i = 0; i < numberOfTests; i++ ){ resposta = 0; dancarinos = scanner.nextInt(); erros = scanner.nextInt(); notaCorte = scanner.nextInt(); int[] notas = new int[dancarinos]; for( int j = 0; j < dancarinos; j++){ notas[j] = scanner.nextInt(); } int div, resto; for( int j = 0; j < dancarinos; j++ ){ notaAtual = notas[j]; div = notaAtual / 3; resto = notaAtual % 3; switch( resto ){ case 0: if( div >= notaCorte){ resposta++; }else{ if( erros > 0 && div > 0 && div +1 >= notaCorte){ resposta++; erros--; } } break; case 1: if (div >= notaCorte || div + 1 >= notaCorte){ resposta++; }else{ if (erros > 0 && div + 1 >= notaCorte){ resposta++; erros--; } } break; case 2: if (div + 1 >= notaCorte || div >= notaCorte){ resposta++; }else{ if (erros > 0 && div + 2 >= notaCorte){ resposta++; erros--; } } break; } } System.out.println("Case #"+test+": "+resposta); test++; } } }
0
403
A12852
A11627
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; import java.io.File; public class ScoreAnalyzer { public void analyzeInputFile(String fileName) throws Exception { Scanner fileScanner = new Scanner (new File (fileName) ); String line; line = fileScanner.nextLine(); int numberOfTestCases = Integer.parseInt(line.trim()); int N,S,p; for(int i = 1; i<= numberOfTestCases ; i++) { line = fileScanner.nextLine(); Scanner lineScanner = new Scanner(line); N = Integer.parseInt(lineScanner.next().trim()); S = Integer.parseInt(lineScanner.next().trim()); p = Integer.parseInt(lineScanner.next().trim()); // System.out.println("N= "+N+ " S = "+S + " p = "+p); int noSurpriseLowerLimitScore; int surpriseLowerLimitScore; int surpriseHigherLimitScore; noSurpriseLowerLimitScore = 3*p - 2; surpriseLowerLimitScore = 3*p - 4; surpriseHigherLimitScore = 3*p - 3; // System.out.println("3p-2 = "+noSurpriseLowerLimitScore); // System.out.println("3p-4 = "+surpriseLowerLimitScore); // System.out.println("3p-3 = "+surpriseHigherLimitScore); int googlersWithBestResultOfAtLeastP = 0; int numberOfSurpriseScoresLeft = S; for(int j=1; j<=N ; j++) { int googlerScore = Integer.parseInt(lineScanner.next().trim()); if(googlerScore >= p) { // System.out.println("googlerScore = "+googlerScore+" "); if(googlerScore >= noSurpriseLowerLimitScore) { googlersWithBestResultOfAtLeastP++; continue; } if(numberOfSurpriseScoresLeft > 0 ) { if(googlerScore >= surpriseLowerLimitScore && googlerScore <= surpriseHigherLimitScore) { googlersWithBestResultOfAtLeastP++; numberOfSurpriseScoresLeft--; } } } } System.out.println("Case #"+i+": "+googlersWithBestResultOfAtLeastP); } } public static void main(String[] args) throws Exception { ScoreAnalyzer SA = new ScoreAnalyzer(); String inputFile = "B-small-attempt0.in"; SA.analyzeInputFile(inputFile); } }
0
404
A12852
A11665
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.io.PrintWriter; import java.util.HashMap; /** Main function is "solve" **/ public class CodeJamProblem2 { static HashMap<String,String> mappings=null; public static void main(String args[]) { solve(); } private static void solve() { readFromInputAndWriteInOutput(); } private static void readFromInputAndWriteInOutput() { try { File f = new File("B-small-attempt1.in"); FileReader fileReader = new FileReader(f); BufferedReader buff = new BufferedReader(fileReader); String totalTestCases = buff.readLine(); PrintWriter printWriter = new PrintWriter("B-small-attempt1.out"); int testCases = Integer.parseInt(totalTestCases); for(int i =1;i<=testCases;i++) { String line = buff.readLine(); String outputLine = "Case #"+i+": "; String result = solveForThisLine(line); outputLine = outputLine.concat(result); printWriter.println(outputLine); //System.out.println(outputLine); } printWriter.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static String solveForThisLine(String line) { String splitS[] = line.split(" "); int numberOfGooglers = Integer.parseInt(splitS[0]); int numberOfSurprisingScores = Integer.parseInt(splitS[1]); int reqP = Integer.parseInt(splitS[2]); int result = 0; int number=0; int quo = 0; int rem = 0; for(int i = 3;i<splitS.length;i++) { number =Integer.parseInt(splitS[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(numberOfSurprisingScores>=1) { number +=2; quo = number/3; rem = number%3; rem = rem==0? 0 : 1; if(quo>=reqP || (rem+quo)>=reqP) { result=result+1; numberOfSurprisingScores=numberOfSurprisingScores-1; continue; } } } } return result+""; } }
0
405
A12852
A12422
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.InputMismatchException; /** * Created with IntelliJ IDEA. * User: IIoTeP9HuY * Date: 14.04.12 * Time: 5:25 * To change this template use File | Settings | File Templates. */ public class Solver { static int getTripleType(int a, int b, int c) { if (a < 0 || b < 0 || c < 0) return 0; if (a > 10 || b > 10 || c > 10) return 0; if (Math.abs(a - b) > 2 || Math.abs(a - c) > 2 || Math.abs(b - c) > 2) return 0; if (Math.abs(a - b) == 2 || Math.abs(a - c) == 2 || Math.abs(b - c) == 2) return 2; return 1; } public static void main(String[] args) throws IOException { InputReader in = new InputReader(new FileInputStream("input.txt")); OutputWriter out = new OutputWriter(new FileOutputStream("output.txt")); int testCases = in.readInt(); for(int t = 1; t <= testCases; t++) { int N = in.readInt(); int S = in.readInt(); int p = in.readInt(); int[] score = new int[N]; int bestResultNumber = 0; for(int i = 0; i < N; i++) { score[i] = in.readInt(); boolean canWithSurprise = false; boolean canWithoutSurprise = false; for(int firstScore = 0; firstScore <= score[i]; firstScore++) { for(int secondScore = 0; secondScore + firstScore <= score[i]; secondScore++) { int thirdScore = score[i] - firstScore - secondScore; int tripleType = getTripleType(firstScore, secondScore, thirdScore); if (tripleType == 0) continue; if (firstScore < p && secondScore < p && thirdScore < p) continue; if (tripleType == 2 && S <= 0) continue; if (tripleType == 1) canWithoutSurprise = true; else canWithSurprise = true; } } if (canWithoutSurprise) bestResultNumber++; else if (canWithSurprise && S > 0) { bestResultNumber++; S--; } } out.print("Case #" + t + ": " + bestResultNumber + "\n"); } out.close(); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(outputStream); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } }
0
406
A12852
A11567
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 j2012qualifier; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class B { public static String inputDirectory="src/j2012qualifier/"; public static String inputFile="B.in"; public static String outputFile="B.out"; public static PrintWriter output; public static void main(String[] args) throws FileNotFoundException{ Scanner s=new Scanner(new File(inputDirectory + inputFile)); output=new PrintWriter(new File(inputDirectory + outputFile)); int cases = s.nextInt(); for(int Case=1;Case<=cases;Case++){ s.nextLine(); int googlers = s.nextInt(); int maxSupriseScores = s.nextInt(); int targetScore = s.nextInt(); int normalScores = 0; int surpriseScores = 0; for(int i=0;i< googlers; i++) { int score = s.nextInt(); if (targetScore > score) { continue; } int otherScore = (score - targetScore) / 2; if (otherScore >= targetScore - 1) { normalScores++; } else if(otherScore >= targetScore - 2) { surpriseScores++; } } int answer = normalScores + Math.min(surpriseScores, maxSupriseScores); out("Case #"+Case+": "+answer); } output.flush(); } public static void out(String s){ output.println(s); //System.out.println(s); } }
0
407
A12852
A10239
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.practice; /** * * @author Saikat Roy */ import java.io.*; public class Main1 { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void input() throws IOException { int k=1; int n=Integer.parseInt(br.readLine()); while(n--!=0) { String str1=br.readLine(); String[] str2=new String[40]; str2=str1.split("[ ]"); int N=Integer.parseInt(str2[0]); int S=Integer.parseInt(str2[1]); int p=Integer.parseInt(str2[2]); int x=0; int[] arr=new int[N]; while(x<N){ arr[x]=Integer.parseInt(str2[x+3]); x++; } for(int k1=0;k1<N-1;k1++) for(int k2=k1+1;k2<N;k2++) if(arr[k2]<arr[k1]) { int hold=arr[k1]; arr[k1]=arr[k2]; arr[k2]=hold; } // for(int m=0;m<N;m++) // System.out.print(arr[m]+" "); int flag=0; int[] check=new int[6]; check[0]=(3*p)-4; check[1]=(3*p)-3; check[2]=(3*p)-2; check[3]=(3*p)+2; check[4]=(3*p)+3; check[5]=(3*p)+4; String[] allocation=new String[N]; for(int y=0;y<N;y++){ allocation[y]="A"; if(p>1) if(((arr[y]==check[0])||(arr[y]==check[1]||(arr[y]==check[2])))&&(S!=0)) { //System.out.println(y); flag++; S--; //allocation[y]=""; allocation[y]="X"; } } if(S!=0){ for(int y=0;y<N;y++){ if(((arr[y]==check[3])||(arr[y]==check[4]||(arr[y]==check[5])))&&(S!=0)) { // System.out.println("x"); flag++; S--; //allocation[y]=""; allocation[y]="X"; } } } int chk=(3*p)-2; if(p==0) chk=0; for(int y=0;y<N;y++){ // System.out.println(allocation[y]); if(arr[y]>=chk && allocation[y].equals("A")) { //System.out.println("x"); flag++; //allocation[y]=""; allocation[y]="X"; } } //if(S!=0) // flag-=S; // for(int y=0;y<N;y++) // System.out.println(allocation[y]); System.out.print("Case #"+k+": "+flag); if(n!=0) System.out.println(); k++; } } public static void main(String[] args) throws IOException { Main1 ob=new Main1(); ob.input(); } }
0
408
A12852
A10945
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.io.IOException; public class DancingWithGooglers { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new FileReader("input.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt")); int K, N, S, p, i, j; K = Integer.parseInt(br.readLine()); for (i = 0; i < K; i++) { String[] line = br.readLine().split(" "); N = Integer.parseInt(line[0]); S = Integer.parseInt(line[1]); p = Integer.parseInt(line[2]); int[] data = new int[line.length - 3]; for (j = 0; j < data.length; j++) { data[j] = Integer.parseInt(line[j + 3]); // System.out.print(data[j] + " "); } // System.out.println(); int counter = 0; for (j = 0; j < data.length; j++) { int a, b, c; int res; a = (int) Math.floor((double) data[j] / 3); res = data[j] - a; b = (int) Math.floor((double) res / 2); res = res - b; c = res; if (a >= p || b >= p || c >= p) { counter++; } else if ((a + b + c) != 0 && (a + b + c) != 1) { int temp = (p - a) + (p - b) + (p - c); if (temp == 3 && S > 0) { counter++; S--; } else if (temp == 4 && S > 0) { counter++; S--; } } } bw.write("Case #" + (i+1) + ": " + counter); bw.newLine(); } br.close(); bw.close(); } catch (IOException io) { } } }
0
409
A12852
A11847
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.util.*; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.BufferedReader; import java.io.FileReader; import java.lang.Math; import java.util.ArrayList; import java.util.HashMap; import java.math.BigInteger; class CombinationGenerator { private int[] a; private int n; private int r; private BigInteger numLeft; private BigInteger total; public CombinationGenerator (int n, int r) { if (r > n) { throw new IllegalArgumentException (); } if (n < 1) { throw new IllegalArgumentException (); } this.n = n; this.r = r; a = new int[r]; BigInteger nFact = getFactorial (n); BigInteger rFact = getFactorial (r); BigInteger nminusrFact = getFactorial (n - r); total = nFact.divide (rFact.multiply (nminusrFact)); reset (); } //------ // Reset //------ public void reset () { for (int i = 0; i < a.length; i++) { a[i] = i; } numLeft = new BigInteger (total.toString ()); } //------------------------------------------------ // Return number of combinations not yet generated //------------------------------------------------ public BigInteger getNumLeft () { return numLeft; } //----------------------------- // Are there more combinations? //----------------------------- public boolean hasMore () { return numLeft.compareTo (BigInteger.ZERO) == 1; } //------------------------------------ // Return total number of combinations //------------------------------------ public BigInteger getTotal () { return total; } //------------------ // Compute factorial //------------------ private static BigInteger getFactorial (int n) { BigInteger fact = BigInteger.ONE; for (int i = n; i > 1; i--) { fact = fact.multiply (new BigInteger (Integer.toString (i))); } return fact; } //-------------------------------------------------------- // Generate next combination (algorithm from Rosen p. 286) //-------------------------------------------------------- public int[] getNext () { if (numLeft.equals (total)) { numLeft = numLeft.subtract (BigInteger.ONE); return a; } int i = r - 1; while (a[i] == n - r + i) { i--; } a[i] = a[i] + 1; for (int j = i + 1; j < r; j++) { a[j] = a[i] + j - i; } numLeft = numLeft.subtract (BigInteger.ONE); return a; } } public class One { public static void main(String args[]) { String filename = args[0]; int i=0,j=0; int testcase=0 ; String out=""; BufferedWriter bufferedWriter = null; try { BufferedReader in = new BufferedReader(new FileReader(filename)); String str; boolean output; str = in.readLine(); testcase = Integer.parseInt(str); //Construct the BufferedWriter object bufferedWriter = new BufferedWriter(new FileWriter("oneoutput.wpd")); for (i=0;i <testcase; i++) { int N=0,S=0,P=0; int[] t=new int[10000000]; str = in.readLine(); /* StringTokenizer st2 = new StringTokenizer(str, ","); while (st2.hasMoreElements()) { System.out.println(st2.nextElement()); } */ StringTokenizer st = new StringTokenizer(str," "); System.out.println(st); N = Integer.parseInt((String)st.nextElement()); S = Integer.parseInt((String)st.nextElement()); P = Integer.parseInt((String)st.nextElement()); System.out.println("N="+N+" S="+S); for (j=0;j<N;j++) t[j] = Integer.parseInt((String)st.nextElement()); //declare data structures here // initialize with non surprizes end int[] indices; CombinationGenerator gen = new CombinationGenerator (N, S);//3C2 BigInteger numCombinations = gen.getTotal (); System.out.println ("Num combinations to test " + numCombinations.toString ()); int maxwinner=-1; // for each case while (gen.hasMore ()) { int nowinner=0; indices = gen.getNext (); int[][] score= new int[N][3]; // initialize with non surprizes for ( j=0;j<N;j++) { if(t[j]%3 ==0 ) { score[j][0]=t[j]/3; score[j][1]=t[j]/3; score[j][2]=t[j]/3; } if(t[j]%3 ==1 ) { score[j][0]=t[j]/3; score[j][1]=t[j]/3; score[j][2]=(t[j]/3)+1; } if(t[j]%3 ==2 ) { score[j][0]=t[j]/3; score[j][1]=(t[j]/3)+1; score[j][2]=(t[j]/3)+1; } } for (int i1 = 0; i1 < indices.length; i1++) { System.out.println ("indices["+i1+"]="+indices[i1]); // over write with surprises if (t[indices[i1]] >0) { if(t[indices[i1]]%3 ==0 ) { score[indices[i1]][0]=t[indices[i1]]/3-1; score[indices[i1]][1]=(t[indices[i1]]/3); score[indices[i1]][2]=(t[indices[i1]]/3)+1; } if(t[indices[i1]]%3 ==1 ) { score[indices[i1]][0]=(t[indices[i1]]-4)/3; score[indices[i1]][1]=((t[indices[i1]]-4)/3)+2; score[indices[i1]][2]=((t[indices[i1]]-4)/3)+2; } if(t[indices[i1]]%3 ==2 ) { score[indices[i1]][0]=t[indices[i1]]/3; score[indices[i1]][1]=(t[indices[i1]]/3); score[indices[i1]][2]=(t[indices[i1]]/3)+2; } } } // compute largest. for (int l=0;l<N;l++) { System.out.println ("score["+l+"]="+score[l][0]+","+score[l][1]+","+score[l][2]); if(score[l][2]>=P) nowinner++; System.out.println ("nowwinner="+nowinner+"l="+l); } if(maxwinner<nowinner) maxwinner=nowinner; } out="Case #"+(i+1)+": "; out += maxwinner+"\n"; System.out.println ("out ="+out); bufferedWriter.write(out); } in.close(); } catch (IOException ex) { ex.printStackTrace();} finally { //Close the BufferedWriter try { if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } public static StringBuffer[] rotateAndDrop(String grid[], int N,int K) { int m,o; StringBuffer reverseStr[] = new StringBuffer[N]; for (m=0;m<N;m++) { reverseStr[m]= (new StringBuffer(grid[m])).reverse(); System.out.println ("reverseStr["+m+"]="+reverseStr[m]); for (o=0;o<N;o++) { /*if(reverseStr[m].charAt(o)=='.') { StringBuffer tmp=new StringBuffer(reverseStr[m].substring(o+1,N)); System.out.println ("After reverseStr["+m+"]="+reverseStr[m]); System.out.println ("tmp="+tmp); reverseStr[m]= tmp.append("."); System.out.println ("After reverseStr["+m+"]="+reverseStr[m]); }*/ } } return reverseStr; } public static String results(StringBuffer grid[], int N,int K) { char[][] ch=new char[N][N]; StringBuffer out=new StringBuffer(); boolean Blue=false,Red=false; int m,o,i; for (m=0;m<N;m++) { for (o=0;o<N;o++) { ch[m][o]=grid[m].charAt(o); } } for (m=0;m<N;m++) { for (o=0;o<N;o++) { if (ch[m][o] != '.' ) { try{ //check horizontally int j=0; for(i=0;i<K;i++) { if( ch[m][o] == ch[m][o+i] ) j++; else break; } if (j==K) { out.append(ch[m][o]); } //check vertically j=0; for(i=0;i<K;i++) { if( ch[m][o] == ch[m+i][o] ) j++; else break; } if (j==K) { out.append(ch[m][o]); } //check diagonally j=0; for(i=0;i<K;i++) { if( ch[m][o] == ch[m+i][o+i] ) j++; else break; } if (j==K) { out.append(ch[m][o]); } //check diagonally j=0; for(i=0;i<K;i++) { if( ch[m][o] == ch[m-i][o-i] ) j++; else break; } if (j==K) { out.append(ch[m][o]); } } catch(Exception r) { } } } } if (out != null) { if (out.indexOf("B")>0 ) Blue =true; if (out.indexOf("R")>0 ) Red =true; } if (Blue && Red) return "BOTH"; if (Blue) return "Blue"; if (Red) return "Red"; return "Neither"; } }
0
410
A12852
A11401
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 DancingWithTheGooglers { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int numCases, currentCase, numGooglers, surprisingScores, searchFor, answer, currentScore; ArrayList<Integer> scores; numCases = scan.nextInt(); currentCase = 0; while (currentCase < numCases) { currentCase++; numGooglers = scan.nextInt(); surprisingScores = scan.nextInt(); searchFor = scan.nextInt(); scores = new ArrayList<Integer>(); for (int i = 0; i < numGooglers; i++) scores.add(scan.nextInt()); answer = 0; for (int i = 0; i < scores.size(); i++) { currentScore = scores.get(i); currentScore = currentScore / 3; if (scores.get(i) == 0 && searchFor != 0) { } else if (currentScore > searchFor) { answer++; } else if (currentScore * 3 == scores.get(i)) { if (currentScore == searchFor) { answer++; } else if (surprisingScores > 0 && (currentScore + 1 == searchFor || currentScore - 1 == searchFor)) { answer++; surprisingScores--; } } else if ((currentScore * 3) + 1 == scores.get(i)) { if (currentScore == searchFor || currentScore + 1 == searchFor) { answer++; } else if (surprisingScores > 0 && (currentScore - 1 == searchFor)) { answer++; surprisingScores--; } } else if ((currentScore * 3) + 2 == scores.get(i)) { if (currentScore == searchFor || currentScore + 1 == searchFor) { answer++; } else if (surprisingScores > 0 && (currentScore + 2 == searchFor)) { answer++; surprisingScores--; } } } System.out.printf("Case #%d: %d\n", currentCase, answer); } } }
0
411
A12852
A11244
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; } }
/** * Copyright 2012 Christopher Schmitz. All Rights Reserved. */ package com.isotopeent.codejam.lib.converters; import com.isotopeent.codejam.lib.InputConverter; public class StringLine implements InputConverter<String> { private String input; @Override public boolean readLine(String data) { input = data; return false; } @Override public String generateObject() { return input; } }
0
412
A12852
A11215
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 java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; public class Utils { static final String outputFileName = "D:\\output.txt"; static ArrayList<String> outputData = new ArrayList<String>(); public static void run(Class<?> cls){ Object obj = null; try { obj = cls.newInstance(); } catch (Exception e1) { e1.printStackTrace(); } outputData.clear(); String[] args = Utils.readInput(cls); Method method = getMethod(obj.getClass()); executeMethod(obj, args, method); writeToFile(); } private static void executeMethod(Object obj, String[] args, Method method) { int index = 0; int n = Integer.valueOf(args[index++]); if (n == args.length - 1){ for(int i = 0; i < n; i++){ Class<?>[] t = method.getParameterTypes(); Object[] par = new Object[t.length]; for (int j = 0; j < t.length; j++) { par[j] = parseParameter(args[index++], t[j]); } try { printOutput(i+1, method.invoke(obj, par)); } catch (Exception e) { e.printStackTrace(); } } }else{ for(int i = 0; i < n; i++){ Class<?>[] t = method.getParameterTypes(); Object[] par = new Object[t.length]; String[] sp = args[index++].split(" "); if(t.length == sp.length){ for (int j = 0; j < t.length; j++) { String[] sArr = new String[Integer.valueOf(sp[j])]; for (int k = 0; k < sArr.length; k++) { sArr[k] = args[index++]; } par[j] = sArr; } } try { printOutput(i+1, method.invoke(obj, par)); } catch (Exception e) { e.printStackTrace(); } } } } private static String[] readInput(Class<?> cls){ String fileName = cls.getSimpleName() + ".in"; BufferedReader in = new BufferedReader(new InputStreamReader(cls.getResourceAsStream(fileName))); ArrayList<String> res = new ArrayList<String>(); String s; try { while((s = in.readLine()) != null){ res.add(s); } } catch (IOException e) { e.printStackTrace(); } return res.toArray(new String[]{}); } private static Method getMethod(Class<?> cls){ Method[] methods = null; try { methods = cls.getDeclaredMethods(); for(Method m : methods) if(Modifier.isPublic(m.getModifiers())) return m; } catch (Exception e) { e.printStackTrace(); } return null; } private static Object parseParameter(String arg, Class<?> cls) { if(cls == int.class){ return Integer.valueOf(arg); }else if(cls == int[].class){ String[] split = arg.split(" "); int[] res = new int[split.length]; for (int i = 0; i < res.length; i++) { res[i] = Integer.valueOf(split[i]); } return res; }else if(cls == long[].class){ String[] split = arg.split(" "); long[] res = new long[split.length]; for (int i = 0; i < res.length; i++) { res[i] = Long.valueOf(split[i]); } return res; }else if(cls == String.class){ return arg; } return null; } private static void printOutput(int count, Object res) { Class<?> cls = res.getClass(); String data = "Case #" + count + ": "; if(cls == int[].class){ int[] array = (int[]) res; for (int i = 0; i < array.length; i++) { data += array[i] + " "; } data = data.substring(0, data.length() - 1); }else{ data += res; } System.out.println(data); outputData.add(data); } private static void writeToFile() { try { FileWriter fstream = new FileWriter(outputFileName); BufferedWriter out = new BufferedWriter(fstream); for(String s : outputData){ out.write(s); out.newLine(); } out.close(); fstream.close(); } catch (IOException e1) { e1.printStackTrace(); } } }
0
413
A12852
A12936
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; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.Scanner; public class QualB { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new FileInputStream(new File("/home/rush/sample-in.txt"))); PrintWriter out = new PrintWriter(new FileOutputStream("/home/rush/sample-out.txt")); // Scanner in = new Scanner(System.in); // PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int cnt = 0; for (int j = 0; j < n; j++) { int ti = in.nextInt(); if (ti % 3 == 1) { if (ti / 3 + 1 >= p) cnt++; } else { if (ti % 3 == 0) { if (ti / 3 >= p) { cnt++; } else if (ti != 0 && s > 0 && ti / 3 + 1 == p) { cnt++; s--; } } if (ti % 3 == 2) { if (ti / 3 + 1 >= p) { cnt++; } else if (s > 0 && ti / 3 + 2 == p) { cnt++; s--; } } } } out.printf("Case #%d: %d", (i+1), cnt); out.println(); } out.flush(); } }
0
414
A12852
A10108
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.FileWriter; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class B { // public final static String IN_FILE = "B.in"; // public final static String OUT_FILE = "B.out"; public final static String IN_FILE = "B-small-attempt0.in"; public final static String OUT_FILE = "B-small-attempt0.out"; private static Scanner IN; public static void main(String[] args) throws Exception { InputStream in = new FileInputStream(IN_FILE); PrintWriter out = new PrintWriter(new FileWriter(OUT_FILE)); IN = new Scanner(in); int T = IN.nextInt(); for (int t = 1; t <= T; t++) { int N = IN.nextInt(); int S = IN.nextInt(); int p = IN.nextInt(); int[] M = new int[N]; for (int i = 0; i < N; i++) { M[i] = IN.nextInt(); } int minP = p >= 2 ? p * 3 - 4 : p; int pp = p >= 1 ? p * 3 - 2 : p; Arrays.sort(M); int r = 0; // System.out.println(minP + " " + pp + " " + p); for (int i = 0; i < N; i++) { if (M[i] < minP) continue; if (M[i] < pp) { if (S <= 0) { continue; } S--; } r++; } out.println("Case #" + t + ": " + r); } out.flush(); out.close(); in.close(); } }
0
415
A12852
A12389
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 B{ public static void main(String[] args){ try{ String inputFile = "B-small-attempt0.in"; String outputFile = "B-small-attempt0.out"; Scanner sc = new Scanner(new File(inputFile)); FileWriter fwStream = new FileWriter( outputFile ); BufferedWriter bwStream = new BufferedWriter( fwStream ); PrintWriter pwStream = new PrintWriter( bwStream ); int numCase = sc.nextInt(); for(int i = 0; i < numCase; i++){ int numGoogler = sc.nextInt(); int numSurprising = sc.nextInt(); int lowLimit = sc.nextInt(); int[] points = new int[numGoogler]; for(int j = 0; j < numGoogler; j++){ points[j] = sc.nextInt(); } int answer = 0; int surprising = 0; for(int j = 0; j <numGoogler; j++){ if(lowLimit * 3 - 2 <= points[j]) answer++; else if((lowLimit * 3) - 4 <= points[j] && surprising < numSurprising && points[j] != 0){ answer++; surprising++; } } pwStream.print("Case #"+(i+1)+ ": "); pwStream.print(answer); pwStream.println(); } pwStream.close(); sc.close(); } catch(Exception e){e.printStackTrace();} } }
0
416
A12852
A12240
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.*; class ProblemB { public static void main(String[] args) { try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("input.txt"); BufferedWriter out = new BufferedWriter(new FileWriter("output.txt")); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); int[][] judge = new int[3][1]; int googler = 0, surprise = 0, p = 0; int count = 0; String strLine, outputLine; int line = 0; int control = 0; //to get rid of the first line br.readLine(); //Read File Line By Line while ((strLine = br.readLine()) != null) { line++; outputLine = "Case #"+line+": "; //outputLine = ""; String tempString = ""; control = 0; count = 0; for (int i = 0; i < strLine.length(); ++i) { if (strLine.charAt(i) == ' ' || i == strLine.length()-1) { if (i == strLine.length()-1) { tempString += ""+strLine.charAt(i); } switch (control) { case 0 : googler = Integer.parseInt(tempString); judge = new int[3][googler]; break; case 1 : surprise = Integer.parseInt(tempString); break; case 2 : p = Integer.parseInt(tempString); break; default : int score = Integer.parseInt(tempString); judge[0][control-3] = score/3; judge[1][control-3] = score/3; judge[2][control-3] = score/3; if (score%3 == 1) { judge[2][control-3]++; } else if (score%3 == 2) { judge[1][control-3]++; judge[2][control-3]++; } break; } control++; tempString = ""; continue; } tempString += ""+strLine.charAt(i); } System.out.println(googler+" "+surprise+" "+p); for (int i = 0; i < googler; ++i) { System.out.print(judge[0][i]+" "); System.out.print(judge[1][i]+" "); System.out.print(judge[2][i]+" "); System.out.println(); } for (int i = 0; i < googler; ++i) { if (judge[2][i] == p-1 && judge[2][i] == judge[1][i] && judge[0][i] > 0 && judge[1][i] > 0 && surprise > 0) { judge[2][i]++; judge[1][i]--; surprise--; } } for (int i = 0; i < googler; ++i) { if (judge[0][i] >= p || judge[2][i] >= p) { count++; } } outputLine += ""+count; out.write(outputLine); out.newLine(); System.out.println(outputLine); System.out.println(); } //Close the input stream in.close(); out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
417
A12852
A10502
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 dom.zar.jam.qualifications; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) { Scanner in = new Scanner(System.in); int inputLines = in.nextInt(); for (int i = 0; i < inputLines;) { int googlersAmount = in.nextInt(); int suprising = in.nextInt(); int minPoints = in.nextInt(); final int[] googlers = new int[googlersAmount]; for (int k = 0; k < googlersAmount; ++k) { googlers[k] = in.nextInt(); } System.out.println("Case #" + ++i + ": " + result(suprising, minPoints, googlers)); } } private static int result(int suprising, int minPoints, int[] googlers) { final List<Integer> filtered = new ArrayList<Integer>(); for (int points : googlers) { boolean hasMin = (points / 3) >= minPoints; boolean oneLessThanMin = ((points - minPoints) >> 1) == (minPoints - 1); if (!(hasMin || oneLessThanMin)) { filtered.add(points); } } int probable = 0; for (Integer points : filtered) { if (points - minPoints < 0) continue; int restPoints = (points - minPoints) >> 1; if (Math.abs(restPoints - minPoints) <= 2) probable++; } probable = Math.min(probable, suprising); return googlers.length - filtered.size() + probable; } }
0
418
A12852
A10795
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_with_googlers; import java.io.IOException; import java.util.ArrayList; public class FindNumber { public static Integer start (String casus) { String[] splitInput = casus.split(" "); ArrayList<Integer> intinput = new ArrayList<Integer>(); for (String s: splitInput) { intinput.add(Integer.parseInt(s)); System.out.print(s + " "); } System.out.println(); int nr=0; int googlers = intinput.get(0); int surprise = intinput.get(1); int p = intinput.get(2); for(int i=0; i<3; i++) { intinput.remove(0); } for(int i=0; i<googlers; i++) { boolean passtest = false; System.out.println("Working on digit " + intinput.get(i) + " with surprise " + surprise + " and test " + p); if (p==0) { passtest = true; System.out.println("test was set to 0"); } else if (intinput.get(i)>0) { if ((intinput.get(i)/3)>=p) { passtest=true; System.out.println("Integer " + intinput.get(i) + " was devided by three and the result was bigger or equal to " + p); } else if (((intinput.get(i)-p)/2)>=(p-1)){ passtest=true; System.out.println("Integer " + intinput.get(i) + " was deminished by " + p + " and the result was devided by two. The result of this was bigger or equal to " + (p-1)); } else if (((intinput.get(i)-p)/2)>=(p-2)&&surprise>0) { passtest=true; surprise--; System.out.println("Integer " + intinput.get(i) + " was deminished by " + p + " and the result was devided by two. The result of this was bigger or equal to " + (p-2) + " and we still had some surprises left."); } } if (passtest) nr++; System.out.println(" nr is now set to " + nr); } return nr; } }
0
419
A12852
A11110
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.seol.codejam; import java.io.File; import java.util.Map; import java.util.Scanner; import java.util.TreeMap; /** * Solution for http://code.google.com/codejam/contest/1150485/dashboard#s=p1 */ public class DancingWithTheGooglers { public static int solveCase(int[] scores, int surpriseNum, int neededScore) { int len = scores.length; int maxWithNeeded = neededScore*3; int suprCnt = surpriseNum; int res=0; for(int i = 0; i < len; i++) { if(scores[i] < neededScore) { continue; }else if(scores[i] >= maxWithNeeded || maxWithNeeded - scores[i] <= 2) { res++; } else if (maxWithNeeded - scores[i] <= 4 && suprCnt > 0){ suprCnt--; res++; } } return res; } public static void main(String[] args) throws Exception { solveAllCases("D:/worspaces/google_codejam/test_data/dance2"); } public static void solveAllCases(String fileName) throws Exception { Scanner sc = new Scanner(new File(fileName)); int cases = sc.nextInt(); // String tmp = sc.nextLine(); for (int i = 0; i < cases; i++) { int n = sc.nextInt(); int surp = sc.nextInt(); int score = sc.nextInt(); int[] ar = new int[n]; for(int q =0; q < n; q++) { ar[q] = sc.nextInt(); } int res = solveCase(ar, surp, score); System.out.println("Case #" + (i + 1) + ": " + res); // System.out.printf("Case #%1$d: %2$.7f \n" , (i+1), res); } // System.out.println("MAX:" + max); } }
0
420
A12852
A11106
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 code.jam.y2012.quali; import java.io.*; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class ProblemB { private static String PATH = "F:\\dev\\projects\\code-jam-2012\\src\\code\\jam\\y2012\\quali"; File inputFile = new File(PATH, "B-small-attempt0.in"); File outputFile = new File(PATH, "B-small-attempt0.out"); BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); public static void main(String[] args) throws Exception { new ProblemB().solve(); } void solve() throws Exception { in = new BufferedReader(new FileReader(inputFile)); out = new PrintWriter(outputFile); for (int testCase = 1, testCount = nextInt(); testCase <= testCount; testCase++) { solve(testCase); } out.close(); } void solve(int testCase) throws IOException { final int googlers = nextInt(); final int surprises = nextInt(); final int atLeastRate = nextInt(); int googlersPass = 0; int surprisesUsed = 0; for (int i = 0; i < googlers; i++) { final double minSafeAverage = (atLeastRate * 3 - 2) / 3d; final double minSurpriseAverage = (atLeastRate * 3 - 4) / 3d; final int googlerTotal = nextInt(); if (atLeastRate==0 && googlerTotal==0) { googlersPass++; continue; } if (googlerTotal==0) { continue; } final double googlerAverage = googlerTotal / 3d; if (googlerAverage>=minSafeAverage) { //System.out.println("pass: " + googlerTotal + " " + googlerAverage); googlersPass++; continue; } if (googlerAverage>=minSurpriseAverage && surprises>surprisesUsed) { //System.out.println("PASS: " + googlerTotal + " " + googlerAverage); googlersPass++; surprisesUsed++; continue; } } print("Case #" + testCase + ": " + googlersPass); } private void print(String text) { out.println(text); System.out.println(text); } /** * helpers */ String nextToken() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } int nextChar() throws IOException { return in.read(); } 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 nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) { return true; } st = new StringTokenizer(s); } return false; } }
0
421
A12852
A12249
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 asem.core.util; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.math.BigInteger; /** * @author A.Alathwari * * InputReader * */ public class InputReader extends BufferedReader { /** * @param in */ public InputReader(Reader in) { super(in); // TODO Auto-generated constructor stub } /** * @param in * @param sz */ public InputReader(Reader in, int sz) { super(in, sz); // TODO Auto-generated constructor stub } public InputReader(String fileName) throws java.io.FileNotFoundException { // TODO Auto-generated constructor stub this(new FileReader(fileName)); } public String readLine(boolean skipEmptyLines) throws IOException { String str = this.readLine(); if (skipEmptyLines) while (str.length() == 0) str = this.readLine(); return str; } private String readIntegral() throws IOException { int c = this.read(); while (c == ' ' || c == '\n' || c == '\t' || c == '\r') c = this.read(); boolean sign = false; while (c == '-') { c = this.read(); sign = !sign; } StringBuffer buf = new StringBuffer(); while (Character.isDigit(c)) { buf.append((char) c); this.mark(1); c = this.read(); } this.reset(); return (sign) ? "-" + buf.toString() : buf.toString(); } private String readFlat() throws IOException { int c = this.read(); while (c == ' ' || c == '\n' || c == '\t' || c == '\r') c = this.read(); boolean sign = false; while (c == '-') { c = this.read(); sign = !sign; } StringBuffer buf = new StringBuffer(); while (Character.isDigit(c) || c == '.') { buf.append((char) c); this.mark(1); c = this.read(); } this.reset(); return (sign) ? "-" + buf.toString() : buf.toString(); } public int readInt() throws IOException { return Integer.parseInt(readIntegral()); } public long readLong() throws IOException { return Long.parseLong(readIntegral()); } public double readDouble() throws IOException { return Double.parseDouble(readFlat()); } public BigInteger readBigInteger() throws IOException { try { return new BigInteger(readWord()); } catch (NumberFormatException e) { throw new java.util.InputMismatchException(); } } @SuppressWarnings("deprecation") public String readWord() throws IOException { int c = this.read(); while (Character.isSpace((char)c)) c = this.read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = this.read(); } while (!Character.isSpace((char)c) && Character.isDefined(c)); return res.toString(); } @SuppressWarnings("deprecation") public String readString() throws IOException { int c = this.read(); while (Character.isSpace((char) c)) c = this.read(); StringBuffer buf = new StringBuffer(); while (Character.isDefined(c)) { buf.append((char) c); this.mark(1); c = this.read(); } this.reset(); return buf.toString(); } @SuppressWarnings("deprecation") public char readCharacter() throws IOException { char c = (char) this.read(); while (Character.isSpace(c)) c = (char) this.read(); return c; } }
0
422
A12852
A11178
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.*; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.Callable; /** * * @author ken */ public class DancingParser implements Parser { public Map<Integer, Callable<String>> parse(String fileName) throws IOException { Map<Integer, Callable<String>> retval = new HashMap<Integer, Callable<String>>(); BufferedReader reader = new BufferedReader(new FileReader(fileName)); int testCases = Integer.parseInt(reader.readLine()); for (int i = 1; i <= testCases; i++) { String[] tokens = reader.readLine().split("\\s+"); long surprises = Long.parseLong(tokens[1]); long minScore = Long.parseLong(tokens[2]); List<Long> totals = new ArrayList<Long>(); for (int j = 3; j < tokens.length; j++) { totals.add(Long.parseLong(tokens[j])); } retval.put(i, new DancingAlgorithm(i, surprises, minScore, totals)); } return retval; } }
0
423
A12852
A11133
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.*; class Source3 { public static void main(String[] args) throws IOException { String s,word,buffer; FileReader input = new FileReader("B-small.in"); BufferedReader in = new BufferedReader(input); File file = new File("B-small.out"); BufferedWriter out = new BufferedWriter(new FileWriter(file)); s = in.readLine(); int count= Integer.parseInt(s); int i=1; while ((s = in.readLine()) != null && s.length() != 0) { out.write("Case #"+(i++)+": "); Scanner scan =new Scanner(s); int N =Integer.parseInt(scan.next()); int S=Integer.parseInt(scan.next()); int p=Integer.parseInt(scan.next()); int[] t =new int[200]; for(int x=0;x<N;x++) { t[x]= Integer.parseInt(scan.next()); } int ans = perform(N,S,p,t); out.write(ans+"\n"); } out.close(); } public static int perform(int N,int S ,int p ,int[] t) { int count=0; int surprise=0; boolean pass=false; int staticP=p; for(int x=0;x<N;x++) { pass=false; p=staticP; while(p<=10&&!pass) { //System.out.println("SCORE : "+t[x]); int remain = t[x]-p; int[][] possibleNS = {{p,p},{p+1,p+1},{p,p+1},{p,p-1},{p-1,p-1} }; int[][] possibleS = {{p+2,p+2},{p,p+2},{p+1,p+2},{p-2,p-2},{p-2,p-1},{p-2,p} }; //System.out.print("TRI: "+p); if(equalpair(remain,possibleNS)) { count++; pass=true; } else if(equalpair(remain,possibleS)) { if(surprise<S) { count++; surprise++; pass=true; } } p++; } } return count; } public static boolean equalpair(int num,int[][] pair) { boolean check=false; for(int i=0;i<pair.length;i++) { if(num==(pair[i][0]+pair[i][1])) { if(pair[i][0]>=0&&pair[i][0]<=10&&pair[i][1]>=0&&pair[i][1]<=10) { check=true; //System.out.println(" "+pair[i][0]+" "+pair[i][1]); } } } return check; } }
0
424
A12852
A11625
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.surprisingGooglers; public class FileFormatException extends RuntimeException { public FileFormatException() { super(); } public FileFormatException(String message, Throwable cause) { super(message, cause); } public FileFormatException(String message) { super(message); } public FileFormatException(Throwable cause) { super(cause); } }
0
425
A12852
A10356
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 Q2 { public static void main(String[] args) { Scanner s = new Scanner(Q2.class.getResourceAsStream("B-small-attempt1.in")); int n = s.nextInt(); int nt = 1; while (n-- > 0) { int resp = 0; int ng = s.nextInt(); int ex = s.nextInt(); int nm = s.nextInt(); if (nm == 0) { resp = ng; while (ng-- > 0) { int nota = s.nextInt(); } } else if (nm == 1) { while (ng-- > 0) { int nota = s.nextInt(); if (nota >= 1) { resp++; } } } else { while (ng-- > 0) { int nota = s.nextInt(); if (nota >= nm * 3 - 2) { resp++; } else if (nota >= nm * 3 - 4 && ex > 0) { resp++; ex--; } } } System.out.println("Case #" + nt + ": " + resp); nt++; } } }
0
426
A12852
A12437
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; } }
/* * Created on Apr 14, 2012 * */ package com.codejam.y2k12.qualification; import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; /** * @author manveer * */ public class DancingGooglers { public static boolean isSurprising(int[] scores) { int a = scores[0], b = scores[1], c = scores[2]; if (Math.abs(a - b) == 2) return true; if (Math.abs(c - b) == 2) return true; if (Math.abs(a - c) == 2) return true; return false; } public static int[][] getPossibleScores(int total) { // 3 --> (1,1,1), (0,1,2) // 4 --> (1,1,2), (0,2,2) // 5 --> (1,2,2), (1,1,3) int[][] result = new int[2][3]; int first[] = new int[3]; int second[] = new int[3]; result[0] = first; result[1] = second; if(total <= 1) { first[0] = 0; first[1] = 0; first[2] = total; second[0] = 0; second[1] = 0; second[2] = total; return result; } int base = total / 3; if (total % 3 == 0) { first[0] = base; first[1] = base; first[2] = base; second[0] = base - 1; second[1] = base; second[2] = base + 1; } else if (total % 3 == 1) { first[0] = base; first[1] = base; first[2] = base + 1; second[0] = base - 1; second[1] = base + 1; second[2] = base + 1; } else { first[0] = base; first[1] = base + 1; first[2] = base + 1; second[0] = base; second[1] = base; second[2] = base + 2; } //System.out.println("Score : " + total + " " + Arrays.toString(result[0]) + " " + Arrays.toString(result[1])); return result; } public static boolean isAcceptableResult(int[] result, int p) { for (int i = 0; i < result.length; i++) { if (result[i] >= p) return true; } return false; } public static int findMaxGooglers(int[] scores, int s, int p, int current) { if(current >= scores.length) return 0; //System.out.println("Current: " + current); int currScore = scores[current]; int[][] results = getPossibleScores(currScore); boolean isFirstAcceptable = isAcceptableResult(results[0], p); boolean isFirstSurprising = isSurprising(results[0]); boolean isSecondAcceptable = isAcceptableResult(results[1], p); boolean isSecondSurprising = isSurprising(results[1]); boolean canTakeFirst = true; boolean canTakeSecond = true; if (s <= 0 && isFirstSurprising) { canTakeFirst = false; } if (s <= 0 && isSecondSurprising) { canTakeSecond = false; } int firstPath = 0, secondPath = 0; if (canTakeFirst) { firstPath = (isFirstAcceptable ? 1 : 0); //if(firstPath == 1) // System.out.println(Arrays.toString(results[0])) ; int sFirst = (isFirstSurprising ? s - 1 : s); firstPath += (findMaxGooglers(scores, sFirst, p, current + 1)); } if (canTakeSecond) { secondPath = (isSecondAcceptable ? 1 : 0); //if(secondPath == 1) // System.out.println(Arrays.toString(results[1])); int sSecond = (isSecondSurprising ? s - 1 : s); secondPath += (findMaxGooglers(scores, sSecond, p, current + 1)); } return Math.max(firstPath, secondPath); } public static void main(String args[]) throws FileNotFoundException { Scanner scan = new Scanner(new File(args[0])); int T = Integer.parseInt(scan.nextLine()); for (int i = 1; i <= T; i++) { int N = scan.nextInt(); int S = scan.nextInt(); int p = scan.nextInt(); int scores[] = new int[N]; for (int j = 0; j < N; j++) { scores[j] = scan.nextInt(); } //System.out.println(Arrays.toString(scores) + " " + p); scan.nextLine(); int result = findMaxGooglers(scores, S, p, 0); System.out.println("Case #" + i + ": " + result); } } }
0
427
A12852
A12702
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.StringTokenizer; public class q2 { public static int spl,threshold,players,output; public static void main(String []args) throws IOException { PrintWriter pw=new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); BufferedReader br=new BufferedReader(new FileReader("input.txt")); int arr[]=new int[107]; int limit=Integer.parseInt(br.readLine()); String x1; String word=""; for(int li=1;li<=limit;li++) { x1=br.readLine(); int j=0; StringTokenizer st =new StringTokenizer(x1); while (st.hasMoreElements()) { String token = st.nextElement().toString(); arr[j]=Integer.parseInt(token); j++; } spl=arr[1]; threshold=arr[2]; players=arr[0]; output=find(arr); pw.println("Case #"+li+": "+output); arr=new int[107]; } pw.close(); } public static int find(int arr[]) { int a=0,b=0,c=0; int op=0; for(int i=3;i<(players+3);i++) { int num=arr[i]; int num2=num; boolean check=true; a=num/3; b=a; c=a; int diff=num2-(a*3); if(diff==0) { if(a>=threshold||b>=threshold||c>=threshold) op++; else { if(spl>0) { if((a-1)>0) { if((a-1)>=threshold||b>=threshold||(c+1)>=threshold) { op++; spl--; } } } } } if(diff==1) { if((a+1)>=threshold||b>=threshold||c>=threshold) { op++; } else { if(spl>0) { if((a+1)>=threshold||(b-1)>=threshold||(c+1)>=threshold) { op++; spl--; } } } } if(diff==2) { if((a+1)>=threshold||(b+1)>=threshold||c>=threshold){ op++; } else { if(spl>0) { if((a+2)>=threshold||b>=threshold||c>=threshold) { op++; spl--; } } } } } return op; } }
0
428
A12852
A12155
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.lang.*; public class problemB { public static void main(String args[])throws Exception { Scanner cin=new Scanner(System.in); int numcases = cin.nextInt(); int N,S,P,T; double avg,s; int v; for(int i=0;i<numcases;i++){ v = 0; N = cin.nextInt(); S = cin.nextInt(); P = cin.nextInt(); for(int n=0;n<N;n++){ T = cin.nextInt(); avg = ((double)(T + 2.0)/3.0); if(avg >= P){ v++; }else if(S > 0 && T >= P){ avg = ((double)(T + 4.0)/3.0); if(avg >= P){ S--; v++; } } } System.out.println("Case #"+ (i+1) + ": " + v); } } }
0
429
A12852
A10537
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 compete; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; public class Dance { private static void print(String sth) { System.out.println(sth); } private static int best(int S, int P, int [] totals) { int ret=0; if (P==0) return totals.length; for (int i = 0;i<totals.length;i++) { int t = totals[i]; if (t>=P*3-2) { ret++; continue; } else if (P*3>3 && t>=P*3-4 && S>0) { S--; ret++; } } return ret; } public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new FileReader("input.txt")); int num = Integer.parseInt(in.readLine()); for (int i=0;i<num;i++) { String sentence = in.readLine(); Scanner s = new Scanner(sentence); int N = s.nextInt(); int S = s.nextInt(); int P = s.nextInt(); int totals[] = new int[N]; for (int j=0;j<N;j++) { totals[j] = s.nextInt(); } print("Case #"+(1+i)+": "+best(S,P,totals)); } } }
0
430
A12852
A13193
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 classes; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.InputStreamReader; public class Dancing { public static void main(String[] args) { try { FileInputStream fstream = new FileInputStream("/Users/jleibsly2002/B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine(); int N = Integer.parseInt(strLine); for(int i = 0; i < N; i++) { String[] integers = br.readLine().split(" "); int num = Integer.parseInt(integers[0]); int S = Integer.parseInt(integers[1]); int p = Integer.parseInt(integers[2]); int[] scores = new int[num]; for(int j = 3; j < num+3; j++) { scores[j-3] = Integer.parseInt(integers[j]); } int count = 0; for(int score : scores) { if(score==0) { if(p==0) { count++; } } else { int rem = score%3; if(rem>0) { if(rem == 1) { int noSurprise = (score/3)+1; if(noSurprise>=10) noSurprise=10; if(noSurprise>=p) { count++; } } else if(rem == 2) { int noSurprise = (score/3)+1; if(noSurprise>=10) noSurprise=10; if(noSurprise>=p) { count++; } else if(S>0) { int surprise = noSurprise+1; if(surprise>=p) { count++; S--; } } } } else { int noSurprise = score/3; if(noSurprise>=10) noSurprise=10; if(noSurprise>=p) { count++; } else if(S>0) { int surprise = noSurprise+1; if(surprise>=p) { count++; S--; } } } } } System.out.println("Case #" + (i+1) + ": " + count); } in.close(); } catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } }
0
431
A12852
A12371
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.List; import java.util.Scanner; public class ProblemB { public static void main(String[] args) throws IOException { BufferedReader consoleIn = new BufferedReader(new InputStreamReader(System.in)); String line = consoleIn.readLine(); int T = Integer.valueOf(line); for(int i = 0; i < T; i++){ line = consoleIn.readLine(); Scanner sc = new Scanner(line); int N = sc.nextInt(); int S = sc.nextInt(); int P = sc.nextInt(); int[] scores = new int[N]; for(int j = 0; j < N; j++){ scores[j] = sc.nextInt(); } int[] supMax = new int[N]; int[] norMax = new int[N]; for(int j = 0; j < N; j++){ int score = scores[j]; int res = score % 3; supMax[j] = (score - res) / 3 + 1; if(res == 2){ supMax[j]++; } norMax[j] = (score - res) / 3 + 1; if(res == 0){ norMax[j]--; } if(score == 0 || score == 1 || score == 30 || score == 29 || score == 28){ supMax[j] = norMax[j]; } } int needSup = 0; int nor = 0; for(int j = 0; j < N; j++){ if(norMax[j] >= P){ nor++; } else if(supMax[j] >= P){ needSup++; } } int result; if(needSup <= S){ result = nor + needSup; } else { result = nor + S; } StringBuilder sb = new StringBuilder(); System.out.printf("Case #%d: %d", i+1, result); System.out.println(sb.toString()); } } }
0
432
A12852
A11837
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 bc=new Scanner(System.in); int testCases=bc.nextInt(); for(int i=0;i<testCases;i++) { int count1=0; int best=0; int n=bc.nextInt(); int a1[]=new int[n]; int surprise=bc.nextInt(); int limit=bc.nextInt(); for(int j=0;j<n;j++) { a1[j]=bc.nextInt(); } for(int q=0;q<n;q++) { /*System.out.println("The value of array is "+a1[q]); */ } int array1[][]=new int[n][3]; for(int j=0;j<n;j++) { array1[j][0]=a1[j]/3; int t=a1[j]-array1[j][0]; int data1=t/2; int data2=t-data1; if(a1[j]!=0) { if(data1-data2==0) { if(limit-data1==1) { if(count1<surprise) { count1++; best++; array1[j][1]=data1--; array1[j][2]=data2++; } else { array1[j][1]=data1; array1[j][2]=data2; } } else if (limit-data1==0) { array1[j][1]=data1; array1[j][2]=data2; best++; } else if(limit-data1>1) { array1[j][1]=data1; array1[j][2]=data2; } else if(limit-data1<0) { array1[j][1]=data1; array1[j][2]=data2; best++; } } else if((data2-data1)==1) { if(limit<=data2) { array1[j][1]=data1; array1[j][2]=data2; best++; } else { array1[j][1]=data1; array1[j][2]=data2; } } } else{ if(limit==0) { best++; } } } System.out.println("Case #"+(i+1)+": " +best); } } }
0
433
A12852
A12339
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.codejam2012.awanish; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; import java.util.StringTokenizer; public class GooglersDance { private static int count = 0; /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner inputScan = new Scanner(System.in); int noOfCases = Integer.parseInt(inputScan.nextLine()); String cases; int noOfGooglers; int noOfSurprisingTrip; int topScore; for (int i = 1; i <= noOfCases; i++) { cases = inputScan.nextLine(); count = 0; ArrayList totalScores = new ArrayList(); StringTokenizer st = new StringTokenizer(cases, " "); noOfGooglers = Integer.parseInt(st.nextToken()); noOfSurprisingTrip = Integer.parseInt(st.nextToken()); topScore = Integer.parseInt(st.nextToken()); while (st.hasMoreTokens()) { totalScores.add(st.nextToken()); } int total; int triplet; int remainder; ArrayList<Number> triplets; ArrayList<ArrayList<Number>> dancers = new ArrayList<ArrayList<Number>>(); int c = 0; for (Object t : totalScores) { triplets = new ArrayList<Number>(); total = Integer.parseInt(t.toString()); triplet = total / 3; remainder = total % 3; triplets.add(triplet); if (remainder == 2) { triplets.add(triplet + 1); triplets.add(total - (triplet * 2 + 1)); } else { triplets.add(triplet); triplets.add(total - triplet * 2); } dancers.add(triplets); } // System.out.println(dancers); analyzeSurprises(dancers, noOfSurprisingTrip, topScore); System.out.println("Case #" + i + ": " + count); } } private static void analyzeSurprises(ArrayList<ArrayList<Number>> dancers, int noOfSurprisingTrip, int topScore) { // TODO Auto-generated method stub for (ArrayList<Number> list : dancers) { if (max(list) >= topScore) { count++; } else if (noOfSurprisingTrip > 0 && checkForSurprise(list,topScore)) { noOfSurprisingTrip--; count++; } } } private static boolean checkForSurprise(ArrayList<Number> list, int topScore) { // TODO Auto-generated method stub int topScoreCount = 0; for (Number n : list) { if (n.intValue()==topScore-1){ topScoreCount++; } } if (topScoreCount>=2 && topScore!=1) { return true; } return false; } private static int max(ArrayList<Number> list) { // TODO Auto-generated method stub int max = 0; for (Number n : list) { if (n.intValue() > max) { max = n.intValue(); } } return max; } }
0
434
A12852
A12709
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 codejam02; import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; import java.util.StringTokenizer; public class CodeJam02 { public static void main(String[] args) { try { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T,N,S,p,score; String input,output; int maxGooglers,temp ; T = Integer.parseInt(br.readLine()); for (int i=0;i<T;i++) { maxGooglers = 0; temp = 0; input = br.readLine(); StringTokenizer st = new StringTokenizer(input); N = Integer.parseInt(st.nextToken()); S = Integer.parseInt(st.nextToken()); p = Integer.parseInt(st.nextToken()); for (int j=0; j<N; j++) { score = Integer.parseInt(st.nextToken()); if(p<2) { if(score >= p) maxGooglers++; } else { if(score==(3*p-4)||score==(3*p-3)) { temp++; } else if(score>(3*p-3)) { maxGooglers++; } } } if(temp<S) maxGooglers+=temp; else maxGooglers+=S; System.out.println("Case #" +(i+1) + ": " + maxGooglers); } } catch (IOException ex) { Logger.getLogger(CodeJam02.class.getName()).log(Level.SEVERE, null, ex); } } }
0
435
A12852
A12615
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.kiwien.google; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; 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.List; public class DancingWithTheGooglers { public static void main(String[] args) { final FileInputStream fstream; String lineStr; final StringBuilder sb = new StringBuilder(); try { fstream = new FileInputStream("./testdata/test.in"); final DataInputStream in = new DataInputStream(fstream); final BufferedReader br = new BufferedReader(new InputStreamReader(in)); final int testNum = Integer.parseInt(br.readLine()); if (testNum <= 0 || testNum > 100) { return; } for (int i = 0; i < testNum; i++) { lineStr = br.readLine(); sb.append("Case #" + (i + 1) + ": " + process(lineStr) + "\n"); } writeToFile(sb.toString()); System.out.println(sb.toString()); System.out.println("Finished."); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (NumberFormatException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private static void writeToFile(String str) { BufferedWriter writer = null; try { File out = new File("./results/dancing.out"); writer = new BufferedWriter(new FileWriter(out)); writer.write(str); System.out.println("Test result saved to " + out.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } finally { try { if (writer != null) writer.close(); } catch (IOException e) { } } } private static String process(String inputStr) { String[] input = inputStr.split(" "); if (input.length >= 3) { int n = Integer.parseInt(input[0]); if (n < 0 || n > 100) { return ""; } int s = Integer.parseInt(input[1]); if (s < 0 || s > n) { return ""; } int p = Integer.parseInt(input[2]); if (p < 0 || p > 10) { return ""; } List<Integer> totalPoints = new ArrayList<Integer>(); for (int i = 3; i < input.length; i++) { int totalPoint = Integer.parseInt(input[i]); if (totalPoint < 0 || totalPoint > 30) { return ""; } totalPoints.add(totalPoint); } return "" + getMaximumNum(n, s, p, totalPoints.toArray(new Integer[0])); } return "invalid"; } /** * * @param n googler number * @param s surprising number * @param p maximum result * @param totalPoints * @return */ public static int getMaximumNum(Integer n, Integer s, Integer p, Integer[] totalPoints) { int count = 0; for (int t : totalPoints) { int nonSurprisingMax = 3 * p - 2; int surprisingMax = 3 * p - 4; if (t >= nonSurprisingMax) { count++; } else if (s > 0 && t >= 2 && t <= 28) { if (t >= surprisingMax) { count++; s--; } } } return count; } }
0
436
A12852
A12802
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; public class DancingGooglers { public int googlers( int surprise, int mincount, int[] scores ) { int counter = 0; for( int i = 0; i < scores.length; i++ ) { int s = scores[i] % 3; int base = scores[i] / 3; if( s == 0 ) { if( base >= mincount ) { counter++; } else { if( surprise > 0 && base > 0 && base + 1 >= mincount ) { counter++; surprise--; } } } else if( s == 1 ) { if(base >= mincount || base +1 >= mincount) { counter++; } else { if(surprise > 0 && base +1 >= mincount) { counter++; surprise--; } } } else if( s == 2 ) { if(base >= mincount || base +1 >= mincount) { counter++; } else { if(surprise > 0 && base +2 >= mincount) { counter++; surprise--; } } } } return counter; } public static void main( String[] args ) { DancingGooglers dg = new DancingGooglers(); try { FileWriter fw = new FileWriter( "output.out" ); BufferedWriter out = new BufferedWriter( fw ); FileReader fr = new FileReader( "in.in" ); BufferedReader br = new BufferedReader( fr ); String size = br.readLine(); String temp = ""; int k = 0; while( ( temp = br.readLine() ) != null ) { String[] split = temp.trim().split( " " ); int googlercount = Integer.parseInt( split[0] ); int surprise = Integer.parseInt( split[1] ); int mincount = Integer.parseInt( split[2] ); int[] scores = new int[googlercount]; for(int i = 0;i<googlercount;i++) { scores[i] = Integer.parseInt( split[i + 3] ); } out.write( "Case #" + ( ++k ) + ": " + dg.googlers( surprise, mincount, scores ) + "\n" ); } fr.close(); out.close(); } catch( FileNotFoundException e ) { e.printStackTrace(); } catch( IOException e ) { e.printStackTrace(); } } }
0
437
A12852
A12900
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; public class App { /** * @param args */ public static void main(String[] args) { Reader reader = new Reader(); ArrayList<String> input = reader.LinesReader(); ArrayList<String> output = new ArrayList(); for (String i : input) { output.add(handleCase(i)); } reader.output(output); } private static String handleCase(String s) { String output = ""; String[] split = s.split(" "); ArrayList<Integer> listInt = new ArrayList<Integer>(); for (String string : split) { listInt.add(Integer.valueOf(string)); } int nbGooglers = listInt.get(0); int nbSurprising = listInt.get(1); int bestResultNeeded = listInt.get(2); int nbAchieved = 0; for (int i = 0; i < nbGooglers; i++) { double score = listInt.get(3 + i); if (Math.ceil(score / 3) >= bestResultNeeded) { nbAchieved++; } else if (nbSurprising > 0) { // prevention cas negatif double maxAdded = 4; if (score < maxAdded) maxAdded = score; if (((score + maxAdded) / 3) >= bestResultNeeded) { nbAchieved++; nbSurprising--; } } } return "" + nbAchieved; } }
0
438
A12852
A11118
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.googlecode.codejam.model; import java.util.Arrays; import java.util.concurrent.Callable; public abstract class JamCaseResolver implements Callable<String> { private final int caseNumber; public JamCaseResolver(int caseNumber) { this.caseNumber = caseNumber; } @Override public final String call() throws Exception { return this.resolve(); } protected abstract String resolve(); protected long[] parse(final String[] numbers) { final long[] parsed = new long[numbers.length]; for (int i = 0; i < numbers.length; i++) parsed[i] = this.parse(numbers[i]); return parsed; } protected long parse(final String number) { return Long.parseLong(number); } protected int[] parseInt(final String[] numbers) { final int[] parsed = new int[numbers.length]; for (int i = 0; i < numbers.length; i++) parsed[i] = this.parseInt(numbers[i]); return parsed; } protected int parseInt(final String number) { return Integer.parseInt(number); } protected long sum(final Iterable<Long> elements) { long sum = 0; for (final long element : elements) sum += element; return sum; } protected long sum(final Long[] elements) { return this.sum(Arrays.asList(elements)); } protected String toMatrixString(final String matrixString) { return matrixString.replaceAll("\\},\\{", "\n").replaceAll("(^\\{\\{|\\}\\}$)|,", ""); } public int getCaseNumber() { return caseNumber; } @Override public String toString() { return "JamCaseResolver [caseNumber=" + caseNumber + "]"; } }
0
439
A12852
A12178
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 hk.polyu.cslhu.codejam.thread; import hk.polyu.cslhu.codejam.lib.ResultCollector; import hk.polyu.cslhu.codejam.solution.Solution; import java.util.List; import org.apache.log4j.Logger; public abstract class JamThread implements Runnable { public static Logger logger = Logger.getLogger(JamThread.class); private ResultCollector resultCollector; private int indexOfList; private List<List<String>> testCaseList; private Solution solution; /** * Return the solution * * @return Solution */ public Solution getSolution() { return solution; } /** * Set the solution used for test cases * * @param solution Solution */ public void setSolution(Solution solution) { this.solution = solution; } /** * Return the result collector * * @return ResultCollector */ public ResultCollector getResultCollector() { return resultCollector; } /** * Set the result collector * * @param resultCollector ResultCollector */ public void setResultCollector(ResultCollector resultCollector) { this.resultCollector = resultCollector; } /** * Return the index of list * * @return int The index of list */ public int getIndexOfList() { return indexOfList; } /** * Set the index of list * * @param indexOfList int The index of list */ public void setIndexOfList(int indexOfList) { this.indexOfList = indexOfList; } /** * Set the list of test cases * * @param testCaseList List<LIst<String>> */ public void setTestCaseList(List<List<String>> testCaseList) { this.testCaseList = testCaseList; logger.debug("Total " + testCaseList.size() + " test cases have been added"); } /** * Get the list of test cases * * @return List<List<String>> The list of test cases */ public List<List<String>> getTestCaseList() { return this.testCaseList; } public abstract void run(); }
0
440
A12852
A10164
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 qualification.dancing; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; public class App { public static final String INPUT_FILE_NAME = "C:\\Users\\Fred\\Desktop\\input.txt"; private int T; private int numberOfGooglers; private int numberOfSurprises; private int floor; public App() { execute(); } public void execute() { ArrayList<String> linhas = scanning(INPUT_FILE_NAME); ArrayList<OneCase> allCases = new ArrayList<OneCase>(); for (int i = 0; i < T; i++) { int[] placar = extractParameters(linhas.get(i)); allCases.add(new OneCase(getNumberOfGooglers(), getNumberOfSurprises(), getFloor(), placar)); } for (int i = 0; i < T; i++) { OneCase oneCase = allCases.get(i); int resp = oneCase.counting(oneCase.devolveMaxTodos(oneCase.getPlacar())); int j = i + 1; System.out.println("Case #" + j + ": " + resp); } } public static void main(String[] args) { new App(); } public int[] extractParameters(String linha) { String[] pedacos = linha.split(" "); setNumberOfGooglers(Integer.parseInt(pedacos[0])); setNumberOfSurprises(Integer.parseInt(pedacos[1])); setFloor(Integer.parseInt(pedacos[2])); int[] placar = new int[getNumberOfGooglers()]; for (int k = 0; k < getNumberOfGooglers(); k++) { placar[k] = Integer.parseInt(pedacos[k + 3]); } return placar; } public ArrayList<String> scanning(String fileName) { ArrayList<String> linhas = new ArrayList<String>(); File dominioArq = new File(fileName); try { FileReader dominioFileReader = new FileReader(dominioArq); BufferedReader reader = new BufferedReader(dominioFileReader); String linha = ""; int count = 0; while ((linha = reader.readLine()) != null) { if (count == 0 && fileName.equals(INPUT_FILE_NAME)) setT(Integer.parseInt(linha)); else linhas.add(new String(linha)); count++; } reader.close(); dominioFileReader.close(); } catch (IOException e) { e.printStackTrace(); } return linhas; } public void setT(int numberOfCases) { this.T = numberOfCases; } public int getNumberOfGooglers() { return numberOfGooglers; } public void setNumberOfGooglers(int numberOfGooglers) { this.numberOfGooglers = numberOfGooglers; } public int getNumberOfSurprises() { return numberOfSurprises; } public void setNumberOfSurprises(int numberOfSurprises) { this.numberOfSurprises = numberOfSurprises; } public int getFloor() { return floor; } public void setFloor(int floor) { this.floor = floor; } public int getT() { return T; } public class OneCase { int numberOfGooglers; int numberOfSurprises; int floor; int[] placar; OneCase(int N, int S, int p, int[] t) { this.numberOfGooglers = N; this.numberOfSurprises = S; this.floor = p; this.placar = t; //testeSanidade(); } public void testeSanidade() { if (placar.length != numberOfGooglers) System.out.println("ERRO: entrada de dados."); else System.out.println("entrada de dados esta ok."); } public int[] devolveMax(int placarIndividual) { int[] max = new int[2]; switch(placarIndividual % 3) { case 0 : { max[0] = (placarIndividual / 3); max[1] = (placarIndividual / 3) + 1; break; } case 1 : { max[0] = (placarIndividual - 1) / 3 + 1; max[1] = (placarIndividual - 4) / 3 + 2; break; } case 2 : { max[0] = (placarIndividual - 2) / 3 + 1; max[1] = (placarIndividual - 2) / 3 + 2; break; } default : break; } return max; } public HashMap<Integer,int[]> devolveMaxTodos(int[] placar) { HashMap<Integer,int[]> mappingMax = new HashMap<Integer,int[]>(); for (int i = 0; i < placar.length; i++) { int[] max; switch(placar[i]) { case 0 : { max = new int[]{0,0}; break; } case 1 : { max = new int[]{1,1}; break; } case 29 : { max = new int[]{10,10}; break; } case 30 : { max = new int[]{10,10}; break; } default : { max = devolveMax(placar[i]); break; } } mappingMax.put(new Integer(i), max); } return mappingMax; } public void printMaxForEachGoogler(HashMap<Integer,int[]> mapping) { for (int i = 0; i < numberOfGooglers; i++) { System.out.println("googler #" + i + ": {" + mapping.get(i)[0] + ", " + mapping.get(i)[1] + "}"); } } public int counting(HashMap<Integer,int[]> mapping) { int count = 0; int count1 = 0; int count2 = 0; for (int i = 0; i < numberOfGooglers; i++) { int[] individualMaximos = mapping.get(new Integer(i)); if (isPossibleGetBetter(individualMaximos, floor)) count2++; else{ if (isSufficient(individualMaximos, floor)) count1++; } } count = count1 + Math.min(count2, numberOfSurprises); return count; } public boolean isPossibleGetBetter(int[] maximos, int parametro) { boolean isPossible = false; if ( (parametro == Math.max(maximos[0], maximos[1])) && (maximos[0] != maximos[1])) isPossible = true; return isPossible; } public boolean isSufficient(int[] maximos, int parametro) { boolean sufficient = false; if (parametro <= Math.min(maximos[0], maximos[1])) sufficient = true; return sufficient; } public int[] getPlacar() { return placar; } } }
0
441
A12852
A12035
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 jp.funnything.competition.util; public class Prof { private long _start; public Prof() { reset(); } private long calcAndReset() { final long ret = System.currentTimeMillis() - _start; reset(); return ret; } private void reset() { _start = System.currentTimeMillis(); } @Override public String toString() { return String.format( "Prof: %f (s)" , calcAndReset() / 1000.0 ); } public String toString( final String head ) { return String.format( "%s: %f (s)" , head , calcAndReset() / 1000.0 ); } }
0
442
A12852
A11655
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 uk.co.epii.codejam.dancingwiththegooglers; /** * * @author jim */ public class DataRow { public final int N; public final int S; public final int p; public final int[] t; public DataRow(String in) { String[] parts = in.split(" "); N = Integer.parseInt(parts[0]); S = Integer.parseInt(parts[1]); p = Integer.parseInt(parts[2]); t = new int[N]; for (int i = 3; i < N + 3; i++) t[i - 3] = Integer.parseInt(parts[i]); } }
0
443
A12852
A10419
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 qualification.taskC; import Parser.MyReader; import Parser.MyWriter; public class Main { private final static int n = 20000001; public static void main(String[] args) { MyReader myReader = new MyReader( "/Users/shami13/Downloads/C-small-attempt0.in"); MyWriter myWriter = new MyWriter( "/Users/shami13/Downloads/C-small-attempt0.out"); boolean[][] table = new boolean[n][n]; for (int i = 1; i < n; i++) { for (int p = 1; p < n; p++) { table[i][p] = isRecycled(i, p); } } int taskLength = Integer.parseInt(myReader.read()); for (int i = 1; i <= taskLength; i++) { String[] taskString = myReader.read().split(" "); Task task = new Task(Integer.parseInt(taskString[0]), Integer.parseInt(taskString[1]), table); String result = task.execute(); myWriter.writeString("Case #" + i + ": " + result); System.out.println("Case #" + i + ": " + result); } myWriter.close(); } public static boolean isRecycled(int a, int b) { if (a != b) { String bString = "" + b; for (int i = 0; i < bString.length(); i++) { int temp = b % 10; b /= 10; for(int p = 1; p < bString.length(); p ++){ temp *= 10; } b += temp; if (a == b) { return true; } } } return false; } }
0
444
A12852
A12267
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.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(new FileReader("input.txt")); PrintWriter pw = new PrintWriter(new FileWriter("output.txt")); int tn = sc.nextInt(); sc.nextLine(); for(int i = 0; i < tn; i++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int cnt = 0; int cnts = 0; for(int j = 0; j < n; j++) { int oppa = sc.nextInt(); if(oppa >= Math.max(p - 1, 0) * 2 + p) cnt++; else if(oppa >= Math.max(p - 2, 0) * 2 + p) cnts++; } pw.print("Case #" + (i + 1) + ": " + (cnt + Math.min(s, cnts))); pw.println(); } pw.close(); } }
0
445
A12852
A12260
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; public class B { public static int convert(String input) { int output = 0; String[] pairs = input.split(" "); // int N = Integer.parseInt(pairs[0]); int S = Integer.parseInt(pairs[1]); int P = Integer.parseInt(pairs[2]); int[] numbers = new int[pairs.length - 3]; for (int i = 3; i < pairs.length; i++) { numbers[i - 3] = Integer.parseInt(pairs[i]); } boolean[] done = new boolean[numbers.length]; boolean[] five = new boolean[numbers.length]; boolean[] sur = new boolean[numbers.length]; for (int i = 0; i < numbers.length; i++) { int num = numbers[i]; for (int j = P; j <= num; j++) { if ((3 * j) == num || ((j + (j - 1) + (j - 1)) == num && ((j-1)>=0)) || ((j + j + (j - 1)) == num && ((j-1)>=0)) || (j + (j + 1) + (j + 1)) == num || (j + j + (j + 1)) == num ) { // System.out.println("1 : "+num); done[i] = true; five[i] = true; sur[i] = false; break; } } } int surprised = 0; for (int i = 0; i < numbers.length && surprised < S; i++) { if (!done[i]) { int num = numbers[i]; for (int j = P; j <= num; j++) { if ( (((j - 2) + (j - 1) + (j)) == num&& ((j-1)>=0)&& ((j-2)>=0)) || (((j - 2) + (j) + (j)) == num && ((j-2)>=0)) || (((j - 2) + (j - 2) + (j)) == num && ((j-2)>=0)) || ((j + 2) + (j + 1) + (j)) == num || ((j + 2) + (j) + (j)) == num || ((j + 2) + (j + 2) + (j)) == num ) { // System.out.println("2 : "+num); done[i] = true; five[i] = true; sur[i] = true; surprised ++; break; } } } } if(surprised < S){ for (int i = 0; i < numbers.length && surprised < S; i++) { if (!done[i]) { int num = numbers[i]; for (int j = 0; j <= num; j++) { if ( (((j - 2) + (j - 1) + (j)) == num&& ((j-1)>=0)&& ((j-2)>=0)&& ((j-1)!=P)&& ((j-2)!=P)&& ((j)!=P)) || (((j - 2) + (j) + (j)) == num && ((j-2)>=0)&& ((j-2)!=P)&& ((j)!=P)) || (((j - 2) + (j - 2) + (j)) == num && ((j-2)>=0)&&((j-2)!=P)&& ((j)!=P)) ) { // System.out.println("3 : "+num); done[i] = true; five[i] = false; sur[i] = true; surprised ++; break; } } } } } if(surprised < S){ for (int i = 0; i < numbers.length && surprised < S; i++) { if (!sur[i]&&five[i]) { int num = numbers[i]; for (int j = P; j <= num; j++) { if ( (((j - 2) + (j - 1) + (j)) == num&& ((j-1)>=0)&& ((j-2)>=0)) || (((j - 2) + (j) + (j)) == num && ((j-2)>=0)) || (((j - 2) + (j - 2) + (j)) == num && ((j-2)>=0)) || ((j + 2) + (j + 1) + (j)) == num || ((j + 2) + (j) + (j)) == num || ((j + 2) + (j + 2) + (j)) == num ) { // System.out.println("4 : "+num); done[i] = true; five[i] = true; sur[i] = true; surprised ++; break; } } } } } if(surprised < S){ for (int i = 0; i < numbers.length && surprised < S; i++) { if (!sur[i]&&five[i]) { int num = numbers[i]; for (int j = 0; j <= num; j++) { if ( (((j - 2) + (j - 1) + (j)) == num&& ((j-1)>=0)&& ((j-2)>=0)&& ((j-1)!=P)&& ((j-2)!=P)&& ((j)!=P)) || (((j - 2) + (j) + (j)) == num && ((j-2)>=0)&& ((j-2)!=P)&& ((j)!=P)) || (((j - 2) + (j - 2) + (j)) == num && ((j-2)>=0)&&((j-2)!=P)&& ((j)!=P)) ) { // System.out.println("5 : "+num); done[i] = true; five[i] = false; sur[i] = true; surprised ++; break; } } } } } // if(surprised < S) // System.out.println("lesaa"); // System.out.println(surprised + "----"+S); for (int i = 0; i < sur.length; i++) { if(five[i]) output++; } return output; } public static void main(String[] args) { String inputFile = "B-small-attempt4.in"; String outPutFile = "B-small4.out"; try { FileInputStream fstream = new FileInputStream(inputFile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fstream2 = new FileWriter(outPutFile); BufferedWriter out = new BufferedWriter(fstream2); String strLine; strLine = br.readLine(); int casesNum = Integer.parseInt(strLine); for (int i = 0; i < casesNum; i++) { strLine = br.readLine(); String parse = "Case #" + (i + 1) + ": " + convert(strLine); System.out.println(parse); if (i < casesNum - 1) parse += "\n"; out.write(parse); } in.close(); out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
446
A12852
A10233
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.HashMap; public class Dancing { public int specials = 0; public int p = 0; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader stdin = new BufferedReader (new InputStreamReader(System.in)); int n = Integer.parseInt(stdin.readLine()); int j = 0; while(j<n) { String read = stdin.readLine(); String arr[] = read.split("\\s"); int qty = Integer.parseInt(arr[0]); int s = Integer.parseInt(arr[1]); int p = Integer.parseInt(arr[2]); Dancing dancing = new Dancing(); dancing.specials = s; dancing.p = p; int total = 0; for(int i = 3; i<qty+3; i++ ) { total += processGoogler(Integer.parseInt(arr[i]) , dancing); } StringBuffer sb = new StringBuffer(); sb.append("Case #"+(j+1)+": "); sb.append(Integer.toString(total)); j++; System.out.println(sb.toString()); } } private static int processGoogler(int t, Dancing dancing ) { if( t == 0 && dancing.p == 0) return 1; int k = 0; if( t != 0) { if((t-1) % 3 == 0) { k = (t-1)/3; if(k+1>=dancing.p) return 1; return 0; } if(t % 3 == 0) { k = t/3; if(k>= dancing.p) return 1; if(dancing.specials>0) { if(k+1>=dancing.p) { dancing.specials--; return 1; } } } if( (t-2) % 3 == 0) { k =(t-2)/3; if(k+1>= dancing.p) { return 1; } if(dancing.specials>0) { if(k+2>=dancing.p) { dancing.specials--; return 1; } } } } return 0; } }
0
447
A12852
A12503
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; public class DancingWithTheGooglers { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int testCaseNumber; String input; BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); input = in.readLine(); testCaseNumber = Integer.parseInt(input.trim()); int[] totalScoreArray = new int[testCaseNumber]; for(int i=0; i<testCaseNumber; i++){ input = in.readLine(); String[] dataArrayString = input.split(" "); int[] dataArray = new int[dataArrayString.length]; for(int z=0;z<dataArrayString.length; z++){ dataArray[z] = Integer.parseInt(dataArrayString[z]); } int googlerNum = dataArray[0]; int surprisingNum = dataArray[1]; int minPeakScore = dataArray[2]; int score = 0; int minNos; int minS; if(minPeakScore<=1){ minNos = minPeakScore; minS = minPeakScore; } else{ minNos = (minPeakScore*3)-2; minS = (minPeakScore*3)-4; } for(int j=3; j<googlerNum+3; j++){ if(dataArray[j]>=minNos){ score++; } else if(surprisingNum>0 && dataArray[j]>=minS){ score++; surprisingNum--; } } System.out.println(score); totalScoreArray[i] = score; } in.close(); FileWriter fstream = new FileWriter("B-small-attempt0.out"); BufferedWriter out = new BufferedWriter(fstream); for(int i=1; i<=testCaseNumber;i++){ String outLine = "Case #"+i+": "+totalScoreArray[i-1]+"\n"; out.write(outLine); } out.close(); System.out.println("File created successfully."); } }
0
448
A12852
A10426
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 MyAllgoritmicLib; public class BinnomNeutona { public static int C(int k, int n){ return factorial(n)/(factorial(k)*factorial(n-k)); } public static int factorial(int n){ int result = 1; for(int i = n; i > 1; i--){ result *= i; } return result; } }
0
449
A12852
A10749
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.b; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { ProblemB b = new ProblemB(); List<String> lines = CodejamFile.readLines("c:\\tmp\\B-small-attempt0.in"); for (int i = 0; i < lines.size(); i++) { System.out.printf("Case #%d: %d\n", i + 1, b.process(lines.get(i))); } } } class ProblemB { private int S; // the number of surprising triplets of scores private int p; // threashold score // 3 1 5 15 13 11 -> 3 // 3 0 8 23 22 21 -> 2 public int process(String line) { int possiblity = 0; //System.out.println(line); String[] elements = line.split(" "); int N = Integer.parseInt(elements[0]); // the number of Googlers S = Integer.parseInt(elements[1]); p = Integer.parseInt(elements[2]); for (int i = 0; i < N; i++) { int score = Integer.parseInt(elements[i + 3]); //System.out.printf("%d, %d\n", score / 3, score % 3); possiblity += getPossiblity(score) > 0 ? 1 : 0; } return possiblity; } private int getPossiblity(int score) { int r = 0; int avg = score / 3; switch (score % 3) { case 0: if (avg > p) { r = 3; } else if (avg == p) { //if (S > 0) { r = 2; //S--; //} } else if (avg == (p - 1)){ if (avg == 0) { break; } if (S > 0) { r = 1; S--; } } break; case 1: if (avg >= p) { r = 3; } else if (avg == (p -1)) { //if (S > 0) { //S--; r = 2; //} else { //r = 1; //} } break; case 2: if (avg >= p) { r = 3; } if (avg == (p - 1)) { r = 2; } if (avg == (p -2)) { if (S > 0) { S--; r = 1; } } break; } return r; } } class CodejamFile { public static List<String> readLines(String path) { List<String> lines = new ArrayList<String>(); try { FileReader in = new FileReader(path); BufferedReader br = new BufferedReader(in); String line; // br.readLine(); // line count // while ((line = br.readLine()) != null) { lines.add(line); } br.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } return lines; } }
0
450
A12852
A11224
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 DancingWiththeGooglers { /** * @param args */ public static void main(String[] args) { new DancingWiththeGooglers().fun(); } private void fun() { String file = "D:/CodeJam/inputB.in"; try { scan = new Scanner(new File(file)); } catch (FileNotFoundException e) { e.printStackTrace(); } int cases = scan.nextInt(); for(int i = 1; i <= cases ; i++) { int noOfGooglers = findTheResult(); System.out.println("Case #"+i+": "+noOfGooglers); } } private int findTheResult() { int googlers = scan.nextInt(); int surprising = scan.nextInt(); int minScore = scan.nextInt(); int minValue = getMinValue(minScore); int criticValue1 = minValue; int criticValue2 = criticValue1 + 1; int count = 0; int criticalCount = 0; for(int i = 0; i< googlers; i++) { int score = scan.nextInt(); if(minValue == 0) { count++; continue; } else if(minValue == 1) { if(score >= minValue) count++; continue; } if(score >= minValue) { if(score == criticValue1 || score == criticValue2) { if(criticalCount < surprising) { count++; criticalCount++; } } else count++; } } return count; } private int getMinValue(int minScore) { int value = 0; if(minScore > 2) { value = minScore - 2; value = minScore + value*2; } else value = minScore; return value; } Scanner scan = null; }
0
451
A12852
A11407
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.FileOutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /** * * @author Chadi */ class TestCase { int googlers; int surprises; int minScore; int[] scores; public TestCase() { } public int[] split(int sum, boolean surprise) { if (sum == 0) { return new int[]{0,0,0}; } else if (sum == 1) { return new int[]{0,0,1}; } int[] res = new int[3]; if (surprise == false) { res[0] = sum/3; res[1] = (sum - res[0]) / 2; res[2] = sum - res[0] - res[1]; } else { res[0] = (int)(Math.ceil(sum / 3.0)) + 1; res[1] = (sum - res[0]) / 2; res[2] = sum - res[0] - res[1]; } Arrays.sort(res); while (res[2] - res[0] > 2) { res[0]++; res[2]--; Arrays.sort(res); } return res; } public int solve() { int count = 0; for (int i = 0; i < googlers; i++) { int[] curScores = split(scores[i], false); //System.out.println(i + "\t" + Arrays.toString(curScores)); if (curScores[2] >= minScore) { count++; } else { if (surprises > 0) { //System.out.println("Using a surprise!"); int[] curScoresBest = split(scores[i], true); //System.out.println(i + "\t" + Arrays.toString(curScoresBest)); if (curScoresBest[2] >= minScore) { count++; surprises--; } } } } return count; } } public class B { public static void main(String[] args) throws FileNotFoundException, IOException { /* READ INPUT + DATA STRUCTURES */ String input = "B-small-attempt1.in"; //String input = "C-large.in"; String output = input.replace(".in", ".out"); File f = new File(input); Scanner sc = new Scanner(f); int T = Integer.parseInt(sc.nextLine()); TestCase[] cases = new TestCase[T]; for (int i = 0; i < T; i++) { cases[i] = new TestCase(); /* Add inputs to this case */ cases[i].googlers = sc.nextInt(); cases[i].surprises = sc.nextInt(); cases[i].minScore = sc.nextInt(); cases[i].scores = new int[cases[i].googlers]; for (int k = 0; k < cases[i].googlers; k++) { cases[i].scores[k] = sc.nextInt(); } } /* END READ INPUT + DATA STRUCTURES */ File out = new File(output); if (out.exists()) { out.delete(); } PrintWriter pw = new PrintWriter(new FileOutputStream(out, true)); for (int i = 0; i < T; i++) { System.out.println("Solving case: " + "#" + (i+1)); String result = "Case #" + (i+1) + ": " + cases[i].solve(); if (i <= T-2) { pw.println(result); } else { pw.print(result); } } pw.close(); } }
0
452
A12852
A12382
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 java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuffer pal; ArrayList<Integer> puntajes= new ArrayList(); int test= sc.nextInt(), N, S, P, rare, num, count; for (int i=1; i<=test; i++){ N= sc.nextInt(); S= sc.nextInt(); P= sc.nextInt(); count=0; P=3*P-2; rare= P-2; if (P==1) rare =1; System.out.print("Case #"+i+": "); for (int j=0; j<N; j++){ num=sc.nextInt(); if (num>=P){ count++; } else if ((S>0) && (num>=rare)){ S--; count++; } } System.out.println(count); } } }
0
453
A12852
A11734
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 de.johanneslauber.codejam.model; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.util.List; /** * * @author Johannes Lauber - joh.lauber@googlemail.com * */ public abstract class BaseProblem implements IProblem { protected List<ICase> listOfCases; private BufferedWriter out; private int countOutputLines = 0; public BaseProblem() { try { out = new BufferedWriter(new FileWriter("output/output.out")); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } @Override public void setListOfCases(List<ICase> listOfCases) { this.listOfCases = listOfCases; } /** * * @author Johannes Lauber - joh.lauber@googlemail.com * @param stringArray * @return */ protected int[] toIntArray(String[] stringArray) { int[] intArray = new int[stringArray.length]; for (int i = 0; i < stringArray.length; i++) { intArray[i] = Integer.valueOf(stringArray[i]); } return intArray; } /** * * @author Johannes Lauber - joh.lauber@googlemail.com * @param line */ protected void writeToFile(String line) { countOutputLines++; try { out.write("Case #" + countOutputLines + ": " + line); out.newLine(); } catch (IOException e) { e.printStackTrace(); } } /** * * @author Johannes Lauber - joh.lauber@googlemail.com */ protected void closeWriter() { try { out.close(); } catch (IOException e) { e.printStackTrace(); } } }
0
454
A12852
A11865
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.Arrays; public class ProbB { /** * @param args */ public static void main(String[] args) { ArrayList<String> in=Utils.readFile("B-small-attempt0.in.in"); ArrayList<String> out =new ArrayList<String>(); for (int i = 1; i < in.size(); i++) { String[] str=in.get(i).split(" "); int n= Integer.parseInt(str[0]); int surprise=Integer.parseInt(str[1]); int p=Integer.parseInt(str[2]); int[] elem=new int[n]; for (int j = 0; j < n; j++) { elem[j]=Integer.parseInt(str[j+3]); } Arrays.sort(elem); int count=0; for (int j = elem.length-1; j >=0 ; j--) { if(elem[j]>=(3*p-2)){ count++; }else if(elem[j]>=(3*p-4)){ if(surprise==0||p==1){ break; }else{ count++; surprise--; } }else{ break; } } out.add("Case #"+i+": "+count); Utils.writeFile(out, "B-small-attempt0"); } } }
0
455
A12852
A12616
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 DanceGooglers { static String name = "B-small-attempt2"; public static void main(String args[]) throws IOException { BufferedReader in = new BufferedReader(new FileReader(name + ".in")); PrintWriter out = new PrintWriter(name + ".out"); int t = Integer.parseInt(in.readLine()), caseN = 1; while (caseN <= t) { int ans = 0; StringTokenizer tok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(tok.nextToken()), s = Integer.parseInt(tok .nextToken()), p = Integer.parseInt(tok.nextToken()); // System.out.println(n + " " + s + " " + p); for (int i = 0; i < n; i++) { int total = Integer.parseInt(tok.nextToken()); // System.out.println(total); if (total < p) continue; if (total >= p * 3 - 2) { ans++; continue; } if (total >= p * 3 - 4 && s > 0) { s--; ans++; } } out.print("Case #"); out.print(caseN++); out.print(": "); out.println(ans); // System.out.println(caseN - 1 + " ans " + ans); } out.flush(); } }
0
456
A12852
A13200
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.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) { try { BufferedReader lector = new BufferedReader(new FileReader(args[0])); int iterations = Integer.parseInt(lector.readLine()); int numOfGooglers = 0; int surprisingScores = 0; int requestedPunctuation = 0; int googlersWithPunct= 0; int googlerPunctuation = 0; int mediumPunctuation = 0; int restPuntuaction = 0; String linea = null; String[] values = null; for (int idx=1; idx <= iterations; idx++) { //Obtenemos la línea actual o caso a trata linea = lector.readLine(); //Obtenemos los valores de la línea actual values = linea.split("\\s"); //Obtenemos el número de bailadores numOfGooglers = Integer.parseInt(values[0]); //Obtenemos el número de puntuaciones sorprendentes surprisingScores = Integer.parseInt(values[1]); //Obtenemos la puntuación máxima requestedPunctuation = Integer.parseInt(values[2]); //Para este caso ponemos los resultados a 0 googlersWithPunct = 0; //Hacemos el tratamiento específico para cada bailador for (int i=0; i<numOfGooglers ; i++) { //Obtenemos la puntuación actual del concursante googlerPunctuation = Integer.parseInt(values[i+3]); if (googlerPunctuation >= requestedPunctuation) { //Determinamos si el concursante puede haber obtenido la nota mínima mediumPunctuation = googlerPunctuation / 3; restPuntuaction = googlerPunctuation % 3; //Si la media de puntuación es igual o mayor a la puntuación máxima ya sabemos que ese concursante lo cumple if (mediumPunctuation >= requestedPunctuation) { googlersWithPunct++; } else { if (surprisingScores == 0) { //Si no puede haber resultados sorprendentes if (restPuntuaction != 0 && (mediumPunctuation + 1 == requestedPunctuation)) { googlersWithPunct++; } } else { //Si aun puede haber sorprendentes if (restPuntuaction == 1 && (mediumPunctuation + 1 == requestedPunctuation)) { googlersWithPunct++; } else if (restPuntuaction == 2 && (mediumPunctuation + 2 >= requestedPunctuation)) { googlersWithPunct++; surprisingScores--; } else if (restPuntuaction == 0 && (mediumPunctuation + 1 >= requestedPunctuation)) { googlersWithPunct++; surprisingScores--; } } } } } System.out.printf("Case #%d: %s\n", idx, googlersWithPunct); } } catch (FileNotFoundException ex) { System.out.println("Error:: Juego de pruebas no pasado por línea de comandos"); } catch (IOException ex) { System.out.println("Error:: Se ha producido un error en el procesamiento del archivo"); } } }
0
457
A12852
A11929
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.BufferedOutputStream; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Scanner; class results { public int numgooglers,numsurprising,p,counter = 0; public int[] scores; HashMap<Integer,Integer> maxifnotsurprising, maxifsurprising; results(int numgooglers, int numsurprising, int p,HashMap<Integer,Integer> maxifnotsurprising, HashMap<Integer,Integer> maxifsurprising) { this.numgooglers = numgooglers; this.numsurprising = numsurprising; this.p = p; scores = new int[numgooglers]; this.maxifnotsurprising = maxifnotsurprising; this.maxifsurprising = maxifsurprising; } public void addscore(int i) { scores[counter] = i; counter++; } public int maxgreaterthanp() { int max = 0; int remainingsurprising = numsurprising; for (int i=0;i<numgooglers;i++) { if (maxifnotsurprising.get(scores[i])>=p) max++; else if (remainingsurprising>0 && scores[i] > 1 ) { //If it's surprising, minimum score is 2 if (maxifsurprising.get(scores[i])>=p) { max++; remainingsurprising--; } } } return max; } } public class DancingWithGooglers { final static String inputfile = "B-small-attempt0.in",outfile = "output.txt"; static HashMap<Integer,Integer> maxifnotsurprising,maxifsurprising; public static void main(String[] args) { maxifnotsurprising = new HashMap<Integer,Integer>(); maxifsurprising = new HashMap<Integer,Integer>(); for(int i=0;i<11;i++) { //Smallest for (int j=i;j<i+3;j++){ //Middle for (int k=j;k<i+3;k++) { //System.out.println(i+","+j+","+k); int sum = i+j+k; if (k-i == 2) { //Is surprising if (!maxifsurprising.containsKey(sum)) maxifsurprising.put(sum, k); else if (maxifsurprising.get(sum)<k) maxifsurprising.put(sum, k); } else { if (!maxifnotsurprising.containsKey(sum)) maxifnotsurprising.put(sum, k); else if (maxifnotsurprising.get(sum)<k) maxifnotsurprising.put(sum, k); } } } } ArrayList<results> cases = new ArrayList<results>(); Scanner sc = null; try { sc = new Scanner(new File(inputfile)); } catch (FileNotFoundException e) { System.err.println("OHONEZ"); } int numtestcases = sc.nextInt(); for (int i=0;i<numtestcases;i++) { results temp = new results(sc.nextInt(), sc.nextInt(), sc.nextInt(),maxifnotsurprising,maxifsurprising); for (int j=0;j<temp.numgooglers;j++) temp.addscore(sc.nextInt()); cases.add(temp); } FileWriter fstream = null; try { fstream = new FileWriter(outfile); BufferedWriter out = new BufferedWriter(fstream); for (int i=0;i<cases.size();i++) { System.out.println("Case #"+(i+1)+": "+cases.get(i).maxgreaterthanp()); out.write("Case #"+(i+1)+": "+cases.get(i).maxgreaterthanp()+"\n"); } out.close(); } catch (IOException e) {} } }
0
458
A12852
A12523
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 Main { public static void main(String[] args) { Scanner reader = new Scanner (System.in); int nCases = reader.nextInt(); for(int i=1; i<=nCases; i++) { int nGoolers = reader.nextInt(); int nSurprising = reader.nextInt(); int p = reader.nextInt(); int minSurprising,minNotSurprising; if(p>=2) { minSurprising = (p-2)*2 + p; minNotSurprising = (p-1)*2 +p; } else if (p==1){ minSurprising = (p-1)*2 +p; minNotSurprising = (p-1)*2 +p; } else { minSurprising = 0; minNotSurprising = 0; } int nBestResult = 0; int[] scoreTriplets = new int[nGoolers]; for(int j=0; j<nGoolers; j++) { scoreTriplets[j] = reader.nextInt(); if(scoreTriplets[j] >= minNotSurprising) { nBestResult++; } else if(scoreTriplets[j] < minNotSurprising && scoreTriplets[j] >= minSurprising) { if(nSurprising > 0) { nBestResult++; nSurprising--; } } } System.out.println("Case #" + i + ": " + nBestResult); } } }
0
459
A12852
A11998
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 Dancing_With_the_Googlers { public int solve1(int s, int p, int[] t) { int ans=0; for (int i=0;i<t.length;i++) { boolean next=false; for(int a0=0;a0<=t[i];a0++) { for(int a1=0;a0+a1<=t[i];a1++) { int a2=t[i]-a1-a0; if(a2<0) continue; if(Math.abs(a0-a1)<=2 && Math.abs(a1-a2)<=2 && Math.abs(a0-a2)<=2) if(Math.abs(a0-a1)<2 && Math.abs(a1-a2)<2 && Math.abs(a0-a2)<2) { if(a0>=p || a1>=p || a2>=p) { ans++; next=true; break; } } } if(next) break; } if(next) continue; for(int a0=0;a0<=t[i];a0++) { for(int a1=0;a0+a1<=t[i];a1++) { int a2=t[i]-a1-a0; if(a2<0) continue; if(Math.abs(a0-a1)<=2 && Math.abs(a1-a2)<=2 && Math.abs(a0-a2)<=2) if((Math.abs(a0-a1)==2 || Math.abs(a1-a2)==2 || Math.abs(a0-a2)==2) && s>0) { if(a0>=p || a1>=p || a2>=p) { s--; ans++; next=true; break; } } } if(next) break; } } return ans; } public int solve(int s, int p, int[] t) { int whichContainsMoreThanP=0; int ans=0; for (int i=0;i<t.length;i++) { if(t[i]==0) { if(0>=p) ans++; continue; }else if(t[i]==1) { if(1>=p) ans++; continue; }else if(t[i]==2) { if(1>=p) ans++; else if(2>=p && s>0) { ans++; s--; } continue; } int reminder=t[i]%3; int division=t[i]/3; switch(reminder) { case 0:// 1,2 or 0,0 if(division>=p) whichContainsMoreThanP++; else if(division-1+2>=p && s>0) { s--; ans++; } break; case 1:// 2,2 or 0,1 if(division+1>=p) whichContainsMoreThanP++; else if(division-1+2>=p && s>0) { s--; ans++; } break; case 2:// 0,2 or 1,1 if(division+1>=p) whichContainsMoreThanP++; else if(division+2>=p && s>0) { s--; ans++; } break; default: } } return ans+whichContainsMoreThanP; } } /* import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; public class Program { public static void main(String[] args) { try { FileWriter fileWriter=new FileWriter("B-small-attempt0.out"); FileReader fileReader=new FileReader("B-small-attempt0.in"); BufferedReader in = new BufferedReader(fileReader); int T= Integer.parseInt(in.readLine()); for(int t=1;t<=T;t++) { String[] tokens= in.readLine().split(" "); int N= Integer.parseInt(tokens[0]); int[] values=new int[N]; int S= Integer.parseInt(tokens[1]); int p= Integer.parseInt(tokens[2]); for(int n=0;n<N;n++) { values[n]= Integer.parseInt(tokens[n+3]); } Dancing_With_the_Googlers d=new Dancing_With_the_Googlers(); int result=d.solve(S, p, values); fileWriter.write("Case #"+t +": " +result+"\n"); } fileWriter.close(); fileReader.close(); } catch (Exception e) { System.out.println("Error! Exception: "+e); } } } */
0
460
A12852
A11446
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.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Scanner; public class Main { private Scanner scanner; private PrintWriter writer; public Main(InputStream is, OutputStream os) { scanner = new Scanner(is); writer = new PrintWriter(os); } public void solve() { // Unit Tests: int tmp; int tmp1[] = {15,13,11}; if (calculate(1, 5, tmp1)!=3) return; int tmp2[] = {23,22,21}; if (calculate(0, 8, tmp2)!=2) return; int tmp3[] = {8,0}; if (calculate(1, 1, tmp3)!=1) return; int tmp4[] = {29,20,8,18,18,21}; if (calculate(2, 8, tmp4)!=3) return; for (int i=0; i<200; i++) System.out.println(""); int cases = scanner.nextInt(); for (int i = 1; i <= cases; i++) { writer.print("Case #"); writer.print(i + ": "); scanner.nextLine(); int n = scanner.nextInt(); // number of Googlers int s = scanner.nextInt(); // number of surprising triplets int p = scanner.nextInt(); // minimum score int t[] = new int[n]; for (int j = 0; j < n; j++) t[j] = scanner.nextInt(); System.out.println(i + ": MinScore=" + p + ", Surprising Triplets=" + s); int result = calculate(s, p, t); writer.println(result); System.out.println(" -> " + result); System.out.println("-------------"); } writer.flush(); } private int calculate(int noSurprisingScores, int minimumScore, int[] scores) { int result = 0; for (int score : scores) { int triplet[] = new int[3]; System.out.print(score + ": "); switch (score % 3) { case 0: if (score / 3 >= minimumScore) { result++; //System.out.println((score / 3) + "," + (score / 3) + "," + (score / 3)); } else { if (noSurprisingScores > 0) if (score / 3 + 1 >= minimumScore && score / 3 - 1 >= 0) { result++; noSurprisingScores--; System.out.println((score / 3 - 1) + "," + (score / 3) + "," + (score / 3 + 1) + " *"); } } break; case 1: if ((score-1)/3 + 1 >= minimumScore) { result++; //System.out.println((score-1)/3 + "," + ((score-1)/3) + "," + ((score-1)/3 + 1)); } else { // Surprising Triplet führt nicht zur Erhöhung des max Scores } break; case 2: if ((score-2)/3 + 1 >= minimumScore) { result++; //System.out.println((score-2)/3 + "," + ((score-2)/3 + 1) + "," + ((score-2)/3 + 1)); } else { if (noSurprisingScores > 0) if ((score - 2) / 3 + 2 >= minimumScore) { result++; noSurprisingScores--; //System.out.println((score-2)/3 + "," + (score-2)/3 + "," + ((score-2)/3 + 2) + " *"); } } break; } } return result; } /* * private boolean exceedsMinumumScore(int[] triplet, int minScore) { for * (int i=0; i<3; i++) if (triplet[i] >= minScore) return true; return * false; } */ public static void main(String[] args) { try { InputStream is = new FileInputStream("input/B-small-attempt0.in"); OutputStream os = new FileOutputStream("output/B-small-attempt0.out"); Main problem = new Main(is, os); problem.solve(); } catch (FileNotFoundException e) { e.printStackTrace(); } //System.out.println("finished"); } }
0
461
A12852
A11050
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 qualifiers.dancing; 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; public class Dancing { public static void main(String[] args) { try { FileReader fileReader = new FileReader("input/B-small-attempt0.in"); BufferedReader bufferedReader = new BufferedReader(fileReader); String record = null; int numOfCases = -1; int lineCount = 0; List<String> inputList = new ArrayList<String>(); // Read input while ((record = bufferedReader.readLine()) != null) { // First row is number of cases if (lineCount == 0) { numOfCases = Integer.valueOf(record); } // Input else { inputList.add(record); } lineCount++; } fileReader.close(); // Perform algo List<Integer> results = new ArrayList<Integer>(); for (String input : inputList) { String[] inputStrArray = input.split(" "); int numOfGooglers = Integer.valueOf(inputStrArray[0]); int numOfSurprisingScores = Integer.valueOf(inputStrArray[1]); int point = Integer.valueOf(inputStrArray[2]); // Constraints int constraint1 = ((3 * point - 4) < point) ? point : (3 * point - 4); int constraint2 = (constraint1 < 2) ? constraint1 : constraint1 + 1; int surePassConstraint = (constraint2 < 2) ? constraint2 : constraint2 + 1; // Calc int result = 0; int count = 3 + numOfGooglers; for (int i = 3; i < count; i++) { int totalScoreOfGoogler = Integer.valueOf(inputStrArray[i]); // Sure pass if (totalScoreOfGoogler >= surePassConstraint) { result++; } // Sure fail else if (totalScoreOfGoogler < constraint1) { continue; } // Surprise score else if (totalScoreOfGoogler == constraint1 || totalScoreOfGoogler == constraint2) { if (numOfSurprisingScores > 0) { result++; numOfSurprisingScores--; } else { continue; } } } results.add(result); } // Write output FileWriter fileWriter = new FileWriter("output/results.out"); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); for (int i = 0; i < results.size(); i++) { int result = results.get(i); bufferedWriter.write("Case #" + (i+1) + ": " + result); if (i < results.size() - 1) bufferedWriter.write("\n"); } //Close the output stream bufferedWriter.close(); } catch (IOException e) { System.out.println("IOException error!"); e.printStackTrace(); } } }
0
462
A12852
A13207
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; /** * * @author Sohail */ public class Triplet { public int normal; public int surprising; }
0
463
A12852
A12970
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; public class Triplet { public int first; public int second; public int third; public Triplet(int first, int second, int third){ this.first = Math.max(Math.max(first, second), third); if (first == this.first){ this.second = Math.max(second, third); this.third = Math.min(second, third); } else if (second == this.first){ this.second = Math.max(first, third); this.third = Math.min(first, third); } else{ this.second = Math.max(first, second); this.third = Math.min(first, second); } } @Override public String toString() { return "(" + first + ", " + second + ", " + third + ") " + (isSurprising()?"(*)":""); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + first; result = prime * result + second; result = prime * result + third; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Triplet other = (Triplet) obj; if (first != other.first) return false; if (second != other.second) return false; if (third != other.third) return false; return true; } public int sum() { return first + second + third; } public int max() { return first; } public boolean isSurprising() { return ((Math.abs(first-second) == 2) || (Math.abs(first-third) == 2) || (Math.abs(second-third) == 2)); } }
0
464
A12852
A13127
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.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; class IOSystem { private String filePath; private List<String> inputList = new ArrayList<String>(); private StringBuilder sb = new StringBuilder(); private int readSize = 0; private int appendedSize = 0; public IOSystem(String filePath) { this(filePath," "); } public IOSystem(String filePath,String sep) { this.filePath = filePath; try { BufferedReader br = new BufferedReader(new FileReader(filePath+".in")); String line = null; while((line=br.readLine())!=null) { inputList.addAll(Arrays.asList(line.split(sep))); } } catch (Exception e) { e.printStackTrace(); } } public int size(){return inputList.size();} public boolean hasNext(){return readSize < size();} public int nextInt(){return Integer.parseInt(inputList.get(readSize++));} public long nextLong(){return Long.parseLong(inputList.get(readSize++));} public double nextDouble(){return Double.parseDouble(inputList.get(readSize++));} public String nextString(){return new String(inputList.get(readSize++));} public <T> void appendAnswer(T answer){sb.append("Case #"+(++appendedSize)+": "+answer.toString()+"\n");}; public void output(){ try { BufferedWriter bw = new BufferedWriter(new FileWriter(filePath+".ou")); bw.write(sb.toString()); bw.flush(); System.out.println("output ->"+filePath+".ou"); } catch (IOException e) { e.printStackTrace(); } } }
0
465
A12852
A12803
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.FileOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.util.LinkedList; import java.util.List; import java.util.Scanner; public class Solver { private final static String DIR_PATH = "e:\\jam\\"; private final static String IN_FILE_NAME = "B-small-attempt2.in"; private final static String OUT_FILE_NAME = IN_FILE_NAME.replaceAll("\\..*$", ".out"); private final static File sInFile = new File(DIR_PATH, IN_FILE_NAME); private final static File sOutFile = new File(DIR_PATH, OUT_FILE_NAME); private final PrintStream mOut; private final Scanner mScanner; private static class ProxyOutputStream extends FilterOutputStream { public ProxyOutputStream(OutputStream out) { super(out); } @Override public void write(byte[] b, int off, int len) throws IOException { System.out.write(b, off, len); super.write(b, off, len); } } public static void main(String[] args) { try { Solver solver = new Solver(sInFile, sOutFile); solver.solve(); } catch(IOException ex) { ex.printStackTrace(); } } public Solver(File inFile, File outFile) throws IOException { mScanner = new Scanner(inFile); mOut = new PrintStream(new ProxyOutputStream(new FileOutputStream(outFile))); } private void printSolution(int no, String solution) { if(no == 0) { throw new IllegalArgumentException("Solution number is 0! Should start with 1!"); } mOut.println(String.format("Case #%d: %s", no, solution)); } private void solve() throws IOException { int problemsCount = mScanner.nextInt(); mScanner.nextLine(); for(int i = 0; i < problemsCount; i++) { int participants = mScanner.nextInt(); int surprises = mScanner.nextInt(); int minBestScore = mScanner.nextInt(); List<Integer> scores = new LinkedList<Integer>(); for(int s = 0; s < participants; s++) { scores.add(mScanner.nextInt()); } String solution = Integer.toString(solve(scores, minBestScore, surprises)); printSolution(i + 1, solution); } } private int solve(List<Integer> scores, int minBestScore, int surprises) { int totalPassed = 0; int almostPassed = 0; for(Integer score : scores) { int maxOk = 0; int maxSurprise = 0; if(score > 0) { int scoreCase = score % 3; switch(scoreCase) { case 0: maxOk = score / 3; maxSurprise = score / 3 + 1; break; case 1: maxOk = maxSurprise = score / 3 + 1; break; case 2: maxOk = score / 3 + 1; maxSurprise = score / 3 + 2; break; } } else { maxOk = 0; maxSurprise = 0; } if(maxOk >= minBestScore) { totalPassed++; } else if(maxSurprise >= minBestScore) { almostPassed++; } } totalPassed += Math.min(surprises, almostPassed); return totalPassed; } }
0
466
A12852
A11197
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.*; /** * * @author kronenthaler */ public class B { static HashMap<Integer, Set<ArrayList<Integer>>> cache = new HashMap<Integer, Set<ArrayList<Integer>>>(); public static void main(String arg[]){ try{ int max = 0; for(int i=0;i<=10;i++){ for(int j=0;j<=10;j++){ for(int k=0;k<=10;k++){ if(Math.abs(i-j)<=2 && Math.abs(j-k)<=2 && Math.abs(i-k)<=2){ if(cache.get(i+j+k)==null) cache.put(i+j+k, new HashSet<ArrayList<Integer>>()); ArrayList<Integer> a = new ArrayList<Integer>(); a.add(i); a.add(j); a.add(k); Collections.sort(a); cache.get(i+j+k).add(a); max = Math.max(max, cache.get(i+j+k).size()); } } } } Scanner in = new Scanner(new FileInputStream("b-small.in")); //Scanner in = new Scanner(new FileInputStream("b-large.in")); System.setOut(new PrintStream("b.out")); int T = in.nextInt(); for(int cases=1;cases<=T;cases++){ int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int g[] = new int[n]; for(int i=0;i<n;i++){ g[i] = in.nextInt(); } System.out.printf("Case #%d: %d\n",cases, bt(g,s,p,0,0)); } }catch(Exception e){ e.printStackTrace(); } } static int bt(int[]g, int s, int p, int acum, int current){ if(current == g.length) return s==0?acum:-1; int max = -1; Set<ArrayList<Integer>> a = cache.get(g[current]); for(ArrayList<Integer> arr : a){ if(Math.abs(arr.get(0)-arr.get(2))==2){ if(s!=0) max = Math.max(max, bt(g, s-1, p, acum + (arr.get(2)>=p?1:0), current+1)); }else{ max = Math.max(max, bt(g, s, p, acum + (arr.get(2)>=p?1:0), current+1)); } } return max; } }
0
467
A12852
A11957
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 prg2; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; /** * @author Brijesh Mistry * */ public class GooglerDance { public static void main(String[] args) { try{ FileInputStream fstream = new FileInputStream("b1.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String fileline; //Read File Line By Line int j =0 ; String strTestcases ; int iTestcases = 0; //Read no of testcases if(((strTestcases = br.readLine()) != null)){ System.out.println("Test cases:"+strTestcases); iTestcases = Integer.parseInt(strTestcases); } //int noofGoogler = 0; //int noOfSurprises = 0; //int noOfSurprisesRemaining = 0; //int limitScore = 0; //int minscore = 0; //int totalWinner = 0; for(int k=1;k<=iTestcases;k++){ //for(int k=1;k<=3;k++){ int noofGoogler = 0; int noOfSurprises = 0; int noOfSurprisesRemaining = 0; int limitScore = 0; int minscore = 0; int totalWinner = 0; if((fileline = br.readLine()) != null){ //System.out.println ("line #"+(k)+" "+fileline); StringTokenizer st = new StringTokenizer(fileline, " "); noofGoogler = Integer.parseInt(st.nextToken()); noOfSurprises = Integer.parseInt(st.nextToken()); limitScore = Integer.parseInt(st.nextToken()); //System.out.println(k+"Parameters fetched:"+noofGoogler+" : "+noOfSurprises+ " : "+limitScore); //Logic that gives the no of players //store Max scores into ArrayList ArrayList<Integer> maxScores = new ArrayList<Integer>(); ArrayList<Integer> secondscore =new ArrayList<Integer>(); for(int i=0;i<noofGoogler;i++){ maxScores.add(Integer.parseInt(st.nextToken())); } //Max scores we have into List //NOW Check for normal score minscore = (limitScore-1)*2+limitScore; for(int score:maxScores){ if(score>=minscore && score >= limitScore){ totalWinner +=1; }else{ //System.out.println("adding score: case :"+k+":"+score); secondscore.add(score); } } noOfSurprisesRemaining = noOfSurprises; if(noOfSurprisesRemaining>0){ minscore = (limitScore-2)*2+limitScore; //System.out.println("min score"+minscore); for(int score:secondscore){ if(score>=minscore && noOfSurprisesRemaining>0 && score >= limitScore){ //ystem.out.println("for Surprises score: case :"+k+":" +score); totalWinner +=1; noOfSurprisesRemaining --; } } } System.out.println("Case #"+k+": "+totalWinner); } } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any e.printStackTrace(); } } }
0
468
A12852
A13138
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 exercises; import IO.Input; /** * * @author dannocz */ public class Exercise2 { public static void run(Input input){ // for (String st : input.getTestCases()) { // input.addResultCase(Parser.parse(st)); // } // input.printResultCases(); } }
0
469
A12852
A11575
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.util.StringTokenizer; import java.io.FileReader; public class B { /** * @param args */ public static void main(String[] args) throws Exception { BufferedReader reader = null; String fileName = "B-small-attempt0.in"; String outputFileName=fileName.replace(".in", ".out"); reader=new BufferedReader(new FileReader(fileName)); File outFile=new File(outputFileName); outFile.createNewFile(); int T = Integer.parseInt(reader.readLine()); for (int i = 1; i <=T; i++) { StringTokenizer token=new StringTokenizer(reader.readLine()," "); int n=Integer.parseInt(token.nextToken()); int s=Integer.parseInt(token.nextToken()); int p=Integer.parseInt(token.nextToken()); int[] t=new int[n]; Score[] ns=new Score[n];//not surprising Score[] ss=new Score[n];//surprising for(int j=0;j<n;j++){ t[j]=Integer.parseInt(token.nextToken()); int avg=t[j]/3; int reminder=t[j]%3; if(reminder==0){ Score ts1=new Score(); Score ts2=new Score(); ts1.s1=avg; ts1.s2=avg; ts1.s3=avg; ns[j]=ts1; if(avg==0){ ss[j]=ns[j]; }else{ ts2.s1=avg-1; ts2.s2=avg; ts2.s3=avg+1; ss[j]=ts2; } }else if(reminder==1){ Score ts1=new Score(); Score ts2=new Score(); ts1.s1=avg+1; ts1.s2=avg+1; ts1.s3=avg-1; ss[j]=ts1; ts2.s1=avg; ts2.s2=avg; ts2.s3=avg+1; ns[j]=ts2; } else if(reminder==2){ Score ts1=new Score(); Score ts2=new Score(); ts1.s1=avg; ts1.s2=avg; ts1.s3=avg+2; ss[j]=ts1; ts2.s1=avg; ts2.s2=avg+1; ts2.s3=avg+1; ns[j]=ts2; } } // System.out.println("Case #"+i+": "+(k+1)+" "+(m+1)); count=0; // System.out.println("n="+n+" s="+s+" p="+p); execute(ns,ss,n,s,p); System.out.println("Case #"+i+": "+count); } } static int count=0; private static void action(Score[] ns,Score[] ss,int p,int[] index){ int count=0; boolean s[]=new boolean[ns.length]; for(int i=0;i<index.length;i++){ s[index[i]]=true; } for(int i=0;i<s.length;i++){ Score so=null; if(s[i]){ so=ss[i]; }else{ so=ns[i]; } if(so.max()>=p){ count++; } // System.out.println(so.toString()); } B.count=Math.max(B.count, count); } public static void execute(Score[] ns,Score[] ss,int n,int r,int p) { if(r==0){ action(ns,ss,p,new int[0]); return; } int i = 0, j; int[] a = new int[n]; a[i] = 0; while (true) { if ((a[i] - i) <= (n - r)) { if (i == (r - 1)) { int[] index = new int[r]; for (j = 0; j < r; j++) { index[j] = a[j]; } action(ns,ss,p,index); a[i] = a[i] + 1; continue; } i++; a[i] = a[i - 1] + 1; } else { if (i == 0) { break; } i--; a[i]++; } } } } class Score{ int s1; int s2; int s3; int p; boolean isSurprising(){ if(Math.abs(s1-s2)>=2 || Math.abs(s1-s3)>=2 || Math.abs(s2-s3)>=2){ return true; } return false; } public String toString(){ return s1+","+s2+","+s3; } public int max(){ return Math.max(Math.max(s1, s2),s3); } }
0
470
A12852
A10416
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 qualification.taskA; import java.util.Map; public class Task { private Map<Character, Character> dictionary ; public Task(Map<Character, Character> dictionary ) { this.dictionary = dictionary; } public String execute(String original) { StringBuilder result = new StringBuilder(); for(int i = 0; i < original.length(); i++){ result.append(dictionary.get(original.charAt(i))); } return result.toString(); } }
0
471
A12852
A12547
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.*; public class template { public static void main(String[] args) throws IOException { StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); //PrintWriter out = new PrintWriter("output.txt"); in.nextToken(); int count = (int)in.nval; for(int c = 1 ; c <= count ; c++) { in.nextToken(); int googlers = (int) in.nval; in.nextToken(); int surprisings = (int) in.nval; in.nextToken(); int passScore = (int) in.nval; int pass = 0; int passWithSurprising = 0; // loop through scores for(int i = 0 ; i < googlers ; i++) { in.nextToken(); int score = (int) in.nval; int division = score / 3; int modulo = score % 3; if (modulo > 0) division++; if (division >= passScore) { pass++; } else if (division+1 == passScore && modulo!=1 && score!=0) { passWithSurprising++; } } out.println("Case #" + c + ": " + (pass + Math.min(passWithSurprising, surprisings))); } out.flush(); out.close(); } }
0
472
A12852
A10020
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; public class OutputWriter { private BufferedWriter bw = null; private long counter = 1; public OutputWriter(String fileName) { try { bw = new BufferedWriter(new FileWriter(new File(fileName))); } catch (IOException e) { e.printStackTrace(); } } public void writeCaseLine(String output) { try { bw.write("Case #" + counter + ": " + output+"\n"); } catch (IOException e) { e.printStackTrace(); } counter++; } public void flushAndClose() { try { bw.flush(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
473
A12852
A12271
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; } }
/** * Created by IntelliJ IDEA. * User: SONY * Date: 19.02.12 * Time: 13:12 * To change this template use File | Settings | File Templates. */ import java.io.*; import java.util.*; import static java.lang.Math.*; public class Main extends Thread { public Main(String inputFileName, String outputFileName) { try { this.input = new BufferedReader(new FileReader(inputFileName)); this.output = new PrintWriter(outputFileName); this.setPriority(Thread.MAX_PRIORITY); } catch (Throwable e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(666); } } final int doit2() throws Throwable { int N = nextInt(), S = nextInt(), p = nextInt(); int t[] = new int[N]; for (int i = 0; i < N; ++i) t[i] = nextInt(); int[][] dp = new int[N + 1][S + 2]; for (int i = 0; i < N; ++i) { for (int j = 0; j <= Math.min(S, i); ++j) { int act = t[i]; if (act >= 3 * p - 2) { dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j] + 1); } else { dp[i + 1][j] = Math.max(dp[i + 1][j], dp[i][j]); } if (act >= 2 && act <= 28) { dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j]); if (act >= Math.max(p, 3 * p - 4)) { dp[i + 1][j + 1] = Math.max(dp[i + 1][j + 1], dp[i][j] + 1); } } } } return dp[N][S]; } final String doit(int ID) throws Throwable { return String.format("Case #%d: %d", ID, doit2()); } private void solve() throws Throwable { int testCases = nextInt(); for (int i = 1; i <= testCases; ++i) { output.println(doit(i)); } } public void run() { try { solve(); } catch (Throwable e) { System.err.println(e.getMessage()); e.printStackTrace(); System.exit(666); } finally { output.close(); } } public static void main(String... args) { new Main("input.txt", "output.txt").start(); } private int nextInt() throws IOException { return Integer.parseInt(next()); } private double nextDouble() throws IOException { return Double.parseDouble(next()); } private long nextLong() throws IOException { return Long.parseLong(next()); } private String next() throws IOException { while (tokens == null || !tokens.hasMoreTokens()) { tokens = new StringTokenizer(input.readLine()); } return tokens.nextToken(); } private StringTokenizer tokens; private BufferedReader input; private PrintWriter output; }
0
474
A12852
A11886
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.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; public class ProblemB { public static void main(String [] args){ doIt(); } public static void doIt(){ try{ BufferedWriter out = new BufferedWriter(new FileWriter("B-small-attempt5.out")); FileInputStream fstream = new FileInputStream(new File("B-small-attempt5.in")); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; int testLines = Integer.parseInt(br.readLine()); int caseCounter = 0; while ((strLine = br.readLine()) != null) { int possibs = 0; String[] str = strLine.split(" "); int n = Integer.parseInt(str[0]); int s = Integer.parseInt(str[1]); int p = Integer.parseInt(str[2]); for (int i = 3 ; i < str.length ; i++) { int score = Integer.parseInt(str[i]); if(score >= (3*p -2)){ possibs++; } else if(s > 0 && score >= (3*p -4) && score >= 2){ s--; possibs++; } } caseCounter++; out.write("Case #" + caseCounter + ": " + possibs); out.newLine(); } in.close(); out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
475
A12852
A10710
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; } }
/* * Google Code Challenge Java * * Code written for the Google Code Challenge by Greg Dougherty * Created: May 7, 2011 * * Copyright 2011 by Greg Dougherty */ package com.google.GregTD.CodeJam2012Quals.Dancing; import java.io.*; /** * @author Greg Dougherty * */ public class Dancing { private static final String kInSuffix = ".in"; private static final String kOutSuffix = ".out"; /** * @param args */ public static void main (String[] args) { String inName = args[0]; int nameLen = inName.indexOf (kInSuffix); String outName = inName.substring (0, nameLen) + kOutSuffix; File dataFile = new File (args[0]); File resultFile = new File (outName); try { BufferedReader dataReader = new BufferedReader (new FileReader (dataFile)); BufferedWriter dataWriter = new BufferedWriter (new FileWriter (resultFile)); String line = dataReader.readLine (); // Get first line int numCases = Integer.valueOf (line).intValue (); // Run each test case for (int i = 0; i < numCases; ++i) { // Get data line = dataReader.readLine (); String[] entries = line.split (" "); int numGoog = new Integer (entries[0]).intValue (); int maxSurprise = Integer.valueOf (entries[1]).intValue (); int minScore = Integer.valueOf (entries[2]).intValue (); int bestTotal = minScore * 3 - 2; int surpriseTotal = Math.max (minScore * 3 - 4, minScore); int[] scores = new int[numGoog]; for (int j = 0; j < numGoog; ++j) scores[j] = Integer.valueOf (entries[3 + j]).intValue (); int numWin = 0; int numSurprise = 0; for (int j = 0; j < numGoog; ++j) { if (scores[j] >= bestTotal) ++numWin; else if (scores[j] >= surpriseTotal) ++numSurprise; } numWin += Math.min (maxSurprise, numSurprise); dataWriter.write ("Case #" + (i + 1) + ": " + numWin); dataWriter.newLine (); dataWriter.flush (); } } catch (IOException ioE) { ioE.printStackTrace (); } } }
0
476
A12852
A11814
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.Scanner; public class GooglerDancing { /** * @param args */ public static void main(String[] args) { new GooglerDancing().run(); } public void run(){ int numDancers, targetScore, numSurprising, score, numWins; ArrayList<Dancer> dancers; Scanner input = new Scanner(System.in); int numCases = input.nextInt(); input.nextLine(); int caseNum = 1; while(caseNum <= numCases){ numWins = 0; dancers = new ArrayList<Dancer>(); numDancers = input.nextInt(); numSurprising = input.nextInt(); targetScore = input.nextInt(); for(int dancer = 0; dancer < numDancers; dancer++){ score = input.nextInt(); dancers.add(new Dancer(score)); } for(Dancer d : dancers){ if(d.DefiniteWin(targetScore)){ numWins++; } else if(d.score == 0 || d.DefiniteLoss(targetScore)){ // Do nothing } else if (numSurprising > 0 && d.WinningSurprise(targetScore)){ numWins++; numSurprising--; } } System.out.printf("Case #%d: %d%n", caseNum, numWins); caseNum++; } } } class Dancer { public int score; public Dancer(int score){ this.score = score; } public boolean WinningSurprise(int targetScore){ int firstScore = score - targetScore; int remainder = firstScore - (targetScore - 2); if(remainder >= (targetScore - 2)){ return true; } return false; } public boolean DefiniteWin(int targetScore){ int border = targetScore - 1; double avg = score / 3.0; if(avg > border){ return true; } return false; } public boolean DefiniteLoss(int targetScore){ int border = targetScore - 2; double avg = score / 3.0; if(avg >= border){ return false; } return true; } }
0
477
A12852
A10497
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.Scanner; public class B { public static void main(String[] args) { CaseB[] cases = read("B-small-attempt0.in"); /* // test reading for (CaseB c : cases) { print(c.getInfo()); }*/ for (CaseB c : cases) { // for each case for (int i = 0; i < c.t.length; i++) { // for each googler int avgBase = c.t[i] / 3; int addPoint = c.t[i] % 3; int bestResult = avgBase; // assume no surprising first, if addpoint > 0, best result is at least avgBase + 1 if (addPoint > 0) { bestResult += 1; } if (bestResult >= c.p) { // already larger than p, no surprising needed c.increment(); } else { // use surprising point if possible, 3 conditions // 1. still has surprising point to use // 2. addPoint is 0 or 2 (surprising can make a difference) // 3. total point >= 2 (can't make point 2 apart if the total point is < 2) if (c.hasS() && addPoint != 1 && c.t[i] >= 2) { // when addPoint is 0 or 2, best result can be incremented by 1 if is surprising triplet if (bestResult + 1 >= c.p) { c.useS(); c.increment(); } } } } } // write result writeFile(cases, "B-small-attempt0.out"); print("Complete!"); } public static void printf(String format, Object... args) { System.out.printf(format, args); } public static void print(Object o) { System.out.println(o); } public static void writeFile(CaseB[] result, String out) { PrintWriter writer = null; try { writer = new PrintWriter(out); for (int i = 0; i < result.length; i++) { writer.printf("Case #%d: %s\n", i+1, result[i]); } writer.flush(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (writer != null) { writer.close(); } } } public static CaseB[] read(String file) { BufferedReader reader = null; CaseB[] cases = null; try { reader = new BufferedReader(new FileReader(file)); // get test case count int caseCount = Integer.parseInt(reader.readLine()); cases = new CaseB[caseCount]; for (int i = 0; i < cases.length; i++) { Scanner scan = new Scanner(reader.readLine()); int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); int[] t = new int[n]; for (int x = 0; x < n; x++) { t[x] = scan.nextInt(); } cases[i] = new CaseB(s, p, t); scan.close(); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } return cases; } } class CaseB { //private int n; // number of Googler private int s; // number of surprising triplets int p; // expected best result int[] t; // total score of each Googler private int result; public CaseB(int s, int p, int[] t) { this.s = s; this.p = p; this.t = t; this.result = 0; } public void increment() { result++; } public boolean hasS() { return s > 0; } public void useS() { s--; } public int getResult() { return result; } public void setResult(int result) { this.result = result; } @Override public String toString() { return "" + result; } public String getInfo() { String out = t.length + " " + s + " " + p; for (int i = 0; i < t.length; i++) { out += " " + t[i]; } return out; } }
0
478
A12852
A11162
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 google; import java.io.File; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Arber */ public class Google { /** * @param args the command line arguments */ public static void main(String[] args) { Path input_path = new File("Input.in").toPath(); try { List<String> input_list = Files.readAllLines(input_path,Charset.forName("UTF-8")); int begin = 0; while(begin<input_list.size()) { int start = new Integer(input_list.get(begin)).intValue(); for(int i = 0; i<start; i++) { String[] in = input_list.get(begin+i+1).split(" "); int[] t = new int[in.length-3]; for(int j=3; j<in.length;j++) { t[j-3] = new Integer(in[j]).intValue(); } System.out.println("Case #"+(i+1)+": " +google4(new Integer(in[0]).intValue(), new Integer(in[1]).intValue(), new Integer(in[2]).intValue(), t)); } begin = begin + start + 1; } } catch (IOException ex) { Logger.getLogger(Google.class.getName()).log(Level.SEVERE, null, ex); } } public static int google3(int n, int m) { ArrayList<String> a1 = new ArrayList<String>(); for(int i = n; i<=m; i++) { for(int j = 1; j<(""+n).length();j++) { int rec = recycled(""+i, j); if(rec>=n &&rec<=m && rec != i) { if(rec<i) { String tem = (""+rec)+(""+i); if(!a1.contains(tem)) a1.add(tem); } else { String tem = (""+i)+(""+rec); if(!a1.contains(tem)) a1.add(tem); } } } } return a1.size(); } public static int recycled(String s, int m) { s = s.substring(s.length()-m) + s.substring(0,s.length()-m); return new Integer(s).intValue(); } public static int google4(int T,int s,int p, int[] t) { int rez = 0; for(int i=0; i<T; i++) { if(t[i]>=3*p-2) rez++; else if((t[i]>=3*p-4&&s>0&&p>1)) { s--; rez++; } } return rez; } }
0
479
A12852
A10414
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.HashMap; import java.util.Map; import java.util.Scanner; public class B { public static void main(String[] args){ String in ="small.txt"; String out = "output.txt"; Scanner sc; String answers[]=new String[3]; try { sc = new Scanner(new File(in)); int T = sc.nextInt(); //System.out.println(sc.nextLine()); sc.nextLine(); answers = new String[T]; for(int zz =0;zz<T;zz++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int[] score = new int[N]; int pMinSurprised,pMinNoSurprised; if(p==1){ pMinSurprised = 1; pMinNoSurprised = 1; } else if(p==0){ pMinSurprised = 0; pMinNoSurprised = 0; } else{ pMinSurprised = p * 3 - 4; pMinNoSurprised = p * 3 - 2; } int nbSurprised = 0; int googlers = 0; for(int i =0;i<N;i++) { score[i] = sc.nextInt(); if(score[i]>=pMinNoSurprised) googlers++; else if(score[i]>=pMinSurprised) nbSurprised++; } if(nbSurprised>S) googlers+=S; else googlers+=nbSurprised; int z = zz+1; answers[zz]="Case #"+z+": "+googlers+"\n"; } } catch (FileNotFoundException e) { e.printStackTrace(); } try { PrintWriter pw = new PrintWriter(out); for(int i=0;i<answers.length;i++) pw.println(answers[i]); pw.close(); } catch (Exception e){ System.out.println(e.toString()); } } }
0
480
A12852
A12865
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 qualr2012.problemB; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.Collections; import java.util.LinkedList; import java.util.TreeSet; import java.util.logging.Logger; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.ArrayUtils; import org.springframework.util.Assert; public class DancingWithGooglers { static Logger log = Logger.getLogger(DancingWithGooglers.class.getName()); final static String inputFileName = "B-small-attempt1.in"; final static String outputFileName = "B-small-attempt1.out"; public static void main(String[] args) throws IOException { String pkgName = DancingWithGooglers.class.getPackage().getName().replaceAll("\\.", "/"); String inputFile = "src/main/java/" + pkgName + "/" + inputFileName; String outputFile = "target/" + pkgName + "/" + outputFileName; FileUtils.forceMkdir(new File("target/" + pkgName)); BufferedReader reader = new BufferedReader(new FileReader(inputFile)); PrintWriter writer = new PrintWriter(outputFile); int numCase = Integer.parseInt(reader.readLine()); int i, j; String[] str; int[] maxNoSurprise = new int [31]; int[] maxSurprise = new int [31]; for (i = 0; i < 31; ++i) { maxNoSurprise[i] = (int)Math.ceil(i/3.0); maxSurprise[i] = (int)Math.ceil(i/3.0 + 0.5); } maxSurprise[0] = 0; for(int _case = 1; _case <= numCase; ++_case) { LinkedList<Integer> t_LL = new LinkedList<Integer>(); Integer[] t = null; str = reader.readLine().split(" "); int N, S, p; N = Integer.parseInt(str[0]); S = Integer.parseInt(str[1]); p = Integer.parseInt(str[2]); for (i = 3; i < str.length; ++i) { t_LL.add(Integer.parseInt(str[i])); } Collections.sort(t_LL); t = t_LL.toArray(new Integer[0]); Assert.isTrue(t.length == N); // move i to the first no-surprise triplet which has max score >= p for (i = 0; i < t.length; ++i) { if (maxNoSurprise[t[i]] >= p) { break; } } // for each available S, use it to maximize the number of Googlers to the left of i for (; i >= 1 && S > 0 && maxSurprise[t[i-1]] >= p; i--, S--) { } int answer = t.length - i; log.info(answer+""); writer.println("Case #" + _case + ": " + answer); } reader.close(); writer.close(); } }
0
481
A12852
A10038
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.FileReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; public class DancingWithGooglers1 extends Thread{ //private static int rating[] = {0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,8,8,8,9,9,9,10,10,10}; private static int totalJudge = 3; /** * @param args */ public static void main(String[] args) throws Exception{ new DancingWithGooglers1().parseFile(); } public void parseFile() throws Exception { File file = null; FileReader reader = null; BufferedReader br = null; File outFile = null; PrintWriter prntWriter = null; try { file = new File("B-small-attempt2.in"); reader = new FileReader(file); br = new BufferedReader(reader); outFile = new File("B-small-attempt2.out"); prntWriter = new PrintWriter(outFile); String str = ""; int liTotalCases = 0; if((str = br.readLine())!=null) { liTotalCases = Integer.parseInt(str); //System.out.println('liTotalCases::: '+liTotalCases); for(int i=0;i<liTotalCases;i++) { //System.out.println('---------------------Start--------------------------------'); int noOfGooglerWithBest = 0; String line = br.readLine(); String[] strArr = line.split(" "); int totalGooglers = Integer.valueOf(strArr[0]); int totalSurprise = Integer.valueOf(strArr[1]); int bestResult = Integer.valueOf(strArr[2]); List<List<RatingSet>> finalRat = new ArrayList<List<RatingSet>>(); for(int j=3;j<totalGooglers+3;j++) { // System.out.print(strArr[j]+" "); List<RatingSet> rsSet = isGooglerWithBestResult(Integer.valueOf(strArr[j]), bestResult,totalSurprise); System.out.println(rsSet); finalRat.add(rsSet); } System.out.println("final: "+finalRat); List<List<RatingSet>> orderedSet = new ArrayList<List<RatingSet>>(); for(List<RatingSet> res:finalRat){ if(totalMax(res, bestResult)==res.size()) { noOfGooglerWithBest++; } else { orderedSet.add(res); } } System.out.println("orderedSet:: "+orderedSet); for(List<RatingSet> remainingSet:orderedSet){ for(RatingSet rs:remainingSet){ if(totalSurprise>0 && rs.isSurprisingCondition() && rs.isHavingBestScore(bestResult)) { noOfGooglerWithBest++; totalSurprise--; break; } else { } } } System.out.println("Case #"+ (i+1) + ": "+ noOfGooglerWithBest); prntWriter.write("Case #"+ (i+1) + ": "+ noOfGooglerWithBest +"\n"); prntWriter.flush(); //System.out.println('-------------------End----------------------------------'); } } } catch (Exception e) { e.printStackTrace(); } finally{ if(reader!=null) reader.close(); if(br!=null) br.close(); if(prntWriter!=null) prntWriter.close(); } } private int totalMax(List<RatingSet> res,int bestScore){ int totalBest = 0; for(RatingSet r:res) { if(r.isHavingBestScore(bestScore)){ totalBest++; } } System.out.println(totalBest); return totalBest; } public List<RatingSet> isGooglerWithBestResult(int totalScore, int bestResult,int totalSurprise) { System.out.println("totalScore: "+totalScore); int n = totalScore/totalJudge; ArrayList<Integer> set = new ArrayList<Integer>(); for(int i=-2;i<=2;i++){ if(n-i>=0 && n-i<=10) set.add(n-i); } List<RatingSet> rsSet = findPosibleSubSets(set, bestResult, totalScore, totalSurprise); return rsSet; } private List<RatingSet> findPosibleSubSets(ArrayList<Integer> set,int bestResult,int totalScore,int totalSurprise){ List<RatingSet> allSetList = new ArrayList<RatingSet>(); List<RatingSet> rattingSet = getListOfRatingSet(set); for(RatingSet rs:rattingSet) { if(rs.getTotal()==totalScore && rs.isValidRating()){ allSetList.add(rs); } } return allSetList; } private List<RatingSet> getListOfRatingSet(ArrayList<Integer> set){ List<RatingSet> rattingSet= new ArrayList<RatingSet>(); for(int i=0;i<set.size();i++){ for(int j=i;j<set.size();j++) { for(int k=j;k<set.size();k++) { rattingSet.add(new RatingSet(set.get(i), set.get(j), set.get(k))); } } } return rattingSet; } } class RatingSet { int r1; int r2; int r3; public RatingSet(int r1,int r2,int r3) { this.r1 = r1; this.r2 = r2; this.r3 = r3; } public int getTotal(){ return r1+r2+r3; } public boolean isHavingBestScore(int bestScore){ if(r1>=bestScore) { return true; } else if(r2>=bestScore) { return true; } else if(r3>=bestScore) { return true; } else { return false; } } public boolean isSurprisingCondition() { if(maxRating()-minRating()==2){ return true; } else { return false; } } @Override public String toString() { return "{" + r1 + "," + r2 + "," + r3 + "}"; } public int minRating(){ int min = r1; if(r2<min) { min = r2; } if(r3<min){ min = r3; } return min; } public int maxRating(){ int max = r1; if(r2>max) { max = r2; } if(r3>max){ max = r3; } return max; } public boolean isValidRating(){ return (maxRating()-minRating()<=2)?true:false; } }
0
482
A12852
A12175
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 hk.polyu.cslhu.codejam.solution; import java.util.List; import org.apache.log4j.Logger; public abstract class Solution implements Cloneable { public static Logger logger = Logger.getLogger(Solution.class); protected String result; /** * Set the problem to be solved * * @param problemDesc List<String> The description of problem */ public abstract void setProblem(List<String> problemDesc); /** * Solve the problem */ public abstract void solve(); /** * Return the result of problem * * @return String Result */ public String getResult() { return this.result; } public Solution clone() throws CloneNotSupportedException { return (Solution) super.clone(); } }
0
483
A12852
A13236
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 jam; import java.util.Scanner; public class Main_B { static int[] results; public static void main(String[] args) { Scanner scan = new Scanner(System.in); int tests = Integer.valueOf(scan.nextLine()); results = new int[tests]; int c = 0; while(c < tests) { solve(scan.nextLine(), c); c++; } //print results System.out.println("Output"); for (int i = 0; i < results.length; i++) { System.out.println("Case #" + (i+1) + ": " + results[i]); } } //N S P {numbers separated by spaces} public static void solve(String s, int on) { String[] parts = s.split(" "); //int num = Integer.valueOf(parts[0]); int surp = Integer.valueOf(parts[1]); int max = Integer.valueOf(parts[2]); int high = 3*max - 2; int high_w_surp = 3*max - 4; int[] vals = gather(parts); int num_pep = 0; for (int i = 0; i < vals.length; i++) { if(vals[i] >= Math.max(high, max)) { num_pep++; } else if(vals[i] >= Math.max(high_w_surp, max) && surp > 0) { surp--; num_pep++; } } results[on] = num_pep; } public static int[] gather(String[] vals) { int[] nums = new int[vals.length-3]; for (int i = 0; i < nums.length; i++) { nums[i] = Integer.valueOf(vals[i+3]); } return nums; } }
0
484
A12852
A12506
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.Scanner; public class MaxBestResult { public static void main(String[] args) throws FileNotFoundException { File input = new File("B-small-attempt0.in"); Scanner data = new Scanner(input); PrintStream output = new PrintStream(new File("B-small-attempt0.out")); int times = data.nextInt(); for(int i = 1; i <= times; i++){ String text = data.next() + data.nextLine(); Scanner line = new Scanner(text); Round temp = new Round(line); output.println("Case #" + i + ": " + temp.calculate()); } } }
0
485
A12852
A10895
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 codejam.y11.round0.CandySplitting; import codejam.y12.round0.DancingGooglers; import codejam.y12.round0.SpeakingInTongues; import utils.Jam; /** * * @author Fabien Renaud */ public class MainEntryPoint { public static void main(String[] args) { Jam j = new DancingGooglers("/home/fabien/B-small-attempt0.in"); j.run(); } }
0
486
A12852
A10892
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 utils; /** * * @author fabien */ public interface JamCaseSolver { public void parse(); public void solve(); }
0
487
A12852
A11473
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.io.PrintWriter; import java.util.StringTokenizer; public class Googlers { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt1.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("B-small-attempt1.out"))); int T = Integer.parseInt(in.readLine()); for (int q = 1; q <= T; q++) { StringTokenizer st = new StringTokenizer(in.readLine()); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int P = Integer.parseInt(st.nextToken()); int SurCount = 0; int[] sum = new int[N]; int res = 0; for (int i = 0; i < sum.length; i++) { sum[i] = Integer.parseInt(st.nextToken()); if (sum[i] >= 2 && (sum[i] + 1) % 3 == 0 && (sum[i] + 1) / 3 >= P) { res++; } else if (sum[i] >= 1 && (sum[i] + 2) % 3 == 0 && (sum[i] + 2) / 3 >= P) { res++; } else if (sum[i] % 3 == 0) { if (sum[i] / 3 >= P) { res++; } else if (sum[i] >= 3 && SurCount < S && (sum[i] + 3) / 3 >= P) { res++; SurCount++; } } else if (sum[i] >= 2 && (sum[i] + 4) % 3 == 0 && SurCount < S && (sum[i] + 4) / 3 >= P) { res++; SurCount++; } // System.out.println(i + " : " + res + " : " + SurCount); } out.write("Case #" + q + ": " + res + "\n"); // System.out.println("BE"); } out.close(); } }
0
488
A12852
A12060
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.math.*; public class Dance { public void cal(String filename) throws NumberFormatException, IOException { BufferedReader in = new BufferedReader(new FileReader(filename)); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("bar.txt"))); int count = 1; String s = in.readLine(); int all = Integer.parseInt(s); while((s = in.readLine()) != null) { int result = 0; if(count > all) break; String[] elements = s.split(" "); int dancer_num = Integer.parseInt(elements[0]); int surprise_num = Integer.parseInt(elements[1]); int least = Integer.parseInt(elements[2]); for(int i = 0; i < dancer_num; i++) { if( 3 + i >= elements.length) break; int data = Integer.parseInt(elements[3 + i]); if(data <= 30 && data>=0) { if(data / 3 >= least) result = result + 1; else { int second = (data - least) / 2; int third = data - second - least; if(Math.abs(least - second) <= 1 &&Math.abs(least - third) <= 1) { if(second >= 0 && third >= 0) result = result + 1; } else if(Math.abs(least - second) <= 2 &&Math.abs(least - third) <= 2) { if(surprise_num > 0 && second >= 0 && third >= 0) { result = result + 1; surprise_num = surprise_num - 1; } } else {} } } } out.println("Case #" + count +": " + result); count = count + 1; } out.close(); } public static void main(String[] args) throws NumberFormatException, IOException { Dance d = new Dance(); d.cal("B-small-attempt0.in"); } }
0
489
A12852
A11756
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; /** * */ /** * @author Bryan * */ public class problemB { /** * @param args */ public static void main(String[] args) { String filePath = "/Users/Bryan/Documents/CodeJam/ProblemB/B-small-attempt0.in"; boolean isFirstLine = true; int counter = 1; StringBuffer resultString = new StringBuffer(); try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(filePath); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By Line while ((strLine = br.readLine()) != null) { if (isFirstLine){ isFirstLine = false; continue; } int maxNoGoogler = 0; resultString.append("Case #" + counter + ": "); String[] numberList = strLine.split(" "); int noOfGoogler = Integer.parseInt(numberList[0]); int noOfSuprise = Integer.parseInt(numberList[1]); int individualTarget = Integer.parseInt(numberList[2]); // ArrayList<Integer> totalScoreList = new ArrayList<Integer>(); for ( int a = 3; a < numberList.length; a++){ // totalScoreList.add(Integer.parseInt(numberList[a])); if ( Integer.parseInt(numberList[a]) >= miniTotal(noOfGoogler, individualTarget) ){ maxNoGoogler++; }else if ( noOfSuprise > 0 && Integer.parseInt(numberList[a]) >= miniTotalWithSuprise(noOfGoogler, individualTarget) ){ noOfSuprise--; maxNoGoogler++; } } resultString.append(maxNoGoogler); resultString.append("\n"); counter++; } // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } writeStringToFile(resultString.toString()); } private static int miniTotalWithSuprise(int noOfGoogler, int individualTarget){ int min = (3 * individualTarget) - (2 * (3 - 1)); if ( min < individualTarget){ return individualTarget; } return min; } private static int miniTotal(int noOfGoogler, int individualTarget){ int min = (3 * individualTarget) - (3 - 1); if ( min < individualTarget){ return individualTarget; } return min; } private static void writeStringToFile(String outputString) { try { // Create file FileWriter fstream = new FileWriter("/Users/Bryan/Documents/CodeJam/ProblemB/output.txt"); BufferedWriter out = new BufferedWriter(fstream); out.write(outputString); // Close the output stream out.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
490
A12852
A11641
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.StringTokenizer; /** * Created by IntelliJ IDEA. * User: marcus * Date: 4/13/12 * Time: 8:18 PM * To change this template use File | Settings | File Templates. */ public class DancingGooglers { public static void main(String a[]) throws IOException { int T = 0; FileInputStream fInputstream = null; try { fInputstream = new FileInputStream("B-small.in"); } catch (FileNotFoundException e) { //e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } DataInputStream in = new DataInputStream(fInputstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; FileWriter fstream = new FileWriter("B-small.out"); BufferedWriter out = new BufferedWriter(fstream); String strT = null; strT = br.readLine(); T = Integer.parseInt(strT); for(int i = 1; i <= T; i++) { String testCase = br.readLine(); StringTokenizer st = new StringTokenizer(testCase, " "); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); //System.out.println("Number of Googlers: " + N); //System.out.println("Number of Surprises: " + S); //System.out.println("Great to have: " + p); int result = 0; int [] markSheet = new int[N]; for(int j = 0; j < N; j++){ markSheet[j] = Integer.parseInt(st.nextToken()); } for (int k = 0; k < N; k++){ int minValue = p > 1 ? ((p -1) * 3): p; //System.out.println("Min Value : " + minValue); if(markSheet[k] >= p ){ if(p == 0 && markSheet[k] >= 0){ // m = 0 result++; } else if(markSheet[k] > p && p <= 1){ // m = 1, 2 result++; }else if(markSheet[k] > ((p -1) * 3)){ result++; } else if(S > 0){ if(markSheet[k] == ((p -1) * 3)){ result++; S--; } else { int rem = markSheet[k] % 3; int val = markSheet[k] / 3; if(rem > 1){ if((val + 2) >= p){ result++; S--; } } else { if((val + 1) >= p){ result++; S--; } } } } } } System.out.println("Case #" + i + ": " + result); System.out.println("S: " + S); out.write("Case #" + i + ": " + result + "\n"); } in.close(); out.close(); } }
0
491
A12852
A10491
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.IOException; import java.util.Scanner; public class QuestionB { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { File fileread = new File("B-small-attempt2.in.txt"); File filewrite = new File(QuestionB.class.getName() + "output4.txt"); GCIFileReader fr = new GCIFileReader(fileread); GCIFileWriter fw = new GCIFileWriter(filewrite); GCIResult res = new GCIResult(); String s = fr.getLine(); int n = Integer.parseInt(s); for (int i=0; i < n ; i++) { String l = fr.getLine(); Scanner sc = new Scanner(l); int con = sc.nextInt(); int spe = sc.nextInt(); int p = sc.nextInt(); int countOk = 0; int countOKSpe = 0; for (int j = 0 ; j < con ; j++) { int acon = sc.nextInt(); if (acon >= p) { if ((acon / 3.0) >= (p)) { countOk++; continue; } if (Double.compare((acon / 3.0),(Math.abs(p - 0.7))) >= 0) { countOk++; continue; } if (Double.compare((acon / 3.0),(Math.abs(p - 2 + 0.5 ))) >=0 ) { countOKSpe++; continue; } } } int finalOkSpe = countOKSpe > spe ? spe : countOKSpe; int tres = countOk + finalOkSpe; res.addCase(String.valueOf(tres)); } fw.writeResult(res); } }
0
492
A12852
A12351
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.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class B { private int n, p, a[], memo[][]; private void work() throws IOException { Scanner sc = new Scanner(new FileReader("B-small-attempt2.in")); PrintWriter pw = new PrintWriter(new FileWriter("B-small-attempt2.out")); a = new int[200]; memo = new int[200][200]; int nc = sc.nextInt(); for (int tc = 1; tc <= nc; tc++) { pw.printf("Case #%d: ", tc); n = sc.nextInt(); int s = sc.nextInt(); p = sc.nextInt(); for (int i = 0; i < n; i++) { a[i] = sc.nextInt(); Arrays.fill(memo[i], Integer.MIN_VALUE); } int res = go(0, s); if (res < 0) res = 0; pw.printf("%d\n", res); } pw.close(); } private int go(int pos, int s) { if (pos == n) return s == 0 ? 0 : -200; if (memo[pos][s] > Integer.MIN_VALUE) return memo[pos][s]; int k = a[pos] / 3; int m = a[pos] % 3; int max = k; if (m > 0) max++; int maxs = k + 1; if (m == 2) maxs++; int ret = (max >= p ? 1 : 0) + go(pos + 1, s); if (s > 0 && (k > 0 || m == 2)) { int t = (maxs >= p ? 1 : 0) + go(pos + 1, s - 1); if (t > ret) ret = t; } return memo[pos][s] = ret; } public static void main(String[] args) throws IOException { new B().work(); } }
0
493
A12852
A12967
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.List; public class ListUtils { public static String pureList(List<?> list) { StringBuilder builder = new StringBuilder(); for (Object elem : list) { builder.append(" " + elem); } return builder.substring(1).toString(); } }
0
494
A12852
A12024
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.awt.geom.*; import java.io.*; import java.math.*; import java.util.*; import java.util.regex.*; import static java.lang.Math.*; public class Main { public Main() throws IOException { String input; int t; input = br.readLine(); t = Integer.valueOf(input); for (int i = 0; i < t; i++) { if (i > 0) sb.append("\r\n"); input = br.readLine(); work(input, i); } System.out.print(sb); } boolean isGood(int score, int P) { int max = score / 3; if ((score % 3) > 0) max++; if (max >= P) return true; return false; } boolean isSurprise(int score, int P) { int max = score / 3; if (((score % 3) == 0) && (max > 0)) max++; else max += score % 3; if (max >= P) return true; return false; } private void work(String input, int t) { //debug(input); int ret = 0; String[] inputArray = input.split(" "); int N = Integer.valueOf(inputArray[0]); int S = Integer.valueOf(inputArray[1]); int P = Integer.valueOf(inputArray[2]); for (int i = 3; i < N + 3; i++) { int score = Integer.valueOf(inputArray[i]); if (isGood(score, P)) { //debug("score:", score, " Good!!"); ret++; continue; } if (S == 0) continue; if (isSurprise(score, P)) { //debug("score:", score, " Surprise!!"); ret++; S--; } } sb.append("Case #"); sb.append(String.valueOf(t + 1)); sb.append(": "); sb.append(String.valueOf(ret)); } StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { new Main(); } public static void debug(Object... arr) { System.err.println(Arrays.deepToString(arr)); } }
0
495
A12852
A10516
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 static java.util.Arrays.sort; import java.io.*; import java.util.*; public class ProblemB { public static void main(String[] args) throws Throwable { Scanner in = new Scanner(new File("b.in")); PrintWriter out = new PrintWriter("b.out"); int testCount = Integer.parseInt(in.nextLine().trim()); for (int i = 0; i < testCount; i++) { out.print("Case #" + (i + 1) + ": "); solve(in, out); } out.close(); } static void solve(Scanner in, PrintWriter out) { int n = in.nextInt(); int m = in.nextInt(); int p = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } sort(a); int ans = 0; for (int i = n - 1; i >= 0; i--) { int z = (a[i] + 2) / 3; if (z >= p) { ++ans; continue; } if (p >= 2 && z == p - 1 && a[i] % 3 != 1 && m > 0) { --m; ++ans; } else { break; } } out.println(ans); } }
0
496
A12852
A12302
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.ArrayList; import java.io.*; import java.util.Scanner; public class Dance { public static int lowScore(int a) { return a/3; } public static int mediumScore(int a) { if (a%3==0) return a/3; else return a/3 + 1; } public static int surprisingScore(int a) { if (a == 0) return 0; if (a == 1) return 1; if (a == 2) return 2; if (a%3 == 0) return a/3 + 1; else return a/3+2; } public static int maxAbove(ArrayList<Integer> l, int S, int p) { int aboveP = 0; for (Integer a : l) { if (lowScore(a) >= p) { aboveP++; //System.out.println(a + "low"); } else if (mediumScore(a) >= p) { aboveP++; //System.out.println(a + "med"); } else if (surprisingScore(a) >= p && S > 0) { aboveP++; S--; //System.out.println(a+"surprise"); } } return aboveP; } public static void main(String[] args) throws Exception{ /*ArrayList<Integer> l = new ArrayList<Integer>(); l.add(29); l.add(20); l.add(8); l.add(18); l.add(18); l.add(21); System.out.println(maxAbove(l, 2, 8));*/ Scanner in = new Scanner(new File(args[0])); int tests = in.nextInt(); for (int i = 1 ; i <= tests; i++) { int googlers = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); ArrayList<Integer> nums = new ArrayList<Integer>(); for (int j = 0; j < googlers; j ++ ) { nums.add(in.nextInt()); } System.out.println("Case #" + i + ": " + maxAbove(nums, S, p)); } //int[] m = new int[] {15} } }
0
497
A12852
A13237
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 B { public B(Scanner in, PrintWriter out) { int T = in.nextInt(); in.nextLine(); for (int t=0; t<T; t++) { int N = in.nextInt(); int S = in.nextInt(); int P = in.nextInt(); int[] vals = new int[31]; for (int i=0; i<N; i++) vals[in.nextInt()]++; int ans = 0; for (int d=0; d<=2; d++) for (int a=0; a<=10; a++) for (int b=Math.max(a-d,0); b<=a; b++) for (int c=Math.max(a-d,0); c<=a; c++) { if (d < 2 && a >= P) { ans+=vals[a+b+c]; vals[a+b+c]=0; } else if (a >= P) { int tmp = Math.min(vals[a+b+c], S); S -= tmp; ans += tmp; vals[a+b+c] -= tmp; } } out.printf("Case #%d: %d\n",t+1,ans); } out.close(); } public static void main(String[] args) throws FileNotFoundException { new B(new Scanner(new File("b.in")),new PrintWriter(new File("b.out"))); } }
0
498
A12852
A10784
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.FileReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class ProblemB { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new FileReader(new File("B-small-attempt4.in"))); PrintWriter pw = new PrintWriter(new File("B-small-attempt4.out")); int n, s,p, count, temp; int t= new Integer(br.readLine()); for(int c=1; c<=t; c++) { pw.append("Case #"+c+": "); StringTokenizer st = new StringTokenizer(br.readLine()); n = new Integer(st.nextToken()); s= new Integer(st.nextToken()); p = new Integer(st.nextToken()); count=0; if(p==0) count=n; else for(int i=0; i< n ; i++) { temp= new Integer(st.nextToken()); if(temp< p ) continue; temp = (temp-p)/2; if(temp >=p-1) count++; else if (temp>=p-2 && s>0 && p>1) { count++; s--; } } pw.append(count+""); pw.append('\n'); } pw.flush(); pw.close(); br.close(); } }
0
499