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
A10134
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 qualifying; import java.util.*; public class DancingWithGooglers { public static void main(String[] args) { Scanner in = new Scanner(System.in); final int T = in.nextInt(); for (int testCase = 1; testCase <= T; ++testCase) { // initialize parameters int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int[] t = new int[N]; for (int i = 0; i < N; ++i) t[i] = in.nextInt(); Arrays.sort(t); // make as many people as possible >= p int overCount = 0; for (int i = N - 1; i >=0; --i) { int disagree = minDisagreement(t[i], p); if (disagree > 2) { break; } else if (disagree == 2 && S == 0) { break; } else if (disagree == 2) { --S; } ++overCount; } assert (S == 0); System.out.printf("Case #%d: %d\n", testCase, overCount); } } private static int minDisagreement(int total, int minHighScore) { if (total >= 3 * minHighScore) return 0; else if (total < minHighScore) return Integer.MAX_VALUE; //i.e. impossible else return minHighScore - (total - minHighScore)/2; } }
0
300
A12852
A12504
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; /** * * @author Rashmika */ public class Main { public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); int numLines = 0, i=0; String str = ""; String[] testRounds = new String[1]; while ((str = in.readLine()) != null && str.length() != 0) { if(numLines!=0){ testRounds[i++] = str; }else{ numLines = Integer.parseInt(str); testRounds = new String[numLines]; } } for(int j=0; j<numLines-1; j++){ output("Case #"+(j+1)+": "+getWinners(testRounds[j]) +"\n"); } output("Case #"+(numLines)+": "+getWinners(testRounds[numLines-1])); } catch (IOException e) { } //System.out.println(""+getWinners("2 1 1 8 0")); } public static void output(String line){ try{ FileWriter fstream = new FileWriter("dancing.out",true); BufferedWriter out = new BufferedWriter(fstream); out.write(line); out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } public static int getWinners(String line){ String[] temp = line.split(" "); int N = Integer.parseInt(temp[0]); int S = Integer.parseInt(temp[1]); int P = Integer.parseInt(temp[2]); int player[] = new int[N]; for(int i=0; i<N; i++){ player[i] = Integer.parseInt(temp[3+i]); } int winnerCount = 0; //for a single round int total; int n1; for(int i=0; i<N; i++){ total = player[i]; if(total==0){ if(P<=0){ winnerCount++; //System.out.println("Counted "+i); continue; } }else if(total%3==0){ n1 = total/3; //System.out.println(i+":"+n1+" "+total); if( (n1>=P) ){ //System.out.println("Counted "+i); winnerCount++; continue; }else if( (S>0) && ((n1+1)>=P) ){ //System.out.println("Counted "+i); winnerCount++; S--; continue; } }else if(total%3==1){ n1 = total/3 + 1; //System.out.println(i+":"+n1+" "+total); if( (n1>=P) ){ //System.out.println("Counted "+i); winnerCount++; continue; } }else if(total%3==2){ n1 = total/3 + 1; //System.out.println(i+":"+n1+" "+total); if( (n1>=P) ){ //System.out.println("Counted simile"+i); winnerCount++; continue; }else if( (S>0) && ((n1+1)>=P) ){ //System.out.println("Counted "+i); winnerCount++; S--; continue; } } } return winnerCount; } }
0
301
A12852
A11093
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.Scanner; class Solution { private final String FILE_IN = "B-small-attempt0.in"; private final String FILE_OUT = "B-small-attempt0.out"; private final Scanner mScanner; private final PrintWriter mOut; private final boolean perm[] = new boolean[101]; public Solution() throws FileNotFoundException { mScanner = new Scanner(new FileInputStream(FILE_IN)); mOut = new PrintWriter(new FileOutputStream(FILE_OUT)); } public void closeFiles() { mScanner.close(); mOut.close(); } static private boolean canHaveP(int summ, int p, boolean s) { int modulo = summ % 3; int div = summ / 3; if (modulo == 0) { return div + ((s) ? ((summ >= 1) ? 1 : 0) : 0) >= p; } if (modulo == 1) { return div + ((summ >= 1) ? 1 : 0) >= p; } else { int max = div; if (s && summ >= 2) { max += 2; } else if (summ >= 1) { max += 1; } return max >= p; } } private boolean nextPerm(int n) { int trues = 0; for (int i = 0; i < n - 1; i++) { if (!perm[i]) { continue; } if (!perm[i + 1]) { perm[i + 1] = true; for (int j = 0; j <= i; j++) { perm[j] = j < trues; } return true; } else { trues++; } } return false; } void solve(int caseId, int n, int s, int p, int[] ti) { for (int i = 0; i < n + 1; i++) { perm[i] = i < s; } int maxSurprises = 0; do { int surprises = 0; for (int i = 0; i < n; i++) { if (canHaveP(ti[i], p, perm[i])) { surprises++; } } if (surprises > maxSurprises) { maxSurprises = surprises; } } while (nextPerm(n)); mOut.println("Case #" + (caseId + 1) + ": " + maxSurprises); } Solution run() { int t = mScanner.nextInt(); mScanner.nextLine(); int[] ti = new int[100]; for (int i = 0; i < t; i++) { int n = mScanner.nextInt(); int s = mScanner.nextInt(); int p = mScanner.nextInt(); for (int j = 0; j < n; j++) { ti[j] = mScanner.nextInt(); } if (mScanner.hasNext()) { mScanner.nextLine(); } solve(i, n, s, p, ti); } return this; } } public class Main { public static void main(String[] args) throws FileNotFoundException { new Solution().run().closeFiles(); } }
0
302
A12852
A11909
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 dancing; import java.io.*; import java.util.*; /** * * @author Ewka */ public class Dancing { /** * @param args the command line arguments */ public static void main(String[] args) { FileReader fr=null; PrintWriter fw=null; BufferedReader br; int noOfLines=0; int noOfGooglers=0; int noOfSurprising=0; int noOfOut=0; int p=0; int noOfUsedSurp=0; String[] temp; try { fw = new PrintWriter ("outputDancing.txt"); } catch(Exception e) { System.out.print("nie udalo sie"); } try { fr = new FileReader("B-small-attempt1.txt"); } catch(FileNotFoundException e) { System.out.println(e.getMessage()); } br = new BufferedReader(fr); String s; try{ s=br.readLine(); noOfLines = Integer.parseInt(s); for (int i=0;i<noOfLines;i++) { System.out.print("Case #"+(i+1)+": "); fw.print("Case #"+(i+1)+": "); noOfOut = 0; noOfUsedSurp=0; s=br.readLine(); temp = s.split(" "); noOfGooglers = Integer.parseInt(temp[0]); int[] Scores = new int[noOfGooglers]; noOfSurprising = Integer.parseInt(temp[1]); p = Integer.parseInt(temp[2]); for (int j=0;j<noOfGooglers;j++) { Scores[j] = Integer.parseInt(temp[j+3]); } Arrays.sort(Scores); for (int j=0;j<noOfGooglers;j++) { if (Scores[j]/3 >= p) { noOfOut++; } else if (Scores[j] > p) { if ((p+(p-1)+(p-1) == Scores[j]) || (p+(p)+(p-1) == Scores[j])) { noOfOut++; } else if (noOfUsedSurp < noOfSurprising) { if ((p+(p-2)+(p-2) == Scores[j]) || (p+(p-2)+(p-1) == Scores[j])) { noOfOut++; noOfUsedSurp++; } } } } System.out.println(noOfOut); fw.print(noOfOut); fw.println(); } fr.close(); fw.close(); } catch(Exception e) { } } }
0
303
A12852
A12033
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; import java.math.BigDecimal; /** * Utility for BigDeciaml */ public class BD { public static BigDecimal ZERO = BigDecimal.ZERO; public static BigDecimal ONE = BigDecimal.ONE; public static BigDecimal add( final BigDecimal x , final BigDecimal y ) { return x.add( y ); } public static BigDecimal add( final BigDecimal x , final double y ) { return add( x , v( y ) ); } public static BigDecimal add( final double x , final BigDecimal y ) { return add( v( x ) , y ); } public static int cmp( final BigDecimal x , final BigDecimal y ) { return x.compareTo( y ); } public static int cmp( final BigDecimal x , final double y ) { return cmp( x , v( y ) ); } public static int cmp( final double x , final BigDecimal y ) { return cmp( v( x ) , y ); } public static BigDecimal div( final BigDecimal x , final BigDecimal y ) { return x.divide( y ); } public static BigDecimal div( final BigDecimal x , final double y ) { return div( x , v( y ) ); } public static BigDecimal div( final double x , final BigDecimal y ) { return div( v( x ) , y ); } public static BigDecimal mul( final BigDecimal x , final BigDecimal y ) { return x.multiply( y ); } public static BigDecimal mul( final BigDecimal x , final double y ) { return mul( x , v( y ) ); } public static BigDecimal mul( final double x , final BigDecimal y ) { return mul( v( x ) , y ); } public static BigDecimal sub( final BigDecimal x , final BigDecimal y ) { return x.subtract( y ); } public static BigDecimal sub( final BigDecimal x , final double y ) { return sub( x , v( y ) ); } public static BigDecimal sub( final double x , final BigDecimal y ) { return sub( v( x ) , y ); } public static BigDecimal v( final double value ) { return BigDecimal.valueOf( value ); } }
0
304
A12852
A10845
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; import java.util.Scanner; public class Main { public static void main (String[] args) throws IOException { Writer writer = new FileWriter("/home/a/dev/codejam-2012/B-submit.txt"); Scanner scanner = new Scanner(new File("/home/a/dev/codejam-2012/A-dev.txt")); int n_cases = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < n_cases; ++i) { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int [] scores = new int[N]; for (int j = 0; j < scores.length; ++j) { scores[j] = scanner.nextInt(); } Main main = new Main(); writer.write("Case #" + (i + 1) + ": " + main.solve(S, p, scores) + "\n"); } writer.close(); } public int solve (int S, int p, int [] scores) { int count = 0; for (int score : scores) { int mod = score % 3; int max; if (mod == 0) { max = score / 3; if (max >= p) { ++count; continue; } if (score < 3) { continue; } if (max < p - 1) { continue; } if (S > 0) { --S; ++count; continue; } } else if (mod == 1) { max = (score - 1) / 3 + 1; if (max >= p) { ++count; continue; } continue; } else if (mod == 2) { max = (score - 2) / 3 + 1; if (max >= p) { ++count; continue; } if (max < p - 1) { continue; } if (S > 0) { --S; ++count; continue; } } } return count; } }
0
305
A12852
A12017
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; import java.io.InputStream; public class Input { static final int BUFFER_SIZE = 65535; static final int STRING_SIZE = 1024; InputStream in; byte[] buffer; byte[] strBuffer; int pos; public Input(InputStream in) { this.in = in; this.buffer = new byte[BUFFER_SIZE]; this.strBuffer = new byte[STRING_SIZE]; this.pos = BUFFER_SIZE; } void skipWhitespace() throws IOException { byte b; do { b = readByte(); } while (b <= ' '); --pos; } public byte readByte() throws IOException { if (pos == BUFFER_SIZE) { in.read(buffer); pos = 0; } return buffer[pos++]; } public int readInt() throws IOException { skipWhitespace(); int number = 0; int digit = readByte(); int sign = 1; if (digit == '-') { sign = -1; } else { number = digit - '0'; } digit = readByte(); while (digit >= '0') { number *= 10; number += digit - '0'; digit = readByte(); } return sign * number; } public long readLong() throws IOException { skipWhitespace(); long number = 0; int digit = readByte(); int sign = 1; if (digit == '-') { sign = -1; } else { number = digit - '0'; } digit = readByte(); while (digit >= '0') { number *= 10; number += digit - '0'; digit = readByte(); } return sign * number; } public double readDouble() throws IOException { skipWhitespace(); double number = 0; int digit = readByte(); double sign = 1; if (digit == '-') { sign = -1; } else { number = digit - '0'; } digit = readByte(); while (digit >= '0') { number *= 10; number += digit - '0'; digit = readByte(); } if (digit == '.' || digit == ',') { digit = readByte(); double remainder = 0; int depth = 0; while (digit >= '0') { remainder *= 10; remainder += digit - '0'; depth++; digit = readByte(); } if (depth == 1) { number += remainder / 10; } else { number += remainder / (Math.pow(10, depth)); } } return sign * number; } public String readString() throws IOException { skipWhitespace(); int length = 0; do { strBuffer[length++] = readByte(); } while (strBuffer[length - 1] > ' '); return new String(strBuffer, 0, length - 1); } }
0
306
A12852
A10782
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class DanceGoogle { public static void main( String[] args ) throws IOException { File fileOut = new File( "B-small-attempt4.out" ); BufferedWriter writer = new BufferedWriter( new FileWriter(fileOut) ); Scanner sc = new Scanner( new File ( "B-small-attempt4.in" ) ); int count = 0; int number = sc.nextInt(); int caseNumber = number; for ( int caseNumberIndex = 0; caseNumberIndex < caseNumber; caseNumberIndex++ ) { int numberOfDancer = sc.nextInt(); int numberOfSuprise = sc.nextInt(); int bestScore = sc.nextInt(); int compare = ( bestScore * 3 ) - 2; for ( int dancerIndex = 0; dancerIndex < numberOfDancer; dancerIndex++ ) { number = sc.nextInt(); if ( ( number > 28 ) || ( number < 2 ) ) { if ( number > 28 ) count++; else if( (number > 0) && (bestScore == 1) ) count++; } else if ( number < compare ) { if ( number >= (compare - 2 ) ) { if ( numberOfSuprise > 0 ) { numberOfSuprise--; count++; } } } else count++; } if ( bestScore == 0 ) count = numberOfDancer; writeOutput( writer, count, caseNumberIndex ); count = 0; } writer.close(); sc.close(); } private static void writeOutput( BufferedWriter writer, int count, int caseNumber ) throws IOException { writer.append( "Case #" + (caseNumber+1) ); writer.append( ": " + count ); writer.append( "\r\n" ); } }
0
307
A12852
A12763
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 GoogleCount{ public GoogleCount(String line, int i, BufferedWriter out){ int count=0; try { // ArrayList<Goods> gooda = new ArrayList(); // TreeSet<Integer> goods = new TreeSet(); StringTokenizer token = new StringTokenizer(line); out.write("Case #"+Integer.toString(i)+": "); String str = null; Goods cur; int countS=0, countG=0; while (token.hasMoreTokens()){ str = token.nextToken(); int totG=Integer.parseInt(str); str = token.nextToken(); int totS=Integer.parseInt(str); str = token.nextToken(); int best=Integer.parseInt(str); int curr,temp; while (token.hasMoreTokens() && count<totG){ str = token.nextToken(); curr=Integer.parseInt(str); if(curr>=best){ if (curr-best>=((best-1)*2)){ countG++; } else if(curr-best>=((best-2)*2) && countS<totS){ countS++; countG++; } } count++; } } out.write(Integer.toString(countG)); System.out.print("\n"); out.write("\n"); } catch (IOException ex){ ex.printStackTrace(); } } }
0
308
A12852
A11498
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 template; import java.util.ArrayList; public class TestCaseSolver implements Runnable { private ArrayList<TestCase> testCases; private int ref; public TestCaseSolver(ArrayList<TestCase> tcs, int ref) { testCases = tcs; this.ref = ref; } public TestCaseSolver(TestCase tc, int ref) { ArrayList<TestCase> tcs = new ArrayList<>(); tcs.add(tc); testCases = tcs; this.ref = ref; } public int getRef() { return ref; } @Override public void run() { for (TestCase tc : testCases) { long startTime = System.nanoTime(); solve(tc); long duration = System.nanoTime() - startTime; double secs = (double)duration / (1000000000d); tc.setTime(secs); System.out.println("Thread " + ref + " solved testcase " + tc.getRef() + " in " + String.format("%.2f", secs) + " secs."); } } private void solve(TestCase tc) { ArrayList<Integer> totals = tc.getIntegerList("props"); int num = totals.remove(0); int surp = totals.remove(0); int p = totals.remove(0); if (num != totals.size()) {Utils.die("err count");} int deffo = 0; int maybe = 0; for (Integer i : totals) { if (i >= (3 * p - 2)) { deffo++; continue; } if (i >= (3 * p - 4) && i > 0) { maybe++; } } if (maybe > surp) {maybe = surp;} tc.setSolution(new Integer(deffo + maybe)); } }
0
309
A12852
A10043
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 Qual2012; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Qual2012B { public static void main(String args[]){ String filePath = "X:\\GCJ\\2012B-small-attempt0.in"; // String filePath = "X:\\GCJ\\2012B-large-attempt0.in"; FileInputStream fis = null; BufferedReader readFile = null; String line; try { fis = new FileInputStream(filePath); readFile = new BufferedReader(new InputStreamReader(fis, "ISO-8859-1")); line = readFile.readLine(); int T = Integer.parseInt(line); for (int i = 1; i <= T; i++) { line = readFile.readLine(); System.out.println("Case #" + i + ": " + solve(line) ); } } catch(Exception e) { e.printStackTrace(); }finally{ try { fis.close(); readFile.close(); } catch (IOException e) { e.printStackTrace(); } } } private static int solve (String line) { String[] temp = line.split(" "); int n = Integer.parseInt(temp[0]); int s = Integer.parseInt(temp[1]); int p = Integer.parseInt(temp[2]); int[] t = new int[n]; int ret = 0; for (int i = 0; i < n; i++) t[i] = Integer.parseInt(temp[i + 3]); for (int i = 0; i < n; i++) { int remainder = t[i] % 3; int max = (t[i] + 2) / 3; if (max >= p) { ret++; continue; } else if (remainder != 1 && t[i] > 0 && max + 1 >= p && s > 0) { ret++; s--; } } return ret; } }
0
310
A12852
A11952
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 gs.taral.gcj2012; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; public class Dancing { public static void main(String[] args) throws NumberFormatException, IOException { List<String> input = readInput(args[0]); List<String> output = solve(input); writeOutput(args[1], output); } private static String solveCase(String line) { String[] tokens = line.split(" "); int n = Integer.parseInt(tokens[0]); int s = Integer.parseInt(tokens[1]); int p = Integer.parseInt(tokens[2]); int[] t = new int[n]; for (int i = 3; i < tokens.length; i++) t[i - 3] = Integer.parseInt(tokens[i]); int definitely = 0; int possibly = 0; for (int score : t) { if (score >= 3 * p - 2) definitely++; else if (p > 1 && score >= 3 * p - 4 ) possibly++; } int result = definitely + Math.min(possibly, s); return String.valueOf(result); } private static List<String> solve(List<String> input) { List<String> output = new ArrayList<String>(); for (String line : input) output.add(solveCase(line)); return output; } private static List<String> readInput(String filename) throws FileNotFoundException, IOException { BufferedReader in = new BufferedReader(new FileReader(filename)); List<String> input = new ArrayList<String>(); int n = Integer.parseInt(in.readLine()); while (true) { String line = in.readLine(); if (line == null) break; input.add(line); } if (input.size() != n) throw new IllegalArgumentException(); return input; } private static void writeOutput(String filename, List<String> output) throws IOException { PrintWriter out = new PrintWriter(new FileWriter(filename)); for (int i = 0; i < output.size(); i++) { int caseNumber = i + 1; String line = output.get(i); out.println("Case #" + caseNumber + ": " + line); } out.close(); } }
0
311
A12852
A11040
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 fixjava; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import java.util.Map.Entry; public abstract class Filter<T> { abstract boolean accept(T item); public static <U> ArrayList<U> list(Iterable<U> collection, Filter<U> filter) { ArrayList<U> filtered = new ArrayList<U>(); for (U item : collection) if (filter.accept(item)) filtered.add(item); return filtered; } public static <U> HashSet<U> set(Set<U> set, Filter<U> filter) { HashSet<U> filtered = new HashSet<U>(); for (U item : set) if (filter.accept(item)) filtered.add(item); return filtered; } public static <K, V> HashMap<K, V> mapKeys(Map<K, V> map, Filter<K> keyFilter) { HashMap<K, V> filtered = new HashMap<K, V>(); for (Entry<K, V> ent : map.entrySet()) if (keyFilter.accept(ent.getKey())) filtered.put(ent.getKey(), ent.getValue()); return filtered; } public static <K, V> HashMap<K, V> mapValues(Map<K, V> map, Filter<V> valueFilter) { HashMap<K, V> filtered = new HashMap<K, V>(); for (Entry<K, V> ent : map.entrySet()) if (valueFilter.accept(ent.getValue())) filtered.put(ent.getKey(), ent.getValue()); return filtered; } }
0
312
A12852
A11383
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 gcj_qr_b; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.Scanner; /** * * @author amahdy */ public class GCJ_QR_B { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { new GCJ_QR_B().start(); } private void start() throws FileNotFoundException, IOException { Scanner in = new Scanner( new FileReader("/home/amahdy/b-small.in")); int x = in.nextInt(); in.nextLine(); for (int i = 0; i < x; ) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int[] t = new int[N]; for(int j=0; j<N; j++) { t[j] = in.nextInt(); } int max=0; for(int j=0; j<N; j++) { if(t[j]==0) { if(p==0) { max++; } continue; } int min = t[j]/3; int diff = t[j] - (3*min); switch (diff) { case 0: if(min>=p) { max++; }else if(min+1==p && S>0) { S--; max++; } break; case 1: if(min<10 && min+1>=p) { max++; } break; case 2: if(min<10 && min+1>=p) { max++; }else if(min<9 && min+2==p && S>0) { S--; max++; } break; } } System.out.println("Case #" + ++i + ": " + max); } } }
0
313
A12852
A12182
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; } }
/* ========================================================== * (C) Copyright 2007-present Facebook. All rights reserved. * ========================================================== */ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; /** * . * * @author */ public class Dancers { public static void main( String[] args ) throws NumberFormatException, IOException { final BufferedReader in = new BufferedReader( new FileReader( "/Users/oded/a/ttt/src/in.txt" ) ); final int numLines = Integer.parseInt( in.readLine() ); for( int i = 0; i < numLines; i++ ) { handleLine( in.readLine(), i ); } } private static void handleLine( String readLine, int lineNumber ) { String[] numbers = readLine.split( " " ); int n = Integer.parseInt( numbers[ 0 ] ); int s = Integer.parseInt( numbers[ 1 ] ); int p = Integer.parseInt( numbers[ 2 ] ); int results = 0; int thresholdNotS = p * 3 - 3 > 0 ? p * 3 - 3 : 0; int thresholdS = p * 3 - 5 > 0 ? p * 3 - 5 : 0; for( int i = 3; i < n + 3; i++ ) { int score = Integer.parseInt( numbers[ i ] ); if( p == 0 ) { results++; } else if( score > ( thresholdNotS ) ) { results++; } else if( s > 0 && score > thresholdS ) { results++; s--; } } System.out.println( "Case #" + ( lineNumber + 1 ) + ": " + results ); } }
0
314
A12852
A10787
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 dancing.with.the.googlers; import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; public class DancingWithTheGooglers { static int numberOfTests; static int[] testResults; static ScoreCounter[] orders; public static void main(String[] args) { InitInput(); for (int i = 0; i < numberOfTests; i++) { try { testResults[i] = orders[i].Count2(); if (testResults[i] != orders[i].Count2()) { System.out.print(i); } } catch (Exception ex) { Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); } } writeResult(); } static void InitInput() { try { FileReader input = new FileReader("B-small-attempt4.in"); try (BufferedReader bufRead = new BufferedReader(input)) { String line = bufRead.readLine(); numberOfTests = Integer.parseInt(line); testResults = new int[numberOfTests]; orders = new ScoreCounter[numberOfTests]; for (int i = 0; i < numberOfTests; i++) { line = bufRead.readLine(); if (line == null) { break; } orders[i] = new ScoreCounter(line); } } } catch (IOException ex) { Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); } } static void writeResult() { FileWriter output = null; try { output = new FileWriter("output"); try (BufferedWriter bufWrite = new BufferedWriter(output)) { for (int i = 0; i < numberOfTests; i++) { String result = "Case #"+(i+1)+": "+testResults[i]; bufWrite.write(result); bufWrite.newLine(); } } } catch (IOException ex) { Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); } finally { try { output.close(); } catch (IOException ex) { Logger.getLogger(DancingWithTheGooglers.class.getName()).log(Level.SEVERE, null, ex); } } } }
0
315
A12852
A12672
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 gcj12_qb; import java.io.FileOutputStream; import java.util.Arrays; import java.util.Scanner; /** * * @author youssefgamil */ public class Gcj12_qB { /** * @param args the command line arguments */ public static int scores[]=new int[40];//10+10+10=30 public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); FileOutputStream out=new FileOutputStream("out.txt"); int tc,i,j,k,T=sc.nextInt(); int N,S,p,res; for(tc=1;tc<=T;tc++) { N=sc.nextInt(); S=sc.nextInt(); p=sc.nextInt(); Arrays.fill(scores,0); res=0; for(i=0;i<N;i++) scores[sc.nextInt()]++; for(int h=0;h<N;h++) for(i=0;i<11;i++) for(j=i;j<11;j++) for(k=j;k<11;k++) if(scores[i+j+k]>0) { if(Math.abs(k-j)>2 || Math.abs(k-i)>2 || Math.abs(i-j)>2) continue; if(Math.max(i,Math.max(j,k))>=p) { if(Math.abs(i-j)==2 || Math.abs(k-j)==2 || Math.abs(k-i)==2) { if(S>0) { S--; res++; scores[i+j+k]--; } } else { // res++; // scores[i+j+k]--; } } // System.out.println("Posible sol="+i+","+j+","+k+"\t\tS="+S); } for(int h=0;h<N;h++) for(i=0;i<11;i++) for(j=i;j<11;j++) for(k=j;k<11;k++) if(scores[i+j+k]>0) { if(Math.abs(k-j)>2 || Math.abs(k-i)>2 || Math.abs(i-j)>2) continue; if(Math.max(i,Math.max(j,k))>=p) { if(Math.abs(i-j)==2 || Math.abs(k-j)==2 || Math.abs(k-i)==2) { if(S>0) { // S--; // res++; // scores[i+j+k]--; } } else { res++; scores[i+j+k]--; } } // System.out.println("Posible sol="+i+","+j+","+k+"\t\tS="+S); } res=Math.min(res,N); System.out.print(("Case #"+tc+": "+res+"\n")); out.write(("Case #"+tc+": "+res+"\n").getBytes()); } out.close(); // TODO code application logic here } }
0
316
A12852
A12977
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.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class Problem2 implements Runnable { private void solve() throws IOException { int ntest = nextInt(); for (int t = 1; t <= ntest; t++) { int n = nextInt(); int s = nextInt(); int p = nextInt(); int[] totalPoint = new int[7]; for (int i = 0; i <= n - 1; i++) totalPoint[i] = nextInt(); int[] mask = new int[4]; int res = 0; for (mask[0] = 0; mask[0] <= 1; mask[0]++) for (mask[1] = 0; mask[1] <= 1; mask[1]++) for (mask[2] = 0; mask[2] <= 1; mask[2]++) { int sumNMask = 0; for (int i = 0; i <= n - 1; i++) sumNMask += mask[i]; if (sumNMask == s) { int sumGooglerSatisfied = 0; for (int i = 0; i <= n - 1; i++) if (satisfy(totalPoint[i], p, mask[i])) sumGooglerSatisfied++; res = Math.max(res, sumGooglerSatisfied); } } writer.println("Case #" + t + ": " + res); } } private boolean satisfy(int totalPoint, int p, int surprising) { for (int first = p; first <= 10; first++) for (int second = Math.max(0, first - 2); second <= first; second++) for (int third = Math.max(0, first - 2); third <= first; third++) { int minVal = Math.min(second, third); if (first + second + third == totalPoint){ if (surprising == 1 && first - minVal == 2) return true; if (surprising == 0 && first - minVal <= 1) return true; } } return false; } public static void main(String[] args) { new Problem2().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader(new InputStreamReader(new FileInputStream("D:\\workspace\\Code Jam 2012\\B0.in"))); tokenizer = null; writer = new PrintWriter(new File("output.txt")); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } }
0
317
A12852
A11327
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 problemB { public static void main(String[]args) { Scanner scanner = new Scanner(System.in); int N = scanner.nextInt(); for(int num=1;num<=N;num++) { int cnt = scanner.nextInt(); int suprise = scanner.nextInt(); int reach = scanner.nextInt(); final int not = 2*(reach>=2?(reach-2):0)+reach; final int sup = 2*(reach>=1?(reach-1):0)+reach; int res = 0; int points[] = new int[cnt]; for(int i=0;i<cnt;i++) { int point = scanner.nextInt(); if(point<not) continue; if(sup>point) { if(suprise>0) res++; suprise--; continue; } res++; } System.out.println("Case #"+num+": "+res); } } }
0
318
A12852
A13107
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.OutputStream; import java.io.IOException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.io.FileInputStream; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream; try { inputStream = new FileInputStream("B-small-attempt0.in"); } catch (IOException e) { throw new RuntimeException(e); } OutputStream outputStream; try { outputStream = new FileOutputStream("gcj2.out"); } catch (IOException e) { throw new RuntimeException(e); } Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); GCJ2 solver = new GCJ2(); solver.solve(1, in, out); out.close(); } } class GCJ2 { public void solve(int testNumber, Scanner in, PrintWriter out) { int cases = in.nextInt(); for(int caseNum =0;caseNum<cases;caseNum++) { int res = 0; int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int normal = Math.max(p,p*3-2); int surprise = Math.max(p,p*3-4); for(int i=0;i<N;i++) { int score = in.nextInt(); if(score>=normal)res++; else if(score>=surprise && S>0) { res++; S--; } } out.println("Case #"+(caseNum+1)+": "+res); } } }
0
319
A12852
A12962
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Dancing_With_the_Googlers { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("input.in")); //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); FileWriter fw = new FileWriter("output.txt"); int t = Integer.parseInt(in.readLine()); int num = 1; while (t-- > 0) { String[] a = in.readLine().split(" "); int n = Integer.parseInt(a[0]); int s = Integer.parseInt(a[1]); int p = Integer.parseInt(a[2]); Integer[] inp = new Integer[n]; for (int i = 0; i < inp.length; i++) { inp[i] = Integer.parseInt(a[i + 3]); } Arrays.sort(inp); int c = 0; for (int i = 0; i < inp.length; i++) { int first = inp[i] / 3; int rem = inp[i] - first; int second = rem / 2; int third = rem - (rem / 2); if (first == second && second == third) { if (first >= p) { c++; } else if (s > 0 && first > 0 && first + 1 >= p) { c++; s--; } } else if (first == second && second == third - 1) { if (third >= p) c++; } else if (second == third) { if (third >= p) { c++; } else if (third > 0 && third + 1 >= p && s > 0) { c++; s--; } } } fw.write("Case #" + num++ + ": " + c + "\n"); } fw.flush(); fw.close(); } }
0
320
A12852
A11506
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; public class Dancers { public static void main(String[] args) throws FileNotFoundException, IOException { Scanner sc = new Scanner(new File("D:/testing/B-small-attempt0.in")); BufferedWriter bf = new BufferedWriter(new FileWriter("D:/testing/b.txt", false)); int T = sc.nextInt(); for (int i = 1; i <= T; i++) { int N, S, p; int hscr = 0, mscr = 0; N = sc.nextInt(); S = sc.nextInt(); p = sc.nextInt(); for (int j = 0; j < N; j++) { int scr = sc.nextInt(); if (scr > 3 * (p - 1)) { hscr++; } else if (p>1 && scr > 3 * (p - 2) + 1) { mscr++; } } int max=hscr+ Math.min(S, mscr); System.out.println("Case #" + i+": "+max); bf.write("Case #" + i+": "+max+ "\n"); } bf.close(); } }
0
321
A12852
A11091
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Reader; import java.io.Writer; import java.util.ArrayList; import java.util.List; public class Main { static final String inputFilename = "B-small-attempt0.in"; static class DataSet { public int bestScore, specialScoreCount; public int[] scores; @Override public String toString() { StringBuilder sb = new StringBuilder("<$DataSet:") .append(bestScore).append(", ") .append(specialScoreCount).append(", "); if (null != scores) { sb.append("["); for (int i=0, n=scores.length; i<n; ++i) { sb.append(scores[i]); if (i<n-1) sb.append(", "); } sb.append("]"); } return sb.append(">").toString(); } public static DataSet parse(String input) { if (null == input) return null; DataSet result = new DataSet(); int begin = 0; int end = input.indexOf(' '); int scoresCount = Integer.parseInt(input.substring(begin, end)); begin = end + 1; end = input.indexOf(' ', begin); result.specialScoreCount = Integer.parseInt(input.substring(begin, end)); begin = end + 1; end = input.indexOf(' ', begin); result.bestScore = Integer.parseInt(input.substring(begin, end)); result.scores = new int[scoresCount]; for (int i=0; i<scoresCount; ++i) { begin = end + 1; end = input.indexOf(' ', begin); if (end < 0) result.scores[i] = Integer.parseInt(input.substring(begin)); else result.scores[i] = Integer.parseInt(input.substring(begin, end)); } return result; } } public static Reader getFileReader(String filename) { BufferedReader result = null; try { result = new BufferedReader(new FileReader(filename)); } catch (FileNotFoundException e) { System.err.println("Couldn't find the file \""+filename+"\""); e.printStackTrace(); } return result; } public static String readLine(BufferedReader reader) { try { return reader.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } public static void closeReader(Reader r) { try { r.close(); } catch (IOException e) { e.printStackTrace(); } } public static Writer getFileWriter(String filename) { BufferedWriter result = null; try { result = new BufferedWriter(new FileWriter(filename)); } catch (IOException e) { e.printStackTrace(); } return result; } public static void writeLine(BufferedWriter writer, String line) { try { writer.write(line); writer.newLine(); } catch (IOException e) { e.printStackTrace(); } } public static void closeWriter(Writer w) { try { w.close(); } catch (IOException e) { e.printStackTrace(); } } public static String formatCase(int caseNumber, int result) { return new StringBuilder("Case #").append(caseNumber).append(": ").append(result).toString(); } public static float diffScore(int best, int score) { int remainder = score-best; float avg = remainder/2f; return avg-best; } public static void main(String[] args) { BufferedReader in = (BufferedReader) getFileReader(inputFilename); int lineCount = Integer.parseInt(readLine(in)); List<DataSet> dataSets = new ArrayList<DataSet>(); for (int i=0; i<lineCount; ++i) { dataSets.add(DataSet.parse(readLine(in))); } closeReader(in); // perform the testing BufferedWriter out = (BufferedWriter) getFileWriter("out.txt"); for (int i=0, n=dataSets.size(); i<n; ++i) { DataSet set = dataSets.get(i); int usedSurprises = 0; int setResult = 0; for (int j=0, m=set.scores.length; j<m; ++j) { float diff = diffScore(set.bestScore, set.scores[j]); if (set.scores[j] >= set.bestScore) { if (diff >= -1) setResult++; else if (diff >= -2 && usedSurprises < set.specialScoreCount) { setResult++; usedSurprises++; } } } writeLine(out, formatCase(i+1, setResult)); } closeWriter(out); } }
0
322
A12852
A11643
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 me.mevrad.codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class SolutionB { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub readFile("B-small-attempt13.in"); processData(); writeFile(); } public static void readFile(String filename) { try { BufferedReader in = new BufferedReader(new FileReader(filename)); String line; while ((line = in.readLine()) != null) { // System.out.println(line); processLine(line); } in.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } static int counter = 0; static ArrayList<DataTemplate> data = new ArrayList<DataTemplate>(); static ArrayList<String> finalText = new ArrayList<String>(); public static void processLine(String line) { if (counter == 0) { counter++; return; } String[] splited = line.split(" "); DataTemplate dt = new DataTemplate(); int c = 0; for (String s : splited) { if (c == 0) dt.numberOfGooglers = Integer.parseInt(s); else if (c == 1) dt.surprisingScores = Integer.parseInt(s); else if (c == 2) dt.p = Integer.parseInt(s); else { dt.scores.add(Integer.parseInt(s)); } c++; System.out.println(s); } data.add(dt); counter++; System.out.println("Next line"); } public static void processData() { counter = 0; System.out.println("processData data size:"+ data.size()); for (DataTemplate dt : data) { counter++; int c = 0; for (int i = 0; i < dt.scores.size(); i++) { boolean visited = false; int temp = dt.scores.get(i) / 3; if(dt.p> dt.scores.get(i)) continue; if(temp < 0 && Math.ceil(temp) >= dt.p){ c++; continue; } if(temp >= dt.p){ c++; continue; } int temp1 = (dt.scores.get(i)-dt.p)/2; if(dt.p-temp1<2){ c++; continue; } if((dt.p - temp1 == 2) && dt.surprisingScores >0){ dt.surprisingScores--; c++; continue; } //System.out.println("temp: " + temp); // if(temp < 0 && Math.ceil(temp) >= dt.p){ // c++; // dt.scores.remove(i); // i--; // visited = true; // } // if (temp >= dt.p && !visited) { // c++; // dt.scores.remove(i); // i--; // visited = true; // } // else if(temp >= 1 && temp%1>0 && Math.floor(temp)+1 >= dt.p && !visited){ // c++; // //System.out.println("temp1: " + Math.ceil(temp)+1); // dt.scores.remove(i); // i--; // visited = true; // } // else if (dt.surprisingScores > 0 && !visited && temp > 0.5 && (temp%1 > 0.5 || temp%1 == 0)) { // temp += 2; // //System.out.println("temp2: " + temp); // if (temp >= dt.p) { // c++; // dt.scores.remove(i); // i--; // dt.surprisingScores--; // } // } } System.out.println(counter+ ": Score: " + c); String s = ""; s += "Case #"+counter+": "+c; finalText.add(s); } } public static void writeFile(){ try { FileWriter fstream = new FileWriter("out13.out"); BufferedWriter out = new BufferedWriter(fstream); for(String s : finalText){ out.write(s); out.write("\n"); } out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
323
A12852
A10555
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.morl99.b; import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; import codejam.morl99.a.ProblemA; public class ProblemB { public void solveSet(PrintWriter pw, BufferedReader reader) throws IOException { String firstLine = reader.readLine(); Scanner scanner = new Scanner(firstLine); scanner.useDelimiter(" "); int T = scanner.nextInt(); for (int i = 1; i <= T; i++) { scanner = new Scanner(reader.readLine()); scanner.useDelimiter(" "); int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int[] t = new int[N]; for (int googler = 0; googler < N; googler++) { t[googler] = scanner.nextInt(); } System.out.println("-- N: " + N + " S: " + S + " p>="+p +" t:"+ Arrays.toString(t) ) ; int solution = solveLine(N,S,p,t); pw.printf("Case #%d: %d",i,solution); pw.println(); } } public int solveLine(int N, int S, int p, int[] t) { int casesAbove = 0; for (int i = 0; i < N; i++) { if (isRegularScoreAbove(t[i], p)) { casesAbove++; continue; } //Whenever a regular score is not above the limit, but the best surprising distribution is //we take the greedy approach and assume this was a surprising score. What better than a score above //could we hope for? if (S > 0 && isSurprisingScoreAbove(t[i], p)) { S--; casesAbove++; } } return casesAbove; } public boolean isRegularScoreAbove(int ti, int p) { //This is the formular for the best score that can be achieved, if no score can be //apart more than 1 from any other score int best = ti/3 + Math.min(ti%3,1); System.out.println("Best regular score for " + ti + " is " + best); return best >= p; } public boolean isSurprisingScoreAbove(int ti, int p) { //integer division, which is exactly what we want! int b = ((ti-1) / 3); int best = b + 1 + (ti-b*3+1)/3; //Special case, that we are near zero... best = Math.min(ti,best); System.out.println("Best surprising score for " + ti + " is " + best); return best >= p; } public static void main(String[] args) throws IOException { ProblemB p = new ProblemB(); OutputStream output = new FileOutputStream("res/B.out", false); PrintWriter pw = new PrintWriter(output); BufferedReader reader = new BufferedReader(new FileReader("res/B-small-attempt1.in")); p.solveSet(pw, reader); pw.close(); reader.close(); } }
0
324
A12852
A12633
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.*; class GoogleDance{ public static int isSurprise(int total, int p) { int mod = total % 3; if(p>total) { return 2; } if(mod==0) { if(p<=total/3) { return 0; } else if(p==total/3+1) { return 1; } } else if(mod==1) { if(p<=total/3+1) { return 0; } } else if(mod==2) { if(p<=total/3+1) { return 0; } else if(p==total/3+2) { return 1; } } return 2; } public static void main(String[] args) throws IOException { String filename ="dancers.txt"; FileReader fr = new FileReader("B-small-attempt0.in"); BufferedReader br = new BufferedReader(fr); FileWriter fstream = new FileWriter("output.txt"); BufferedWriter out = new BufferedWriter(fstream); int testcases = Integer.parseInt(br.readLine()); for (int i=1;i<=testcases;i++) { String line = br.readLine(); int N = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ')+1); int S = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ')+1); int p = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ')+1); int[] dancers = new int[N]; for(int k=0;k<N-1;k++) { int x = Integer.parseInt(line.substring(0, line.indexOf(' '))); line = line.substring(line.indexOf(' ')+1); dancers[k]=x; } dancers[N-1]=Integer.parseInt(line); int count = 0; for(int l = 0; l<N;l++) { int check = isSurprise(dancers[l], p); if(check==0) { count++; } else if(check==1&&S>0) { count++; S--; } } out.write("Case #"+i+": "+count); if(i!=testcases) { out.write("\n"); } } br.close(); out.close(); } }
0
325
A12852
A10918
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.FileOutputStream; import java.io.PrintWriter; import java.io.FileInputStream; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream; try { inputStream = new FileInputStream("B-small-attempt1.in"); } catch (IOException e) { throw new RuntimeException(e); } OutputStream outputStream; try { outputStream = new FileOutputStream("dancinggooglers.out"); } catch (IOException e) { throw new RuntimeException(e); } StreamInputReader in = new StreamInputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); DancingGooglers solver = new DancingGooglers(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } } class DancingGooglers { public void solve(int testNumber, StreamInputReader in, OutputWriter out) { out.print("Case #" + testNumber + ": "); int n = in.readInt(), s = in.readInt(), p = in.readInt(); int res = 0; for(int i = 0; i < n; ++i) { int t = in.readInt(); if (t >= 3 * Math.max(0, p-1) + 1 || t >= 3 * p || t >= Math.max(0, 3 * p - 1)) { ++res; } else if (s > 0 && t >= 3 * Math.max(0, p-2) + 2) { --s; ++res; } } out.printLine(res); } } class StreamInputReader extends InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public StreamInputReader(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++]; } } 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(); } } abstract class InputReader { public abstract int read(); 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 String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String next() { return readString(); } protected boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } }
0
326
A12852
A11112
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 DancingGooglers { public static void main(String args[]) throws Exception { Scanner in = new Scanner(new File("B-small-attempt6.in")); FileWriter out = new FileWriter(new File("B-small-attempt6.out.txt")); int t = Integer.parseInt(in.nextLine()); for(int x = 1; x <= t; x++) { String str = in.nextLine(); Scanner sn = new Scanner(str); int n, s, p, y; n = sn.nextInt(); s = sn.nextInt(); p = sn.nextInt(); y = 0; int scores[] = new int[n]; for(int a = 0; a < n; a++) { scores[a] = sn.nextInt(); } for(int score : scores) { int base = score/3; switch(score % 3) { case 0 : { if(base >= p) { y++; } else if(s > 0 && base > 0 && base + 1 >= p) { y++; s--; } } break; case 1 : { if(base >= p || base + 1 >= p) { y++; } else if(s > 0 && base + 1 >= p) { y++; s--; } } break; case 2 : { if(base + 1 >= p || base >= p) { y++; } else if(s > 0 && base + 2 >= p) { y++; s--; } } } } System.out.println("Case #" + x + ": " + y); out.write("Case #" + x + ": " + y + "\n"); } out.flush(); out.close(); } }
0
327
A12852
A10090
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 se.round1.util; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; public class JamUtil { public static BufferedReader getReader(String path) { File file = new File(path); FileInputStream fis = null; try { fis = new FileInputStream(file); } catch (FileNotFoundException e) { e.printStackTrace(); } BufferedReader bf = new BufferedReader(new InputStreamReader(fis)); return bf; } public static BufferedWriter getWriter(String path) { try { return new BufferedWriter(new FileWriter(path)); } catch (IOException e) { e.printStackTrace(); } return null; } }
0
328
A12852
A10844
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 qualifying; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; /** * Google Code Jam, Problem B. Result finder * * @author Petar * */ public class Dancers { private static BufferedReader in; private static BufferedWriter out; /** * Main, reads in scores, outputs max num of Googler's with result p * * @param args */ public static void main(String[] args) { List<Integer> scores; int numSurprise, numGooglers, p, maxGooglers; String currLine = ""; try { out = new BufferedWriter(new FileWriter(".out")); in = new BufferedReader(new FileReader(".in")); int testNum = Integer.parseInt(in.readLine()); for (int i = 0; i < testNum; i++) { maxGooglers = 0; currLine = in.readLine(); String[] testBound = currLine.split(" "); numGooglers = Integer.parseInt(testBound[0]); numSurprise = Integer.parseInt(testBound[1]); p = Integer.parseInt(testBound[2]); System.out .println(String .format("The bounds of the problem are %d googlers, %d surprising results and %d p value", numGooglers, numSurprise, p)); // Read in the scores scores = new ArrayList<Integer>(numGooglers); for (int j = 0; j < numGooglers; j++) { scores.add(Integer.parseInt(testBound[j + 3])); } // Determine the tallies for (Integer score : scores) { if (score < (3 * p - 4) || score < p) { continue; } else if (score >= (3 * p - 2)) { maxGooglers++; } else { if (numSurprise > 0) { maxGooglers++; numSurprise--; } } } Collections.sort(scores); out.write(String.format("Case #%d: %d", i + 1, maxGooglers)); out.newLine(); } in.close(); out.flush(); out.close(); } catch (FileNotFoundException e) { System.err.println("Input file was not found"); } catch (IOException e) { System.err.println("Problem reading from input file"); e.printStackTrace(); } } }
0
329
A12852
A11287
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.io.PrintWriter; import java.util.Scanner; public class QualB { public void run()throws IOException { Scanner in = new Scanner(new File("b.in")); PrintWriter out = new PrintWriter("b.out"); int nt = in.nextInt(); in.nextLine(); for(int it = 1;it <= nt; it++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int [] a = new int[n]; for(int i=0;i<n;i++) a[i] = in.nextInt(); int ret = 0; for(int i=0;i<n;i++) { int q = a[i] % 3; int max = a[i] / 3; if(q != 0) max++; if(max >= p) ret++; else { max = a[i] / 3; if(a[i] != 0) max++; if(q == 2) max++; if(max >= p && s > 0) { ret++; s--; } } } out.println("Case #" + it + ": " + ret); } out.close(); } /** * @param args */ public static void main(String[] args)throws IOException { new QualB().run(); } }
0
330
A12852
A12006
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.utility; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class FileWriterUtility { public static File getFile(String outputFileLoc) { File outputFile = null; if (outputFileLoc != null) { outputFile = new File(outputFileLoc); if (!outputFile.exists()) { try { outputFile.createNewFile(); } catch (IOException e) { System.out.println("Error :" + e.getMessage()); } } } return outputFile; } public static File getNewFile(String outputFileLoc) { File outputFile = null; if (outputFileLoc != null) { outputFile = new File(outputFileLoc); if (!outputFile.exists()) { try { outputFile.delete(); outputFile.createNewFile(); } catch (IOException e) { System.out.println("Error :" + e.getMessage()); } } } return outputFile; } public static BufferedWriter getBufferedWriter(File outputFile) { BufferedWriter bufferedWriter = null; if (outputFile != null) { FileWriter fileWriter; try { fileWriter = new FileWriter(outputFile); bufferedWriter = new BufferedWriter(fileWriter); } catch (IOException e) { System.out.println("Error :" + e.getMessage()); } } return bufferedWriter; } public static BufferedWriter getBufferedWriter(String fileName) { BufferedWriter bufferedWriter = null; if (fileName != null) { File file = new File(fileName); bufferedWriter = getBufferedWriter(file); } return bufferedWriter; } public static void write(BufferedWriter bufferedWriter, String outputString) { if (bufferedWriter != null && outputString != null) { try { bufferedWriter.write(outputString); } catch (IOException e) { System.out.println("Error :" + e.getMessage()); } } } public static void writeNewLine(BufferedWriter bufferedWriter) { if (bufferedWriter != null) { try { bufferedWriter.write("\n"); } catch (IOException e) { System.out.println("Error :" + e.getMessage()); } } } public static void closeBufferedWriter(BufferedWriter bufferedWriter) { if (bufferedWriter != null) { try { bufferedWriter.close(); } catch (IOException e) { System.out.println("Error :" + e.getMessage()); } } } }
0
331
A12852
A13125
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 Game { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader(new File("/Users/atai/Play/Codejam/input.txt"))); PrintWriter prn = new PrintWriter(new FileWriter("output.txt")); int numTests = Integer.parseInt(br.readLine().trim()); for (int i = 0; i < numTests; i++) { String[] arg = br.readLine().trim().split(" "); int N = Integer.parseInt(arg[0]); int S = Integer.parseInt(arg[1]); int p = Integer.parseInt(arg[2]); int min; int surMin; if (p < 2) { min = p; surMin = -1; } else { min = 3*p-4; surMin = 3*p-3; } int pass = 0; int count_sur = 0; for (int j = 0; j < N; j++) { int val = Integer.parseInt(arg[3+j]); if (val < min) continue; else { if (val <= surMin) count_sur++; else pass++; } } if (count_sur >= S) prn.printf("Case #%d: %d\n", i+1, S+pass); else { prn.printf("Case #%d: %d\n", i+1, count_sur + pass); } } prn.close(); } }
0
332
A12852
A12536
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author JOSE */ public class DancingWithTheGooglers { public void process() { ArrayList<String> inputList = readFile("B-small-attempt0.in"); String output = ""; int testCase = 0; for (int i = 0; i < inputList.size(); i++) { String input = inputList.get(i); if (i == 0) { testCase = Integer.parseInt(input); } else { int result = eachTestcaseProcess(input); output = output + "Case #" + i + ": " + result; if (i != (inputList.size() - 1)) { output = output + '\n'; } } } writeFile(output); } public int eachTestcaseProcess(String input) { // String test = "3 1 5 15 13 11"; String spliInputt[] = input.split("\\s"); int googler = 0; int serprise = 0; int p = 0; double[] totalpoint = null; int resultCount = 0; for (int i = 0; i < spliInputt.length; i++) { if (i == 0) { googler = Integer.parseInt(spliInputt[i]); totalpoint = new double[googler]; } else if (i == 1) { serprise = Integer.parseInt(spliInputt[i]); } else if (i == 2) { p = Integer.parseInt(spliInputt[i]); } else { totalpoint[i - 3] = Double.parseDouble(spliInputt[i]); } } int[][] triplet = new int[googler][3]; for (int i = 0; i < totalpoint.length; i++) { double divide = totalpoint[i] / 3; double mod = totalpoint[i] % 3; triplet[i][0] = (int) divide; triplet[i][1] = (int) divide; triplet[i][2] = (int) divide; for (int j = 0; j < mod; j++) { triplet[i][j]++; } } for (int i = 0; i < triplet.length; i++) { boolean flag = false; int checkSurprising = 0; while (checkSurprising != -1) { checkSurprising = findSurprising(triplet, i); if (checkSurprising != -1) { flag = isEquealOrGreaterThanP(triplet, p, i); if (flag && (checkSurprising != 1 || serprise > 0)) { if (checkSurprising == 1) { serprise--; } resultCount++; checkSurprising = -1; } else { if (triplet[i][1] > 0) { triplet[i][0]++; triplet[i][1]--; } else { checkSurprising = -1; } } } } } return resultCount; } private int findSurprising(int[][] triplet, int i) { int a = (triplet[i][0] - triplet[i][1]); int b = (triplet[i][0] - triplet[i][2]); int c = (triplet[i][1] - triplet[i][2]); int result = -1; if (a < 2 && b < 2 && c < 2) { result = 0; } else if ((a <= 2 && b <= 2 && c <= 2)) { result = 1; } return result; } private boolean isEquealOrGreaterThanP(int[][] triplet, int p, int i) { boolean result = false; for (int j = 0; j < 3; j++) { if (triplet[i][j] >= p) { result = true; } } return result; } private ArrayList<String> readFile(String fileName) { BufferedReader br = null; ArrayList<String> inputList = null; try { File file = new File(fileName); br = new BufferedReader(new FileReader(file)); String message = null; inputList = new ArrayList<String>(); while ((message = br.readLine()) != null) { inputList.add(message); } } catch (IOException ex) { ex.printStackTrace(); } finally { try { br.close(); } catch (IOException ex) { ex.printStackTrace(); } return inputList; } } private void writeFile(String message) { BufferedWriter bw = null; try { File file = new File("Output.txt"); bw = new BufferedWriter(new FileWriter(file)); bw.write(message); } catch (IOException ex) { ex.printStackTrace(); } finally { try { bw.close(); } catch (IOException ex) { ex.printStackTrace(); } } } public static void main(String[] args) { DancingWithTheGooglers dwtg = new DancingWithTheGooglers(); dwtg.process(); } }
0
333
A12852
A10280
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.FileInputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class B { static int[][] dp; static int[] sum; static int p; public static int abs(int a) { return (a < 0) ? -a : a; } public static int go(int i, int j) { if (j < 0) return -1000; if (i == sum.length) { if (j != 0) return -1000; else return 0; } else if (dp[i][j] != -1) return dp[i][j]; else { int max = 0; for (int a = 0; a <= 10; a++) for (int b = 0; b <= 10 && a + b <= sum[i]; b++) for (int c = 0; c <= 10 && c + a + b <= sum[i]; c++) { if (abs(a - b) <= 2 && abs(a - c) <= 2 && abs(b - c) <= 2) { int cool = 0; int awesome = 0; if (abs(a - b) == 2 || abs(b - c) == 2 || abs(a - c) == 2) cool = 1; if (a >= p || b >= p || c >= p) awesome = 1; max = Math.max(max, awesome + go(i + 1, j - cool)); } } return dp[i][j] = max; } } public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader( new FileInputStream("B.in"))); PrintWriter out = new PrintWriter("B.out"); int tc = Integer.parseInt(in.readLine()); for (int cc = 1; cc <= tc; cc++) { StringTokenizer strtok = new StringTokenizer(in.readLine(), " "); int n = Integer.parseInt(strtok.nextToken()); int s = Integer.parseInt(strtok.nextToken()); p = Integer.parseInt(strtok.nextToken()); dp = new int[n][s + 1]; for (int[] a : dp) Arrays.fill(a, -1); sum = new int[n]; for (int i = 0; i < n; i++) sum[i] = Integer.parseInt(strtok.nextToken()); out.printf("Case #%d: %d\n", cc, go(0, s)); } out.close(); in.close(); } }
0
334
A12852
A11704
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 y2012.Qualification; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class DancingWithGooglers extends IOStream { List<Triplet> completeEntries = new ArrayList<Triplet>(); List<Triplet> aboveList = new ArrayList<Triplet>(); List<Triplet> belowList = new ArrayList<Triplet>(); List<Triplet> considerableList = new ArrayList<Triplet>(); static int P_bestResult = 0; int N = 0; int surprisingTriplets = 0; public DancingWithGooglers(String fileName) { super(fileName); } private int runThisTestCase() throws IOException { completeEntries = new ArrayList<Triplet>(); aboveList = new ArrayList<Triplet>(); belowList = new ArrayList<Triplet>(); considerableList = new ArrayList<Triplet>(); int[] intValues = splitString2Int(bufferedReader.readLine().trim().split(" ")); N = intValues[0]; surprisingTriplets = intValues[1]; P_bestResult = intValues[2]; createTriplets(intValues); int max = (surprisingTriplets > considerableList.size()) ? considerableList.size() : surprisingTriplets; System.out.println(aboveList.size() + max ); return aboveList.size() + max; } private void createTriplets(int[] intValues) { for(int i=3; i<intValues.length; i++){ Triplet triplet = new Triplet(intValues[i]); completeEntries.add(triplet); distingushTriplet(triplet); } } private void distingushTriplet(Triplet triplet) { int sum = triplet.getSum(); int normalMax = sum/3 + ((sum%3 == 0)? 0 : 1); int atMax = sum/3 + ((sum%3 == 2)? 2 : 1); if(sum == 0){ normalMax = atMax = 0; } if(P_bestResult <= normalMax) aboveList.add(triplet); else if(P_bestResult > atMax) belowList.add(triplet); else considerableList.add(triplet); } public static void main(String[] args) { DancingWithGooglers obj = new DancingWithGooglers("/net/10.0.0.60/Users/454083/Desktop/Moshin/CodeJam/DancingGooglers"); try { obj.getReader(); obj.getWriter(); int testcases = Integer.parseInt(bufferedReader.readLine().trim()); for(int testcase=1; testcase<=testcases; testcase++){ int value = obj.runThisTestCase(); System.out.println("Case #" + testcase + ": " + value); bufferedWriter.write("Case #" + testcase + ": " + value + "\n"); } obj.close(); } catch (IOException e) { e.printStackTrace(); } } } class Triplet { int sum = 0; int reminder = 0; boolean suprise = false; int maxScore = 0; public Triplet(int sum) { this.sum = sum; if ((reminder = sum % 3) == 1) maxScore = (int) (sum / 3) + 1; } public boolean isSuprise() { return suprise; } public void setSuprise(boolean suprise) { this.suprise = suprise; } public int getMaxScore() { return maxScore; } public void setMaxScore(int maxScore) { this.maxScore = maxScore; } public int getSum() { return sum; } public int getReminder() { return reminder; } } class IOStream { static public BufferedReader bufferedReader = null; static public BufferedWriter bufferedWriter = null; String fileName = ""; public IOStream(String fileName) { this.fileName = fileName; } protected void getReader() throws IOException { bufferedReader = new BufferedReader(new FileReader(new File(fileName + ".in"))); } protected void getWriter() throws IOException { bufferedWriter = new BufferedWriter(new FileWriter(new File(fileName + ".out"))); } protected void close() throws IOException { if (bufferedReader != null) bufferedReader.close(); if (bufferedWriter != null) { bufferedWriter.flush(); bufferedWriter.close(); } } protected int[] splitString2Int(String[] words){ int[] ints = new int[words.length]; int i=0; for(String str: words){ ints[i] = Integer.parseInt(str); i++; } return ints; } }
0
335
A12852
A10646
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 codejam2; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /** * * @author Albatross */ public class Main { public static void main(String[] args) throws FileNotFoundException, IOException { String final_output=""; try{ FileReader input = new FileReader("Input.txt"); BufferedReader bufRead = new BufferedReader(input); String line; line = bufRead.readLine(); int testCases = Integer.parseInt(line); for (int i=0; i<testCases; i++) { line = bufRead.readLine(); String[] numbers = line.split(" "); int Googlers = Integer.parseInt(numbers[0]); int Surprising = Integer.parseInt(numbers[1]); int Limit = Integer.parseInt(numbers[2]); int[] GooglerPoints = new int[Googlers]; for (int j=0; j<Googlers; j++) { GooglerPoints[j] = Integer.parseInt(numbers[3+j]); } int LimitPass = 0; for (int x : GooglerPoints) { double minNum = Math.floor(x/3); double remPts = x - (3*minNum); if (minNum>=Limit) LimitPass++; else if (remPts!=0 && minNum+1>=Limit) LimitPass++; else if (Surprising!=0) { if(remPts==2 && minNum+2>=Limit){ LimitPass++; Surprising--; } else if(remPts==0 && minNum+1>=Limit && minNum!=0){ LimitPass++; Surprising--; } } } final_output = final_output+"Case #"+(i+1)+": "+LimitPass+"\n"; } bufRead.close(); } finally{ } FileWriter output_file = new FileWriter("Output.txt"); BufferedWriter bufWrite = new BufferedWriter(output_file); try{ bufWrite.write(final_output); } finally{ bufWrite.close(); } } }
0
336
A12852
A11904
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 qualitfy; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Test { public static void main (String args[]) throws FileNotFoundException { Scanner in = new Scanner(new File ("src//qualitfy/input.in")); int T = in.nextInt(); for (int i = 0; i < T; i++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int count = 0; int n1=0,n2=0,n3=0; for (int j = 0; j < N; j++) { int no = in.nextInt(); int div = no % 3; n1 = n2 = n3 = no/3; if (div==1) n3 = n3 + 1; if (div == 2) n2 = n3 = n3 + 1; if (n3 >= p) count++; else if (S != 0 && no >= 2) { if(n2 == n3) { n3 = n3 + 1; n2 = n2 - 1; if (n3 >= p) { count++; S--; } } } } System.out.println("Case #" + (i + 1) + ": " + count); } } }
0
337
A12852
A11219
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class Dancing { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int caseCount = sc.nextInt(); for (int i = 1; i <= caseCount; i++) { int N = sc.nextInt(); int numSuprise = sc.nextInt(); int p = sc.nextInt(); int bestN = 0; for (int j = 1; j <= N; j++) { int result = getThree(sc.nextInt(), numSuprise, p); if (result > 1) { result = 1; numSuprise--; } bestN += result; } System.out.println("Case #" + i + ": " + bestN); } } private static int getThree(int total, int numSuprise, int p) { if (total == 0 && p > 0) { return 0; } else if ((total - p) < (p - 2) * 2) { return 0; } else if ((total - p) == (p - 2) * 2 || (total - p) == (p * 2 - 3)) { if (numSuprise <= 0) { return 0; } else { return 2; } } else { int average = total * 10 / 3; if (average % 10 == 0) { if (average >= p * 10) { return 1; } else { return 0; } } else if (average % 10 == 3) { if ((average + 7) >= p * 10) { return 1; } else { return 0; } } else { if ((average + 4) >= p * 10) { return 1; } else { return 0; } } } } }
0
338
A12852
A11266
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class Scores { private String fileName; private FileReader file; private FileWriter fileOutput; private PrintWriter pw; private BufferedReader br; private int NbGog; private int NbSurp; private int maxScore; private int nbTest; private boolean verbose; public Scores (String[] args){ try{ fileName =(args[0]); file = new FileReader(fileName); br = new BufferedReader(file); fileOutput=new FileWriter(fileName+"_sol.txt"); pw = new PrintWriter(fileOutput); } catch (Exception e) { e.printStackTrace(); } nbTest=1; verbose=false; } public int readNum(String line, int startPos, int [] endPos) { String s=""; int i=0; while(startPos<line.length() && line.charAt(startPos)!=' ') { s+=line.charAt(startPos); startPos++; i++; } if(endPos!=null) endPos[0]=startPos+1; return Integer.parseInt(s); } public void dealWithFile () throws IOException{ float gogAvg=0; int total=0; int pos[]=new int [1]; String line = br.readLine(); int nbTests= Integer.parseInt(line); if(verbose) System.out.println("nbTests: " + nbTests ); for(nbTest=1; nbTest<= nbTests; nbTest++) { total=0; line = br.readLine(); NbGog=readNum(line, 0,pos); NbSurp=readNum(line, pos[0],pos); maxScore=readNum(line, pos[0],pos); if(verbose) System.out.print("\nNbGog: " + NbGog + " NbSurp: " +NbSurp +" maxScore: " + maxScore +" -> "); for(int j=0; j<NbGog;j++) { int num=readNum(line, pos[0],pos); gogAvg=(float)num/(float)3; int gobAvgInt=(int) gogAvg; if(verbose) System.out.print( num + "("+ gogAvg+ ")"); if(gobAvgInt+2>=maxScore) { float gogAvgDec= gogAvg-gobAvgInt; if(gogAvgDec<0.3 && gobAvgInt>=maxScore) //NO * { if(verbose) System.out.println("eq.0"); total++; } else if( gogAvgDec<0.3 && gobAvgInt-1>=0 && gobAvgInt+1<=10&& gobAvgInt+1>=maxScore&& NbSurp>0) // * { if(verbose) System.out.println("eq.0_S"); total++; NbSurp--; } else if(gogAvgDec>=0.3 && gogAvgDec<0.6 && gobAvgInt+1<=10 && gobAvgInt+1>=maxScore) { if(verbose) System.out.println("eq.33"); total++; } else if(gogAvgDec>=0.6 && gobAvgInt+1>=maxScore && gobAvgInt+1<=10) { if(verbose) System.out.println("eq.66"); total++; } else if(gogAvgDec>=0.6 && gobAvgInt+2>=maxScore && gobAvgInt+2<=10 && NbSurp>0) { if(verbose) System.out.println("eq.66_S"); total++; NbSurp--; } else if(verbose) System.out.println("NO"); } } //if(verbose) System.out.println("Case #"+nbTest+": " +total); pw.println("Case #"+nbTest+": " +total); } } public static void main(String[] args) throws IOException { if(args.length!=1) { System.out.println("Usage: java AlphabetSoup.java <instanceFileName>"); System.exit(0); } Scores scores= new Scores(args); scores.dealWithFile(); if(scores.verbose) System.out.println("End"); scores.file.close(); scores.fileOutput.close(); } }
0
339
A12852
A11017
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 fixjava; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Set; import java.util.Map.Entry; public class HashMapDualKey<K1, K2, V> extends HashMap<K1, HashMap<K2, V>> { private static final long serialVersionUID = 1L; /** Returns whether the dual map contains the given key in the K1 space */ @Override public boolean containsKey(Object key) { return this.containsKey(key); } public boolean containsKey(K1 key1, K2 key2) { HashMap<K2, V> map2 = this.get(key1); if (map2 == null) return false; else return map2.containsKey(key2); } /** Searches all (K1, K2) pairs to see if any of them map to the value. Runs in O(K1) time. */ public boolean containsValueAll(Object value) { for (HashMap<K2, V> map2 : this.values()) if (map2 != null && map2.containsValue(value)) return true; return false; } public V get(K1 key1, K2 key2) { HashMap<K2, V> map2 = this.get(key1); if (map2 == null) return null; else return map2.get(key2); } public Set<K2> keySet(K1 key1) { HashMap<K2, V> map2 = this.get(key1); if (map2 == null) return null; else return map2.keySet(); } public V put(K1 key1, K2 key2, V value) { HashMap<K2, V> map2 = this.get(key1); if (map2 == null) this.put(key1, map2 = new HashMap<K2, V>()); return map2.put(key2, value); } public void putAll(ArrayList<Tuple3<? extends K1, ? extends K2, V>> items) { for (Tuple3<? extends K1, ? extends K2, V> item : items) put(item.getField0(), item.getField1(), item.getField2()); } public void putAllListOfLists(ArrayList<Pair<? extends K1, ArrayList<Pair<? extends K2, V>>>> listOfLists) { for (Pair<? extends K1, ArrayList<Pair<? extends K2, V>>> pair1 : listOfLists) { K1 k1 = pair1.getLeft(); for (Pair<? extends K2, V> pair2 : pair1.getRight()) put(k1, pair2.getLeft(), pair2.getRight()); } } @Override public HashMap<K2, V> remove(Object key1) { return this.remove(key1); } public V remove(K1 key1, K2 key2) { HashMap<K2, V> map2 = this.get(key1); if (map2 == null) return null; V ret = map2.remove(key2); if (map2.isEmpty()) this.remove(key1); return ret; } /** Returns size across all (K1, K2) pairs. Runs in O(K1) time. */ public int sizeAll() { int size = 0; for (HashMap<K2, V> map2 : this.values()) if (map2 != null) size += map2.size(); return size; } /** Returns union of values across all (K1, K2) pairs. Runs in O(N) time. */ public HashSet<V> valuesAll() { HashSet<V> values = new HashSet<V>(); for (HashMap<K2, V> map2 : this.values()) if (map2 != null) values.addAll(map2.values()); return values; } /** Returns the map as a list of Tuple3<K1, K2, V>. Runs in O(N) time. */ public ArrayList<Tuple3<K1, K2, V>> getAsList() { ArrayList<Tuple3<K1, K2, V>> result = new ArrayList<Tuple3<K1,K2,V>>(); for (Entry<K1, HashMap<K2, V>> ent1 : this.entrySet()) { K1 k1 = ent1.getKey(); HashMap<K2, V> map2 = ent1.getValue(); if (map2 != null) { for (Entry<K2, V> ent2 : map2.entrySet()) { K2 k2 = ent2.getKey(); V v = ent2.getValue(); result.add(Tuple3.make(k1, k2, v)); } } } return result; } /** Returns the map as a list of Pair<K1, ArrayList<Pair<K2, V>>>. Runs in O(N) time. */ public ArrayList<Pair<K1, ArrayList<Pair<K2, V>>>> getAsListOfLists() { ArrayList<Pair<K1, ArrayList<Pair<K2, V>>>> result = new ArrayList<Pair<K1, ArrayList<Pair<K2, V>>>>(this.size()); for (Entry<K1, HashMap<K2, V>> ent1 : this.entrySet()) { K1 k1 = ent1.getKey(); HashMap<K2, V> map2 = ent1.getValue(); if (map2 != null) { ArrayList<Pair<K2, V>> listOfK2VPairs = new ArrayList<Pair<K2,V>>(map2.size()); for (Entry<K2, V> ent2 : map2.entrySet()) { K2 k2 = ent2.getKey(); V v = ent2.getValue(); listOfK2VPairs.add(Pair.make(k2, v)); } result.add(Pair.make(k1, listOfK2VPairs)); } } return result; } }
0
340
A12852
A12354
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 GoogleB { public static int doit(int s, int p, ArrayList<Integer> arr){ int count =0 ; for (int i = 0; i < arr.size(); i++){ if ((p-1>=0 && arr.get(i) >= 2*(p-1) + p) || (arr.get(i) >= 3*p)){ count++; arr.remove(i); i--; } else if ((p-2 >= 0 && arr.get(i) >= 2*(p-2) + p && s > 0)){ arr.remove(i); s--; i--; count++; } } return count; } public static void main(String[] args) throws Exception{ Scanner scan = new Scanner(new File("B-small.txt")); int lines = scan.nextInt(); for (int i = 0; i < lines; i++){ int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); ArrayList<Integer> arr = new ArrayList<Integer>(); for (int j = 0; j < n; j++){ arr.add(scan.nextInt()); } System.out.println("Case #" + (i+1) + ": " + doit(s, p, arr)); } } }
0
341
A12852
A12285
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.brootdev.gcj2012.problemB; import com.brootdev.gcj2012.common.Data; import java.io.IOException; public class Main { private Data data; private long casesNumber; private long currentCase; public static void main(String[] args) throws IOException { new Main().go(args[0], args[1]); } public void go(String inFile, String outFile) throws IOException { data = new Data(inFile, outFile); casesNumber = data.readLongLine(); for (currentCase = 0; currentCase < casesNumber; currentCase++) { data.writeCaseHeader(currentCase); processCase(); } data.out.flush(); } private void processCase() throws IOException { long[] longs = data.readLongsArrayLine(); long N = longs[0]; long S = longs[1]; long p = longs[2]; long p3 = p * 3; long sum = 0; long s = 0; for (int g = 3; g < longs.length; g++) { long pts = longs[g]; if (pts < p) { continue; } if (pts >= p3 - 2) { sum++; } else if (pts >= p3 - 4) { s++; } } sum += Math.min(S, s); data.out.println(sum); } }
0
342
A12852
A13104
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package googleCodeJam; import static java.lang.System.out; import java.io.BufferedReader; import java.io.FileReader; public class DancingWithTheGooglers { private static final int MAXN = 128; private static int inc0(int num, int p) { if (num == 0) { return (p == 0) ? 1 : 0; } int t = num / 3; int m = num % 3; return ((m == 0 && t >= p) || (m == 1 && t+1 >= p) || (m == 2 && t+1 >= p)) ? 1 : 0; } private static int inc1(int num, int p) { if (num == 0) { return 0; } int t = num / 3; int m = num % 3; return ((m == 0 && t+1 <= 10 && t+1 >= p) || (m == 1 && t+1 >= p) || (m == 2 && t+2 <= 10 && t+2 >= p)) ? 1 : 0; } public static void main(String[] args) throws Exception { if (args.length == 1) { int[] g = new int[MAXN]; int[][] f = new int[MAXN][MAXN]; // opening the input BufferedReader in = new BufferedReader(new FileReader(args[0])); // reading the number of test cases String line = null; int numberOfTestCases = ((line = in.readLine()) != null) ? Integer.parseInt(line) : 0; for (int t = 0; t < numberOfTestCases; t ++) { line = in.readLine(); out.print("Case #" + (t+1) + ": "); // parsing input String[] input = line.split(" "); int n = Integer.parseInt(input[0]); int s = Integer.parseInt(input[1]); int p = Integer.parseInt(input[2]); for (int i = 0; i < n; i ++) { g[i] = Integer.parseInt(input[3 + i]); } // computation f[0][0] = inc0(g[0], p); for (int i = 1; i < n; i ++) { f[i][0] = f[i-1][0] + inc0(g[i], p); } if (s > 0) { f[0][1] = inc1(g[0], p); } for (int i = 1; i < n; i ++) { for (int j = 1; j <= i+1 && j <= s; j ++) { f[i][j] = Math.max(f[i-1][j-1] + inc1(g[i], p), f[i-1][j] + inc0(g[i], p)); } } out.println(f[n-1][s]); } // closing the input in.close(); } else { // show the usage System.err.println("Using: java googleCodeJam.DancingWithThegooglers input"); } } }
0
343
A12852
A12611
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; public class Problem { public static void main(String[] args) throws IOException { new DancingGooglers("src/B-large.in", "src/hj2.txt"); } }
0
344
A12852
A13009
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.*; public class Googlers { public static void main(String[] args) throws Throwable{ Scanner scan = new Scanner(new File("in_b")); scan.nextLine(); int l = 1; while(scan.hasNextLine()){ String[] line = scan.nextLine().split(" "); int surprise = Integer.valueOf(line[1]); int p = Integer.valueOf(line[2]); int min = (p * 3) - 2; int sup = min - 2; int ok = 0; for(int i = 3; i < line.length ; i++){ int score = Integer.valueOf(line[i]); if(p == 1){ if(score == 0){ continue; } } if(score >= min){ ok++; continue; } if(score >= sup){ if(surprise > 0){ ok++; surprise--; } } } System.out.println("Case #" + l + ": " + ok); l++; } } }
0
345
A12852
A13063
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class Dancing { public enum Category {containsHighNotSupprising, containsHighOnlyIfSupprising, doesNotContainHigh}; public class Score { public Score(int p, int score) { this.score = score; this.category = getCategoryFor(p, score); } private Category getCategoryFor(int p, int score) { if (score >= 29) { return Category.containsHighNotSupprising; } else if (score == 1) { if (p == 0 || p == 1) { return Category.containsHighNotSupprising; } return Category.doesNotContainHigh; } else if (score == 0) { if (p == 0) { return Category.containsHighNotSupprising; } return Category.doesNotContainHigh; } else if (score >= (3*p)-2) { return Category.containsHighNotSupprising; } else if (score >= (3*p)-4) { return Category.containsHighOnlyIfSupprising; } return Category.doesNotContainHigh; } public int score; public Category category; } public class TestCase { int p; int s; List<Score> scores = new ArrayList<Score>(); public TestCase(String line) { Scanner scan = new Scanner(line); int numScores = scan.nextInt(); s = scan.nextInt(); p = scan.nextInt(); for(int i = 0; i < numScores; i++) { int score = scan.nextInt(); scores.add(new Score(p,score)); } } public int getResult() { int countContainsHighNotSurprising = 0; int countContainsHighOnlyIfSurprising = 0; for(Score score : scores) { if(score.category==Category.containsHighNotSupprising) countContainsHighNotSurprising++; else if(score.category==Category.containsHighOnlyIfSupprising) countContainsHighOnlyIfSurprising++; } return countContainsHighNotSurprising + Math.min(s,countContainsHighOnlyIfSurprising); } } public static final PrintStream out = System.out; public static final BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public int numCases; public void doCase(int caseNumber) throws Exception { String line = in.readLine(); TestCase testCase = new TestCase(line); out.println(testCase.getResult()); } public void run() throws Exception { numCases = Integer.parseInt(in.readLine().trim()); for (int i = 1; i <= numCases; i++) { out.print("Case #" + i + ": "); doCase(i); } } public static void main(String[] args) throws Exception { new Dancing().run(); } }
0
346
A12852
A12783
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.text.Format; import java.util.Formatter; import java.util.List; import java.util.Set; import java.util.HashSet; import java.util.ArrayList; import java.math.*; public class Dancing { static public String getContents(File aFile) { //...checks on aFile are elided StringBuilder contents = new StringBuilder(); try { //use buffering, reading one line at a time //FileReader always assumes default encoding is OK! BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; //not declared within while loop /* * readLine is a bit quirky : * it returns the content of a line MINUS the newline. * it returns null only for the END of the stream. * it returns an empty String if two newlines appear in a row. */ while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents.toString(); } static public void setContents(File aFile, String aContents) throws FileNotFoundException, IOException { if (aFile == null) { throw new IllegalArgumentException("File should not be null."); } if (!aFile.exists()) { throw new FileNotFoundException ("File does not exist: " + aFile); } if (!aFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + aFile); } if (!aFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + aFile); } //use buffering Writer output = new BufferedWriter(new FileWriter(aFile)); try { //FileWriter always assumes default encoding is OK! output.write( aContents ); } finally { output.close(); } } /** Simple test harness. */ public static void main (String... aArguments) throws IOException { File testFile = new File("/Users/MatFuck/Dropbox/Projects/Code Jam Qualification 2009/src/A-small-practice-1.in"); //System.out.println("Original file contents: " + getContents(testFile)); String[] in = getContents(testFile).split(System.getProperty("line.separator")), params= in[0].split(" "); long ans[] = new long[2000]; int NC=Integer.parseInt(params[0].trim()); for(int ci=0;ci<NC;ci++) { String[] req = in[ci+1].split(" "); long googlersN = Long.parseLong(req[0].trim()), surprising = Long.parseLong(req[1].trim()), criteria = Long.parseLong(req[2].trim()) ; ans[ci + 1] = 0; for(long i=0;i<googlersN;i++){ long score = Long.parseLong(req[(int) (i+3)].trim()); score -= criteria; if (score >= 0) { score /= 2; if (((criteria - score) == 2) && (surprising > 0)) { ans[ci + 1]++; surprising--; } else { if ((criteria - score) < 2) { ans[ci + 1]++; } } } } } String out =""; StringBuilder contents = new StringBuilder(); for (int i=0;i<NC;i++){ try { contents.append( "Case #" + (i+1)+ ": " + ans[i+1] ); contents.append(System.getProperty("line.separator")); } catch (Exception ex){ ex.printStackTrace(); } } out = contents.toString(); File outFile = new File("/Users/MatFuck/Dropbox/Projects/Code Jam Qualification 2009/src/A-small-practice-1.txt"); outFile.createNewFile(); setContents(outFile, out); System.out.println(getContents(outFile)); } }
0
347
A12852
A10869
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; public class BDancingWithTheGooglers { static int dance(int n, int s, int p, int[] tot) { int count = 0; int countSurprise = 0; int min = p + 2*Math.max(0, p - 1); int minSurprise = p + 2*Math.max(0, p - 2); for(int i = 0; i < n; ++i) { if(tot[i] >= min) { ++count; continue; } if(tot[i] >= minSurprise && countSurprise < s) { ++count; ++countSurprise; } } return count; } public static void main(String[] args) throws NumberFormatException, IOException { String filename = "B-small-attempt0.in"; BufferedReader r = new BufferedReader(new FileReader(filename)); int t = Integer.parseInt(r.readLine()); PrintWriter p = new PrintWriter("b.out"); for(int i = 0; i < t; ++i) { String[] test = r.readLine().split(" "); int n = Integer.parseInt(test[0]); int s = Integer.parseInt(test[1]); int pp = Integer.parseInt(test[2]); int[] tot = new int[n]; for(int a = 0; a < n; ++a) { tot[a] = Integer.parseInt(test[3 + a]); } int j = i + 1; p.println("Case #" + j + ": " + dance(n, s, pp, tot)); } p.flush(); p.close(); } }
0
348
A12852
A11364
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class qualB { public static void main(String[] args) { String prblm="B"; boolean fl=!true; String filein=prblm+"-"+((fl)?"large":"small")+".in.txt"; String fileout=prblm+"-"+((fl)?"large":"small")+".out.txt"; try { BufferedReader fr= new BufferedReader(new FileReader(filein)); BufferedWriter fw= new BufferedWriter(new FileWriter(fileout)); String s=fr.readLine(); int n=Integer.parseInt(s); for (int i = 1; i <= n; i++) { s=fr.readLine(); String[] tok=s.split(" "); int N=Integer.parseInt(tok[0]); int S=Integer.parseInt(tok[1]); int p=Integer.parseInt(tok[2]); int ng=0; int nag=0; for (int j = 3; j < tok.length; j++) { int ssc=Integer.parseInt(tok[j]); int bsc=(ssc+2)/3; if (bsc>=p) ng++; else if (bsc==p-1 && ssc%3!=1 && ssc>0) nag++; } System.out.println((ng+Math.min(S, nag))); fw.write("Case #"+i+": "+ (ng+Math.min(S, nag)) +"\n"); } fr.close(); fw.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
349
A12852
A10881
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 ProblemB { static int[] cycles; public static void main(String [] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); for(int i = 0; i < T; i++){ String[] input = br.readLine().split(" "); int N = Integer.parseInt(input[0]); int S = Integer.parseInt(input[1]); int p = Integer.parseInt(input[2]); int max = Math.max(3*p - 2, p); // p, p-1, p-1 int min = Math.max(3*p - 4, p); // p, p-1, p-2 OR p, p-2, p-2 int count = 0; for(int j = 0; j < N; j++){ int sum = Integer.parseInt(input[j+3]); if(sum >= max) count++; else if(sum >= min && S > 0){ //System.out.println(sum); count++; S--; } } System.out.println("Case #" + (i+1) + ": " + count); } } }
0
350
A12852
A12106
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 GoogleDance { public static void main(String[] args) { File inputFile = new File("input.txt"); Scanner s; try { s = new Scanner(inputFile); int lineCount = s.nextInt(); s.nextLine(); int googlers, surprising, target, max; int score; for(int i = 1; i <= lineCount; i++) { max = 0; googlers = s.nextInt(); surprising = s.nextInt(); target = s.nextInt(); for(int j = 0; j < googlers; j++) { score = s.nextInt(); if(score == 0 && target == 0) max++; else if(score <= target) continue; else if(score / 3 >= target) max++; else { score -= target; if(score/2 >= target) max++; else if(Math.abs(score/2 - target) < 2) max++; else if(surprising > 0 && Math.abs(score/2 - target) < 3) { max++; surprising--; } } } System.out.println("Case #"+i+": "+max); } s.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
0
351
A12852
A11731
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.impl; import de.johanneslauber.codejam.model.BaseProblem; import de.johanneslauber.codejam.model.ICase; import de.johanneslauber.codejam.model.IProblem; /** * * @author Johannes Lauber - joh.lauber@googlemail.com * */ public class DancingGooglersProblem extends BaseProblem implements IProblem { @Override public void solveCases() { for (ICase currentCase : super.listOfCases) { StringBuilder builder = new StringBuilder(); DancingGooglersCase dancingGoogleCase = (DancingGooglersCase) currentCase; int[] maxPointsForGooglers = dancingGoogleCase .getMaxPointsOfGooglers(); int minLimitOfPoints = dancingGoogleCase.getMinLimitOfPoints(); int numberOfTriplets = dancingGoogleCase.getNumberOfTriplets(); int numberOfGooglersHigherLimit = 0; for (int i = 0; i < maxPointsForGooglers.length; i++) { int maxPointsForGoogler = maxPointsForGooglers[i]; double quotient = (double) maxPointsForGoogler / (double) 3; // zero is a special case if (maxPointsForGoogler != 0) { // test whether a triplet with 1 or 2 apart is possible with // the // current min level if ((Math.round(quotient) + 1) >= minLimitOfPoints) { // test whether apart is 1 or 2 if ((minLimitOfPoints - 1) >= quotient) { // are ther more triplets left? if (numberOfTriplets > 0) { numberOfGooglersHigherLimit++; numberOfTriplets--; } else { // its possible to make a triplet with apart of // 2, // but no more left System.out.println("no more left"); } } else { numberOfGooglersHigherLimit++; } } } else if (minLimitOfPoints == 0) { // if the limit and the max points are 0, it's possible numberOfGooglersHigherLimit++; } } // for (int i = 0; i < maxPointsForGooglers.length; i++) { // if (((maxPointsForGooglers[i] + 2) / 3) >= minLimitOfPoints) { // numberOfGooglersHigherLimit++; // } else if ((numberOfTriplets > 0) // && (((maxPointsForGooglers[i] + 4) / 3) >= minLimitOfPoints)) { // numberOfTriplets--; // numberOfGooglersHigherLimit++; // } // } this.writeToFile(String.valueOf(numberOfGooglersHigherLimit)); } this.closeWriter(); } }
0
352
A12852
A11590
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 ru.sidorkevich.google.jam.qualification.b; import com.sun.org.apache.bcel.internal.generic.FieldOrMethod; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class TripletGenerator { private static int MIN_SCORE = 0; private static int MAX_SCORE = 10; public static List<Triplet> generateTriples(int sum) { List<Triplet> result = new ArrayList<Triplet>(); for (int score1 = MIN_SCORE; score1 <= MAX_SCORE; score1++) { for (int score2 = MIN_SCORE; score2 <= MAX_SCORE; score2++) { for (int score3 = MIN_SCORE; score3 <= MAX_SCORE; score3++) { if (score1 + score2 + score3 == sum && isCorrect(score1, score2, score3)) { Triplet newTriplet = new Triplet(score1, score2, score3); if (!result.contains(newTriplet)) { result.add(newTriplet); } } } } } return result; } private static boolean isCorrect(int score1, int score2, int score3) { return Math.abs(score1 - score2) <= Triplet.MAX_DISTANCE && Math.abs(score1 - score3) <= Triplet.MAX_DISTANCE && Math.abs(score2 - score3) <= Triplet.MAX_DISTANCE; } }
0
353
A12852
A11715
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package codejam; import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author user */ public class CodeJam { /** * @param args the command line arguments */ public static void main(String[] args) { FileReader fin = null; FileWriter fout = null; try { fin = new FileReader("input.txt"); fout = new FileWriter("Output.txt"); BufferedWriter out = new BufferedWriter(fout); BufferedReader in = new BufferedReader(fin); int t; t = Integer.parseInt(in.readLine()); int j = 0,N,S,P; String[] k; while (t > j) { k = in.readLine().split(" "); N = Integer.parseInt(k[0]); S = Integer.parseInt(k[1]); P = Integer.parseInt(k[2]); int arr; int count = 0; int f,mod,ml,temp; for (int i = 0; i < N; i++) { arr = Integer.parseInt(k[i + 3]); f = arr / 3; mod = arr%3; if (f>= P) { count++; } else if(f == P-1) { if(mod >= 1) { count++; } else { if(f != 0 && S > 0) { count++; S--; } } } else if(f == P-2&& S > 0) { if(mod >= 2) { count++; S--; } } // if(P == 0) // { // count++; // continue; // } // if(arr == 0) { // continue; // } // f = arr / P; // mod = arr%P; // if (f >= 3) { // count ++; // } // else if(f == 1) // { // continue; // } // else // { // ml = P; // temp = (ml - mod)/2; // ml -= temp; // mod += temp; // if (P - mod > 2) { // continue; // } // else if (P - mod == 2) // { // if(S > 0) // { // S --; // count ++; // } // } // else // { // count ++; // } // } } out.write("Case #" + (j + 1) + ": " + count + "\n"); out.flush(); j ++; } } catch (IOException ex) { Logger.getLogger(CodeJam.class.getName()).log(Level.SEVERE, null, ex); } finally { try { fin.close(); fout.close(); } catch (IOException ex) { Logger.getLogger(CodeJam.class.getName()).log(Level.SEVERE, null, ex); } } } }
0
354
A12852
A11095
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 Solution { public static void main(String args[]){ try{ FileInputStream fin=new FileInputStream("C:\\Program lang\\Google Code Jam\\input00.txt"); DataInputStream datain=new DataInputStream(fin); BufferedReader br=new BufferedReader(new InputStreamReader(datain)); int T=Integer.parseInt(br.readLine()); for(int j=0;j<T;j++){ StringTokenizer st=new StringTokenizer(br.readLine()); int N=Integer.parseInt(st.nextToken());// googlers int S=Integer.parseInt(st.nextToken());// surprising triplets int p=Integer.parseInt(st.nextToken());// least max of triplet int out=0; for(int i=0;i<N;i++){ int num=Integer.parseInt(st.nextToken()); if(num%3==0){ if(num/3>=p){ out++; } else if((num+3)/3==p && S>0 && num>=3) { S--; out++; } } else if(num%3==1){ if((num+2)/3>=p) out++; } else{ if((num+1)/3>=p && num>=2) out++; else if((num+4)/3>=p && S>0 && num>=2) { out++; S--; } } } System.out.println("Case #"+(j+1)+": "+out); } }catch(Exception e){ System.out.println(e); } } }
0
355
A12852
A12922
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.problems; import google.loader.Challenge; public abstract class AbstractChallenge implements Challenge{ private final int problemNumber; private String result; public AbstractChallenge(int i) { this.problemNumber = i; } protected void setResult(String result){ this.result = result; } @Override public String getResult() { return "Case #"+problemNumber+": "+result+"\n"; } protected int getInt(int pos, String[] tokens) { return Integer.parseInt(tokens[pos]); } }
0
356
A12852
A12153
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.ArrayList; public class DancingWithTheGooglers { ArrayList<String> result = new ArrayList<>(); public void solve(int N, int S, int p, int[] ts){ int max = 0; if(p==0){ max = ts.length; result.add(""+max); return; } //Filter of those how cannot have p based on total score ArrayList<Integer> totals = new ArrayList<>(); for(int i=0;i<ts.length;i++){ if(ts[i]>=3*p-4&&ts[i]>0){ totals.add(ts[i]); } } //Count those that must have a score above p without surprise ArrayList<Integer> needSurprise = new ArrayList<>(); for(int i=0;i<totals.size();i++){ int val = totals.get(i); if(val>=3*p-2){ max++; }else{ needSurprise.add(val); } } if(S>=needSurprise.size()){ max += needSurprise.size(); }else{ max += S; } result.add(""+max); } public void saveResults(String file){ try { FileWriter fstream = new FileWriter(file); BufferedWriter out = new BufferedWriter(fstream); int count = 1; for(int i=0;i<result.size();i++){ String s = "Case #" + count++ + ": " + result.get(i) + "\n"; out.write(s); } out.close(); } catch (Exception e) { // TODO: handle exception } } public static void main(String[] args) { DancingWithTheGooglers dwtg = new DancingWithTheGooglers(); String file = args[0]; try{ BufferedReader br = new BufferedReader(new FileReader(new File(file))); String line = br.readLine(); int numRows = Integer.parseInt(line); while((line=br.readLine())!=null){ String[] ss = line.split(" "); int N = Integer.parseInt(ss[0]); int S = Integer.parseInt(ss[1]); int p = Integer.parseInt(ss[2]); int[] ts = new int[N]; for(int i=0;i<N;i++){ ts[i] = Integer.parseInt(ss[3+i]); } dwtg.solve(N,S,p,ts); } }catch (Exception e) { System.out.println(e.getMessage()); } dwtg.saveResults(args[1]); } }
0
357
A12852
A10391
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 qualification2012; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class B { private final String f = "src\\qualification2012\\B-small-attempt0"; private BufferedReader in; private PrintWriter out; private StringTokenizer token; private B() throws IOException { in = new BufferedReader(new FileReader(f+".in")); out = new PrintWriter(f + ".out"); eat(""); int t = nextInt(); for (int i = 1; i <= t; i++) { write("Case #"+i+": "); solve(); } in.close(); out.close(); } private void solve() throws IOException { int n = nextInt(); int s = nextInt(); int p = nextInt(); int scores = 0; int[] googlers = new int[n]; for (int i = 0; i < n; i++) { googlers[i] = nextInt(); } int possibles = 0; for (int i = 0; i < googlers.length; i++) { int g = googlers[i]; if (g >= 3*p - 2 && g >= p) { scores++; } else if (g >= 3*p - 4 && g >= p) { possibles++; } } scores += ((s <= possibles)? s : possibles); write(scores + "\n"); } private String nextLine() throws IOException { return in.readLine(); } private String next() throws IOException { while (!token.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } eat(line); } return token.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(next()); } private long nextLong() throws IOException { return Long.parseLong(next()); } private void eat(String s) { token = new StringTokenizer(s); } private void write(String s) { System.out.print(s); out.print(s); } public static void main(String[] args) { try { new B(); } catch (IOException e) { e.printStackTrace(); } } }
0
358
A12852
A10011
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.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); private void run() throws IOException { in = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter("output.txt"); int T = nextInt(); for (int t = 0; t < T; t++) { out.print("Case #" + (t + 1) + ": "); int n = nextInt(); int s = nextInt(); int p = nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); int ans = 0; for (int i = 0; i < n; i++) { if (a[i] == 0) { if (p == 0) ans++; continue; } if (a[i] % 3 == 0) { if (a[i] / 3 >= p) { ans++; continue; } if (a[i] / 3 + 1 >= p && s > 0) { ans++; s--; } } if (a[i] % 3 == 1) if (a[i] / 3 + 1 >= p) { ans++; } if (a[i] % 3 == 2) { if (a[i] / 3 + 1 >= p) { ans++; continue; } if (a[i] / 3 + 2 >= p && s > 0) { ans++; s--; } } } out.println(ans); } in.close(); out.close(); } void chk(boolean b) { if (b) return; System.out.println(new Error().getStackTrace()[1]); exit(999); } void deb(String fmt, Object... args) { System.out.printf(Locale.US, fmt + "%n", args); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } 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
359
A12852
A11564
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codeJam; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class DancingWithGooglers { private static int inputLength = 1; /** * @param args the command line arguments */ public static void main(String[] args) { String filename = "DancingWithGooglers/input.txt"; if (args.length > 0) { filename = args[0]; } try { Scanner sc = new Scanner (new File(filename)); String input; int testCount = Integer.parseInt(sc.nextLine()); String out = ""; // Split the input into separate tests and collect the output. for (int i = 0; i < testCount; i++) { input = ""; for (int row = 0; row < inputLength; row++) { input += sc.nextLine() + System.lineSeparator(); } out += "Case #" + (i+1) + ": "; out += runTest(input); out += System.lineSeparator(); } System.out.println(out); BufferedWriter output = new BufferedWriter(new FileWriter( "DancingWithGooglers/output.txt")); output.write(out); output.close(); } catch (FileNotFoundException ex) { System.err.println("Input file not found"); System.exit(1); } catch (IOException ex) { } } public static String runTest(String input) { Scanner sc = new Scanner(input); long googlers = sc.nextLong(); int surprise = sc.nextInt(); int p = sc.nextInt(); ArrayList<Integer> scores = new ArrayList<Integer>(); while(sc.hasNextInt()) { scores.add(sc.nextInt()); } Long betterThan = new Long(0); int minPNormal = p - 1 < 0 ? 0 : p - 1; int minPSurprise = p - 2 < 0 ? 0 : p - 2; for (int score: scores) { if (score >= minPNormal * 2 + p) { betterThan++; } else if (surprise > 0 && score >= minPSurprise * 2 + p) { betterThan++; surprise--; } } return betterThan.toString(); } }
0
360
A12852
A12248
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.googe.codejam.qround; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; /** * @author A.Alathwari * * Problem A : * */ public class ProblemA implements Runnable { asem.core.util.InputReader fin; java.io.PrintWriter fout; /** * @param fin * @param fout */ public ProblemA(asem.core.util.InputReader fin, PrintWriter fout) { this.fin = fin; this.fout = fout; } /** * @param fin * @param fout * @throws IOException * @throws FileNotFoundException */ public ProblemA(String fin, String fout) throws FileNotFoundException, IOException { this.fin = new asem.core.util.InputReader(new FileReader(fin)); this.fout = new PrintWriter(System.out); } /* (non-Javadoc) * @see java.lang.Runnable#run() */ @Override public void run() { // TODO Auto-generated method stub try { String ciphertext1 = new String("ejp mysljylc kd kxveddknmc re jsicpdrysi"); String ciphertext2 = new String("rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"); String ciphertext3 = new String("de kr kd eoya kw aej tysr re ujdr lkgc jv qz"); String plaintext1 = new String("our language is impossible to understand"); String plaintext2 = new String("there are twenty six factorial possibilities"); String plaintext3 = new String("so it is okay if you want to just give up zq"); String code = new String("abcdefghijklmnopqrstuvwxyz"); String code2 = new String(); char ch = ' '; for (int i = 0; i < 26; i++) { ch = code.charAt(i); if (plaintext1.indexOf(ch) >= 0) code2 += ciphertext1.charAt(plaintext1.indexOf(ch)); else if (plaintext2.indexOf(ch) >= 0) code2 += ciphertext2.charAt(plaintext2.indexOf(ch)); else if (plaintext3.indexOf(ch) >= 0) code2 += ciphertext3.charAt(plaintext3.indexOf(ch)); else code2 += ch; } for (int tNum = 1, inT = fin.readInt(); tNum <= inT; tNum++) { String ciphertext = fin.readLine(true); String plaintext = new String(); for (int i = 0; i < ciphertext.length(); i++) if (code2.indexOf(ciphertext.charAt(i)) >= 0) plaintext += code.charAt(code2.indexOf(ciphertext.charAt(i))); else if (ciphertext.charAt(i) == ' ') plaintext += ciphertext.charAt(i); System.out.println("Case #" + tNum + ": " + plaintext); } } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
361
A12852
A11804
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.Arrays; import java.util.Comparator; public class Qualify { public static void main(String[] args) { try { BufferedReader reader = new BufferedReader(new FileReader(new File("B-small-attempt3.in"))); int cases = Integer.parseInt(reader.readLine()); for (int d = 0; d < cases; d++) { // parse String line = reader.readLine(); String[] spLine = line.split(" "); int googs = Integer.parseInt(spLine[0]); int surprises = Integer.parseInt(spLine[1]); int prize = Integer.parseInt(spLine[2]); Googler[] googArr = new Googler[googs]; // find the solutions for each googler for (int r = 0; r < googs; r++) { googArr[r] = new Googler(); Integer total = Integer.parseInt(spLine[(r + 3)]); googArr[r].poss(total, prize); } // sort the array based on how many possibilities it has Arrays.sort(googArr, new Comparator<Googler>() { @Override public int compare(Googler o1, Googler o2) { // TODO Auto-generated method stub return new Integer(o1.trueCounter) .compareTo(o2.trueCounter); } }); int surCounter = 0; int winCounter = 0; /* * boolean prizeSurprise = false; boolean prizeNoSurprise = * false; boolean failSurprise = false; boolean failNoSurprise = * false; */ for (int i = 0; i < googs; i++) { if (googArr[i].trueCounter == 1) { if (googArr[i].prizeSurprise == true) { winCounter++; surCounter++; googArr[i].used = true; } else if (googArr[i].prizeNoSurprise == true) { winCounter++; googArr[i].used = true; } else if (googArr[i].failSurprise == true) { surCounter++; googArr[i].used = true; } else { // nothing to do with this googArr[i].used = true; } } } for (int i = 0; i < googs && surCounter < surprises; i++) { if (googArr[i].used == false) { if (googArr[i].prizeSurprise == true && googArr[i].prizeNoSurprise == false) { winCounter++; surCounter++; googArr[i].used = true; break; } } } for (int i = 0; i < googs && surCounter < surprises; i++) { if (googArr[i].used == false) { if (googArr[i].prizeSurprise == true) { winCounter++; surCounter++; googArr[i].used = true; break; } } } for (int i = 0; i < googs && surCounter < surprises; i++) { if (googArr[i].used == false) { if (googArr[i].failSurprise == true) { surCounter++; googArr[i].used = true; } } } for (int i = 0; i < googs; i++) { if (googArr[i].used == false) { if (googArr[i].prizeNoSurprise) { winCounter++; googArr[i].used = true; } } } System.out.println("Case #" + (d+1) + ": " + winCounter); } } catch (Exception ex) { ex.printStackTrace(); } } }
0
362
A12852
A12833
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.lang.Double.parseDouble; import static java.lang.Integer.parseInt; import static java.lang.Long.parseLong; import static java.lang.System.exit; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { static BufferedReader in; static PrintWriter out; static StringTokenizer tok; static int test; static void solve() throws Exception { int n = nextInt(); int s = nextInt(); int p = nextInt(); int ans = 0; for (int i = 0; i < n; i++) { int t = nextInt(); if ((t + 2) / 3 >= p) { ++ans; } else if (s > 0 && t > 0 && (t + 4) / 3 >= p) { --s; ++ans; } } printCase(); out.println(ans); } static void printCase() { out.print("Case #" + test + ": "); } static void printlnCase() { out.println("Case #" + test + ":"); } static int nextInt() throws IOException { return parseInt(next()); } static long nextLong() throws IOException { return parseLong(next()); } static double nextDouble() throws IOException { return parseDouble(next()); } static String next() throws IOException { while (tok == null || !tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } public static void main(String[] args) { try { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); int tests = nextInt(); for (test = 1; test <= tests; test++) { solve(); } in.close(); out.close(); } catch (Throwable e) { e.printStackTrace(); exit(1); } } }
0
363
A12852
A11200
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 Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int T = sc.nextInt(); int caseNum = 0; while(caseNum++<T){ int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int[] t = new int[n]; for(int i=0; i<n; i++){ t[i] = sc.nextInt(); } int[][] triplet = new int[n][3]; for(int i=0; i<n; i++){ triplet[i][0] = t[i]/3; triplet[i][1] = t[i]/3; triplet[i][2] = t[i]/3; int tmp = 0; for(int j=t[i]%3; j>0; j--){ triplet[i][tmp++]++; } } int ans = 0; for(int i=0; i<n; i++){ if(triplet[i][0]>=p && triplet[i][0]!=triplet[i][1]){ ans++; triplet[i][0] = -1; } else if(triplet[i][0]!=triplet[i][1]){ triplet[i][0] = -1; } else if(triplet[i][0]>=p){ ans++; triplet[i][0] = -1; } else if(triplet[i][1]>0){ triplet[i][0]++; triplet[i][1]--; } } int count = 0; for(int i=0; i<n; i++){ if(triplet[i][0]>=p){count++;} } if(count>=s){ans += s;} else {ans += count;} System.out.println("Case #"+caseNum+": "+ans); } } }
0
364
A12852
A10483
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.HashSet; import java.util.Scanner; public class Dance { private int[] mTotalScores; private int mMaxSurprise; private int mP; private int mAnswer; public Dance(int[] totalScores, int maxSurprise, int p) { mTotalScores = totalScores; mMaxSurprise = maxSurprise; mP = p; recurse(0, 0, 0); } public int getAnswer() { return mAnswer; } private void recurse(int index, int surprises, int qualified) { if (surprises > mMaxSurprise) return; if (index >= mTotalScores.length) { if (qualified > mAnswer) { mAnswer = qualified; } return; } Pair[] pos = scoreVariations(mTotalScores[index]); for (int i = 0; i < pos.length; i++) { int localSurprises = surprises; int localQualified = qualified; if (pos[i].surprise) localSurprises++; if (pos[i].max >= mP) localQualified++; recurse(index + 1, localSurprises, localQualified); } } // Get possible score variations public static Pair[] scoreVariations(int score) { HashSet<Pair> set = new HashSet<Pair>(); int fStart = score / 3; int fEnd = Math.min(10, fStart + 3); for (int i = fStart; i <= fEnd; i++) { int sStart = i; int sEnd = Math.min(10, i + 2); for (int j = sStart; j <= sEnd; j++) { int k = score - i - j; if (Math.abs(i - k) > 2 || Math.abs(j - k) > 2 || k > 10 || k < 0) { // Invalid case continue; } boolean surprise = Math.abs(i - k) == 2 || Math.abs(j - k) == 2 || Math.abs(i - j) == 2; int max = Math.max(i, Math.max(j, k)); set.add(new Pair(max, surprise)); } } return set.toArray(new Pair[0]); } public static void main(String[] args) { Scanner in = new Scanner(System.in); int num = in.nextInt(); for (int i = 0; i < num; i++) { int num2 = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int[] scores = new int[num2]; for (int j = 0; j < num2; j++) { scores[j] = in.nextInt(); } Dance d = new Dance(scores, s, p); System.out.println("Case #" + (i + 1) + ": " + d.getAnswer()); } } }
0
365
A12852
A11948
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.awt.Point; import java.lang.Math; class Case{ int num0,num1,num2,num3; String result=""; public Case(File aFile) { try{ StringBuilder contents = new StringBuilder(); BufferedReader input = new BufferedReader(new FileReader(aFile)); String line = input.readLine(); num0 = Integer.valueOf(line).intValue(); int i=1; while (i<=num0 && ( line = input.readLine()) != null){ StringTokenizer st = new StringTokenizer(line," "); num1=Integer.valueOf(st.nextToken()).intValue(); num2=Integer.valueOf(st.nextToken()).intValue(); num3=Integer.valueOf(st.nextToken()).intValue(); Vector v1=new Vector(); for (int j=0; j<num1; j++){ int inum1=Integer.valueOf(st.nextToken()).intValue(); v1.addElement(inum1); } oneCase(i,num1,num2,num3,v1); i++; } } catch (IOException ex){ ex.printStackTrace(); } } public String getResult (){ return result; } public void oneCase (int c,int n1,int n2,int n3,Vector vv){ String re=""; int noSurpriseScore=Math.max(0,n3*3-2); int needSurpriseScore=Math.max(0,n3*3-4); if (n3==1){ needSurpriseScore=1; } int re_y=0; for (int i=0; i<vv.size(); i++){ int score=((Integer)(vv.elementAt(i))).intValue(); if (score>=noSurpriseScore){ re_y++; } else if (n2>0 && score>=needSurpriseScore){ re_y++; n2--; } } //*** output System.out.println(" "); System.out.println("case="+c+": "+n1+":"+n2+":"+n3+" "+vv); //*** re=re_y+""; result+="Case #"+c+": "+re+System.getProperty("line.separator"); } } public class ReadWriteTextFile { static public String getContents(File aFile) { StringBuilder contents = new StringBuilder(); try { BufferedReader input = new BufferedReader(new FileReader(aFile)); try { String line = null; while (( line = input.readLine()) != null){ contents.append(line); contents.append(System.getProperty("line.separator")); } } finally { input.close(); } } catch (IOException ex){ ex.printStackTrace(); } return contents.toString(); } static public void setContents(File aFile, String aContents) throws FileNotFoundException, IOException { if (aFile == null) { throw new IllegalArgumentException("File should not be null."); } if (!aFile.exists()) { throw new FileNotFoundException ("File does not exist: " + aFile); } if (!aFile.isFile()) { throw new IllegalArgumentException("Should not be a directory: " + aFile); } if (!aFile.canWrite()) { throw new IllegalArgumentException("File cannot be written: " + aFile); } Writer output = new BufferedWriter(new FileWriter(aFile)); try { output.write( aContents ); } finally { output.close(); } } public static void main (String... aArguments) throws IOException { File testFile = new File("D:\\java\\readwritetext\\Dancing With the Googlers\\source.txt"); File testFile2 = new File("D:\\java\\readwritetext\\Dancing With the Googlers\\result.txt"); Case allcases = new Case(testFile); setContents(testFile2, allcases.getResult()); } }
0
366
A12852
A12038
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 enum Direction { UP , DOWN , LEFT , RIGHT; public int dx() { switch ( this ) { case UP: case DOWN: return 0; case LEFT: return -1; case RIGHT: return 1; default: throw new RuntimeException( "assert" ); } } public int dy() { switch ( this ) { case UP: return -1; case DOWN: return 1; case LEFT: case RIGHT: return 0; default: throw new RuntimeException( "assert" ); } } public Direction reverese() { switch ( this ) { case UP: return DOWN; case DOWN: return UP; case LEFT: return RIGHT; case RIGHT: return LEFT; default: throw new RuntimeException( "assert" ); } } public Direction turnLeft() { switch ( this ) { case UP: return LEFT; case DOWN: return RIGHT; case LEFT: return DOWN; case RIGHT: return UP; default: throw new RuntimeException( "assert" ); } } public Direction turnRight() { switch ( this ) { case UP: return RIGHT; case DOWN: return LEFT; case LEFT: return UP; case RIGHT: return DOWN; default: throw new RuntimeException( "assert" ); } } }
0
367
A12852
A11970
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 static void main(String []args){ Scanner input = new Scanner(System.in); int cases = input.nextInt(); int []result = new int[cases]; //input.nextLine(); for(int i = 0; i < cases ;i++){ int n = input.nextInt(); int s = input.nextInt(); int p = input.nextInt(); for(int j = 0 ;j<n;j++){ int total = input.nextInt(); int avg = total/3; int mod = total%3; if(total/3.0 > p-1){ result[i]++; }else{ if(avg == p-1 || (avg+mod)>=p){ if(s>0 && avg>0){ result[i]++; s--; } } } } } try { BufferedWriter output = new BufferedWriter(new FileWriter("outfilename.txt")); for(int i = 1; i<=cases ;i++){ System.out.println("Case #"+i+": "+result[i-1]); output.write("Case #"+i+": "+result[i-1]+"\n"); } output.close(); } catch (IOException e) { } } }
0
368
A12852
A12420
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 reusable; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; public abstract class CodeJamBase { private final List<String> inputLines; private final String filename; private int testCases; private int index = 0; public CodeJamBase(String filename) { this.filename = (filename != "") ? filename : "sample"; try { inputLines = Files.readAllLines(Paths.get("data/" + this.filename + ".in"), Charset.defaultCharset()); } catch (IOException e) { throw new RuntimeException("Failed to read file: '" + this.filename + "'"); } setup(); } protected void setup() { setTestCases(nextInt()); } protected abstract String solution(); public void run() { long startTime = System.currentTimeMillis(); List<String> outputLines = new ArrayList<>(); for (int i = 0; i < testCases; i++) { String outputLine = "Case #" + (i + 1) + ": " + solution(); outputLines.add(outputLine); System.out.println(outputLine); } try { Files.write(Paths.get("data/" + filename + ".out"), outputLines, Charset.defaultCharset()); } catch (IOException e) { throw new RuntimeException("Failed to write file: '" + filename + "'"); } System.out.println(); System.err.println("Total run time: " + ((System.currentTimeMillis() - startTime) / 1000d) + "s"); } protected final String nextString() { return inputLines.get(index++); } protected final int nextInt() { return Integer.parseInt(nextString()); } protected final String[] nextStringArray() { return inputLines.get(index++).split(" "); } protected final int[] nextIntArray() { String[] items = nextStringArray(); int[] result = new int[items.length]; for (int i = 0; i < items.length; i++) { result[i] = Integer.parseInt(items[i]); } return result; } public final void setTestCases(int testCases) { this.testCases = testCases; } }
0
369
A12852
A11831
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 googlers; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { public static int calcWIS(int n){ if(n - 2 < 0) return 0; return ((n - 2) / 3) + 2; } public static int calcWOS(int n){ if(n - 1 < 0) return 0; return ((n - 1) / 3) + 1; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub //String fileName = args[0]; String fileName = "googlers/B-small-attempt0.in"; Scanner sC = null; try { sC = new Scanner(new File(fileName)); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } int T = sC.nextInt(); int N, S, p; int[] tab, wiS, woS; for(int i = 0; i < T; i++){ N = sC.nextInt(); S = sC.nextInt(); p = sC.nextInt(); tab = new int[N]; wiS = new int[N]; woS = new int[N]; for(int j = 0; j < N; j++){ tab[j] = sC.nextInt(); wiS[j] = calcWIS(tab[j]); woS[j] = calcWOS(tab[j]); //System.out.println(tab[j] + " " + wiS[j] + " " + woS[j]); } int count = 0; for(int j = 0; j < N; j++){ if(woS[j] >= p){ count++; } if(woS[j] < p && wiS[j] >= p && S > 0){ count++; S--; } } System.out.println("Case #" + (i + 1) + ": " + count); } } }
0
370
A12852
A11121
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_quali; import java.util.Scanner; /** * * @author sansarun */ public class Dancing { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int caseNum = sc.nextInt(); for (int currentCase = 1; currentCase <= caseNum; currentCase++) { int googlers = sc.nextInt(); int surprise = sc.nextInt(); int p = sc.nextInt(); int alreadyPass = 0; int canHelp = 0; for (int i = 0; i < googlers; i++) { int totalScore = sc.nextInt(); int maxCompound = findMaxCompound(totalScore); int fragment = totalScore % 3; if (totalScore < 3) { if(findMaxCompound(totalScore) >= p) { alreadyPass++; } } else { switch (fragment) { case 1: if (maxCompound >= p) { alreadyPass++; } break; case 0: case 2: if (maxCompound >= p) { alreadyPass++; } else if (maxCompound + 1 >= p) { canHelp++; } break; } } } int totalPass = alreadyPass + (canHelp > surprise ? surprise : canHelp); System.out.println(String.format("Case #%d: %d", currentCase, totalPass)); } } private static int findMaxCompound(int n) { return (int) Math.round(Math.ceil(n / 3.0)); } }
0
371
A12852
A11757
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 Dance { public static void main(String[] args) { Scanner cin = new Scanner(System.in); int linenum = cin.nextInt(); for(int idx = 1; idx < linenum+1; idx++) { System.out.print("Case #" + idx + ": "); int n = cin.nextInt(); int s = cin.nextInt(); int p = cin.nextInt(); int ans = 0; for(int i=0; i < n; i++) { int score = cin.nextInt(); if(score == 0) { if(p == 0) ans++; else continue; } else if(score == p*3 || score == p*3 - 1 ||score == p*3 - 2 || score > p*3) { ans++; } else if(score == p*3 - 3 || score == p*3 - 4) { if(s > 0) { s--; ans++; } else { continue; } } else { continue; } } System.out.println(ans); } } }
0
372
A12852
A11919
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; import java.io.FileNotFoundException; import java.util.Arrays; public class Dancing2 { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File("222.in")); int numOfTests = Integer.parseInt(in.nextLine()); for(int tests = 0; tests < numOfTests; tests++) { int googlers = in.nextInt(); int specials = in.nextInt(); //Number of special cases int lookingFor = in.nextInt(); //Number it must contain at least int found = 0; int foundSpecials = 0; int[] googScores = new int[googlers]; for(int googs = 0; googs < googlers; googs++) { googScores[googs] = in.nextInt(); } Arrays.sort(googScores); for(int i = 0; i < googlers; i++) { int score = googScores[i]; boolean completed = false; int[] scores = {lookingFor,lookingFor,lookingFor}; if(scores[0] == 1) { scores[1] = 1; scores[2] = 1; } if(scores[0] == 0) { scores[1] = 0; scores[2] = 0; } while(!completed && specials != foundSpecials) { if((scores[0] + (scores[1]-2) + (scores[2]-2)) > score && scores[0] > 1) break; if(scores[0] < 2) { if(scores[0] > score) break; } if((scores[0] + (scores[1]-2) + (scores[2]-2)) == score && scores[0] > 1) { found += 1; foundSpecials += 1; completed = true; break; } if((scores[0] + (scores[1]-2) + (scores[2]-1)) == score && scores[0] > 1) { found += 1; foundSpecials += 1; completed = true; break; } if((scores[0] + (scores[1]-2) + (scores[2])) == score && scores[0] > 1) { found += 1; foundSpecials += 1; completed = true; break; } if((scores[0] + (scores[1]-1) + (scores[2]+1)) == score && scores[0] >= 1)//102 { found += 1; foundSpecials += 1; completed = true; break; } if((scores[0] + (scores[1]) + (scores[2]+2)) == score ) //002 { found += 1; foundSpecials += 1; completed = true; break; } if((scores[0] + (scores[1]+1) + (scores[2]+2)) == score) //012 { found += 1; foundSpecials += 1; completed = true; break; } if((scores[0] + (scores[1]+2) + (scores[2]+2)) == score) //022 { found += 1; foundSpecials += 1; completed = true; break; } scores[0] += 1; if (scores[0] >= 2) { scores[1] = (scores[0]); scores[2] = (scores[0]); } else { scores[1] = 1; scores[2] = 1; } }//end of while if((scores[0] + (scores[1]-1) + (scores[2]-1)) <= score && specials == foundSpecials && !completed) { found += 1; } }//end for(goog) System.out.println("Case #" + (tests+1) + ": " + found); }//end for(tests) }//end method }//end class
0
373
A12852
A12405
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 qual; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class B { public static void main(String[] args) throws Exception{ String in_file = "q/b/s_in.txt"; String out_file = in_file.replace("_in.txt", "_out.txt"); BufferedReader in = new BufferedReader(new FileReader(in_file)); BufferedWriter out = new BufferedWriter(new FileWriter(out_file)); int t = Integer.parseInt(in.readLine()); for (int i = 1; i <= t; i++){ String[] tmp = in.readLine().split(" "); int n = Integer.parseInt(tmp[0]); int s = Integer.parseInt(tmp[1]); int p = Integer.parseInt(tmp[2]); int[] res = new int[n]; for (int j = 0; j < n; j++){ res[j] = Integer.parseInt(tmp[j + 3]); } int min = p > 0 ? p + (p-1) * 2 : p; int sup_min = p > 1 ? p + (p-2) * 2 : p; int count = 0; for (int j = 0; j < n; j++){ int cres = res[j]; if (cres >= min) { count++; } else if (s > 0 && cres >= sup_min) { count++; s--; } } out.write("Case #" + i + ": " + count + "\n"); } in.close(); out.close(); } }
0
374
A12852
A11816
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedList; import java.util.Scanner; import java.util.StringTokenizer; /** * * @author bilal */ public class Googler { static String[] inputBuffer; static int testCasesCount = 0; public Googler(InputStream is) { Scanner scanner = new Scanner(is); testCasesCount = scanner.nextInt(); inputBuffer = new String[testCasesCount]; int loopCounter = 0; scanner.nextLine(); while (scanner.hasNextLine()) { String nextTestCase = scanner.nextLine(); inputBuffer[loopCounter] = nextTestCase; loopCounter++; if (loopCounter == testCasesCount) { break; } } } public void solve_Googlers(String[] input) { int solution = 0; int googlers; int surprisingCases; int targetHighestScore; for (int i = 0; i < input.length; i++) {//iterate over all test cases System.out.print("Case #" + (i + 1) + ": "); solution = 0; StringTokenizer st = new StringTokenizer(input[i]); googlers = Integer.parseInt(st.nextToken()); surprisingCases = Integer.parseInt(st.nextToken()); targetHighestScore = Integer.parseInt(st.nextToken()); //create Score objects from remaining tokens LinkedList<Integer> sortedScores = new LinkedList<Integer>(); while (st.hasMoreTokens()) { sortedScores.add(Integer.parseInt(st.nextToken())); } Collections.sort(sortedScores); //traverse over sorted collection for (int j = googlers - 1; j >= 0; j--) { int totalScore = sortedScores.get(j); int j1 = (int) Math.ceil(totalScore / 3.0); int j2 = (int) Math.ceil((totalScore - j1) / 2.0); int j3 = totalScore - j1 - j2; //System.out.println(">>>>>"+j1+" "+j2+" "+j3); // if (j1 >= targetHighestScore) {//this googler scored the higheest target score solution++; continue; } if (surprisingCases <= 0) { break;//no more surpising cases -> no more solutions } //deal with surprising cases if (j1 == j2 && (j1 + 1) >= targetHighestScore && j2 > 0) { surprisingCases--; solution++; } } System.out.print(solution); if (i != input.length - 1) { System.out.println(); } //break;//deal with only first case } } public static void main(String[] args) { Googler goolger = new Googler(System.in); goolger.solve_Googlers(inputBuffer); } class Scores { int totalScore; int j1, j2, j3; public Scores(int totalScore, int j1, int j2, int j3) { this.totalScore = totalScore; this.j1 = j1; this.j2 = j2; this.j3 = j3; } } }
0
375
A12852
A10718
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileWriter; import java.util.HashMap; import java.util.Scanner; import java.util.logging.Logger; public class B2012 { public static void main(String[] args) throws Exception { File f = new File("C:\\gcj\\b_res.txt"); FileWriter w = new FileWriter(f); Scanner sca = new Scanner(new File("C:\\gcj\\b.txt")); int T = sca.nextInt(); for (int i = 0; i < T; i++) { int N = sca.nextInt(); int S = sca.nextInt(); int p = sca.nextInt(); int[] t = new int[N]; int res = 0; int puwede = 0; for (int j = 0; j < N; j++) { t[j] = sca.nextInt(); if (t[j] >= p * 3 - 2) { res++; } else if (t[j] >= p * 3 - 4 && p * 3 - 4 > 0) { puwede++; } } res += Math.min(puwede, S); w.write("Case #" + (i + 1) + ": " + res + "\n"); } w.flush(); w.close(); } }
0
376
A12852
A12622
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 B { private static final String PROBLEM_NAME = "B-small"; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader r = new BufferedReader(new FileReader(PROBLEM_NAME + ".in")); BufferedWriter w = new BufferedWriter(new FileWriter(PROBLEM_NAME + ".out")); int testsNumber = Integer.parseInt(r.readLine()); for (int i = 0; i < testsNumber; ++i) { String[] line = r.readLine().split(" "); int n = Integer.parseInt(line[0]); int s = Integer.parseInt(line[1]); int p = Integer.parseInt(line[2]); int good = 0; int almost = 0; for (int j = 0; j < n; ++j) { int sum = Integer.parseInt(line[3 + j]); if (sum % 3 == 0) { if (sum / 3 >= p) { ++good; } else if (sum / 3 > 0 && sum / 3 + 1 >= p) { ++almost; } continue; } if (sum % 3 == 1) { if (sum / 3 + 1 >= p) { ++good; } continue; } if (sum % 3 == 2) { if (sum / 3 + 1 >= p) { ++good; } else if (sum / 3 + 2 >= p) { ++almost; } continue; } } w.write("Case #" + (i + 1) + ": "); w.write(good + ((almost < s)? almost: s) + ""); w.newLine(); } r.close(); w.close(); } }
0
377
A12852
A11915
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 qual; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class Googlers { public static void main(String[] args) throws IOException { new Googlers().run(); } int solve(int s, int p, int[] scores) { Arrays.sort(scores); for (int i = 0; i < scores.length / 2; i++) { int t = scores[i]; scores[i] = scores[scores.length - 1 - i]; scores[scores.length - 1 - i] = t; } int count = 0; for (int i = 0; i < scores.length; i++) { int cur = scores[i]; int a, b, c; if (cur % 3 == 0) { a = cur / 3; b = cur / 3; c = cur / 3; } else if (cur % 3 == 1) { a = cur / 3 + 1; b = cur / 3; c = cur / 3; } else { a = cur / 3 + 1; b = cur / 3 + 1; c = cur / 3; } if (a >= p) count++; else { if (a == b && b > 0 && s > 0) { a++; b--; if (a >= p) { count++; s--; } } } } return count; } public void run() throws IOException { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int testsCount = in.nextInt(); for (int t = 0; t < testsCount; t++) { int n = in.nextInt(), s = in.nextInt(), p = in.nextInt(); int[] scores = new int[n]; for (int i = 0; i < n; i++) { scores[i] = in.nextInt(); } int ans = solve(s, p, scores); out.printf("Case #%d: %d\n", t + 1, ans); } out.close(); } }
0
378
A12852
A12619
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Dancing { static int[] max_surprising = new int[31]; static int[] max_no_surprising = new int[31]; public static void main(String[] args) throws IOException { max_surprising[0] = 0; max_no_surprising[0] = 0; max_surprising[1] = 0; max_no_surprising[1] = 0; for (int i = 2; i < 29; i++) { int remainder = i % 3; int quotient = i / 3; if (remainder == 0) { max_no_surprising[i] = quotient; max_surprising[i] = quotient + 1; } else if (remainder == 1) { max_no_surprising[i] = quotient + 1; max_surprising[i] = quotient + 1; } else { max_no_surprising[i] = quotient + 1; max_surprising[i] = quotient + 2; } } max_no_surprising[29] = 10; max_surprising[29] = 10; max_no_surprising[30] = 10; max_surprising[30] = 10; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(in.readLine()); for (int i = 0; i < cases; i++) { String[] inp = in.readLine().split(" "); int surprisesLeft = Integer.parseInt(inp[1]); int target = Integer.parseInt(inp[2]); String[] scores = new String[inp.length - 3]; for(int j = 0; j < scores.length; j++) scores[j] = inp[j+3]; int answer = calculate(scores, surprisesLeft, target); System.out.println("Case #" + (i+1) + ": " + answer); } } public static int calculate(String[] scoresRemaining, int surprisesLeft, int target) { int count = 0; if (scoresRemaining.length == surprisesLeft) { for (int i = 0; i < scoresRemaining.length; i++) { if (max_surprising[Integer.parseInt(scoresRemaining[i])] >= target) { count++; } } return count; } else if (surprisesLeft == 0) { for (int i = 0; i < scoresRemaining.length; i++) { if (max_no_surprising[Integer.parseInt(scoresRemaining[i])] >= target) { count++; } } return count; } else { int score = Integer.parseInt(scoresRemaining[0]); String[] temp = new String[scoresRemaining.length - 1]; for (int i = 0; i < temp.length; i++) { temp[i] = scoresRemaining[i + 1]; } if (max_no_surprising[score] >= target) { return 1 + calculate(temp, surprisesLeft, target); } else if (max_surprising[score] >= target) { return 1 + calculate(temp, surprisesLeft - 1, target); } else { return calculate(temp, surprisesLeft, target); } } } }
0
379
A12852
A11298
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 org.pokuri; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /** * @author Pokuri * @since Apr 14, 2012 * org.pokuri.Googlers */ public class Googlers{ private BufferedReader reader = null; /** * @param filePath * @return */ protected void openFile(String filePath){ try { reader = new BufferedReader(new FileReader(new File(filePath))); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } } protected void closeFile(){ try { reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } protected BufferedWriter openOutputFile(String filePath){ try { return new BufferedWriter(new FileWriter(new File(filePath))); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } protected int noOfTestCases(){ try { return Integer.parseInt(reader.readLine()); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return 0; } protected String nextCase(){ try { return reader.readLine(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } protected void generateOutput() throws IOException { openFile("input/Googlers.input"); int cases = noOfTestCases(); BufferedWriter outputFile = openOutputFile("output/Googlers.txt"); for(int i=1; i<=cases; i++){ String nextCase = nextCase(); String[] split = nextCase.split(" "); int noOfSurprises = Integer.parseInt(split[1]); int minBestScore = Integer.parseInt(split[2]); int bestScoreGooglers = 0; // for each score find it'shad best score or not for(int k=3; k<split.length; k++){ // check that the score can have best score in it int score = Integer.parseInt(split[k]); // first check that score is greater than or equal to the min.best score if(score >= minBestScore){ // now find the max score that can be when all triplets are min.best score int multiplied = minBestScore*3; // if score is more than sum of tripltes -2 then we can arrange them to form at lest a best score in it if(score >= multiplied - 2){ bestScoreGooglers++; } // if not found then check we left with any surprises of not. // the use that surpeise to make that score good enough for forming min.best score in triplets else if(noOfSurprises > 0 && score >= multiplied - 4){ bestScoreGooglers++; noOfSurprises--; } } } outputFile.write("Case #"+i+": "+bestScoreGooglers); outputFile.newLine(); } outputFile.flush(); outputFile.close(); closeFile(); } public static void main(String[] args) throws IOException { Googlers googlers = new Googlers(); googlers.generateOutput(); } }
0
380
A12852
A12563
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 Problem2 { public static void main(String arg[]) { try{ FileInputStream fstream = new FileInputStream("textfile.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter foutstream = new FileWriter("D:\\Problem2output.txt"); BufferedWriter out = new BufferedWriter(foutstream); String strLine,copyStrLine=""; int caseCount = -1; strLine = br.readLine(); caseCount = Integer.parseInt(strLine); for(int j=0; j < caseCount; j++) //System.out.println (strLine); { strLine = br.readLine(); String[] splitStrings = strLine.split(" "); int countGooglers = Integer.parseInt(splitStrings[0]); int surprisingSet = Integer.parseInt(splitStrings[1]); int pValue = Integer.parseInt(splitStrings[2]); int pMaxCount = 0; for(int i = 0 ; i < countGooglers; i++ ) { int score = Integer.parseInt(splitStrings[3+i]); int n = score / 3; if(pValue > score){ continue; } if(score % 3 == 0){ if(n >= pValue){ pMaxCount++; } if(n == pValue - 1){ if(surprisingSet > 0){ pMaxCount++; surprisingSet--; } } } else if(score % 3 == 1){ if(n >= pValue - 1){ pMaxCount++; } } else{ if(n >= pValue - 1){ pMaxCount++; } if(n == pValue - 2){ if(surprisingSet > 0){ pMaxCount++; surprisingSet--; } } } } System.out.println("Case #" + (j + 1) + ": " + pMaxCount + "\n"); out.write("Case #" + (j + 1) + ": " + pMaxCount + "\n"); } out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
381
A12852
A10890
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 utils; /** * * @author Fabien Renaud */ public abstract class Jam implements Runnable, JamParser { protected final String[] lines; protected final JamCase[] cases; protected final int t; private final String filenameInput; private final String filenameOutput; private final String[] output; private final StopWatch timer; private int count; protected Jam(String filename) { this.filenameInput = filename; this.filenameOutput = filename.replace(".in", ".out"); this.count = 0; this.lines = File.readAllLines(filenameInput); this.timer = new StopWatch(); this.t = Integer.parseInt(lines[0]); this.cases = new JamCase[t]; this.output = new String[t]; File.delete(filenameOutput); } protected final synchronized void appendOutput(int number, String result) { output[number - 1] = String.format("Case #%1$d: %2$s", number, result); count++; if (count == t) { timer.stop(); saveOutput(); } } private void saveOutput() { if (count != t) { System.err.println(String.format("%1$d results are missing. File not saved.")); } else { File.writeAllLines(filenameOutput, output); System.out.println("File saved at " + filenameOutput); System.out.println("---------- OUTPUT ----------"); for (String s : output) { System.out.println(s); } System.out.println("--- Processed in " + timer.getElapsedSeconds() + " seconds."); } } @Override public final void run() { int j; count = 0; timer.start(); for (int i = 1; i <= t; i++) { j = i - 1; cases[j] = getJamCase(i); if (cases[j] != null) { new Thread(cases[j]).start(); } } } }
0
382
A12852
A12771
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_Round_2012; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { public static void main(String[] args) throws FileNotFoundException, IOException { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintWriter out = new PrintWriter("b.out"); StringTokenizer k; int t,n,s,p,count,player,reminder; t=Integer.parseInt(in.readLine().trim()); for (int i = 1; i <= t; i++) { k=new StringTokenizer(in.readLine()); n=Integer.parseInt(k.nextToken()); s=Integer.parseInt(k.nextToken()); p=Integer.parseInt(k.nextToken()); if(p==0){ out.append("Case #"+i+": "+n+"\n"); continue; } count=0; for (int j = 0; j < n; j++) { player=Integer.parseInt(k.nextToken()); if(player==0)continue; reminder=player%3; switch (reminder){ case 0: if(player/3>=p) count++; else if(s>0 && (player/3)+1>=p){ count++; s--; } break; case 1: if((player/3)+1>=p) count++; break; case 2: if((player/3)+1>=p) count++; else if(s>0 && (player/3)+2>=p){ count++; s--; } break; } } out.append("Case #"+i+": "+count+"\n"); } out.close(); } }
0
383
A12852
A12000
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 codejam.StoreCredit; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author java */ public class DancingGooglers { static BufferedReader in; private static void open() { in = new BufferedReader(new InputStreamReader(System.in)); } private static void close() { try { in.close(); } catch (IOException ex) { Logger.getLogger(StoreCredit.class.getName()).log(Level.SEVERE, null, ex); } } private static int readInt() throws IOException { Integer i = Integer.parseInt(in.readLine()); return i; } private static int[] readInts() throws IOException { String[] vals = in.readLine().split(" "); int[] arr = new int[vals.length]; for (int i = 0; i < vals.length; i++) { arr[i] = Integer.parseInt(vals[i]); } return arr; } public static void main(String[] args) throws IOException { open(); int T = readInt(); for (int t = 0; t < T; t++) { int[] line = readInts(); int N = line[0]; int s = line[1]; int p = line[2]; int pCount = 0; int[] scores = new int[line.length - 3]; System.arraycopy(line, 3, scores, 0, scores.length); if (p == 0) { pCount = scores.length; } else { for (int i = 0; i < scores.length; i++) { int score = scores[i]; int minSum = p + (2 * (p - 2) < 0 ? 0 : 2 * (p - 2)); if (p == 1) { if (score >= p) { pCount++; } } else if ((score == minSum || score == minSum + 1) && s > 0) { pCount++; s--; } else if (score > minSum + 1) { pCount++; } } } System.out.println("Case #" + (t + 1) + ": " + pCount); } close(); } }
0
384
A12852
A10083
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; } }
// no.of users // no. of sets // minimum best // scores import java.io.*; import java.util.Scanner; public class Goggler { public static void main(String args[]) { try{ FileWriter fstream = new FileWriter("outB.out"); FileInputStream fstream1=new FileInputStream("B-small-attempt0.in"); DataInputStream in=new DataInputStream(fstream1); BufferedReader input=new BufferedReader(new InputStreamReader(in)); BufferedWriter out = new BufferedWriter(fstream); String strLine; strLine=input.readLine(); int T=Integer.parseInt(strLine); int j=1; while(j<=T) { int N,S,P; strLine=input.readLine(); String[] numbers=strLine.split(" "); int nums[]=new int[numbers.length]; N=Integer.parseInt(numbers[0]); S=Integer.parseInt(numbers[1]); P=Integer.parseInt(numbers[2]); int Score[]=new int[N]; int i=0; for( i=0;i<N;i++){ Score[i]=Integer.parseInt(numbers[i+3]); } int Flag=0; int avg; int rem=0; for(i=0;i<N;i++) { avg=Score[i]/3; //System.out.print(avg); rem=Score[i]%3; //System.out.print(rem); switch(rem) { case 0: { if(P<=avg) Flag=Flag+1; else if(P==avg+1&&S>0&&avg!=0) { S=S-1; Flag=Flag+1;} break; } case 1: { if(P<=avg+1) Flag=Flag+1; break; } case 2: { if(P<=avg+1) Flag=Flag+1; if(P==avg+2&&S>0) { S=S-1; Flag=Flag+1; } break; } } //switch close //System.out.println(Flag); } //System.out.println(Flag); out.write("Case #"+j+": "+Flag+"\r\n"); j=j+1; } out.close(); input.close();}catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
385
A12852
A12105
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 Googlers; import java.io.File; import java.io.FileNotFoundException; import java.util.LinkedList; import java.util.Scanner; import exoD.Ray; public class googlers { static void print(int nbCases, int N, int S, int P, int[] T) { System.out.print(N + " "); System.out.print(S + " "); System.out.print(P); for (int j = 0; j < N; j++) { System.out.print(" " + T[j]); } System.out.println(); } static int maxWinners(int N, int S, int P, int[] T) { int res = 0; int used = 0; if (P == 0) { return N; } else { for (int i = 0; i < N; i++) { if (T[i] >= 3 * P - 2) { res += 1; } else if (T[i] >= 3 * P - 4 && used < S && P >= 2) { used += 1; res += 1; } } } return res; } static void run(int N, int S, int P, int[] T, int turn) { System.out.println("Case #" + turn + ": " + maxWinners(N, S, P, T)); } /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { Scanner f = new Scanner( new File( "C:\\Users\\Jean-Baptiste\\Desktop\\Info2A\\GoogleJam\\src\\Googlers.in")); int nbCases = f.nextInt(); int[] T = { 0 }; int N = 1; int S = 1; int P = 1; for (int i = 0; i < nbCases; i++) { N = f.nextInt(); S = f.nextInt(); P = f.nextInt(); T = new int[N]; for (int j = 0; j < N; j++) { T[j] = f.nextInt(); } run(N, S, P, T, i + 1); } f.close(); } }
0
386
A12852
A11996
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.PrintWriter; import java.util.HashMap; import java.util.Scanner; public class Solution { HashMap<Character, Character> map = new HashMap<>(); Solution() throws Exception { setupIO("B-small-attempt0.in"); } String solve() throws Exception { int n = in.nextInt(); int surprising = in.nextInt(); int p = in.nextInt(); int[] scores = new int[n]; for (int i = 0; i < n; i ++) scores[i] = in.nextInt(); in.nextLine(); int numberOfP = 0; for (int score : scores) { if (noSurprise(score) >= p) numberOfP ++; else if (surprising > 0 && surprise(score) >= p) { surprising --; numberOfP ++; } } return "" + numberOfP; } private int surprise(int score) { if (score < 2 || score > 28) return 0; if (score % 3 == 0) return score / 3 + 1; if (score % 3 == 1) return 0; return score / 3 + 2; } private int noSurprise(int score) { if (score % 3 > 0) return score / 3 + 1; return score / 3; } void solveAll() throws Exception { int cases = in.nextInt(); in.nextLine(); for (int i = 1; i <= cases; i++) { String solution = "Case #" + i + ": " + solve(); System.out.println(solution); out.println(solution); } out.flush(); } // ----------------------------------------------------------------------- static Scanner in; static PrintWriter out; static void setupIO() { in = new Scanner(System.in); out = new PrintWriter(System.out); } static void setupIO(String filename) throws Exception { in = new Scanner(new FileReader(filename)); out = new PrintWriter(new FileWriter(filename + ".out")); } public static void main(String[] args) throws Exception { new Solution().solveAll(); } }
0
387
A12852
A10659
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 google2012; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author g */ public class Google2012 { /** * @param args the command line arguments */ public static void main(String[] args) { try { BufferedReader reader = new BufferedReader(new FileReader(args[0])); String line; int numCases = Integer.parseInt(reader.readLine()); for (int i=0; i<numCases; i++) { line = reader.readLine(); String[] tokens = line.split(" "); int dancers = Integer.parseInt(tokens[0]); int special = Integer.parseInt(tokens[1]); int maxScore = Integer.parseInt(tokens[2]); int minSumWithoutSpecial = maxScore+Math.max((maxScore-1),0)+Math.max(maxScore-1,0); int minSumWithSpecials = maxScore+Math.max(maxScore-2,0)+Math.max(maxScore-2,0); int counter=0; for (int j=0; j<dancers; j++) { int sum = Integer.parseInt(tokens[3+j]); if (sum >= minSumWithoutSpecial) { counter++; continue; } if (sum >= minSumWithSpecials && special > 0) { counter++; special--; continue; } } System.out.println("Case #" + (i+1) + ": " + counter); } } catch (IOException ex) { Logger.getLogger(Google2012.class.getName()).log(Level.SEVERE, null, ex); } } }
0
388
A12852
A11759
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 Problem2 { static ArrayList<Integer> scores; public static void main(String args[]) { try { FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String line; int total; int i = 0, cases; Scanner sc; int number, surprising, minpoints; while ((line = br.readLine()) != null) { if(i == 0) { total = Integer.parseInt(line); i = 1; continue; } sc = new Scanner(line); scores = new ArrayList<Integer>(); number = sc.nextInt(); surprising = sc.nextInt(); minpoints = sc.nextInt(); cases = 0; for(int j = 0; j < number; j++) { scores.add(sc.nextInt()); } for(int score : scores) { int base = (int)(score/3); switch(score%3) { case 0: { if(base>=minpoints) { cases++; } else if(surprising > 0 && base > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 1: { if(base>=minpoints | base + 1 >= minpoints) { cases++; } else if(surprising > 0 && base + 1 >= minpoints) { cases++; surprising--; } break; } case 2: { if(base + 1>= minpoints | base>=minpoints) { cases++; } else if(surprising > 0 && base + 2 >= minpoints) { cases++; surprising--; } break; } } } System.out.println("Case #"+i+": "+cases); write("Case #"+i+": "+cases); i++; } in.close(); }catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } public static void write(String text) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true)); bw.write(text); bw.newLine(); bw.close(); }catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
389
A12852
A12889
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 second; public class Triples { private int [] values; private int surprise=-1; private boolean Boolsurprise; int maxValue=-1; public Triples (int a,int b ,int c){ values=new int [3]; values[0]=a; values[1]=b; values[2]=c; } public int sum(){ return values[0]+values[1]+values[2]; } public boolean isSurprise(){ if(surprise==-1) calculateSurprise(); return Boolsurprise; } private void calculateSurprise() { surprise=1; if(Math.abs(values[0]-values[1])>=2) Boolsurprise=true; if(Math.abs(values[0]-values[2])>=2) Boolsurprise=true; if(Math.abs(values[1]-values[2])>=2) Boolsurprise=true; } public int getMaxValue() { if(maxValue>0) return maxValue; int max=values[0]; for(int i=1;i<values.length;i++) if(values[i]>max) max=values[i]; maxValue=max; return maxValue; } @Override public String toString() { String s=""; for(int i=0;i<values.length;i++) s+=values[i]+" "; if(isSurprise()) s+="(*)"; return s; } }
0
390
A12852
A10959
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{ void solve() throws FileNotFoundException{ File fin = new File("data.in"); File fout = new File("data.out"); Scanner cin = new Scanner(fin); PrintWriter cout = new PrintWriter(fout); int T, n, s, p; T = cin.nextInt(); for(int k = 0; k < T; k++){ n = cin.nextInt(); s = cin.nextInt(); p = cin.nextInt(); int [] num = new int[n]; for(int i = 0; i < n; i++) num[i] = cin.nextInt(); int ans = 0; for(int i = 0; i < n; i++){ if(num[i]/3>=p || (num[i]%3>0 && num[i]/3+1>=p)){ ans++; continue; } if(num[i]%3==2 && num[i]/3+2>=p && s>0){ s--; ans++; } if(num[i]%3==0 && num[i]/3+1>=p && num[i]/3>0 && s>0){ s--; ans++; } } cout.printf("Case #%d: %d\n", k+1, ans); } cout.flush(); } public static void main(String [] args) throws Exception{ B test = new B(); test.solve(); } }
0
391
A12852
A10120
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 com.sun.xml.internal.messaging.saaj.packaging.mime.util.LineInputStream; import sun.tools.tree.ReturnStatement; import javax.swing.*; import java.io.*; import java.util.ArrayList; /** * Date: 14/4/12 * Time: 9:19 AM */ public class GoogleFileStream { public static ArrayList<String> getInput() throws IOException { JFileChooser fc = new JFileChooser(); fc.showOpenDialog(null); File f = fc.getSelectedFile(); ArrayList<String> ret = new ArrayList<String>(); LineInputStream lis = new LineInputStream(new FileInputStream(f)); String line; while( (line = lis.readLine()) != null ) { ret.add(line); } // number of lines: ret.remove(0); return ret; } public static void setOutput(ArrayList<String> ret) throws IOException { JFileChooser fc = new JFileChooser(); fc.showSaveDialog(null); File f = fc.getSelectedFile(); StringBuilder sb = new StringBuilder(); FileWriter fw = new FileWriter(f); for( int i = 0; i < ret.size(); i++ ) { sb.delete(0, sb.length()); sb.append(String.format( "Case #%d: ", i + 1)); sb.append( ret.get(i) ); sb.append( "\n" ); String o = sb.toString(); fw.write( o ); System.out.print(o); } fw.close(); } }
0
392
A12852
A11355
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.DataInputStream; import java.io.FileInputStream; import java.io.InputStreamReader; public class Driver { public static void main(String[] args) { DeTerminator testBed = new DeTerminator(); try{ FileInputStream filestream = new FileInputStream("test.txt"); DataInputStream input = new DataInputStream(filestream); BufferedReader buffer = new BufferedReader(new InputStreamReader(input)); String currentLine; int counter = 1; int j = Integer.parseInt(buffer.readLine()); for(int i = 0; i < j; i++){ currentLine = buffer.readLine(); String delimiter = " "; String[] temp; temp = currentLine.split(delimiter); System.out.println("Case #" + counter + ": " + testBed.determine(temp)); counter++; } input.close(); } catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } }
0
393
A12852
A11751
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.dancing; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { static int suprising, minScore; public static void main(String[] args){ try { // open input file BufferedReader in = new BufferedReader ( new InputStreamReader (System.in)); BufferedReader file = new BufferedReader (new FileReader(in.readLine())); // create output file FileWriter fstream = new FileWriter("output.out"); BufferedWriter out = new BufferedWriter(fstream); // Variables StringTokenizer strtok; String str, tok; int entries, count, googlers, res, g_count,temp; // retrieve number of entries entries = new Integer(file.readLine()); System.out.println("Entries : " + entries); count = 0; // read lines while (((str = file.readLine())!=null) & (count <= entries)) { res = 0; strtok = new StringTokenizer(str); // number of googlers googlers = Integer.parseInt(strtok.nextToken()); System.out.println("Googlers : "+ googlers); // number of suprising entries suprising = Integer.parseInt(strtok.nextToken()); System.out.println("Suprising Scores : " + suprising); // minimum score minScore = Integer.parseInt(strtok.nextToken()); System.out.println("Minimum Score : " + minScore); g_count = 0; while (g_count < googlers) { //temp = Integer.parseInt(strtok.nextToken()); //System.out.println(temp); res += evalScore(Integer.parseInt(strtok.nextToken())); g_count++; } System.out.println("finished?"); count++; out.write("Case #"+count+": "+res+"\n"); } out.close(); } catch(Exception e){ } } public static int evalScore(int score) { // check for non suprising results System.out.print("["+ minScore + "|" + score+"]"); if (score >= (3*minScore - 2)) { System.out.print(" : 1\n"); return 1; } else if (score == 0){ System.out.print(" : 0\n"); return 0; } else { // check for suprising results if (suprising > 0){ if ((score < (3*minScore - 2))&(score >= (3*minScore - 4))) { suprising--; System.out.print(" : 1\n"); return 1; } } } System.out.print(" : 0\n"); return 0; } }
0
394
A12852
A13162
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 tr0llhoehle.cakemix.utility.googleCodeJam; import java.text.ParseException; /** * This class is a base class for all concrete problems. It is used to define * some methods necessary for the IOManager to work. It is crucial that the * addValue-Method gets extended and called (super.addValue(o)) by the extending * class. * * @author Cakemix * @see IOManager * @see Solver */ public abstract class Problem { protected SupportedTypes[] types; protected int cntr = 0; protected boolean isInitialised = false; /** * Returns an array of SupportedTypes which define exactly what data is * stored in this problem. * * The attribute "types" needs to be initialized in the constructor of the * extending class. * * @return An array of SupportedTypes which define exactly what data is * stored in this problem. * @see SupportedTypes */ public SupportedTypes[] getTypes() { return types; } public void addValue(Object o) throws ParseException { if (!isInitialised) { cntr++; isInitialised = (cntr == types.length); } else { throw new ParseException("Tried to add another value to this Problem even though all values are set.", cntr); } } }
0
395
A12852
A12806
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.deepToString; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Hashtable; public class B { public BufferedReader in; public PrintWriter out; void debug(Object...os) {System.err.println(deepToString(os));} static void pl(Object s) {System.out.println(s);} static void p(Object s) {System.out.print(s);} public Hashtable<Integer, B.Triplet> map; class Triplet { int a1 = 0,b1 = 0,c1 = 0; int a2 = 0,b2 = 0,c2 = 0; public Triplet() {} public void tripletSu(int a1, int b1, int c1) { //with surprize this.a1 = a1; this.b1 = b1; this.c1 = c1; } public void tripletNo(int a2, int b2, int c2) { //without surprize this.a2 = a2; this.b2 = b2; this.c2 = c2; } public int getHighestWithSurprize() { int max = a1; if (b1 > max) max = b1; if (c1 > max) max = c1; return max; } public int getHighestWithoutSurprize() { int max = a2; if (b2 > max) max = b2; if (c2 > max) max = c2; return max; } } private B.Triplet generateTriplet(int t) { Triplet trip = new Triplet(); //Handle special cases if (t == 0) return trip; //all values already init to 0, can simple return trip int v = t / 3; if (t == 30) { trip.tripletNo(v, v, v); return trip; } if (t == 29) { trip.tripletNo(v+1, v+1, v); return trip; } if (t == 1) { trip.tripletNo(v+1, v, v); return trip; } //Handle default cases if (t % 3 == 0) { trip.tripletNo(v, v, v); trip.tripletSu(v+1, v, v-1); } else if (t % 3 == 1){ trip.tripletNo(v+1, v, v); trip.tripletSu(v+1, v+1, v-1); } else { trip.tripletNo(v+1, v+1, v); trip.tripletSu(v+2, v, v); } return trip; } private int solve(int N, int S, int p, ArrayList<Integer> s) { int count = 0; int v; Triplet trip; for(int i = 0; i < N; ++i) { trip = map.get(s.get(i)); v = trip.getHighestWithoutSurprize(); if (v >= p) { ++count; } else if (S > 0) { v = trip.getHighestWithSurprize(); if (v >= p) { ++count; --S; //one of the surprizes used } } } return count; } public void run() throws Exception { //pre-generate Triplet cases map = new Hashtable<Integer, B.Triplet>(); for(int i = 0; i <= 30; ++i) map.put(i,generateTriplet(i)); int T,N,S,p,v; ArrayList<Integer> s = new ArrayList<Integer>(); String line;String[] tok; in = new BufferedReader(new FileReader(new File("B-small-attempt0.in"))); out = new PrintWriter(new File("B-small-attempt0.out")); // in = new BufferedReader(new FileReader(new File("B-large.in"))); // out = new PrintWriter(new File("B-large.out")); T = new Integer(in.readLine()); for(int t=1;t<=T;++t) { line = in.readLine(); tok = line.split(" "); N = new Integer(tok[0]); S = new Integer(tok[1]); p = new Integer(tok[2]); s = new ArrayList<Integer>(N); for(int n = 0; n < N; ++n) s.add(new Integer(tok[n+3])); v = solve(N,S,p,s); System.out.println("Case #" + t + ": " + v); out.println("Case #" + t + ": " + v); } in.close();out.close(); } public static void main(String[] args) { try { java.util.Date t1 = new java.util.Date(); new B().run(); java.util.Date t2 = new java.util.Date(); long diff = (t2.getTime() - t1.getTime()); System.out.println("Time: "+(((float)diff)/1000)); } catch (Exception e) { e.printStackTrace(); } } }
0
396
A12852
A10293
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 ndproblem; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Main1 { /** * @param args the command line arguments */ public static void main(String[] args) { Find f=new Find(); f.find(); } } class Find { int size; int start=1; public void find() { try { File inputFile = new File("input.txt"); File tempFile = new File("out.txt"); BufferedReader reader = new BufferedReader(new FileReader(inputFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(tempFile)); FileOutputStream fos=new FileOutputStream(tempFile); String currentLine; int size; int tno,sur,max; int count=0,no,no3; while((currentLine = reader.readLine()) != null) { count=0; String[] sArray = currentLine.split(" "); if(sArray.length<=1) { size=Integer.parseInt(sArray[0]); System.out.println("size="+size); writer.write(currentLine); } else { tno=Integer.parseInt(sArray[0]); sur=Integer.parseInt(sArray[1]); max=Integer.parseInt(sArray[2]); no3=max*3; System.out.print("tno"+tno+"sur"+sur+"max"+max); // writer.write("tno"+tno+"sur"+sur+"max"+max); for(int i=3;i<sArray.length;i++) { no=Integer.parseInt(sArray[i]); if(no==0 ) { } else if(no >= no3 - 2) { count++; } else if(no==no3-3 || no==no3-4) { if(sur>0) { count++; } sur--; } } String s1="Case #"+ start++ +": "+count+"\n"; System.out.println(s1); byte b1[]=s1.getBytes(); fos.write(b1); } } } catch (Exception ex) { System.err.println("FileStreamsTest: " + ex); } } }
0
397
A12852
A10102
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package googlecodejam; /** * * @author ffreakk */ import java.util.Scanner; import java.lang.Math; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.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 nSurprises = 0; int result = 0; int surpriseScore = 3*p - 4; int okScore = 3*p - 2; int scoreArray[] = new int[N]; for (int n=0; n<N; n++) { scoreArray[n] = in.nextInt(); } for (int i=0; i<N; i++) { if (scoreArray[i] >= okScore) result++; else if (scoreArray[i] >= surpriseScore && scoreArray[i]>0) nSurprises++; } result += Math.min(nSurprises, S); System.out.println("Case #" +t+ ": " + result); } } }
0
398
A12852
A12045
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 DancingWithGooglers { final static int[] _3n_2 = new int[] { 2, 5, 8, 11, 14, 17, 20, 23, 26, 29 }; final static int[] _3n_4 = new int[] { 4, 7, 10, 13, 16, 19, 22, 25, 28 }; // return -1 if cannot be written as surprising form public static int surprisingN(int n) { if (n == 0) return -999; for (int i : _3n_2) if (i == n) return (n - 2) / 3; if (n % 3 == 0) // 3n+3 return (n-3) / 3; return (n - 4) / 3; } public static int nonSurprisingN(int n) { if ((n - 1) % 3 == 0) return (n - 1) / 3; if ((n - 2) % 3 == 0) return (n - 2) / 3; return n / 3; } public static int enact(int S, int p, int[] scores) { if (S == 0) { // find best score // return int tmp = 0; for (int i : scores) { int n = nonSurprisingN(i); if (p <= n) tmp++; else if (p == n + 1) { if (i % 3 != 0) tmp++; } } return tmp; } int max = 0; int N = 0; // number of googlers have a best score at least p // setting one valid googler to be surprising case for (int i = 0; i < scores.length; i++) { int tmp = scores[i]; scores[i] = -999; N = enact(S - 1, p, scores); scores[i] = tmp; if (p <= surprisingN(scores[i]) + 2) N++; if (N > max) max = N; } return max; } public static void main(String[] args) throws FileNotFoundException { Scanner sc = new Scanner(new File("B-small-attempt2.in")); int T = sc.nextInt(); for (int i = 0; i < T; i++) { int n = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int[] scores = new int[n]; for (int j = 0; j < n; j++) { scores[j] = sc.nextInt(); } int result = enact(S, p, scores); System.out.format("Case #%d: %d%n", i + 1, result); } } }
0
399