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
A11545
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Problem2 { public Problem2() { super(); } private static int convert(String input) { String[] inputArray = input.split(" "); int noOfCases = Integer.parseInt(inputArray[0]); int noOfSurpriseCasesPossible = Integer.parseInt(inputArray[1]); int p = Integer.parseInt(inputArray[2]); List<Integer> cases = new ArrayList<Integer>(); for(int i = 3;i<inputArray.length; i++) cases.add(Integer.parseInt(inputArray[i])); Collections.sort(cases, Collections.reverseOrder()); int minSurprisingSum = p*3 - 4; int minNonSurprisingSum = p*3 -2; int countNonSurprisingCases = 0; int countSurprisingCases = 0; for(int score:cases) { if(score<minSurprisingSum || score<=p) break; if(score>=minNonSurprisingSum) countNonSurprisingCases++; else if(score>=minSurprisingSum) countSurprisingCases++; } countNonSurprisingCases+=Math.min(countSurprisingCases, noOfSurpriseCasesPossible); //System.out.println(countNonSurprisingCases); return countNonSurprisingCases; } public static void main(String[] args) { try { BufferedReader reader = new BufferedReader(new FileReader("D:\\codejam\\2012\\B.in")); BufferedWriter writer = new BufferedWriter(new FileWriter("D:\\codejam\\2012\\B.out")); //... Loop as long as there are input lines. String line = null; reader.readLine(); int i=1; while ((line=reader.readLine()) != null) { writer.write("Case #"+i+": "+convert(line)); writer.newLine(); // Write system dependent end of line. i++; } //... Close reader and writer. reader.close(); // Close to unlock. writer.close(); // Close to unlock and flush to disk. } catch(Exception ex) { ex.printStackTrace(); } } }
0
0
A12852
A11781
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Scanner; public class GooglerScores { public static void main(String args[]) throws FileNotFoundException { ////////////////////////////////////// // Begin Code Jam regular code // ////////////////////////////////////// Scanner inFile = new Scanner(new File("B-small-attempt0.in")); PrintStream outFile = new PrintStream(new File("B-small0-out.txt")); int numCases = inFile.nextInt(); inFile.nextLine(); // Gets rid of newline char ////////////////////////////////////// // End Code Jam regular code // ////////////////////////////////////// for(int i=1; i<=numCases; i++) { int numGooglers = inFile.nextInt(); int maxNumSurprising = inFile.nextInt(); int leastValid = inFile.nextInt(); int validGooglers = 0; int validSurprising = 0; for(int j=0; j<numGooglers; j++) { int nextTotal = inFile.nextInt(); int[] normalScore = calcNormalScore(nextTotal); int[] surprisingScore = calcSurprisingScore(nextTotal); if(hasValidScore(normalScore, leastValid)) { validGooglers++; } else if (hasValidScore(surprisingScore, leastValid) && validSurprising < maxNumSurprising) { validGooglers++; validSurprising++; } } printCase(outFile, i, validGooglers); } } private static void printCase(PrintStream outStream, int i, int n) { outStream.println("Case #" + i +": " + n); } private static int[] calcNormalScore(int totalScore) { int[] scores = new int[3]; if(totalScore % 3 == 0) { for(int i=0; i<3; i++) { scores[i] = totalScore/3; } } else if(totalScore % 3 == 1) { scores[0] = totalScore / 3; scores[1] = scores[0]; scores[2] = scores[0] + 1; } else if(totalScore % 3 == 2) { scores[0] = totalScore / 3; scores[1] = scores[0] + 1; scores[2] = scores[1]; } return scores; } private static int[] calcSurprisingScore(int totalScore) { int[] scores = new int[3]; if (totalScore % 3 == 1 || totalScore <= 0) { // There is no such surprising score for (int i = 0; i < 3; i++) scores[i] = 0; } else if (totalScore % 3 == 0) { scores[0] = totalScore / 3 - 1; scores[1] = totalScore / 3; scores[2] = totalScore / 3 + 1; } else if (totalScore % 3 == 2) { scores[0] = totalScore / 3; scores[1] = scores[0]; scores[2] = scores[0] + 2; } return scores; } private static boolean hasValidScore(int[] scores, int leastValid) { for(int i=0; i<scores.length; i++) { if(scores[i] >= leastValid) return true; } return false; } }
0
1
A12852
A12785
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.InputStreamReader; import org.junit.Assert; public class DancingWithTheGooglers { public static void main( final String[] args ) throws Exception { final BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ); final int T = Integer.parseInt( br.readLine() ); for ( int ii = 0; ii < T; ++ii ) { final String[] parts = br.readLine().split( " " ); final int N = Integer.parseInt( parts[ 0 ] ); final int S = Integer.parseInt( parts[ 1 ] ); final int p = Integer.parseInt( parts[ 2 ] ); final int[] t = new int[N]; for ( int i = 0; i < N; ++i ) { t[ i ] = Integer.parseInt( parts[ i + 3 ] ); } System.out.printf( "Case #%d: %d\n", ii + 1, solve( N, S, p, t ) ); } } private static int solve( final int n, int s, final int p, final int[] t ) { int cnt = 0; for ( int i = 0; i < t.length; ++i ) { final int k = t[ i ] / 3; final int mod = t[ i ] % 3; if ( k + ( mod > 0 ? 1 : 0 ) >= p ) { ++cnt; } else if ( s > 0 ) { // k + k + k -> k+1 + k + k-1 if ( mod == 0 && k - 1 >= 0 && k + 1 >= p ) { ++cnt; --s; } // k+1 + k + k -> k+1 + k+1 + k-1 (not enough) || k+2 + k + k-1 (not ok) // k+1 + k+1 + k -> k+2 + k + k if ( mod == 2 && k + 2 >= p ) { ++cnt; --s; } } } return cnt; } @org.junit.Test public void statement1() { final int[] t = { 15, 13, 11 }; Assert.assertEquals( 3, solve( 3, 1, 5, t ) ); } @org.junit.Test public void statement2() { final int[] t = { 23, 22, 21 }; Assert.assertEquals( 2, solve( 3, 0, 8, t ) ); } @org.junit.Test public void statement3() { final int[] t = { 8, 0 }; Assert.assertEquals( 1, solve( 2, 1, 1, t ) ); } @org.junit.Test public void statement4() { final int[] t = { 29, 20, 8, 18, 18, 21 }; Assert.assertEquals( 3, solve( 6, 2, 8, t ) ); } }
0
2
A12852
A12003
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader(args[0])); FileWriter out = new FileWriter(args[1]); int T = Integer.parseInt(in.readLine()); for (int t = 1; t <= T; t++) { String data[] = in.readLine().split("\\ "); int N = Integer.parseInt(data[0]); int S = Integer.parseInt(data[1]); int p = Integer.parseInt(data[2]); int[] totalPoints = new int[N]; for (int i = 0; i < N; i++) totalPoints[i] = Integer.parseInt(data[i + 3]); int unconditionalSucc = 0; int failed = 0; int upperLimit; int lowerLimit; if (p >= 2) { upperLimit = 3 * p - 3; lowerLimit = 3 * p - 4; } else if (p == 1) { upperLimit = 0; lowerLimit = 1; } else { upperLimit = -1; lowerLimit = -1; } for (int i = 0; i < totalPoints.length; i++) { if (totalPoints[i] > upperLimit) unconditionalSucc++; else if (totalPoints[i] < lowerLimit) failed++; } int uncertain = N - failed - unconditionalSucc; out.write("Case #" + t + ": " + (Math.min(uncertain, S) + unconditionalSucc) + "\n"); } in.close(); out.close(); } }
0
3
A12852
A10939
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Googlers { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); int nc = Integer.parseInt(in.readLine().trim()); for (int z=1; z<=nc; z++){ String[] line = in.readLine().trim().split("\\s+"); int n = Integer.parseInt(line[0]); int s = Integer.parseInt(line[1]); int p = Integer.parseInt(line[2]); int count = 0; for (int i = 0; i < n; i++) { int num = Integer.parseInt(line[3+i]); if (num>3*p-3) count++; else if ((num>=2)&&(num>=3*p-4)&&(s>0)) { count++; s--; } } out.println(String.format("Case #%d: %d", z,count)); } out.close(); } }
0
4
A12852
A11629
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class B { public final static String FILE_IN = "B-small-attempt0.in"; public final static String FILE_OUT = "B-small-attempt0.out"; public static class Case { public int n, s, p; public int[] t; public String toString() { return "" + n + "," + s + "," + p + ":" + Arrays.toString(t); } } public static Case readCase(BufferedReader r) throws IOException { Case c = new Case(); String[] tk = r.readLine().split(" "); c.n = Integer.parseInt(tk[0]); c.s = Integer.parseInt(tk[1]); c.p = Integer.parseInt(tk[2]); c.t = new int[c.n]; for (int i=0; i<c.n; i++) { c.t[i] = Integer.parseInt(tk[3+i]); } return c; } public static void solveCase(Case c, BufferedWriter w, int index) throws IOException { int t = 0; int sr = c.s; for (int i=0; i<c.t.length; i++) { int q = c.t[i] / 3; int r = c.t[i] % 3; if (r == 0) { if (q >= c.p) { t++; } else if (q > 0 && q + 1 >= c.p && sr > 0) { t++; sr--; } } else if (r == 1) { if (q+1 >= c.p) { t++; } } else { if (q+1 >= c.p) { t++; } else if (q+2 >= c.p && sr > 0) { t++; sr--; } } } w.write("Case #" + (index+1) + ": " + t); w.newLine(); } public static void main(String[] args) throws Exception { BufferedReader r = new BufferedReader(new FileReader(FILE_IN)); BufferedWriter w = new BufferedWriter(new FileWriter(FILE_OUT)); int num = Integer.parseInt(r.readLine()); for (int i=0; i<num; i++) { Case c = readCase(r); solveCase(c, w, i); } w.close(); r.close(); } }
0
5
A12852
A12479
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class Dancing { public static void main(String[] args){ List<String> input=new ArrayList<String>(); List<String> output=new ArrayList<String>(); try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("c:/input/B-small-attempt0.in"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console input.add(strLine); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } /*input done*/ for(int j=1;j<input.size();j++){ String a=input.get(j); //System.out.println("getting input as"+a); String b[]=a.split(" "); int n,s,p,t[]=null; n=Integer.parseInt(b[0]); s=Integer.parseInt(b[1]); p=Integer.parseInt(b[2]); t=new int[n]; for(int i=3;i<b.length;i++){ t[i-3]=Integer.parseInt(b[i]); } int count=0,div,mod; for(int i=0;i<t.length;i++){ div=t[i]/3; mod=t[i]%3; if(div>=p){ count++; //System.out.println("normal"+t[i]); }else if((div+Math.min(mod,1)>=p)){ count++; //System.out.println("with increment"+t[i]); }else if((div+Math.min(mod,2)>=p)&&(s>0)){ count++; if(mod>=2){ s--; //System.out.println("surprised"+t[i]+"remaining s"+s); } }else if((div+1>=p)&&(div>0)&&(s>0)){ count++; s--; //System.out.println("superficial"+t[i]); }else{ //System.out.println("noting happened"+t[i]+" div is "+div+"mod is"+mod); } } output.add(count+""); /*counting done*/ //System.out.println(count); } try { BufferedWriter bw = new BufferedWriter(new FileWriter(new File("C:/output/Dancing.out"), true)); for(int i=0;i<output.size();i++){ bw.write("Case #"+(i+1)+": "+output.get(i)); bw.newLine(); } bw.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
6
A12852
A10864
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.io.FileInputStream; import java.io.IOException; import java.util.Scanner; public class Task2 { public static void main(String[] args) throws IOException { Scanner scanner = new Scanner(new FileInputStream("task21.txt")); int T = scanner.nextInt(); for (int i = 0; i < T; i++) { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int[] t = new int[N]; for (int j = 0; j < N; j++) { t[j] = scanner.nextInt(); } int noProbMin = Math.max(p * 3 - 2, p); int surpriseMin = Math.max(p * 3 - 4, p); int noProbCount = 0; int surpriseCount = 0; for (int googler : t) { if (googler >= noProbMin) { noProbCount++; } if (googler < noProbMin && googler >= surpriseMin) { surpriseCount++; } } surpriseCount = Math.min(surpriseCount, S); System.out.println("Case #" + (i + 1) + ": " + (noProbCount + surpriseCount)); } } }
0
7
A12852
A12641
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.File; import java.io.PrintStream; import java.util.Scanner; public class QualificationB { public static void main(String[] args){ try{ Scanner sc=new Scanner(new File("B.in")); PrintStream ps=new PrintStream("B.out"); int t=sc.nextInt(); for(int i=0;i<t;i++){ int n=sc.nextInt(); int s=sc.nextInt(); int p=sc.nextInt(); int count=0; for(int j=0;j<n;j++){ int x=sc.nextInt(); if(x>(p-1)*3)count++; else if(x>1&&x>(p-1)*3-2&&s>0){ count++; s--; } } ps.println("Case #"+(i+1)+": "+count); } }catch(Exception e){ e.printStackTrace(); } } }
0
8
A12852
A12732
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 abstract class FileWrapper { protected static final String CASE = "Case #"; protected static final String OUTPUT = "result.out"; protected int caseNum = 0; protected String output[] = null; private FileReader fr = null; private BufferedReader br = null; private FileWriter fw = null; private BufferedWriter bw = null; protected void openReadFile(String fileName) throws Exception { this.fr = new FileReader(fileName); this.br = new BufferedReader(this.fr); } protected void closeReadFile() throws Exception { this.br.close(); this.fr.close(); } protected String readLine() throws Exception { return this.br.readLine(); } protected boolean isFileReady() throws Exception { return this.br.ready(); } protected abstract void processInput(String fileName); private void openWriteFile(String fileName) throws Exception { this.fw = new FileWriter(fileName); this.bw = new BufferedWriter(this.fw); } private void closeWriteFile() throws Exception { this.bw.close(); this.fw.close(); } private void writeLine(String line) throws Exception { this.bw.write(line); this.bw.newLine(); } protected void processOutput(String fileName) { try{ this.openWriteFile(fileName); for (int i=0; i<this.caseNum; i++) { this.writeLine(this.output[i]); } this.closeWriteFile(); }catch(Exception e){} } protected abstract void calculate(); }
0
9
A12852
A10567
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.StringTokenizer; /** * * @author parusnik */ public class Codejam { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("input.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt")); int T = Integer.parseInt(br.readLine()); StringTokenizer st; for (int t = 1; t<=T; t++){ bw.write("Case #" + String.valueOf(t) + ": "); st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int k = 0; int d = 0; for (int i = 0; i<n; i++){ int a = Integer.parseInt(st.nextToken()); a-=p; if (a>=0){ a/=2; if (a==p-2) k++; else if (a>p-2) d++; } } d += Math.min(k, s); bw.write(String.valueOf(d)); bw.newLine(); } br.close(); bw.close(); } }
0
10
A12852
A12822
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class Googlers { public static void main(String args[])throws IOException{ Scanner scan = new Scanner(new File(System.getProperty("user.dir")+"/input.in")); FileWriter file = new FileWriter("output.out"); int n=Integer.parseInt(scan.nextLine()); for(int j=0;j<n;j++){ int numGooglers = scan.nextInt(); int totalSurprising = scan.nextInt(); int p = scan.nextInt(); int[] totals = new int[numGooglers]; for(int i=0;i<numGooglers;i++){ totals[i]=scan.nextInt(); } int[] totalsMinus = new int[numGooglers]; for(int i=0;i<numGooglers;i++){ totalsMinus[i]=totals[i]-p; } int max =0; int surprising=0; for(int i=0;i<numGooglers;i++){ if(totalsMinus[i]>=0&&p-(int)Math.floor(totalsMinus[i]/2)<=2){ max++; if(p-(int)Math.floor(totalsMinus[i]/2)==2) surprising++; } } while(surprising>totalSurprising){ surprising--; max--; } file.write("Case #"+Integer.toString(j+1)+": "+Integer.toString(max)+"\r\n"); } file.close(); } }
0
11
A12852
A11834
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class B { public static void main(String[] args) throws IOException { Scanner in = new Scanner(new File("B-small.in")); FileWriter fw = new FileWriter("B-small.out"); int T = in.nextInt(); for (int tc = 1; tc <= T; tc++) { int count = 0; int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int[] totalScores = new int[N]; int special = 0; for(int i = 0; i < N; i++) { totalScores[i] = in.nextInt(); if(totalScores[i] >= 3) { int remainder = totalScores[i] % 3; int mid = totalScores[i] / 3; if(remainder == 0) {//mid mid mid or mid-1 mid mid+1; if(mid >= p) count++; else if(mid+1 >= p && special < S) { special++; count++; } } else if(remainder == 1) {//mid mid mid+1 or mid-1 mid+1 mid+1 if(mid >= p) count++; else if(mid+1 >= p) count++; } else {//mid mid+1 mid+1 or mid mid mid+2 if(mid >= p) count++; else if(mid+1 >= p) count++; else if(mid+2 >= p && special < S) { special++; count++; } } } else { if((totalScores[i] == 0 && p == 0) || (totalScores[i] == 1 && p <= 1)) count++; else if(totalScores[i] == 2) { if(p <=1) { count++; } else if(p == 2 && special < S) { special++; count++; } } } } fw.write ("Case #" + tc + ": " + count + "\n"); } fw.flush(); fw.close(); } }
0
12
A12852
A10693
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.Scanner; public class googler { int cases; int googlers; int surprises; int goal; int[] points; /** * @param args */ public static void main(String[] args) { googler gag = new googler(); } public googler() { parseInput(); } //read in each case line by line. public void parseInput() { try { FileInputStream fstream = new FileInputStream("B-small-attempt4.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fwstream = new FileWriter("Googlers.out"); BufferedWriter out = new BufferedWriter(fwstream); cases = Integer.parseInt(br.readLine()); for (int i = 0; i < cases; i++) { solveCase(br.readLine(), i, out); } out.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } } //parses variables for this case. public void solveCase(String caseArgs, int caseNum, BufferedWriter file) throws IOException { int y = 0; //the number of scores in this case above goal Scanner sc = new Scanner(caseArgs); googlers = sc.nextInt(); surprises = sc.nextInt(); goal = sc.nextInt(); points = new int[googlers]; int bestScore; // building the arrray of scores for (int i = 0; i < points.length; i++) points[i] = sc.nextInt(); //System.out.println("N:" + googlers + " S:" + surprises + " P:" + goal + " " + Arrays.toString(points)); for (int i = 0; i < points.length; i++) { if (unsurprising(points[i])) { y++; //chalk one up } else if (surprises > 0 && surprising(points[i])) { y++; surprises--; } } file.write("Case #" + (caseNum+1) + ": " + y + '\n'); //System.out.println(" Case #" + (caseNum+1) + ": " + y); } //returns best score if unsurprising public boolean unsurprising(int total) { //System.out.println(goal); int min = goal*3; min = min - 2; if (min <= 0) min = goal; //System.out.println("min: " + min + " total: " + total); return (total >= min); } public boolean surprising(int total) { int min = goal*3; min = min - 4; if (min <= 0) min = goal; //System.out.println("Smin: " + min + " Stotal: " + total); return (total >= min); } }
0
13
A12852
A10446
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* a = y b = n c = f d = i e = c f = w g = l h = b i = k j = u k = o l = m m = x n = s o = e p = v q = z r = p s = d t = r u = j v = g w = t x = h y = a z = q */ import java.util.*; public class Dancing { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); sc.nextLine(); for (int i = 0; i < T; i++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int AWESOME = p + 2*(p-1); int SURP_GOOD = p + 2*(p-2); System.out.print("Case #" + (i + 1) + ": "); int goodOnes = 0; int[] curr = new int[N]; for (int j = 0; j < N; j++) { curr[j] = sc.nextInt(); } Arrays.sort(curr); for (int j = N-1; j >= 0; j--) { if (p == 0) goodOnes++; else if (curr[j] >= AWESOME && curr[j] > 0) goodOnes++; else if (curr[j] > 0 && S > 0 && curr[j] >= SURP_GOOD) { goodOnes++; S--; } } System.out.println(goodOnes); } } }
0
14
A12852
A12912
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.menzus.gcj._2012.qualification.b; import com.menzus.gcj.common.InputBlockParser; import com.menzus.gcj.common.OutputProducer; import com.menzus.gcj.common.impl.AbstractProcessorFactory; public class BProcessorFactory extends AbstractProcessorFactory<BInput, BOutputEntry> { public BProcessorFactory(String inputFileName) { super(inputFileName); } @Override protected InputBlockParser<BInput> createInputBlockParser() { return new BInputBlockParser(); } @Override protected OutputProducer<BInput, BOutputEntry> createOutputProducer() { return new BOutputProducer(); } }
0
15
A12852
A11119
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package jam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.Writer; public class Dance { public static void main(String[] x)throws IOException{ File file=new File("A.in"); Writer output = null; File out=new File("A.out"); output = new BufferedWriter(new FileWriter(out)); BufferedReader fileIn = new BufferedReader(new FileReader(file)); String fileLine,delims,outs; String[] tokens; int cases,num,surprise,goal,ans,indA,indB,i; int [] items; fileLine=fileIn.readLine(); cases = Integer.parseInt(fileLine); delims = "[ ]+"; System.out.println("Cases = "+cases); for (i=0;i<cases;++i) { output.write("Case #"); output.write(Integer.toString(i+1)); output.write(": "); fileLine=fileIn.readLine(); tokens = fileLine.split(delims); num = Integer.parseInt(tokens[0]); surprise = Integer.parseInt(tokens[1]); goal = Integer.parseInt(tokens[2]); items = new int[tokens.length-3]; transfer(items,tokens); ans = solve(goal,surprise,items); output.write(Integer.toString(ans)); output.write("\r\n"); System.out.println(ans); } output.close(); } private static int solve(int goal, int surprise, int[] items) { int rej,acc,i,out,s; s = surprise; out = 0; rej = 3*goal-4; if(rej<1) { rej = 1; } acc = 3*goal-3; for(i=0;i<items.length;++i) { if(items[i]>acc) { ++out; } else if(items[i]>=rej&&s>0) { ++out; --s; } else { } } return out; } private static void transfer(int[] items, String[] tokens) { int size = tokens.length; int i = 3; for(i = 3;i<size;++i) { items[i-3] = Integer.parseInt(tokens[i]); } return; } }
0
16
A12852
A12957
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class QuestionB { public static void doPuzzle() { try { File questionfile = new File("B.in"); BufferedReader questionreader = new BufferedReader(new FileReader(questionfile)); File answerfile = new File("B.out"); PrintWriter answerwriter = new PrintWriter(new BufferedWriter(new FileWriter(answerfile))); String[] params = null; String question = questionreader.readLine(); int T = Integer.parseInt(question); int[][] table = makeTable(); for (int i = 0; i < T; i++) { question = questionreader.readLine(); params = question.split(" "); int N = Integer.parseInt(params[0]); int S = Integer.parseInt(params[1]); int p = Integer.parseInt(params[2]); int[] t = new int[N]; for (int j = 0; j < N; j++) t[j] = Integer.parseInt(params[3+j]); answerwriter.println("Case #" + (i+1) + ": " + analyze(table, N, S, p, t)); } answerwriter.close(); questionreader.close(); } catch (FileNotFoundException e) { e.printStackTrace(); return; } catch (IOException e) { e.printStackTrace(); return; } } private static int[][] makeTable() { int[][] scoreTable = new int[31][11]; for (int i = 0; i < 31; i++) { if (i == 0) { for (int j = 0; j < 1; j++) scoreTable[i][j] = 2; for (int j = 1; j < 11; j++) scoreTable[i][j] = 0; continue; } if (i == 1) { for (int j = 0; j < 2; j++) scoreTable[i][j] = 2; for (int j = 2; j < 11; j++) scoreTable[i][j] = 0; continue; } if (i >= 28) { for (int j = 0; j < 11; j++) scoreTable[i][j] = 2; continue; } int shou = i / 3; int amari = i % 3; switch (amari) { case 0: for (int j = 0; j < shou+1; j++) scoreTable[i][j] = 2; scoreTable[i][shou+1] = 1; for (int j = shou+2; j < 11; j++) scoreTable[i][j] = 0; break; case 1: for (int j = 0; j < shou+2; j++) scoreTable[i][j] = 2; for (int j = shou+2; j < 11; j++) scoreTable[i][j] = 0; break; case 2: for (int j = 0; j < shou+2; j++) scoreTable[i][j] = 2; scoreTable[i][shou+2] = 1; for (int j = shou+3; j < 11; j++) scoreTable[i][j] = 0; break; } } return scoreTable; } private static int analyze(int[][] table, int N, int S, int p, int[] t) { int[] count = new int[3]; for (int i = 0; i < t.length; i++) { count[table[t[i]][p]]++; } int border = (count[1] < S) ? count[1] : S; return count[2] + border; } }
0
17
A12852
A10950
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; public class Writer { private String fileName; private BufferedWriter writer; private int i = 1; public Writer(String fileName){ this.fileName = fileName; } public void open() throws Exception{ writer = new BufferedWriter(new FileWriter(new File(fileName))); } public void close() throws Exception{ writer.close(); } public void write(String erg) throws Exception{ writer.write("Case #" + i +": " + erg + "\n"); i++; } }
0
18
A12852
A12132
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.*; /** * Auto Generated Java Class. */ public class Problem_b { public static void main(String[] args) { String [] nums=getWords("B-small-attempt0.in"); int t=Integer.parseInt(nums[0]); for(int i=1;i<nums.length;i++){ String [] tempstr=nums[i].split(" "); int [] temp= new int[tempstr.length]; for(int x=0;x<tempstr.length;x++){ temp[x]=Integer.parseInt(tempstr[x]); } System.out.println("Case #" +i+": "+ check(temp)); } } public static int check(int [] a){ int gnum=a[0]; int surp=a[1]; int p=a[2]; int [] scores=new int [gnum]; for(int i=3;i<a.length;i++){ scores[i-3]=a[i]; } // for(int x:scores) // System.out.print(x+" "); //System.out.println(gnum+" "+surp+" "+p); int max=0; int tempsurps=0; for(int i=0;i<scores.length;i++){ if(scores[i]/3.0 > p-1){ max++; } else if(tempsurps<surp && p-scores[i]/3.0 <= 1.5 && scores[i]!=0){ max++; tempsurps++; } } return max; } public static String [] getWords( String filename ) { String [] list = null; try { Scanner read = new Scanner( new File( filename ) ); int count = 0; while ( read.hasNext() ){ String temp = read.nextLine(); count++; } list = new String[ count ]; read = new Scanner( new File( filename ) ); count = 0; while ( read.hasNext() ){ list[count] = read.nextLine(); count++; } } catch ( IOException e1 ) { System.out.println( "problem reading file" ); } return list; } /* ADD YOUR CODE HERE */ }
0
19
A12852
A10122
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 t2; import java.io.*; import java.util.ArrayList; import java.util.StringTokenizer; import java.util.logging.Level; import java.util.logging.Logger; public class T1 { BufferedWriter out; ArrayList<String> list = new ArrayList<String>(); int i = 1; T1(){ try { out = new BufferedWriter(new FileWriter(new File("output.txt"))); } catch (IOException ex) {} start(); try { out.close(); } catch (IOException ex) { Logger.getLogger(T1.class.getName()).log(Level.SEVERE, null, ex); } } public static void main(String[] args) { T1 t = new T1(); } private void lerArquivo(String input) { File f = new File(input); if(!f.exists()) { System.exit(-1); } try { BufferedReader in = new BufferedReader(new FileReader(f)); String line; int lineCount = 0; in.readLine(); while((line = in.readLine())!=null) { list.add(line); } } catch (Exception e) {} } private void write(String str){ str = "Case #"+i+": "+ str + "\n"; try { out.write(str, 0, str.length()); i++; } catch (IOException ex) { Logger.getLogger(T1.class.getName()).log(Level.SEVERE, null, ex); } } private void start(){ lerArquivo("input.txt"); for(String str: list){ int counter = 0; StringTokenizer st = new StringTokenizer(str); int googlers = Integer.parseInt(st.nextToken()); int surprising = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); for(int i = 0; i < googlers; i++){ int score = Integer.parseInt(st.nextToken()); int base = score / 3; if(base >=p) counter++; else if(base == 0){ if(score >= p && score == 1){ counter++; }else if (score >= p && score == 2 && surprising > 0){ counter++; surprising--; } }else if(score%3 == 0){ if(base+1 >= p && surprising > 0){ surprising--; counter++; } }else if((score % 3) == 1){ if(base+1 >= p) counter++; }else if((score%3) == 2){ if(base+1 >= p){ counter++; }else if(base+2 >= p && surprising > 0){ counter++; surprising--; } } } write(""+counter); } } }
0
20
A12852
A12716
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.dagova.dancingWithTheGooglers; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class DancingWithTheGooglers { /** * @param args */ public static void main(String[] args) { DancingWithTheGooglersSolver solver; BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); int testCasesNumber = 0; try { testCasesNumber = Integer.parseInt(bufferedReader.readLine()); for(int testCase = 0; testCase < testCasesNumber; testCase++) { solver = new DancingWithTheGooglersSolver(); int solution = solver.solve(bufferedReader.readLine()); System.out.println("Case #" + (testCase+1) + ": "+solution); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
21
A12852
A13230
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.eevoskos.codejam; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class DancingWithTheGooglers { static boolean DEBUG = false; class Googler implements Comparable<Googler> { List<Triplet> triplets; public Googler(List<Triplet> triplets) { Collections.sort(triplets); this.triplets = triplets; } List<Triplet> getSuprisingTriplets() { List<Triplet> surprising = new ArrayList<Triplet>(); for (Triplet t : triplets) { if (t.isSurprising()) { surprising.add(t); } } return surprising; } Triplet bestScoreTriplet() { Collections.sort(triplets); return triplets.get(0); } @Override public int compareTo(Googler another) { return this.bestScoreTriplet().compareTo(another.bestScoreTriplet()); } List<Triplet> tripletsWithBestScoreAtLeast(int p) { List<Triplet> list = new ArrayList<Triplet>(); for (Triplet t : triplets) { if (t.bestResult() >= p) { list.add(t); } } return list; } int[] numOftripletsWithBestScoreAtLeast(int p) { // result[0]: number of triplets // result[1]: number of the triplets that are surprising int[] result = new int[2]; result[0] = 0; result[1] = 0; for (Triplet t : triplets) { if (t.bestResult() >= p) { result[0]++; if (t.isSurprising()) { result[1]++; } } } return result; } } class Triplet implements Comparable<Triplet> { int x, y, z; Triplet(int x, int y, int z) { int[] n = new int[] { x, y, z }; Arrays.sort(n); this.x = n[0]; this.y = n[1]; this.z = n[2]; } int sum() { return x + y + z; } @Override public boolean equals(Object obj) { if (obj == null) return false; if (!(obj instanceof Triplet)) return false; return x == ((Triplet) obj).x && y == ((Triplet) obj).y && z == ((Triplet) obj).z; } boolean isSurprising() { int[] n = new int[] {x, y, z}; Arrays.sort(n); return n[2] - n[0] == 2; } @Override public String toString() { String s = x + " " + y + " " + z; if (isSurprising()) { s += " (*)"; } return s; } int bestResult() { return z; } @Override public int compareTo(Triplet another) { if (this.bestResult() > another.bestResult()) { return 1; } else if (this.bestResult() < another.bestResult()) { return -1; } else { return 0; } } } int solveCase(String input) { String[] args = input.split(" "); // Number of Googlers int N = Integer.valueOf(args[0]); // Number of surprising triplets int S = Integer.valueOf(args[1]); // Min best score int p = Integer.valueOf(args[2]); // Total points of Googlers int[] t = new int[args.length - 3]; for (int i = 0; i < t.length; i++) { t[i] = Integer.valueOf(args[i + 3]); } if (DEBUG) printInput(N, S, p, t); return calcResult(N, S, p, t); } int calcResult(int N, int S, int p, int[] t) { int result = 0; List<Googler> googlers = new ArrayList<Googler>(); // For each Googler for (int i = 0; i < N; i++) { // Calculate possible combinations of scores List<Triplet> triplets = getCombinations(t[i]); googlers.add(new Googler(triplets)); if (DEBUG) { System.out.println("Googler #" + (i + 1)); for (Triplet tri : triplets) { System.out.println(tri); } System.out.println(""); } } // Sort by best score Collections.sort(googlers); int surprising = 0; for (Googler g : googlers) { List<Triplet> qt = g.tripletsWithBestScoreAtLeast(p); boolean finishThis = false; for (Triplet tri : qt) { if (finishThis) { continue; } else if (!tri.isSurprising()) { result++; finishThis = true; continue; } else { if (surprising >= S) { continue; } else { surprising++; result++; finishThis = true; continue; } } } } return result; } List<Triplet> getCombinations(int sum) { List<Triplet> triplets = new ArrayList<Triplet>(); for (int x = 0; x <= 10; x++) { for (int y = 0; y <= 10; y++) { for (int z = 0; z <= 10; z++) { Triplet triplet = new Triplet(x, y, z); if (triplet.sum() == sum) { if (triplet.z - triplet.x > 2) { // Impossible case, skip continue; } else if(triplets.contains(triplet)) { // Don't add if duplicate continue; } else { triplets.add(triplet); } } else { // Sum is not proper, skip continue; } } } } return triplets; } static int factorial(int n) { if (n <= 1) { return 1; } else { return n * factorial(n - 1); } } static void printInput(int N, int S, int p, int[] t) { String output = "\n"; output += N + " Googlers, "; output += S + " surprising results. "; output += "How many had best score equal to or greater than " + p + "? "; output += "(scores: "; for (int i = 0; i < t.length; i++) { if (i != 0) { output += ", "; } output += t[i]; } output += ")"; System.out.println(output); } public static void main(String... args) { DancingWithTheGooglers dancing = new DancingWithTheGooglers(); try { BufferedReader c = new BufferedReader(new InputStreamReader(System.in)); // Number of test cases int T = Integer.valueOf(c.readLine()); System.out.println(); // Do, for each test case for (int i = 0; i < T; i++) { // Googlerese string String input = c.readLine(); // Process input int output = dancing.solveCase(input); // Print the translated text System.out.println("Case #" + (i + 1) + ": " + output); } } catch (Exception e) { e.printStackTrace(); } } }
0
22
A12852
A11289
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; public class C implements Runnable { private StringTokenizer st; private BufferedReader in; private PrintWriter out; final String file = "C-small"; Map<Character, Character> cache = new HashMap<Character, Character>(); public void solve(int test) throws IOException { out.print("Case #" + (test + 1) + ": "); if (test == 52) { System.out.println(); } // ======================================================================= int totalEmp = nextInt(); int surprise = nextInt(); int threshold = nextInt(); int ans = 0; List<Integer> scores = new ArrayList<Integer>(); for (int i = 0; i < totalEmp; i++) scores.add(nextInt()); if (threshold == 0) { out.println(String.valueOf(totalEmp)); return; } Collections.sort(scores); int min = (threshold * 3) - 4; min = Math.max(min, 0); for (int i : scores) { if(threshold > i) continue; if (i >= (threshold) * 3 - 2) { ans++; continue; } if ((i == 1) && threshold <= i) { ans++; continue; } if (surprise > 0 && i >= (threshold * 3) - 4) { surprise--; ans++; continue; } } // ======================================================================= out.println(String.valueOf(ans)); } public void run() { try { //in = new BufferedReader(new FileReader( // "C:\\Vinay\\gcj\\GCJ\\src\\C-small.in")); //out = new PrintWriter("C:\\Vinay\\gcj\\GCJ\\src\\C-small.out"); in = new BufferedReader(new FileReader(file + ".in")); out = new PrintWriter(file + ".out"); eat(""); int tests = nextInt(); for (int test = 0; test < tests; ++test) { solve(test); } out.close(); } catch (Exception e) { e.printStackTrace(); failed = true; } } void eat(String s) { st = new StringTokenizer(s); } String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } eat(line); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } static boolean failed = false; public static void main(String[] args) { Locale.setDefault(Locale.US); Thread th = new Thread(new C()); th.start(); try { th.join(); } catch (InterruptedException iex) { } if (failed) { throw new RuntimeException(); } } }
0
23
A12852
A10928
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class B { /** * @param args */ static Scanner scan = new Scanner(System.in); static BufferedReader brscan = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter pw ; static ArrayList<Triplet> arrTriplet = new ArrayList<Triplet>(1000); public static void main(String[] args) throws NumberFormatException, IOException { pw = new PrintWriter("output-B.txt"); // TODO Auto-generated method stub int tc = scan.nextInt(); int googler, surprise, minscore; for (int x=1; x<=tc; x++) { arrTriplet.clear(); googler = scan.nextInt(); surprise = scan.nextInt(); minscore = scan.nextInt(); for (int n = 0; n<googler; n++ ) { arrTriplet.add(ScoreToTriplet(scan.nextInt())); } Collections.sort(arrTriplet); // process // int pass = 0; for (int n = 0; n<googler; n++) { Triplet now = arrTriplet.get(n); if (now.getMax()>=minscore) { pass++; } else if (surprise>0){ if (now.x == now.y && now.y == now.z) { if (now.x+1>=minscore && now.y>0) { pass++; surprise--; } } else if (now.x == now.y) { if (now.x+1>=minscore && now.y>0) { pass++; surprise--; } } } } //debug(); pw.println("Case #"+x+": "+pass); } pw.flush(); pw.close(); } public static void debug() { for (int n=0; n<arrTriplet.size(); n++) { pw.println(arrTriplet.get(n).toString()); } } public static Triplet ScoreToTriplet(int score) { int average = score/3; int remain = score-average*3; if (remain==2) { return new Triplet(average+1, average+1, average); } else if (remain==1) { return new Triplet(average+1, average, average); } else { return new Triplet(average, average, average); } } } class Triplet implements Comparable<Triplet> { int x, y, z; public Triplet(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } @Override public int compareTo(Triplet o) { // TODO Auto-generated method stub if (this.x!=o.x) { return o.x-this.x; } if (this.y!=o.y) { return o.y-this.y; } if (this.z!=o.z) { return o.z-this.z; } return 0; } public int getMax() { if (x>=y && x>=z) { return x; } if (y>=x && y>=z) { return y; } return z; } public int getMin() { if (x<=y && x<=z) { return x; } if (y<=z && y<=x) { return y; } return z; } public String toString() { return "["+x+","+y+","+z+"]"; } }
0
24
A12852
A12621
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Googlers { public static void main(String[] args) throws FileNotFoundException { new Googlers().doProcessing(new File("D:\\codejam\\B\\small.txt")); } public void doProcessing(File inputFile) throws FileNotFoundException { Scanner scanner = new Scanner(inputFile).useDelimiter("\n"); if (scanner != null) { int totalCases = Integer.parseInt(scanner.next().trim()); int k = 1 ; if (totalCases > 0) { while (scanner.hasNext()) { String[] rowValues = scanner.next().trim().split(" "); int totalGooglers = Integer.parseInt(rowValues[0]); // System.out.println("Total Googlers : " + totalGooglers); int totalSuprisingCases = Integer.parseInt(rowValues[1]); // System.out.println("Total Surprising Cases : " + // totalSuprisingCases); int averageScore = Integer.parseInt(rowValues[2]); // System.out.println("Total Success Cases : " + // averageScore); // System.out.println("Total Length : " + rowValues.length); int[] totalMarks = new int[totalGooglers]; int j = 0; for (int i = 3; i < rowValues.length; i++) { totalMarks[j] = Integer.parseInt(rowValues[i].trim()); // System.out.println("Value Put : " + totalMarks[j]); j++; } int successCase = getSuccessCase(totalGooglers, averageScore, totalSuprisingCases, totalMarks); System.out.println("Case #" + k++ + ": " + successCase); } } } scanner.close(); } public boolean doNormalCase(int totalScore, int averageScore) { boolean success = false; int X3value = averageScore * 3; if (totalScore >= X3value) { success = true; } else if ((totalScore >= X3value - 1) || (totalScore >= X3value + 1)) { success = true; } else if ((totalScore >= X3value - 2) || (totalScore >= X3value + 2)) { success = true; } else { success = false; } return success; } public boolean doSurprisingCase(int totalScore, int averageScore) { boolean success = false; int X3value = averageScore * 3; // System.out.println("Total Score : " + totalScore); // System.out.println("Average Score : " + X3value); if (((totalScore >= X3value - 3) || (totalScore >= X3value + 3)) && totalScore > averageScore) { success = true; } else if (((totalScore >= X3value - 4) || (totalScore >= X3value + 4)) && totalScore > averageScore) { success = true; } else { success = false; } return success; } public int getSuccessCase(int totalCses, int averageScore, int surprisingCase, int[] caseValues) { int totalSuccess = 0; for (int i = 0; i < totalCses; i++) { // System.out.println("----------------------Value Put : " + // totalCses); boolean normalCaseSuccess = doNormalCase(caseValues[i], averageScore); if (!normalCaseSuccess) { if (surprisingCase > 0) { boolean surprisingCaseSuccess = doSurprisingCase( caseValues[i], averageScore); if (surprisingCaseSuccess) { // System.out.println("Surprising Success..." + // caseValues[i]); totalSuccess++; surprisingCase--; } } } else { totalSuccess++; } } return totalSuccess; } }
0
25
A12852
A12335
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/** * Program : Test for google code jam * Author : jenogg * Since : 2012.04.14 */ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.Map; public class Subject0102 { /** Mapping map */ private Map<String, String> mapper; /** * Construct */ public Subject0102() { init(); } /** * Initialize. */ private void init() { /* Input 3 ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv Output Case #1: our language is impossible to understand Case #2: there are twenty six factorial possibilities Case #3: so it is okay if you want to just give up */ String input = " abcdefghijklmnopqrstuvwxyz"; String output = " yhesocvxduiglbkrztnwjpfmaq"; mapper = new HashMap<String, String>(); for (int letter=0; letter < input.length(); letter++) { mapper.put(input.substring(letter,letter+1), output.substring(letter,letter+1)); } } /** * Test */ public void test() { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String systemIn; int sentenceSize = 0; String[] sentence = new String[]{}; try { //println("Input"); systemIn = nvl(in.readLine()); sentenceSize = getSentenceSize(systemIn); if (sentenceSize > 0) { sentence = new String[sentenceSize]; for (int index = 0; index < sentenceSize; index++) { systemIn = in.readLine(); sentence[index] = nvl(systemIn); } //println("\n-------------------------------------------\n"); in.close(); //println("Output"); for (int index = 0; index < sentenceSize; index++) { print("Case #" + (index+1) + ": "); printSentence(sentence[index]); } } } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } } /** * Gets size of sentences * @param sentenceSize Sentence size * @return Size of sentences * @throws Exception */ private int getSentenceSize(String sentenceSize) throws Exception { return Integer.parseInt(nvl(sentenceSize, "0")); } /** * Print mapping sentence * @param sentence Source sentence */ private void printSentence(String sentence) { int success = 0; String[] data = sentence.split(" "); int dancers = Integer.parseInt(data[0]); int suprise = Integer.parseInt(data[1]); int cutline = Integer.parseInt(data[2]); if (cutline == 0) { success = dancers; } else { for (int index=0; index < dancers; index++) { int totalPoint = Integer.parseInt(data[3+index]); if (totalPoint == 0) { continue; } int basePoint = totalPoint / 3; int rest = totalPoint % 3; int canPoint = basePoint; if (rest != 0) { canPoint++; } if (canPoint >= cutline) { success++; continue; } if (suprise > 0) { if (rest != 1) { canPoint++; if (canPoint >= cutline) { success++; suprise--; continue; } } } } } println(success); } /** * Replace null to empty string * @param string Input value of string * @return If input string is null then empty string, otherwise trimmed input string */ private String nvl(String string) { return nvl(string, ""); } /** * Replace null to replace string * @param string Input value of string * @param replace Replace value of string * @return If input string is null then empty string, otherwise trimmed input string */ private String nvl(String string, String replace) { return string == null ? "" : string.trim(); } /** * Print out * @param obj Value of object */ private void print(Object obj) { System.out.print(obj); } /** * Print line out */ private void println() { println(""); } /** * Print line out * @param obj Value of object */ private void println(Object obj) { System.out.println(obj); } /** * main * @param args Arguments */ public static void main(String[] args) { Subject0102 subject = new Subject0102(); subject.test(); } }
0
26
A12852
A12931
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package google.loader; import java.util.List; public interface ChallengeReader { List<Challenge> createChallenges(String[] lines); }
0
27
A12852
A11261
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; public class Dancers { public static void main (String args[]){ if (args.length != 1){ System.out.println ("Gimme the right arguments!"); return; } File f = new File(args[0]); int testcases, surprise, p, n; ArrayList <Integer> scores = new ArrayList <Integer>(); try{ BufferedReader in = new BufferedReader (new FileReader(f)); String s; testcases = Integer.parseInt(in.readLine()); for (int i = 1; i<=testcases; i++){ scores.clear(); s = in.readLine(); String temp [] = s.split(" "); n= Integer.parseInt (temp[0]); surprise = Integer.parseInt(temp[1]); p = Integer.parseInt(temp[2]); for (int j =3; j<temp.length; j++){ scores.add(Integer.parseInt(temp[j])); } int count = 0; int countSpecial =0; for (int a : scores){ boolean sp = true; boolean found = false; for (int q = p; q<=10; q++){ int t = a - q; if(t >=0){ int l = t/2; int h = t - l; if (Math.abs(q - l) <=2 && Math.abs(q - h) <=2){ // System.out.println(a + " " + + q + " " + t + " " + l + " " + h) ; if (Math.abs(q - l) <2 && (Math.abs(q - h) <2)){ sp = false; // System.out.println("reg"); } found = true; } } } if (found){ count ++; if (sp){ countSpecial++; // System.out.println("hi"); } } } //System.out.println(count + " " + countSpecial); if (countSpecial > surprise){ count -= (countSpecial - surprise); } System.out.printf ("Case #%d: %d\n", i, count ); } } catch (IOException e){ } } }
0
28
A12852
A10345
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.InputStreamReader; import java.io.PrintWriter; public class B { public static void main (String[] args) { try { //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("src/B-small-attempt0.in")))); PrintWriter pw = new PrintWriter(System.out); int cases = Integer.parseInt(in.readLine()); for (int i = 0; i < cases; i++) { int max=0; String[] data = in.readLine().split(" "); int N = Integer.parseInt(data[0]); int S = Integer.parseInt(data[1]); int p = Integer.parseInt(data[2]); int[] sums = new int[N]; for (int j = 0; j < N; j++) { sums[j] = Integer.parseInt(data[j+3]); } if(p==0) { max=N; } else if (p==1) { for (int j = 0; j < sums.length; j++) { if(sums[j]>0) max++; } } else{ for (int j = 0; j < sums.length; j++) { if(sums[j]>=3*p-2) max++; else if(sums[j]>=3*p-4 && S>0) { max++; S--; } } } System.out.println("Case #"+(i+1)+": "+max); } pw.flush(); } catch(Exception e) { e.printStackTrace(); } } }
0
29
A12852
A12533
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; public class Dancing { public static void main(String[] args) throws FileNotFoundException, IOException { IO.changeGoogleIO('B', 0); Scanner input = new Scanner(System.in); int T = input.nextInt(); int N, S, p, min, now; int result0; String result; for (int i = 0; i < T; ++i) { result = "Case #" + (i + 1) + ": "; result0 = 0; N = input.nextInt(); S = input.nextInt(); p = input.nextInt(); min = 3 * (p - 1); for (int j = 0; j < N; ++j) { now = input.nextInt(); if (now > min) ++result0; else if ((now > (min - 2)) && (now > 0) && (S > 0)) { ++result0; --S; } } result += result0; System.out.println(result); } } }
0
30
A12852
A10009
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.math.BigInteger; import java.util.*; public class r2a { int surprises = 0; int p = 0; int elems[] = new int[100]; int output = 0; /** * @param args */ public static void main(String[] args) { r2a mk = new r2a(); try { FileInputStream fstream = new FileInputStream("d:/cjinput.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String str; int i = 0; while ((str = br.readLine()) != null) { int numOfElems = 0; mk.output = 0; i++; if (i == 1) continue; StringTokenizer strTok = new StringTokenizer(str, " "); while (strTok.hasMoreTokens()) { numOfElems = Integer.parseInt(((String) strTok.nextToken())); mk.surprises = Integer.parseInt(((String) strTok.nextToken())); mk.p = Integer.parseInt(((String) strTok.nextToken())); for (int x = 0; x < numOfElems; x++) { mk.elems[x] = Integer.parseInt(((String) strTok.nextToken())); } } mk.evaluate(i,numOfElems); } in.close(); } catch (Exception e) { System.err.println(e); } } private void evaluate(int rowNum, int numOfElems) { for (int i = 0; i< numOfElems; i++) { if (isValidTotal(elems[i])) output++; } String outputStr = "Case #" + (rowNum -1) + ": " + output; System.out.println(outputStr); } private boolean isValidTotal(int num) { if (p==0) return true; if (num != 0) { int maxVal = 3*p; if (num >= maxVal-2) return true; if (num >= maxVal-4 && surprises > 0) { surprises--; return true; } } return false; } }
0
31
A12852
A10386
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; public class Dancing { private static BufferedReader bufferedReader = new BufferedReader( new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { String line = bufferedReader.readLine(); int cases = Integer.parseInt(line); for (int i = 1; i <= cases; i++) { line = bufferedReader.readLine(); String[] split = line.split(" "); int googlers = Integer.parseInt(split[0]); int surprises = Integer.parseInt(split[1]); int p = Integer.parseInt(split[2]); int[] totals = new int[googlers]; for (int j = 0; j < googlers; j++) { totals[j] = Integer.parseInt(split[3 + j]); } Arrays.sort(totals); int answer = 0; int usedSurprises = 0; for (int j = 0; j < googlers; j++) { if (p == 0) { answer++; } else if (totals[j] >= p + 2 * (p - 1) && p >= 1) { answer++; } else if (usedSurprises < surprises) { if (totals[j] >= p + 2 * (p - 2) && p >= 2) { answer++; usedSurprises++; } } } System.out.println("Case #" + i + ": " + answer); } } }
0
32
A12852
A12300
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.ArrayList; import java.util.List; public class Main { public static void main(String[] args) { List<String> lstLinesOutput = new ArrayList<String>(); List<String> lstLinesInput = FileReaderHandler.openFile("/home/guillaume/Bureau/input"); for(int n=1;n< Integer.parseInt(lstLinesInput.get(0)) + 1;n++){ System.out.println("Case " + n); String sOutput = "Case #" + n + ": "; String sInput = lstLinesInput.get(n); String[] hInput = sInput.split(" "); //to int array int[] iInput = new int[hInput.length]; for(int i=0;i < hInput.length;i++){ iInput[i] = Integer.parseInt(hInput[i]); } int iNbSurprising = iInput[1]; int iToBeat = iInput[2]; int iNbAnswers = 0; for(int i=0;i<iInput[0];i++){ int iScore = iInput[i+3]; if(iScore > 0){ int iBase = iScore/3; int iReste = iScore%3; if(iBase >= iToBeat || iReste > 0 && iBase + 1 >= iToBeat){ iNbAnswers++; }else if(iNbSurprising > 0 && (iReste == 0 && iBase + 1 >= iToBeat || iReste == 2 && iBase + 2 >= iToBeat)){ iNbAnswers++; iNbSurprising--; } } else if(iToBeat == 0){ iNbAnswers++; } } sOutput += iNbAnswers; lstLinesOutput.add(sOutput); } if(Integer.parseInt(lstLinesInput.get(0)) != lstLinesOutput.size()){ System.out.println("ERROR!!!"); } FileWriterHandler.writeToFile(lstLinesOutput); } }
0
33
A12852
A12149
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class B { public static void main (String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int[] best_no_surprise = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10}; int[] best_surprise = {0, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10}; int T = Integer.parseInt(in.readLine()); for (int t = 0; t < T; t++) { StringTokenizer st = new StringTokenizer(in.readLine()); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int[] a = new int[N]; for (int i = 0; i < N; i++) a[i] = Integer.parseInt(st.nextToken()); /*System.out.print(N + " " + S + " " + p); for (int i = 0; i < N; i++) System.out.print(" " + a[i]); System.out.println();*/ int n_over_p = 0; int n_surp = 0; for (int i = 0; i < N; i++) { if (best_no_surprise[a[i]] >= p) n_over_p++; if (best_no_surprise[a[i]] < p && best_surprise[a[i]] >= p) n_surp++; } int max_val = n_over_p + Math.min(S, n_surp); System.out.println("Case #"+(t+1)+": " + max_val); } in.close(); } static void init () { } }
0
34
A12852
A11999
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.InputStreamReader; public class Program { /** * @param args */ public static void main1(String[] args) { Speaking_in_Tongues sit=new Speaking_in_Tongues(); sit.initialize(); sit.register("our language is impossible to understand", "ejp mysljylc kd kxveddknmc re jsicpdrysi"); sit.register("there are twenty six factorial possibilities", "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"); sit.register("so it is okay if you want to just give up", "de kr kd eoya kw aej tysr re ujdr lkgc jv"); for(char o='a';o<= 'z';o++) { System.out.print(sit.map[o]); } try { FileWriter fileWriter=new FileWriter("A-small-attempt0.out"); FileReader fileReader=new FileReader("A-small-attempt0.in"); BufferedReader in = new BufferedReader(fileReader); int T= Integer.parseInt(in.readLine()); for(int t=1;t<=T;t++) { String translated=in.readLine(); String normal= sit.Solve(translated); fileWriter.write("Case #"+t+": "+normal+"\n"); } fileWriter.close(); fileReader.close(); } catch (Exception e) { System.out.println("Error! Exception: "+e); } } public static void main(String[] args) { try { FileWriter fileWriter=new FileWriter("B-small-attempt4.out"); FileReader fileReader=new FileReader("B-small-attempt4.in"); BufferedReader in = new BufferedReader(fileReader); int T= Integer.parseInt(in.readLine()); for(int t=1;t<=T;t++) { String[] tokens= in.readLine().split(" "); int N= Integer.parseInt(tokens[0]); int[] values=new int[N]; int S= Integer.parseInt(tokens[1]); int p= Integer.parseInt(tokens[2]); for(int n=0;n<N;n++) { values[n]= Integer.parseInt(tokens[n+3]); } Dancing_With_the_Googlers d=new Dancing_With_the_Googlers(); int result=d.solve1(S, p, values); fileWriter.write("Case #"+t +": " +result+"\n"); } fileWriter.close(); fileReader.close(); } catch (Exception e) { System.out.println("Error! Exception: "+e); } } }
0
35
A12852
A11214
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package problemb; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; public class DancingWithTheGooglers { public static void main(String[] args) { int T = 1; String G = ""; String[] inputs; BufferedReader reader; reader = new BufferedReader(new InputStreamReader(System.in)); try { T = Integer.parseInt(reader.readLine()); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } StringBuffer buffer = new StringBuffer(); for (int X = 1; X <= T; X++) { try { G = reader.readLine(); inputs = G.split(" "); int N = Integer.parseInt(inputs[0]); int S = Integer.parseInt(inputs[1]); int p = Integer.parseInt(inputs[2]); int[] t; if (inputs.length - 3 > N) { t = new int[N]; } else { t = new int[inputs.length - 3]; } for (int i = 0; i < t.length; i++) { t[i] = Integer.parseInt(inputs[i + 3]); } int surprizing = 0; Arrays.sort(t); int result = 0; for (int j = t.length - 1; j >= 0; j--) { if(p==0){ result = t.length; break; } int dev = t[j] / 3; int mod = t[j] % 3; if (dev >= p) { result++; continue; } if (mod == 1 && dev + 1 >= p) { result++; continue; } if (mod == 2 && dev + 1 >= p) { result++; continue; } if (mod == 2 && dev + 2 >= p && surprizing < S) { surprizing++; result++; continue; } if (mod == 0 && dev > 0 && dev + 1 >= p && surprizing < S) { surprizing++; result++; continue; } } buffer.append("Case #").append(X).append(": ").append(result) .append("\r\n"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } System.out.println(buffer.toString()); } }
0
36
A12852
A10547
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.PrintStream; public class Dance { static int getMaxGooglers(int N,int S, int p, int[] t) { int count=0; int surpriseCount=0; int avg=p*3; for(int i=0;i<N;i++) { if(t[i]>=p) { if(t[i]>=avg-2) count++; else if(surpriseCount<S) { if(t[i]>=avg-4) { count++; surpriseCount++; } } } } return count; } }
0
37
A12852
A12925
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.contest.C; import google.loader.Challenge; import google.problems.AbstractChallenge; import java.util.HashSet; import java.util.Set; public class CChallenge extends AbstractChallenge implements Challenge { private int B; private int A; private int num; Set<String>pairs ; public CChallenge(int number, String line) { super(number); num=0; pairs = new HashSet<String>(); String[] tokens = line.split(" "); A = Integer.parseInt(tokens[0]); B = Integer.parseInt(tokens[1]); int i=0; for( i=A ; i<=B; i++){ calcFor(i); } setResult(""+num); } private void calcFor(int i) { String numString = ""+i; for(int j=1; j<= numString.length()-1; j++){ String first = numString.substring(0,j); String second = numString.substring(j); String third = second+first; check(i, third); } } private void check(int i, String third) { if(third.startsWith("0")){ return; } int j = Integer.parseInt(third); if(A<=i && i<j && j<=B){ String hlp = ""+i+j; if(! pairs.contains(hlp)){ pairs.add(hlp); num++; }else{ System.out.println(""+num+" "+i+" "+j); } } } }
0
38
A12852
A11675
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 jam_b; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author dkozyrev */ public class Jam_B { /** * @param args the command line arguments */ public static void main(String[] args) { List<Map> cases = readFile("C:\\tmp\\testA.txt"); int counter = 1; String delimiter = " "; for (Map<String, String> caseItem : cases) { List<String> lines = Arrays.asList(caseItem.get("str").split(delimiter)); int res = findMax(lines); System.out.println("Case #"+counter+":" + res); counter++; } } public static int findMax(List<String> lines) { int max = 0; int peaopleNum = Integer.parseInt(lines.get(0)); int surprising = Integer.parseInt(lines.get(1)); int find = Integer.parseInt(lines.get(2)); //System.out.println(find); int counter = 0; for(String score : lines) { if(counter > 2) { //find potential Double scoreD = Double.parseDouble(score); if(scoreD/3 >= (find-0.75)) { max++; //System.out.println("1: " + scoreD/3); } else if (surprising>=1 && (scoreD/3 > (find-1.5)) && (find-1.5) > 0 ) { max++; surprising--; //System.out.println("2: " + scoreD/3); } } counter++; //System.out.println(max); } return max; } public static List<Map> readFile(String fname) { List<Map> casesList = new ArrayList<Map>(); { FileReader input = null; try { input = new FileReader(fname); BufferedReader bufRead = new BufferedReader(input); String line; int count = 0; line = bufRead.readLine(); Integer cases = Integer.parseInt(line); count++; while (line != null) { if (count == 1) { line = bufRead.readLine(); count++; continue; } Map<String, String> params = new HashMap<String, String>(); params.put("str", line); line = bufRead.readLine(); casesList.add(params); count++; } bufRead.close(); } catch (FileNotFoundException ex) { Logger.getLogger(Jam_B.class.getName()).log(Level.SEVERE, null, ex); }catch (ArrayIndexOutOfBoundsException e){ System.out.println("Usage: java ReadFile filename\n"); }catch (IOException e){ System.out.println(e.getMessage()); } finally { try { input.close(); } catch (IOException ex) { Logger.getLogger(Jam_B.class.getName()).log(Level.SEVERE, null, ex); } } } return casesList; } }
0
39
A12852
A10357
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class B { public static void main(String[] args) throws IOException { int nCases; String filename="B-small-attempt0"; //String filename="TestB"; Scanner reader = new Scanner (new FileReader(filename + ".in")); PrintWriter writer = new PrintWriter(new FileWriter(filename + ".out")); nCases = reader.nextInt(); for (int i=0; i<nCases; i++){ writer.print("Case #" + (i+1)+": "); int nDancers= reader.nextInt(); int S = reader.nextInt(); int p = reader.nextInt(); int out = 0; //output for (int j=0;j<nDancers;j++){ int temp = reader.nextInt(); if (temp > 3*p-3) out++; else if (S>0 && (temp == 3*p-3 || temp == 3*p-4) && p!=1){ out ++; S--; } } writer.println(out); } writer.flush(); } }
0
40
A12852
A10244
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * Gabriel Shaw * 4/13/12 */ import java.io.File; import java.io.PrintWriter; import java.io.IOException; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { File file = new File("B-small-attempt1.in"); PrintWriter outfile = new PrintWriter("B-small.out"); Scanner infile = new Scanner(file); int numberOfCases; int numberOfGooglers; int desiredScore; int numberOfSuprisingCases; int numberOfGoodScores; numberOfCases = infile.nextInt(); infile.nextLine(); for(int i=0 ; i<numberOfCases ; i++) { numberOfGooglers = infile.nextInt(); numberOfSuprisingCases = infile.nextInt(); desiredScore = infile.nextInt(); numberOfGoodScores = 0; for(int j=0 ; j<numberOfGooglers ; j++) { int totalScore = infile.nextInt(); System.out.println(j +" " +(totalScore - desiredScore - (desiredScore - 1) - (desiredScore - 1))); if(desiredScore <= 1) { if(desiredScore == 1) { if(totalScore - desiredScore >= 0) { numberOfGoodScores++; }//end of if(totalScore - desiredScore >= 0) }//end of if(desiredScore == 1) if(desiredScore == 0) { if(totalScore >= 0) { numberOfGoodScores++; } } } if(!(desiredScore <= 1) && (totalScore - desiredScore - (desiredScore - 1) - (desiredScore - 1)) >= 0) { numberOfGoodScores++; }else { if(!(desiredScore <= 1) && (numberOfSuprisingCases > 0) && (totalScore -desiredScore - (desiredScore - 2) - (desiredScore - 2)) >= 0) { numberOfGoodScores++; numberOfSuprisingCases--; }//end of if((numberOfSuprisingCases > 0) && (totalScore -desiredScore - 2*(desiredScore - 2)) >= 0) }//end of else }//end of for(int j=0 ; j<numberOfGooglers ; j++) outfile.println("Case #" +(i+1) +": " +numberOfGoodScores); if(infile.hasNext()) { infile.nextLine(); } }//end of for(int i=0 ; i<numberOfCases ; i++) outfile.close(); }//end of public static void main(String[] args) throws IOException }//end of public class DancingWithTheGooglers
0
41
A12852
A11913
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 B { public static void main(String[] args) throws IOException { // Scanner in = new Scanner(new File("in/B/test.in")); Scanner in = new Scanner(new File("in/B/small.in")); // Scanner in = new Scanner(new File("in/B/big.in")); // BufferedWriter bw = new BufferedWriter(new FileWriter( // "out/B/test.out")); BufferedWriter bw = new BufferedWriter(new FileWriter( "out/B/small.out")); // BufferedWriter bw = new BufferedWriter(new FileWriter( // "out/B/big.out")); int cases = in.nextInt(); for(int c = 1; c <= cases; c++){ int competitors = in.nextInt(); int surprises = in.nextInt(); int minNote = in.nextInt(); int winners = 0; for(int i = 0; i < competitors; i++){ int max = 0, normal = 0; int note = in.nextInt(); System.err.println(note); if(note == 0){ max = 0; normal = 0; }else if(note == 1){ max = 1; normal = 1; }else if(note > 27){ max = 10; normal = 10; }else{ int mod = note%3; max = note/3 + (mod==0?1:mod); normal = max - (mod!=1?1:0); } if(normal >= minNote){ winners++; continue; } if(max == minNote && surprises > 0){ surprises--; winners++; continue; } } bw.write("Case #" + (c) + ": "+winners); System.err.println("Case #" + (c) + ": "+winners); bw.newLine(); } in.close(); bw.flush(); bw.close(); } }
0
42
A12852
A11471
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithTheGooglers { private PrintWriter out; private Scanner in; private void init() { } private void solve() { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int r = 0; for (int i = 0; i < N; i++) { int best = in.nextInt(); int part = best / 3; int rest = best - part * 3; // rest = 0,1,2 part=4 // 0: 4 4 4->4 3 5; 4 (+1) // 1: 4 4 5->3 5 5; 5 (0) // 2: 4 5 5->4 4 6; 5 (+1) // part=0: +0 // 0: 0 0 0->0 0 0; 0 (+0) // 1: 0 0 1->0 0 1; 1 (+0) // 2: 0 1 1->0 0 2; 1 (+1) // part=1: +0 // 0: 1 1 1->1 0 2; 1 (+1) // 1: 1 1 2->1 1 2; 2 (+0) // 2: 1 2 2->1 1 3; 2 (+1) int max = part + (rest == 0 ? 0 : 1); int add = rest == 1 ? 0 : 1; if (part == 0) { add = rest == 2 ? 1 : 0; } if (S >= 1 && add == 1 && max + 1 == p) { S--; max += add; } if (max >= p) { r++; } } out.println(r); } private void runTests() { init(); int T = Integer.parseInt(in.nextLine()); for (int i = 0; i < T; i++) { out.print("Case #" + (i + 1) + ": "); solve(); } } private void run() { try { runTests(); } finally { close(); } } private void close() { out.close(); in.close(); } public DancingWithTheGooglers() throws FileNotFoundException { this.in = new Scanner(new File("B-small-attempt2.in")); this.out = new PrintWriter(new File("B-small-attempt2.out")); } public static void main(String[] args) throws FileNotFoundException { new DancingWithTheGooglers().run(); } }
0
43
A12852
A11297
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; public class Triplet { private int total; private int mod3; private int div3; private int maxNormal; private int maxSurprise; public Triplet(int totalPoints) { init(totalPoints); } private void init(int totalPoints) { total = totalPoints; mod3 = total % 3; div3 = total / 3; maxNormal = calcMaxNormal(); maxSurprise = calcMaxSurprise(); } public int calcMaxSurprise() { if ( total == 0 ) return 0; return (mod3 == 2) ? div3 + 2 : div3 + 1; } public int calcMaxNormal() { if ( total == 0 ) return 0; return (mod3 == 0) ? div3 : div3 + 1; } public int getMaxNormal() { return maxNormal; } public int getMaxSurprise() { return maxSurprise; } public static void main(String[] args){ System.out.println("Testing Triplet"); for ( int i=0; i<6; i++ ) { Triplet t = new Triplet(i); System.out.println(i+" n:"+t.calcMaxNormal() + " s:" + t.calcMaxSurprise()); } } }
0
44
A12852
A12406
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); OutputBuilder output = new OutputBuilder(); int tests = s.nextInt(); s.nextLine(); for (int i = 0; i < tests; i++) { output.addLine(String.valueOf(getMaxDancers(s.nextLine()))); } System.out.println(output.toString()); } private static int getMaxDancers(String line) { String[] parameters = line.split(" "); int surprising = Integer.parseInt(parameters[1]); int minScore = Integer.parseInt(parameters[2]); int minNorm = minScore * 3 - 2; int minSurp = minNorm - 2; int dancers = 0; for(int i = 3; i < parameters.length; i++){ int sum = Integer.parseInt(parameters[i]); if(sum >= minNorm || (sum > 1 && sum >= minSurp && surprising-- > 0)){ dancers++; } } return dancers; } private static class OutputBuilder{ private final StringBuilder output = new StringBuilder(); private int i = 1; void addLine(String s){ this.output.append("Case #"); this.output.append(this.i); this.output.append(": "); this.output.append(s); this.output.append("\n"); this.i++; } @Override public String toString(){ return this.output.toString(); } } }
0
45
A12852
A12838
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 jpt.codejam; import java.io.PrintStream; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Codejam2012 { static void solve_Qual_B() throws Exception { Scanner in = new Scanner(System.in); PrintStream out = System.out; int cases = in.nextInt(); for (int nCase = 1; nCase <= cases; ++nCase) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int res = 0; for (int i=0; i<N; ++i) { int t = in.nextInt(); int max1 = (t+2)/3; int max2 = (t+4)/3; if (t<=1 || t>=29) max2 = -1; if (max1 >= p) ++res; else if (max2 >= p && S > 0) { ++res; --S; } } out.printf("Case #%d: %d\n", nCase, res); } } static void solve_Qual_C() throws Exception { Scanner in = new Scanner(System.in); PrintStream out = System.out; int[] ten = new int[8]; ten[0] = 1; for (int i=1; i<ten.length; ++i) ten[i] = ten[i-1]*10; int cases = in.nextInt(); for (int nCase = 1; nCase <= cases; ++nCase) { int A = in.nextInt(); int B = in.nextInt(); int res = 0; Set<Integer> ms = new HashSet<Integer>(); for (int n=A; n<=B; ++n) { int d = 1; for (int aux=10; aux<=n; aux*=10) ++d; ms.clear(); for (int k=1; k<d; ++k) { int q = n % ten[k]; if (q<ten[k-1]) continue; int p = n / ten[k]; int m = q * ten[d-k] + p; if (A<=m && B>=m && n!=m && !ms.contains(m)) ++res; ms.add(m); } } out.printf("Case #%d: %d\n", nCase, res/2); } } public static void main(String[] args) throws Exception { solve_Qual_B(); //solve_Qual_C(); //solve_1A_A(); //solve_1A_B(); //solve_1A_C(); } }
0
46
A12852
A11897
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.google.codejam.util; import java.io.File; import java.io.FileWriter; import java.io.IOException; public class CodeJamOutputFile extends File { /** * */ private static final long serialVersionUID = -6971460798309687528L; private FileWriter writer; private Boolean caseZero = false; public CodeJamOutputFile(String pathname) { super(pathname); try { this.setWriter(); } catch (IOException e) { } } private void setWriter() throws IOException { this.writer = new FileWriter(this); } public FileWriter getWriter() { return writer; } public void writeCase(int caseId, String result){ if(caseId == 0){ caseZero = true; } caseId = caseZero ? caseId + 1 : caseId; try { writer.write("Case #"+(caseId) +": " + result + "\n"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void close(){ try { writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
47
A12852
A12656
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 commons; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.LinkedList; import java.util.List; public class FileUtilities { public static void writeFile(List<String> strings, File file) throws IOException { file.createNewFile(); FileWriter writer = new FileWriter(file); for (int i = 1; i <= strings.size(); i++) { writer.write("Case #"); writer.write(i + ": "); writer.write(strings.get(i-1)); writer.write("\n"); } writer.close(); } public static List<String> readFile(File file) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(file)); String input = reader.readLine(); List<String> result = new LinkedList<String>(); while (!(input == null)) { result.add(input); input = reader.readLine(); } reader.close(); return result; } }
0
48
A12852
A10135
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 { private static boolean isValidScore(int score) { return score >=0 && score <= 10; } private static boolean canReach (int tot, int p, boolean canSurprise) { int n = tot / 3; int a,b,c; a = n; b = n; c = tot - a - b; int max = -1; if (a==c) { //a-1, a, a+1 if (isValidScore(a-1) && isValidScore(a) && isValidScore(a+1) && canSurprise) { max = a+1; } //a, a, a else if (isValidScore(a)) max = a; } if (a+1 == c) { //a, a, a+1 if (isValidScore(a) && isValidScore(a+1)) max = a+1; } if (a+2 == c) { //a, a, a+2 if (isValidScore(a) && isValidScore(a+2) && canSurprise) max = a+2; //a, a+1, a+1 else if (isValidScore(a) && isValidScore(a+1)) max = a+1; } return max >= p; } public static void main(String[] args) { Scanner in = new Scanner(System.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 numCanReach = 0; for (int j=0; j < N; j++) { int tot = in.nextInt(); if (canReach(tot, p, false)) numCanReach++; else if (canReach(tot,p, true) && S != 0) { numCanReach++; S--; } } System.out.println("Case #"+(i+1)+": "+numCanReach); } } }
0
49
A12852
A10775
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 googlecodejam2012; import java.io.*; /** * * @author Stephen */ public class GoogleCodeJam2012Num2 { /** * @param args the command line arguments */ public static void main(String[] args) { try { FileInputStream fs = new FileInputStream("input.txt"); DataInputStream in = new DataInputStream(fs); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fws = new FileWriter("output.txt"); BufferedWriter out = new BufferedWriter(fws); String numLine = br.readLine(); System.out.println(numLine); int numCases = Integer.parseInt(numLine); String caseLine; for(int i = 1; i <= numCases; i++) { caseLine = br.readLine(); System.out.println("Case #"+i); String[] splitted = caseLine.split(" "); int numGooglers = Integer.parseInt(splitted[0]); int surprising = Integer.parseInt(splitted[1]); int p = Integer.parseInt(splitted[2]); System.out.println(numGooglers+" Googlers, "+surprising+" surprising results, p="+p); //int[] util = new int[numGooglers]; int maxResult = 0; for(int j = 0; j < numGooglers; j++) { int totalScore = Integer.parseInt(splitted[j+3]); int maxScore = totalScore/3+1; if(totalScore%3 == 0) maxScore--; if(maxScore >= p) maxResult++; else { if(totalScore%3 != 1 && surprising > 0 && maxScore+1 == p && maxScore != 0) { surprising--; maxResult++; } } System.out.println("Total: "+totalScore+" Max: "+maxScore); } System.out.println("Max Result: "+maxResult); out.write("Case #"+i+": "+maxResult+"\r\n"); } in.close(); out.close(); displayOutput(); } catch (Exception e) { System.err.println("Oops! Error occured: " + e.getMessage()); } } public static String gDecode(String input) { String decoded = ""; for(int i = 0; i < input.length(); i++) { if(input.charAt(i) == ' ') decoded += ' '; else decoded += decodeChar(input.charAt(i)-'a'); } return decoded; } public static String googleKey = "yhesocvxduiglbkrztnwjpfmaq"; public static char decodeChar(int encoded) { return googleKey.charAt(encoded); } public static void displayOutput() { System.out.println("START OUTPUT\n-------------------"); try { FileInputStream fs = new FileInputStream("output.txt"); DataInputStream in = new DataInputStream(fs); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String readLine; while ((readLine = br.readLine()) != null) { System.out.println(readLine); } } catch (Exception e) { System.err.println("Oops! Error occured: " + e.getMessage()); } System.out.println("---------------------\nEND OUTPUT"); } }
0
50
A12852
A12630
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; public class dancing { public static void main(String[] args) { // TODO Auto-generated method stub String input=""; StringTokenizer strtok; int googlers, surprises, p, count=0; int line = 0; int totalscore, base, residual; try { BufferedReader inputStream = new BufferedReader(new FileReader("input")); BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt")); line = Integer.parseInt(inputStream.readLine()); for(int i=0; i< line; i++){ input = inputStream.readLine(); strtok = new StringTokenizer(input," "); googlers = Integer.parseInt(strtok.nextToken()); surprises = Integer.parseInt(strtok.nextToken()); p = Integer.parseInt(strtok.nextToken()); for(int j=0 ; j< googlers; j++){ totalscore = Integer.parseInt(strtok.nextToken()); base = totalscore/3; residual = totalscore % 3; triplet normal,surprise; if(residual==0){ //normal normal = new triplet(base,base,base); //surprising surprise = new triplet(base-1,base,base+1); if(normal.score()>=p) count++; else if(surprise.status!="invalid" && surprise.score()>=p && surprises > 0){ count++; surprises--; } } else if(residual==1){ //normal normal = new triplet(base,base,base+1); //surprising but not helpful //new triplet(base-1,base+1,base+1); if(normal.score()>=p) count++; } else if(residual==2){ //normal normal = new triplet(base,base+1,base+1); //surprising surprise = new triplet(base,base,base+2); if(normal.score()>=p) count++; else if(surprise.status!="invalid" && surprise.score()>=p && surprises > 0){ count++; surprises--; } } }//for each googler //System.out.println("Case #"+(i+1)+": "+count); if(i!=line-1) writer.write("Case #"+(i+1)+": "+count+"\r\n"); else writer.write("Case #"+(i+1)+": "+count); count = 0; }//read new line writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }//main }
0
51
A12852
A13085
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Dance { public static void main(String[] args) throws IOException { Scanner in = new Scanner(new File("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new File("dance_small.in")); //Scanner in = new Scanner(System.in); int runs = Integer.parseInt(in.nextLine().trim()); int count = 0; while(++count <= runs) { out.print("Case #" + count + ": "); int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int[] scores = new int[n]; for(int i = 0; i < n; i++) scores[i] = in.nextInt(); int min = Math.max(p, (p*3)-2); int surprise = Math.max(p, (p*3)-4); int num = 0; for(int i = 0; i < n; i++) { if(scores[i] >= min) num++; else if(scores[i] >= surprise && s > 0) { num++; s--; } } out.println(num); } out.close(); } }
0
52
A12852
A11682
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
public interface ICounterZeroEvent { public void fireEvent(); }
0
53
A12852
A12303
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.parijat; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; public class Sol2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("./input.txt"))); FileOutputStream fos = new FileOutputStream("output.txt"); int testcases = Integer.parseInt(reader.readLine()); for(int i=0; i< testcases; i++) { String[] temp = reader.readLine().split(" "); int dancers = Integer.parseInt(temp[0]); int surprises = Integer.parseInt(temp[1]); int min_best_score = Integer.parseInt(temp[2]); int t = min_best_score - 2; if(t< 0) { t = 0; } int min_score_with_surprise = min_best_score + 2*t; t = min_best_score - 1; if(t< 0) { t = 0; } int min_score_normal = min_best_score + 2*t; int success = 0; for(int j=3; j<temp.length; j++) { int score = Integer.parseInt(temp[j]); if(score >= min_score_normal) { success++; } else if(score >= min_score_with_surprise && surprises > 0) { surprises--; success++; } } fos.write(("Case #" + (i+1) + ": " + success + "\n").getBytes()); } } }
0
54
A12852
A11973
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.*; import java.lang.*; public class RQQ2 { public static void main(String[] args) { try { HashMap<Character,Character> map = new HashMap<Character,Character>(); Scanner s = new Scanner(new File("B-small-attempt0.in")); FileWriter o = new FileWriter(new File("out.txt")); Integer lines = Integer.parseInt(s.nextLine()); String str; Integer sup; Integer googlers; Integer p; StringTokenizer st; for (int i = 0; i < lines; i++) { o.write("Case #" + ( i + 1) + ": "); str = s.nextLine(); st = new StringTokenizer(str, " "); googlers = Integer.parseInt(st.nextToken()); sup = Integer.parseInt(st.nextToken()); p = Integer.parseInt(st.nextToken()); int even = 0; int max = 0; for (int j = 0; j < googlers; j++) { int total = Integer.parseInt(st.nextToken()); if ( Math.ceil((double)total / 3.0) >= p ) { max++; } else if ( total != 0 && Math.ceil((double)total/3.0 + 2.0/3.0) >= p) { even++; } } max += Math.min(even, sup); o.write("" + max + "\n"); } s.close(); o.close(); } catch(Exception e) { System.out.println(e.getMessage()); e.printStackTrace(System.out); } } }
0
55
A12852
A10132
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; public class main3 { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader m = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(m.readLine()); for (int i = 0; i < n; i++) { String cas = m.readLine(); String [] a = cas.split(" "); int nofGoogler = Integer.parseInt(a[0]); int nofsurprising = Integer.parseInt(a[1]); int p = Integer.parseInt(a[2]); int check = (3*p) - 2; if (nofsurprising >0) check -=2; int count = 0 ; int co = 0 ; for (int j = 3; j < a.length; j++) { int c = Integer.parseInt(a[j]); if (c >= p && c >=check ){ count++; if(nofsurprising >0 && c < (check+2)) co++; } } if (co > nofsurprising) count -= (co-nofsurprising); System.out.print("Case #"+(i+1)+": "+count); System.out.print("\n"); } } }
0
56
A12852
A12840
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package br.com.luan; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class B { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String line = br.readLine(); int T = Integer.valueOf(line); // Process which number from stdin for (int i = 0; i < T; i++) { StringBuilder sb = new StringBuilder(line.length() + 11); sb.append("Case #"); sb.append(i + 1); sb.append(": "); line = br.readLine(); String[] split = line.split(" "); Integer N = Integer.parseInt(split[0]); Integer S = Integer.parseInt(split[1]); Integer p = Integer.parseInt(split[2]); Integer[] ti = new Integer[N]; for (int j = 0; j < ti.length; j++) { ti[j] = Integer.parseInt(split[3 + j]); } int result = doProcess(N, S, p, ti); sb.append(result); sb.append('\n'); System.out.print(sb.toString()); } } private static int doProcess(Integer n, Integer s, Integer p, Integer[] ti) { final List<Integer> sureList = new ArrayList<Integer>(n); final List<Integer> posiList = new ArrayList<Integer>(n); final int impoMax = 3 * p.intValue() - 4; final int cerMin = 3 * p.intValue() - 2; for (int i = 0; i < ti.length; i++) { Integer in = ti[i]; int sumScore = in.intValue(); if (sumScore < impoMax) { // Impossible to get that score } else if (sumScore >= cerMin) { // Sure the dancer get that score sureList.add(in); } else if (sumScore > 0) { // Possibles dancer who can get that score depending the surprising posiList.add(in); } } int qualified = methodA(posiList, p, s); return sureList.size() + qualified; } private static int methodA(List<Integer> posiList, Integer p, Integer s) { int surprising = s.intValue(); if (surprising == 0) return 0; int result = 0; for (int i = 0; i < surprising && posiList.size() > 0 ; i++) { posiList.remove(0); result += 1; } return result; } }
0
57
A12852
A12995
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.awt.Polygon; import java.awt.geom.Point2D; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class B implements Runnable { private void solve() throws IOException { int N = nextInt(); int S = nextInt(); int p = nextInt(); int[] t =new int[N]; for (int i = 0; i < N; ++i) { t[i] = nextInt(); } Arrays.sort(t); int[] a = new int[N]; for (int i = 0; i < N; ++i) { a[i] = (t[i] + 2) / 3; } int ans = 0; int l = 0; for (l = N - 1; l >= 0 && a[l] >= p; --l) { ++ans; } for (; l >= 0 && S > 0; --l) { if (t[l] % 3 == 0 && t[l] / 3 + 1 >= p && t[l] / 3 + 1 <= 10 && t[l] / 3 - 1 >= 0) { ++ans; --S; } if (t[l] % 3 == 2 && t[l] / 3 + 2 >= p && t[l] / 3 + 2 <= 10) { --S; ++ans; } } out.println(ans); } /** * @param args */ public static void main(String[] args) { (new Thread(new B())).start(); } private BufferedReader br; private StringTokenizer st; private PrintWriter out; private String filename = ""; @Override public void run() { try { br = new BufferedReader(new FileReader("input.txt")); st = new StringTokenizer(""); out = new PrintWriter("output.txt"); int T = nextInt(); for (int i = 1; i <= T; ++i) { out.print("Case #" + i + ": "); solve(); } out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(-1); } } String next() throws IOException { while (!st.hasMoreTokens()) { String temp = br.readLine(); if (temp == null) { return null; } st = new StringTokenizer(temp); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } }
0
58
A12852
A12054
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 ProjB { static Scanner scan = new Scanner (System.in); static void test (int k ) { System.out.print ("Case #" + k + ": "); int N = scan.nextInt(); int S = scan.nextInt(); int p = scan.nextInt(); int[] input = new int[N]; for (int i = 0; i < N; ++i) input[i] = scan.nextInt(); Arrays.sort(input); int min1 = (p >= 1)? 3*p-2:0; int min2 = -1; if (p >= 2) min2 = 3 * p - 4; else if (p == 1) min2 = 1; else min2 = 0; int k1 = N - 1; while (k1 >= 0 && input[k1] >= min1) --k1; int ans = N - 1 - k1; int k2 = k1; while (k2 >=0 && (k1 + 1 - k2) <= S && input[k2] >= min2) --k2; ans += k1 - k2; System.out.println (ans); } public static void main (String[] args) { int T = scan.nextInt(); for (int i = 1; i <= T; ++i) test (i); } }
0
59
A12852
A11483
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.nio.Buffer; import java.util.Arrays; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws Exception { BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("/home/xnike/Downloads/B-small-attempt0.out")); Scanner scanner = new Scanner(new File("/home/xnike/Downloads/B-small-attempt0.in")); int t = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < t; i++) { int n = scanner.nextInt(), s = scanner.nextInt(), p = scanner.nextInt(); int[] ti = new int[n]; for (int j = 0; j < n; j++) { ti[j] = scanner.nextInt(); } scanner.nextLine(); Arrays.sort(ti); int num = 0; for (int k = ti.length - 1; k > -1; k--) { int min = ti[k] / 3, max = ti[k] - 2 * (ti[k] / 3); if (0 == max - min && 2 < ti[k]) { max++; min--; } if (max >= p) { if (max == p && (2 == max - min)) { if (0 < s) { s--; num++; } } else { num++; } } } bufferedWriter.write("Case #" + (i + 1) + ": " + num + "\n"); } bufferedWriter.flush(); } }
0
60
A12852
A13000
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.q2; import qualification.common.InputReader; import qualification.common.OutputWriter; import qualification.q1.Q1Solver; /** * Created by IntelliJ IDEA. * User: ofer * Date: 14/04/12 * Time: 18:55 * To change this template use File | Settings | File Templates. */ public class Q2Sim { public static void main(String[] args){ String inputFile = "input.txt"; String outPutFile = "output.txt"; String[] lines = InputReader.getInputLines(inputFile); Q2Solver solver = new Q2Solver(); int numOfTests = Integer.parseInt(lines[0]); String[] output = new String[numOfTests]; for (int i = 0 ; i < numOfTests ; i++){ String[] splited = lines[i+1].split(" "); int n = Integer.parseInt(splited[0]); int s = Integer.parseInt(splited[1]); int p = Integer.parseInt(splited[2]); int[] sums = new int[n]; for (int j = 0 ; j < n ; j++){ int sum = Integer.parseInt(splited[j+3]); sums[j] = sum; } int res = solver.solve(n,s,p,sums); output[i] = "Case #" + (i+1) + ": " + res; } OutputWriter.writeOutput(outPutFile, output); } }
0
61
A12852
A12001
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dancing { static int N; static int S; static int p; static int[] t; public static boolean normal(int tot){ int max = tot%3==0?tot/3:tot/3+1; return max>=p; } public static boolean surprising(int tot){ int max = tot==0?0:(tot+1)/3+1; return max>=p; } public static int solve(){ int DB=0; int SDB = S; for(int i=0; i<N; i++){ if(normal(t[i])) DB++; else if(SDB > 0 && surprising(t[i])){ DB++; SDB--; } } return DB; } public static void main (String args[]) throws IOException{ BufferedReader be = new BufferedReader(new FileReader("B-small.in")); int T = Integer.parseInt(be.readLine()); for(int i=1; i<=T; i++){ String s = be.readLine(); N = Integer.parseInt(s.split(" ")[0]); S = Integer.parseInt(s.split(" ")[1]); p = Integer.parseInt(s.split(" ")[2]); t = new int[N]; for(int j = 0; j < N; j++) t[j] = Integer.parseInt(s.split(" ")[j+3]); System.out.println("Case #"+i+": "+solve()); } be.close(); } }
0
62
A12852
A12739
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.StringReader; import java.util.ArrayList; import java.util.List; public class Puzzle2 { public static int countGooglersByTarget(int target, int numberOfSurprising, List<Integer> googlerScores) { int count = 0; int totalTarget = 3*target; for (int i = 0; i < googlerScores.size(); i++) { int totalGooglerSum = googlerScores.get(i); if(totalGooglerSum >= totalTarget -2) { count ++; } else if(totalGooglerSum >0 && totalGooglerSum +2 >= totalTarget -2 && numberOfSurprising >0) { count ++; numberOfSurprising--; } } return count; } public static void main(String[] args) { String input = "100\n" + "3 1 5 15 13 11\n" + "3 0 8 23 22 21\n" + "1 0 1 18\n" + "3 0 5 3 16 11\n" + "2 2 6 15 28\n" + "1 0 7 30\n" + "2 1 3 24 1\n" + "2 1 7 10 21\n" + "1 0 10 30\n" + "1 0 7 18\n" + "1 0 3 6\n" + "2 2 2 6 5\n" + "3 3 8 26 22 19\n" + "1 0 3 6\n" + "3 0 2 4 23 24\n" + "1 0 10 17\n" + "2 2 9 10 24\n" + "3 0 0 0 0 0\n" + "1 0 1 7\n" + "2 1 9 18 30\n" + "2 2 0 22 23\n" + "3 1 3 6 5 29\n" + "2 0 3 16 2\n" + "1 0 8 17\n" + "1 1 7 5\n" + "2 0 7 18 30\n" + "3 0 10 3 4 18\n" + "3 3 9 2 7 7\n" + "1 0 3 6\n" + "2 0 6 15 14\n" + "3 2 9 17 26 22\n" + "2 0 7 5 11\n" + "2 1 3 5 5\n" + "3 0 8 30 24 1\n" + "1 0 0 17\n" + "2 1 9 18 24\n" + "3 0 8 27 16 17\n" + "1 0 2 3\n" + "3 0 7 18 24 19\n" + "3 0 7 5 15 17\n" + "3 0 8 16 12 4\n" + "1 0 8 28\n" + "1 1 10 12\n" + "2 2 4 18 23\n" + "2 0 3 25 6\n" + "2 1 4 11 2\n" + "3 2 5 12 11 11\n" + "3 3 7 21 22 14\n" + "3 2 1 12 16 0\n" + "3 0 0 30 30 30\n" + "2 0 3 8 30\n" + "1 1 1 21\n" + "3 0 4 21 24 2\n" + "3 3 3 27 23 8\n" + "1 0 8 7\n" + "1 0 7 17\n" + "3 1 3 24 12 28\n" + "3 0 1 14 26 11\n" + "3 0 9 8 23 1\n" + "2 0 8 12 20\n" + "2 2 8 8 25\n" + "1 0 5 6\n" + "1 0 8 20\n" + "1 0 5 12\n" + "2 1 0 17 25\n" + "3 1 4 1 30 5\n" + "2 1 7 17 17\n" + "1 0 7 11\n" + "3 0 1 5 23 10\n" + "2 0 10 27 15\n" + "1 0 8 1\n" + "3 0 8 30 28 30\n" + "2 1 9 4 9\n" + "3 3 6 6 10 9\n" + "2 2 3 9 13\n" + "1 0 2 1\n" + "2 0 4 8 9\n" + "1 1 10 17\n" + "1 0 3 5\n" + "2 2 1 13 4\n" + "1 1 1 18\n" + "2 0 6 15 14\n" + "2 1 5 12 11\n" + "1 1 2 19\n" + "2 1 1 26 22\n" + "3 3 2 24 19 20\n" + "2 1 10 16 12\n" + "3 0 3 5 6 6\n" + "2 0 2 2 5\n" + "1 0 8 0\n" + "1 0 7 18\n" + "2 2 3 18 18\n" + "3 1 9 24 23 24\n" + "2 0 1 0 0\n" + "1 1 0 18\n" + "2 1 8 20 20\n" + "3 3 4 23 14 12\n" + "1 1 7 9\n" + "1 1 6 6\n" + "2 2 6 8 5\n"; System.out.println(executeTestCase(input)); } private static String executeTestCase(String input) { String strOutput = ""; BufferedReader in = new BufferedReader(new StringReader(input)); int testCases = 0; try { testCases = Integer.valueOf(in.readLine()); } catch (IOException e) { return "Invalid test case input at line 1"; } try { if (testCases > 0) { for (int i = 1; i <= testCases; i++) { String lines[] = in.readLine().split(" "); int numberOfGooglers = Integer.valueOf(lines[0]); int numberOfSurprising = Integer.valueOf(lines[1]); int target = Integer.valueOf(lines[2]); List<Integer> lst = new ArrayList<Integer>(); if(numberOfGooglers > 0) { for(int j=0; j< numberOfGooglers; j++) { lst.add(Integer.valueOf(lines[j+3])); } } strOutput+="Case #" + i + ": " + countGooglersByTarget(target, numberOfSurprising, lst) + "\n"; } } } catch (Exception e) { return "Invalid test case input"; } return strOutput.toString(); } }
0
63
A12852
A11576
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.google.codejam.qualrnd.dncingglers; public class DancingGooglersInput { private int noOfCases; private GooglersScoreboard[] scoreboards; public DancingGooglersInput() { } public DancingGooglersInput(int noOfCases) { this.noOfCases = noOfCases; } public DancingGooglersInput(int noOfCases, GooglersScoreboard[] scoreboards) { this.noOfCases = noOfCases; this.scoreboards = scoreboards; } public int getNoOfCases() { return noOfCases; } public void setNoOfCases(int noOfCases) { this.noOfCases = noOfCases; } public GooglersScoreboard[] getScoreboards() { return scoreboards; } public void setScoreboards(GooglersScoreboard[] scoreboards) { this.scoreboards = scoreboards; } }
0
64
A12852
A10821
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.Scanner; public class Dancing { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(new File("./src/input.txt")); FileWriter fw = new FileWriter("./src/output.txt"); int total = sc.nextInt(); for(int turn = 1; turn <= total; turn++) { int res = 0; int pos = 0; int N = sc.nextInt(), S = sc.nextInt(), p = sc.nextInt(); // fw.write(N + " " + S + " " + p + "\n"); for(int i = 0; i < N; i++) { int next = sc.nextInt(); // fw.write(next + " " + (3*p-2) + "\n"); if (next >= (3*p-2)) {res++;} else if ((p>=2) && (next >= 3*p-4)) {pos++;} } if (pos < S){res = res+pos;} else {res = res + S;} fw.write("Case #" + turn + ": " + res + "\n"); } fw.flush(); fw.close(); } }
0
65
A12852
A12496
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Scanner; public class Dancing { String inputFilePath = "C:\\Temp\\Google\\B-small-attempt1.in"; String outputFilePath = "C:\\Temp\\Google\\output.txt"; public static void main(String[] args) throws NumberFormatException, IOException{ new Dancing().go(); } public void go() throws NumberFormatException, IOException{ FileReader input = new FileReader(inputFilePath); BufferedReader reader = new BufferedReader(input); int numTests = Integer.parseInt(reader.readLine()); ArrayList<Integer> results = new ArrayList<Integer>(); for (int i = 0; i < numTests; i++){ String[] details = reader.readLine().split(" "); int numDancers = Integer.parseInt(details[0]); int numSurprise = Integer.parseInt(details[1]); int targetScore = Integer.parseInt(details[2]); Integer[] scores = new Integer[numDancers]; for (int d = 0; d<numDancers; d++){ scores[d] = Integer.parseInt(details[d+3]); } results.add(solve(numDancers, numSurprise, targetScore, scores)); } PrintWriter out = new PrintWriter(new FileOutputStream(outputFilePath)); for (int i = 0; i<results.size(); i++){ String line = "Case #" +(i+1) + ": " + results.get(i) + "\r\n"; out.write(line); } out.flush(); System.out.println("Done"); } private Integer solve(int numDancers, int numSurprise, int targetScore, Integer[] scores) { // need to calculate the maximum number of dancers who could have gotten at least targetScore int nonSpecialThreshold = (3*targetScore) - 2; int specialThreshold = (3*targetScore) - 4; int numMeetingThreshold = 0; int numPossibleSpecial = 0; if (targetScore == 0){ return numDancers; } for (int i = 0; i<scores.length; i++){ if (scores[i] == 0){ continue; } if (scores[i] >= nonSpecialThreshold){ numMeetingThreshold++; } else if (scores[i] >= specialThreshold) { numPossibleSpecial++; } } return numMeetingThreshold + Math.min(numSurprise, numPossibleSpecial); } }
0
66
A12852
A12298
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.lang.Math; import java.util.Arrays; public class DancingWithTheGooglers { public static int testSize = 0; public static int[] convertString2Nums(int n, String str) { int[] result = new int[n]; int begIndex = 0; int endIndex = 0; for(int i = 0; i < n - 1; i++) { endIndex = str.indexOf(' ', begIndex); result[i] = Integer.parseInt(str.substring(begIndex, endIndex)); begIndex = endIndex + 1; } result[n - 1] = Integer.parseInt(str.substring(begIndex, str.length())); return result; } public static boolean isPossibleScore(int score, int P) { if(0 == P) return true; if(score < P) return false; int remain = (score - P) >> 1; if(P - remain > 1) return false; return true; } public static boolean isSurprisePossible(int score, int P) { if(0 == P) return true; if(score < P) return false; int remain = (score - P) >> 1; if(P - remain > 2) return false; return true; } public static int maxDancers(String input) { int result = 0; String[] params = input.split(" "); int N = Integer.parseInt(params[0]); int S = Integer.parseInt(params[1]); int P = Integer.parseInt(params[2]); int[] a = new int[N]; int numOfSurprise = 0; for(int i = 0; i < N; i++) { a[i] = Integer.parseInt(params[i + 3]); } Arrays.sort(a); for(int i = N - 1; i >= 0 ; i--) { if(isPossibleScore(a[i], P)) { result++; } else { if(numOfSurprise < S && isSurprisePossible(a[i], P)) { result++; numOfSurprise++; } } } /* int i = 0; while(a[i] < P ) { i++; if(i >= N) break; } if(i == N) return 0; int j = 0; for(j = 0; j < S && j + i < N; j++) { result ++; } if(j + i < N) { for(int k = j + i; k < N; k++) { if(isPossibleScore(a[k], P)) result++; } } */ return result; } public static void Output(String inPath, String outPath) { try { FileInputStream fstream = new FileInputStream(inPath); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); File of = new File(outPath); of.delete(); BufferedWriter bw = new BufferedWriter(new FileWriter(new File(outPath), true)); String line = br.readLine(); int[] parameters = convertString2Nums(1, line); int numOfTest = parameters[0]; String str = new String(); for(int i = 0; i < numOfTest; i ++) { line = br.readLine(); str = new String("Case #" + (i+1) + ": " + maxDancers(line)); System.out.println(str); bw.write(str); bw.newLine(); } in.close(); bw.close(); } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } //public static /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub String inFile = new String(); String outFile = new String(); testSize = 1; switch(testSize) { case 0: inFile = new String("./B-test.in"); outFile = new String("./B-test.out"); break; case 1: inFile = new String("./B-small-attempt1.in"); outFile = new String("./B-small-attempt1.out"); break; case 2: inFile = new String("./A-large-practice.in"); outFile = new String("./A-large-practice.out"); break; default: break; } Output(inFile, outFile); } }
0
67
A12852
A10187
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class B { public void solve( Scanner sc, PrintWriter pw ) { int tests = sc.nextInt( ); sc.nextLine( ); for ( int i = 0 ; i < tests; i++ ) { int googlers = sc.nextInt( ); int suprises = sc.nextInt( ); int minScore = sc.nextInt( ); int minimumNsFoundIn = (((3*minScore)-2) > 0 ) ? ((3*minScore)-2) : 0; int minimumSFoundIn = (((3*minScore)-4) > 0 ) ? ((3*minScore)-4) : 2; int out = 0; int[]scores = new int[googlers]; for ( int j = 0 ; j < googlers; j++ ) { scores[j] = sc.nextInt( ); } Arrays.sort( scores ); for ( int j = 0 ; j < scores.length; j++ ) { int score = scores[j]; if ( score >= minimumNsFoundIn ) { out++; } else if ( suprises > 0 && score >= minimumSFoundIn ) { out++; suprises--; } } pw.println( "Case #" + (i+1) + ": " + out ); pw.flush( ); } } public static void main ( String[] args ) throws IOException { Scanner sc = new Scanner(new FileReader("B-small-attempt0.in")); PrintWriter pw = new PrintWriter(new FileWriter("B-small-attempt0.out")); new B( ).solve( sc, pw ); pw.close( ); sc.close( ); } // public final static HashMap<Integer, String> NON_SUPRISING = new HashMap<Integer, String>( ); // public final static HashMap<Integer, String> SUPRISING = new HashMap<Integer, String>( ); // static { // //target = ( 3k-2 > 0 ) ? 3k-2 : 0; // //0 = // //0 = 0 // //1 = 1 // //2 = 4 // //3 = 7 // //4 = 10 // //5 = 13 // //6 = 16 // //7 = 19 // //8 = 22 // //9 = 25 // //10 = 28 // NON_SUPRISING.put( 0, "0 0 0" ); // NON_SUPRISING.put( 1, "0 0 1" ); // NON_SUPRISING.put( 2, "0 1 1" ); // NON_SUPRISING.put( 3, "1 1 1" ); // NON_SUPRISING.put( 4, "1 1 2" ); // NON_SUPRISING.put( 5, "1 2 2" ); // NON_SUPRISING.put( 6, "2 2 2" ); // NON_SUPRISING.put( 7, "2 2 3" ); // NON_SUPRISING.put( 8, "2 3 3" ); // NON_SUPRISING.put( 9, "3 3 3" ); // NON_SUPRISING.put( 10, "3 3 4" ); // NON_SUPRISING.put( 11, "3 4 4" ); // NON_SUPRISING.put( 12, "4 4 4" ); // NON_SUPRISING.put( 13, "4 4 5" ); // NON_SUPRISING.put( 14, "4 5 5" ); // NON_SUPRISING.put( 15, "5 5 5" ); // NON_SUPRISING.put( 16, "5 5 6" ); // NON_SUPRISING.put( 17, "5 6 6" ); // NON_SUPRISING.put( 18, "6 6 6" ); // NON_SUPRISING.put( 19, "6 6 7" ); // NON_SUPRISING.put( 20, "6 7 7" ); // NON_SUPRISING.put( 21, "7 7 7" ); // NON_SUPRISING.put( 22, "7 7 8" ); // NON_SUPRISING.put( 23, "7 8 8" ); // NON_SUPRISING.put( 24, "8 8 8" ); // NON_SUPRISING.put( 25, "8 8 9" ); // NON_SUPRISING.put( 26, "8 9 9" ); // NON_SUPRISING.put( 27, "9 9 9" ); // NON_SUPRISING.put( 28, "9 9 10" ); // NON_SUPRISING.put( 29, "9 10 10" ); // NON_SUPRISING.put( 30, "10 10 10" ); // // //target = // //target = (3k - 4) > 0 ? 3k - 4 : 2 // //0 = 2 // //1 = 2 // //2 = 2 // //3 = 5 // //4 = 8 // //5 = 11 // //6 = 14 // //7 = 17 // //8 = 20 // //9 = 23 // //10 = 26 // SUPRISING.put( 2, "0 0 2" ); // SUPRISING.put( 3, "0 1 2" ); // SUPRISING.put( 4, "0 2 2" ); // SUPRISING.put( 5, "1 1 3" ); // SUPRISING.put( 6, "1 2 3" ); // SUPRISING.put( 7, "1 3 3" ); // SUPRISING.put( 8, "2 2 4" ); // SUPRISING.put( 9, "2 3 4" ); // SUPRISING.put( 10, "2 4 4" ); // SUPRISING.put( 11, "3 3 5" ); // SUPRISING.put( 12, "3 4 5" ); // SUPRISING.put( 13, "3 5 5" ); // SUPRISING.put( 14, "4 4 6" ); // SUPRISING.put( 15, "4 5 6" ); // SUPRISING.put( 16, "4 6 6" ); // SUPRISING.put( 17, "5 5 7" ); // SUPRISING.put( 18, "5 6 7" ); // SUPRISING.put( 19, "5 7 7" ); // SUPRISING.put( 20, "6 6 8" ); // SUPRISING.put( 21, "6 7 8" ); // SUPRISING.put( 22, "6 8 8" ); // SUPRISING.put( 23, "7 7 9" ); // SUPRISING.put( 24, "7 8 9" ); // SUPRISING.put( 25, "7 9 9" ); // SUPRISING.put( 26, "8 8 10" ); // SUPRISING.put( 27, "8 9 10" ); // SUPRISING.put( 28, "8 10 10" ); // } }
0
68
A12852
A10059
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.google.codejam; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class GoogleDance2 { public static void main(String[] args) throws Exception { Scanner in = new Scanner(new BufferedReader(new FileReader("/Users/sunny/Desktop/B-small-attempt0.in"))); PrintWriter out=new PrintWriter(new FileWriter("/Users/sunny/Desktop/B-small.out")); int t = in.nextInt(); int n, s, p ; String line; for( int i = 1 ; i <= t ; i++){ n = in.nextInt() ; s = in.nextInt() ; p = in.nextInt() ; int []scores = new int[n]; for(int j = 0 ; j < n ; j++) { scores[j] = in.nextInt() ; } line = "Case #"+i+": "+findMax(n, s, p, scores); System.out.println(line); out.println(line); } out.close() ; } private static int findMax(int n, int s, int p, int[] scores) { int d ; List<Combination> c= new ArrayList<Combination>(); boolean gp = true, surp = true; for(int i = 0 ; i < n ; i++) { d = scores[i]/3 ; switch (scores[i]%3) { case 0 : if(d>=p) { c.add(new Combination(gp, !surp)); } else if (d+1 >=p && d-1>=0){ c.add(new Combination(gp, surp)); } else { c.add(new Combination(!gp,!surp)); } break ; case 1 : c.add(new Combination(d+1>=p, !surp)); break ; case 2 : if(d+1 >=p) { c.add(new Combination(gp, !surp)); } else if (d+2 >=p) { c.add(new Combination(gp, surp)); } else { c.add(new Combination(!gp, !surp)); } break ; } } return colAlgo(c, n, s); } private static int colAlgo(List<Combination> cs, int n, int s) { int count = 0 ; Combination c ; for(int i = 0 ; i < n ; i++) { c = cs.get(i); if(c.gp){ if(c.sur) { if(s>0){ s--; count++ ; } } else{ count++ ; } } } return count; } private static class Combination { public Combination(boolean gp, boolean surp) { this.gp = gp ; this.sur = surp ; } boolean sur ; boolean gp ; } }
0
69
A12852
A11553
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class B_DancingWithGooglers { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for(int cases=1; cases<=t; cases++) { int players = sc.nextInt(); int surprising = sc.nextInt(); int limit = sc.nextInt(); int count = 0; for(int i=0; i<players; i++) { int score = sc.nextInt(); if(score < limit) { continue; } score = (score - limit) / 2; if(limit - score <= 1) { count ++; } else if(surprising > 0 && limit - score <= 2) { count ++; surprising --; } } System.out.println("Case #"+cases+": "+count); } } }
0
70
A12852
A10560
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.util.ArrayList; import java.util.HashMap; public class DancingWithGoogler { public static void main(String[] args) throws IOException{ BufferedReader file = new BufferedReader(new FileReader(new File("src/input"))); String firstline = file.readLine(); int casenum = Integer.parseInt(firstline); StringWriter s= new StringWriter(); for(int i=0;i<casenum;++i){ int count = 0; String temp = file.readLine(); int start=0,end=0; while(temp.charAt(end)!=' '){ ++end; } int number = Integer.parseInt(temp.substring(start, end)); start = ++end; while(temp.charAt(end)!=' '){ ++end; } int surprise = Integer.parseInt(temp.substring(start, end)); start=++end; while(temp.charAt(end)!=' '){ ++end; } int p = Integer.parseInt(temp.substring(start, end)); start = ++end; for(int j = 0;j<number;++j){ int googler = -1; if(j<number-1){ while(temp.charAt(end)!=' '){ ++end; } googler = Integer.parseInt(temp.substring(start, end)); start = ++end; } else{ googler = Integer.parseInt(temp.substring(start));//end of line has no space } if(googler<2||googler>28){ //no surprising int min = googler/3; if(min>=p)++count; } else{ if(googler<3*p-4){ ;//no-op } else if(googler>3*p-3){ ++count; } else{//only when the sum is 3p-3 or 3p-4 we need a surprise if(surprise>0){ --surprise; ++count; } } } } s.append("Case #"+(i+1)+": "+count); s.append("\n"); } FileWriter fout = new FileWriter("src/out.txt"); fout.write(s.toString()); fout.close(); } }
0
71
A12852
A11979
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.util.Vector; public class DancingWithTheGooglers { public class TestItem { int n; int s; int p; Vector t; int count; TestItem () { t = new Vector(); count = 0; } public int getN() { return n; } public void setN(int n) { this.n = n; this.t.ensureCapacity(n); } public int getS() { return s; } public void setS(int s) { this.s = s; } public int getP() { return p; } public void setP(int p) { this.p = p; } public Vector getT() { return t; } public int getCount() { return count; } public void setCount(int count) { this.count = count; } public void calculate() { int tripleP = 3*p; for (int i = 0; i < n; i++) { int ti = (Integer) t.get(i); if (ti - p >= 0) { int delta = tripleP - ti; if (delta <= 4) { if (delta < 3) { count++; } else { if (s > 0) { s--; count++; } } } } } } } /** * @param args */ public static void main(String[] args) { if (args.length > 0) { String inputFileName = args[0]; try { DancingWithTheGooglers dwtg = new DancingWithTheGooglers(); FileInputStream fstream = new FileInputStream(inputFileName); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine(); String stringArray[] = strLine.split("\\s+"); int T = (new Integer(stringArray[0])).intValue(); ; ; ; ; for (int i = 1; i <= T; i++) { String stringTestData = br.readLine(); // System.out.println(stringTestData); String stringTestDataArray[] = stringTestData.split("\\s+"); /* for (int k = 0; k < stringTestDataArray.length; k++) { System.out.println(stringTestDataArray[k]); } */ TestItem testItem = dwtg.new TestItem(); testItem.setN((new Integer(stringTestDataArray[0])).intValue()); testItem.setS((new Integer(stringTestDataArray[1])).intValue()); testItem.setP((new Integer(stringTestDataArray[2])).intValue()); int limit = testItem.getN() + 3; for (int j = 3; j < limit; j++) { testItem.getT().add((new Integer(stringTestDataArray[j])).intValue()); } testItem.calculate(); System.out.println("Case #" + i + ": " + testItem.getCount()); } /* for (String s : stringArray) { System.out.println (s); }*/ /* while ((strLine = br.readLine()) != null) { System.out.println (strLine); }*/ in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } } void test() { TestItem testItem = new TestItem(); System.out.println("Test size: " + testItem.getT().size()); testItem.setN(5); System.out.println("Test size: " + testItem.getT().size()); testItem.t.add(1); System.out.println("Test size: " + testItem.getT().size()); } }
0
72
A12852
A10766
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.PrintWriter; public abstract class TestCase { public abstract void readInput(BufferedReader in) throws IOException, MalformedInputFileException; public abstract void solve(); public abstract void writeOutput(PrintWriter out); }
0
73
A12852
A11944
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.ArrayList; import java.util.List; import Utils.FileHelper; public class Gcj2012b { private void solve(String inputPath, String filepath) { FileHelper fHelper = new FileHelper(inputPath); String[] inputStr= new String[fHelper.getTotalSize()]; List<String> rstList = new ArrayList<String>(); fHelper.init(inputStr); for (String str : inputStr) { rstList.add(this.caculate(str)); } rstList = format(rstList); FileHelper.writeFile(filepath, rstList); } private String caculate(String str) { String [] inputList = str.split(" "); int rawCnt = 0; int supCnt = 0; int total = Integer.parseInt(inputList[0]); int suprise = Integer.parseInt(inputList[1]); int point = Integer.parseInt(inputList[2]); int[]inputs = new int[inputList.length - 3]; for(int i = 3; i< inputList.length;++i){ inputs[i - 3] = Integer.parseInt(inputList[i]); } for(int v : inputs){ int rst = v / 3; int remain = v % 3; if(remain == 0){ if(rst >= point) rawCnt ++; else if(rst >= point - 1 && rst >=1) supCnt ++; }else if(remain == 2){ if(rst >= point -1)rawCnt ++; else if(rst >= point -2 && rst >=1) supCnt ++; }else if(remain == 1){ if(rst >= point - 1) rawCnt ++; } } return rawCnt + Math.min(suprise, supCnt) +""; } public static void main(String[] args) { Gcj2012b gcj2012b = new Gcj2012b(); String inputPath = "C:\\Users\\xiaohfan\\Desktop\\B-small-attempt0.in"; String filepath = "C:\\Users\\xiaohfan\\Desktop\\output.txt"; gcj2012b.solve(inputPath, filepath); } public static List<String> format(List<String> rstList) { List<String> outputList = new ArrayList<String>(); for(int i = 0; i < rstList.size();++i ){ outputList.add("Case #"+ (i+1) +": "+rstList.get(i)); } return outputList; } }
0
74
A12852
A10965
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.tritree_tritree; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Scanner; public class ProblemBSmall { static private Map<Integer, Integer> MAP_1 = new HashMap<Integer, Integer>(); static private Map<Integer, Integer> MAP_2 = new HashMap<Integer, Integer>(); static { MAP_1.put(10, 28); MAP_1.put(9, 25); MAP_1.put(8, 22); MAP_1.put(7, 19); MAP_1.put(6, 16); MAP_1.put(5, 13); MAP_1.put(4, 10); MAP_1.put(3, 7); MAP_1.put(2, 4); } static { MAP_2.put(10, 26); MAP_2.put(9, 23); MAP_2.put(8, 20); MAP_2.put(7, 17); MAP_2.put(6, 14); MAP_2.put(5, 11); MAP_2.put(4, 8); MAP_2.put(3, 5); MAP_2.put(2, 2); } public static void main(String[] args) throws IOException { File source = new File("B-small-attempt0.in"); Scanner scan = new Scanner(source); int t = scan.nextInt(); scan.nextLine(); List<String> resultList = new ArrayList<String>(); for (int i = 1; i < t + 1; i++) { int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); int[] pointArray = new int[n]; for (int j = 0; j < n; j++) { pointArray[j] = scan.nextInt(); } String result = "Case #" + i + ": " + resolve(s, p, pointArray); resultList.add(result); } SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd_hhmmss"); File resultFile = new File("B-small-" + dateFormat.format(new Date()) + ".out"); FileOutputStream fileOutputStream = new FileOutputStream(resultFile); for (String result: resultList) { result = result + "\n"; fileOutputStream.write(result.getBytes()); } fileOutputStream.flush(); fileOutputStream.close(); } private static int resolve(int s, int p, int[] pointArray) { int cnt = 0; int remainScnt = s; for (int i = 0; i < pointArray.length; i++) { int target = pointArray[i]; if (p*3 -2 <= target) { cnt++; } else if (target == 0) { continue; } else if (0 < remainScnt) { if (p*3 -4 <= target) { cnt++; remainScnt--; } } } return cnt; } }
0
75
A12852
A11598
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.PrintWriter; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Googlerese { static Scanner in; static PrintWriter out; public static void fillDictionary(Map<Character,Character> dic){ dic.put(new Character('a'), new Character('y')); dic.put(new Character('b'), new Character('n')); dic.put(new Character('c'), new Character('f')); dic.put(new Character('d'), new Character('i')); dic.put(new Character('e'), new Character('c')); dic.put(new Character('f'), new Character('w')); dic.put(new Character('g'), new Character('l')); dic.put(new Character('h'), new Character('b')); dic.put(new Character('i'), new Character('k')); dic.put(new Character('j'), new Character('u')); dic.put(new Character('k'), new Character('o')); dic.put(new Character('l'), new Character('m')); dic.put(new Character('m'), new Character('x')); dic.put(new Character('n'), new Character('s')); dic.put(new Character('o'), new Character('e')); dic.put(new Character('p'), new Character('r')); dic.put(new Character('q'), new Character('z')); dic.put(new Character('r'), new Character('p')); dic.put(new Character('s'), new Character('d')); dic.put(new Character('t'), new Character('r')); dic.put(new Character('u'), new Character('j')); dic.put(new Character('v'), new Character('g')); dic.put(new Character('w'), new Character('t')); dic.put(new Character('x'), new Character('h')); dic.put(new Character('y'), new Character('a')); dic.put(new Character('z'), new Character('q')); } public static String translate(String originalWord, Map<Character,Character> dic){ String translatedWord=""; for(int i = 0; i < originalWord.length(); i++){ translatedWord += dic.get(originalWord.charAt(i)); } return translatedWord; } public static void main(String[] args) throws Exception { in = new Scanner(new File("A-small.txt")); out = new PrintWriter(new File("output.txt")); Map<Character,Character> dic = new HashMap<Character, Character>(); fillDictionary(dic); //Read file String Y = null; String[] originalWords; int T = in.nextInt(); //for each case do for (int i = 0; i < T; i++){ //get first O and first B buttons Y = in.nextLine(); originalWords = Y.split(" "); System.out.print("Case " + i + ":"); for(int j = 0; j < originalWords.length; j++){ System.out.print( translate(originalWords[j],dic)) } } out.print(Y); //printf("Case #%d: %s%n", cas, ans); out.close(); } }
0
76
A12852
A10305
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 sebastianco; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; public class DancingWithGooglers { public static void main(String[] args) throws Exception { BufferedReader reader = null; BufferedWriter writer = null; try { reader = new BufferedReader(new FileReader(new File(args[0]))); writer = new BufferedWriter(new FileWriter(new File(args[1]))); final int nrOfTestCases = Integer.valueOf(reader.readLine()); String lineSepartor = ""; for (int i = 1; i <= nrOfTestCases; i++) { writer.write(lineSepartor); writer.write(String.format("Case #%d: %d", i, new TestCase(reader.readLine()).computeMaxGooglers())); lineSepartor = "\n"; } } finally { if (writer != null) { writer.flush(); writer.close(); } reader.close(); } } public static class TestCase { private int n; private int s; private int p; private int[] t; public TestCase(String caseLine) { String[] tokens = caseLine.split(" "); n = Integer.parseInt(tokens[0]); s = Integer.parseInt(tokens[1]); p = Integer.parseInt(tokens[2]); t = new int[n]; for (int i = 0; i < n; i++) { t[i] = Integer.parseInt(tokens[3 + i]); } } // p-1 p p 3p-1 // p-1 p-1 p 3p-2 // p-2 p-1 p 3p-3 // p-2 p-2 p 3p-4 public int computeMaxGooglers() { final int minTotalScore = 3*p - 2; final int minSurprisingScoreA = 3*p - 3; final int minSurprisingScoreB = 3*p - 4; int max = 0; int surprising = s; for (int i = 0; i < n; i++) { if (t[i] >= minTotalScore) { max++; } else { if (surprising > 0 && t[i] > 0 && (t[i] == minSurprisingScoreA || t[i] == minSurprisingScoreB)) { max++; surprising--; } } } return max; } } }
0
77
A12852
A10625
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.io.InputStreamReader; import java.util.StringTokenizer; public class DancingWithTheGooglers { public static File input; public static FileReader inputreader; public static BufferedReader in; public static File output; public static FileWriter outputwriter; public static BufferedWriter out; public static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); public static StringTokenizer st; public static void main(String[] args) { try { String name = "input-2"; setInput(name); setOutput(name + ".out"); int cases = getInt(); for(int caseNr = 1; caseNr <= cases; caseNr++) { int N = getInt(), S = getInt(), p = getInt(); int[] scoreArr = new int[N]; for(int i=0; i<N;i++) { scoreArr[i] = getInt(); } // System.out.println("Case #"+caseNr+". N: " + N + ", S: " + S + ", p: " + p); print("Case #"+caseNr+": "); print(""+getMax(S, scoreArr, p)); print("\n"); } out.flush(); out.close(); in.close(); } catch(Exception e) { e.printStackTrace(); } } public static int getMax(int surprising, int[] scoreArr, int scoreGoal) { return getMaximumOfIndexRecursive(scoreArr.length-1, surprising, scoreArr, scoreGoal, 0); } public static int getMaximumOfIndexRecursive(int index, int surprisingLeft, int[] scoreArr, int scoreGoal, int tempGoal) { if (index == -1) return 0; int thisGoal; //System.out.println("scoreGoal: " + scoreGoal + ", tempGoal: " + tempGoal); if (tempGoal > 10) return 0+getMaximumOfIndexRecursive(index-1, surprisingLeft, scoreArr, scoreGoal, 0); thisGoal = (tempGoal > 0) ? tempGoal : scoreGoal; double _a = (double) ((scoreArr[index] - thisGoal) / 2.0); double _b = _a; int a = (int) Math.floor(_a); int b = (int) Math.ceil(_b); a = Math.max(a, 0); b = Math.max(b, 0); int diff = Math.max(Math.max(Math.abs(a-b), Math.abs(a-thisGoal)), Math.abs(b-thisGoal)); boolean scoreOk = (a >= 0 && a <= 10 && b >= 0 && b <= 10 && (a + b + thisGoal == scoreArr[index])) ? true : false; //System.out.println("Hmm.. case: " + scoreArr[index] + ". Values: " + thisGoal + ", " + a + ", " + b + ". (_a och _b)" + _a + ", " + _b); if (scoreOk && diff < 2) { //System.out.println("YES"); return 1+getMaximumOfIndexRecursive(index-1, surprisingLeft, scoreArr, scoreGoal, 0); } else if (scoreOk && diff == 2 && surprisingLeft > 0) { //System.out.println("YES"); return 1+getMaximumOfIndexRecursive(index-1, surprisingLeft-1, scoreArr, scoreGoal, 0); } else if (tempGoal == 0) { //System.out.println("NO"); return 0+getMaximumOfIndexRecursive(index, surprisingLeft, scoreArr, scoreGoal, scoreGoal+1); } else { //System.out.println("NO"); return 0+getMaximumOfIndexRecursive(index, surprisingLeft, scoreArr, scoreGoal, tempGoal+1); } } // -------------------- I/O stuff ------------------------- public static void setInput(String filename) throws IOException { input = new File(filename); inputreader = new FileReader(input); in = new BufferedReader(inputreader); } public static void setOutput(String filename) throws IOException { output = new File(filename); outputwriter = new FileWriter(output); out = new BufferedWriter(outputwriter); } static void print(String s) throws IOException { System.out.print(s); out.write(s); } static String readLine() throws IOException { //return stdin.readLine(); return in.readLine(); } static String getToken() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(readLine()); return st.nextToken(); } static int getInt() throws IOException { return Integer.parseInt(getToken()); } static String getChar() throws IOException { return getToken(); } static String getLine() throws IOException { return readLine(); } }
0
78
A12852
A11409
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; /********************************************************************* * FileUtils class of static constants and basic file checking routines. * This is the header file of constants and methods that might be * used in any and all contexts. * * Methods: * public static void CheckArgs(int countArgs,String [] args,String usage) * public static void CloseFile(PrintWriter theFile) * public static void CloseFile(Scanner theFile) * public static void CloseLogFile() * public static PrintWriter PrintWriterOpen(String outFileName) * public static PrintWriter PrintWriterOpen(String outFileName) * public static Scanner ScannerOpen(String inFileName) * public static void SetLogFile(String logFileName) * public static void SetLogFile(PrintWriter logFile) * * @author Duncan Buell * @version 1.00 Copyright Duncan A. Buell 1 May 2011 **/ public class FileUtils { private static final String TAG = "FileUtils: "; public static PrintWriter logFile = null; /********************************************************************* * Accessor methods **/ /********************************************************************* * Mutator methods **/ /********************************************************************* * General methods **/ /********************************************************************* * Method to check the number of arguments to the main. * * @param countArgs the number of required arguments * @param args the argument list at the time the class is invoked * @param usage descriptions of the required arguments **/ public static void CheckArgs(int countArgs,String [] args,String usage) { String message; if(countArgs > args.length) { if(1 == countArgs) { message = "ERROR: required " + countArgs + " (" + usage + ") arg not present"; } else { message = "ERROR: required " + countArgs + " (" + usage + ") args not present"; } FileUtils.logFile.printf("%s%n",message); FileUtils.logFile.flush(); System.exit(1); } } // public static void checkArgs(int countArgs,String [] args,String usage) /********************************************************************* * Method to close a PrintWriter file. * @param theFile the <code>PrintWriter</code> file to close. **/ public static void CloseFile(PrintWriter theFile) { // FileUtils.logFile.printf("%s enter (PrintWriter) CloseFile%n",TAG); theFile.flush(); theFile.close(); // FileUtils.logFile.printf("%s leave (PrintWriter) CloseFile%n",TAG); } // public static void CloseFile(PrintWriter theFile) /********************************************************************* * Method to close a Scanner file. * @param theFile The <code>Scanner</code> file to close. **/ public static void CloseFile(Scanner theFile) { // FileUtils.logFile.printf("%s enter (Scanner) CloseFile%n",TAG); theFile.close(); // FileUtils.logFile.printf("%s leave (Scanner) CloseFile%n",TAG); } // public static void CloseFile(Scanner theFile) /********************************************************************* * Method to close the PrintWriter class log file. **/ public static void CloseLogFile() { // FileUtils.logFile.printf("%s enter (PrintWriter) CloseLogFile%n",TAG); FileUtils.logFile.flush(); FileUtils.logFile.close(); // FileUtils.logFile.printf("%s leave (PrintWriter) CloseLogFile%n",TAG); } // public static void CloseLogFile() /********************************************************************* * PrintWriterOpen method to open a file as a PrintWriter. * * The main purpose of this method is to do the error checking in * a subordinate method so as not to clutter up the code flow * in methods that have to open files. * * @param outFileName the <code>String</code> name of the file to open * @return The opened <code>PrintWriter</code> known to be not null **/ public static PrintWriter PrintWriterOpen(String outFileName) { PrintWriter localPrintWriter = null; // FileUtils.logFile.printf("%s enter PrintWriterOpen%n",TAG); if(outFileName.equals("System.out")) { localPrintWriter = new PrintWriter(System.out); } else { try { localPrintWriter = new PrintWriter(new File(outFileName)); } catch (FileNotFoundException fileException) { FileUtils.logFile.println(TAG + "FILE ERROR opening outFile " + outFileName); FileUtils.logFile.println(fileException.getMessage()); FileUtils.logFile.println("in" + System.getProperty("user.dir")); FileUtils.logFile.flush(); System.exit(1); } catch (SecurityException secException) { FileUtils.logFile.println(TAG + "SECURITY ERROR opening outFile " + outFileName); FileUtils.logFile.println(secException.getMessage()); FileUtils.logFile.println("in" + System.getProperty("user.dir")); FileUtils.logFile.flush(); System.exit(1); } } // FileUtils.logFile.printf("%s leave PrintWriterOpen%n",TAG); return localPrintWriter; } // public static PrintWriter PrintWriterOpen(String outFileName) /********************************************************************* * ScannerOpen method to open a file as a Scanner. * * The main purpose of this method is to do the error checking in * a subordinate method so as not to clutter up the code flow * in methods that have to open files. * * @param inFileName the <code>String</code> name of the file to open * @return The opened <code>Scanner</code> known to be not null **/ public static Scanner ScannerOpen(String inFileName) { Scanner localScanner = null; // FileUtils.logFile.printf("%s enter ScannerOpen%n",TAG); if(inFileName.equals("System.in")) { localScanner = new Scanner(System.in); } else { try { localScanner = new Scanner(new File(inFileName)); } catch (FileNotFoundException ex) { FileUtils.logFile.println("TAG + ERROR opening inFile " + inFileName); FileUtils.logFile.println(ex.getMessage()); FileUtils.logFile.println("in" + System.getProperty("user.dir")); FileUtils.logFile.flush(); System.exit(1); } } // FileUtils.logFile.printf("%s leave ScannerOpen%n",TAG); return localScanner; } // public static Scanner ScannerOpen(String inFileName) /********************************************************************* * Method to set the logFile given the name of the file. * * @param logFileName the <code>String</code> name of the log file. **/ public static void SetLogFile(String logFileName) { FileUtils.logFile = FileUtils.PrintWriterOpen(logFileName); } /********************************************************************* * Method to set the logFile given the <code>PrintWriter</code> file. * * @param logFile the <code>PrintWriter</code> log file. **/ public static void SetLogFile(PrintWriter logFile) { FileUtils.logFile = logFile; } /********************************************************************* * Method to convert a string to a double with error checking. * * @param ss the <code>String</code> value to convert. * @param value the default value for an empty string. * @return the converted value as a <code>Double</code>. **/ static public Double StringToDouble(String ss, Double value) { Double returnValue; returnValue = value; ss = ss.trim(); if(0 != ss.length()) { // FileUtils.logFile.printf("nonempty string %s%n", ss); returnValue = Double.valueOf(ss); } return returnValue; } // static public Double stringToDouble(String s, Double value) /********************************************************************* * Method to convert a string to an integer with error checking. * * @param ss the <code>String</code> value to convert. * @param value the default value for an empty string. * @return the converted value as an <code>Integer</code>. **/ static public Integer StringToInteger(String ss, Integer value) { Integer returnValue; returnValue = value; ss = ss.trim(); if(0 != ss.length()) { // FileUtils.logFile.printf("nonempty string %s%n", ss); returnValue = Integer.valueOf(ss); } return returnValue; } // static public Integer stringToInteger(String s, Integer value) } // public class FileUtils
0
79
A12852
A11945
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.Scanner; public class MaxGooglers { /** * @param args */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub System.setIn(new BufferedInputStream(new FileInputStream(".\\input\\B-small-attempt0.in"))); System.setOut(new PrintStream(new File(".\\output\\B-small-attempt0.out"))); Scanner in = new Scanner(System.in); int caseNum=in.nextInt(); for(int i=0;i<caseNum;i++){ int googlers=in.nextInt(); int surprise=in.nextInt(); int p=in.nextInt(); int[] scores=new int[googlers]; int maxNum=0; for(int j=0;j<googlers;j++){ scores[j]=in.nextInt(); } for(int j=0;j<googlers;j++){ if(scores[j]>=p*3-2){ maxNum++; } else if(scores[j]!=0 && scores[j]>=p*3-4){ if(surprise!=0){ surprise--; maxNum++; } } else if(scores[j]==0 && p==0){ maxNum++; } } System.out.println("Case #"+(i+1)+": " +maxNum); } } }
0
80
A12852
A10092
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 a; import java.io.File; import java.io.PrintWriter; import java.util.Scanner; import java.io.IOException; /** * * @author KazakhPride */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { // TODO code application logic here Scanner in = new Scanner(new File("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new File("output.txt")); int n = in.nextInt(); int t = 0; int s = 0; int p = 0; for (int j = 1; j <= n; j++) { out.print("Case #" + j + ": "); t = in.nextInt(); s = in.nextInt(); p = in.nextInt(); int count = 0; int ar[] = new int[t]; for (int i = 0; i < ar.length; i++) { ar[i] = in.nextInt(); } for( int i = 0; i < ar.length; i++ ){ if(ar[i]%3 == 0){ int base = ar[i]/3; //int second = first; //int third = second; if(base >= p){ count++; } else{ if(s > 0 && base > 0 && base + 1 >= p){ count++; s--; } } } else if(ar[i]%3==1){ int base = ar[i]/3; if(base >= p || base + 1 >= p){ count++; } else{ if(s > 0 && base + 1 >= p){ count++; s--; } } } if( ar[i]%3 == 2 ){ int base = ar[i]/3; if(base + 1 >= p || base >= p){ count++; } else{ if( s > 0 && base + 2 >= p ){ count++; s--; } } } } out.println(count); } in.close(); out.close(); } }
0
81
A12852
A12310
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; import static java.lang.Math.abs; public class B { public static void main(String[] args) throws IOException { Scanner in = new Scanner(new FileReader("input.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("output")); int T = in.nextInt(); int n, s, p; for (int i = 1; i <= T; i++) { // read input n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); int[] googlers = new int[n]; for (int j = 0; j < n; j++) googlers[j] = in.nextInt(); // solve int ans = solve(n, s, p, googlers); System.out.println(ans); bw.write("Case #" + i + ": " + ans); bw.newLine(); } bw.close(); } private static int solve(int n, int s, int p, int[] googlers) throws IOException { boolean[] surp = new boolean[n]; boolean[] reach = new boolean[n]; boolean[] both = new boolean[n]; for (int T = 0; T < n; T++) for (int i = 0; i <= 10; i++) for (int j = i; j <= i+2 && j <= 10; j++) for (int k = j; k <= j+2 && j <= 10; k++) if (i+j+k == googlers[T] && check(i, j, k)) { boolean a = isSurprising(i, j, k), b = reached(i, j, k, p); if(!surp[T]) surp[T] = a && !b; if(!reach[T]) reach[T] = b && !a; if(!both[T]) both[T] = a && b; } int max = findMax(n, s, p, surp, reach, both); return max; } private static int findMax(int n, int s, int p, boolean[] surp, boolean[] reach, boolean[] both) { int max = 0; for(int i = 0; i < n; i++) if(both[i] || reach[i])max++; int ss = 0; for(int i = 0; i < n; i++) if(surp[i] || both[i]) ss++; if(ss == s) return max; else // ss > s { for(int i = 0; i < n; i++) if(surp[i] || (both[i] && reach[i])) ss--; if(ss <= s) return max; else return max-(ss-s); } } private static boolean reached(int i, int j, int k, int p) { return Math.max(i, Math.max(j, k)) >= p; } private static boolean isSurprising(int i, int j, int k) { return abs(i - j) == 2 || abs(j - k) == 2 || abs(i - k) == 2; } private static boolean check(int i, int j, int k) { return abs(i - j) <= 2 && abs(j - k) <= 2 && abs(i - k) <= 2; } }
0
82
A12852
A12211
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class Dancing_improved { static int f_Superan_limites(String params){ int superan_limite=0; String[] parametros=params.split(" "); int n_participantes= Integer.parseInt(parametros[0]); int n_sorprendidos= Integer.parseInt(parametros[1]); int nota_limite= Integer.parseInt(parametros[2]); int suma_notas, resto, nota_juego; for(int i=3;i<parametros.length;i++){ // Recorro las sumas de los participantes suma_notas=Integer.parseInt(parametros[i]); resto=suma_notas%3; if(resto==0){ // el resto es el número triplicado! nota_juego=suma_notas/3; if(nota_juego>=nota_limite){ superan_limite++; }else if(nota_juego-1>=0 && n_sorprendidos>0 && ((nota_juego+1)>=nota_limite || (nota_juego+2)>=nota_limite)){ // no supera el límite pero podría hacerlo si quedan sorprendidos n_sorprendidos--; superan_limite++; } }else if((suma_notas+1)%3==0){ // Tendré que jugar con el valor en +-1 nota_juego=(suma_notas+1)/3; if(nota_juego-1>=0 && nota_juego>=nota_limite){ superan_limite++; }else if(nota_juego-1>=0 && n_sorprendidos>0 && (nota_juego+1)>=nota_limite){ n_sorprendidos--; superan_limite++; } }else if((suma_notas+2)%3==0){ // Tendré que jugar con el valor en +-2 nota_juego=(suma_notas+2)/3; if(nota_juego-1>=0 && nota_juego>=nota_limite){ superan_limite++; } } } return superan_limite; } public static void main(String[] args) throws IOException { FileReader fr = new FileReader(args[0]); BufferedReader bf = new BufferedReader(fr); int ntest=0; FileWriter fstream = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream); String lines = bf.readLine(); String liner, linew; int lines_r=0; String[] numbers; int total; while((liner = bf.readLine())!=null && lines_r<=Integer.parseInt(lines)) { ntest++; numbers=liner.split(" "); total=f_Superan_limites(liner); linew="Case #"+ntest+": "+total+"\n"; out.write(linew); lines_r++; } out.close(); fr.close(); } }
0
83
A12852
A13074
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.vp.iface; public interface Problem{ public static int SPEAKGOOGLERESE = 1; public static int DANCINGWITHGOOGLERS = 2; public String solve(String dataset[]); }
0
84
A12852
A11487
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.math.*; import java.util.*; import java.text.*; import java.util.regex.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.lang.Integer.*; import static java.lang.Double.*; import static java.lang.Character.*; public class B { static boolean[][] sup = new boolean[11][31]; static boolean[][] notsup = new boolean[11][31]; static { for (int a = 0; a <= 10; a++) for (int b = a; b <= min(a+2,10); b++) for (int c = b; c <= min(a+2, 10); c++) { if (c > a+1) sup[c][a+b+c] = true; else notsup[c][a+b+c] = true; } } Object solve() { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int supc = 0; int nsupc = 0; for (int i = 0; i < N; i++) { int t = sc.nextInt(); boolean nsupp = false; boolean supp = false; for (int r = p; r <= 10; r++) { if (sup[r][t]) supp = true; if (notsup[r][t]) nsupp = true; } if (nsupp) nsupc++; else if (supp) supc++; } return nsupc + min(S, supc); } private static Scanner sc; private static PrintWriter fw; public static void main(String[] args) throws Exception { String inFile; // inFile = "input.txt"; inFile = "B-small-attempt0.in"; // inFile = "B-large.in"; sc = new Scanner(System.in); sc = new Scanner(new FileInputStream(inFile)); fw = new PrintWriter(new FileWriter("output.txt", false)); int N = sc.nextInt(); sc.nextLine(); for (int cas = 1; cas <= N; cas++) { fw.print("Case #" + cas + ": "); // fw.println("Case #" + cas + ": "); Object res = new B().solve(); if (res instanceof Double) fw.printf("%.10f\n", res); else fw.printf("%s\n", res); fw.flush(); } fw.close(); sc.close(); } }
0
85
A12852
A10684
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.*; public class DancingWithTheGooglers { private BufferedReader br; private BufferedWriter wr; public DancingWithTheGooglers(String filein,String fileout){ try{ br = new BufferedReader(new InputStreamReader(new FileInputStream(filein))); wr = new BufferedWriter(new FileWriter(fileout)); int num = 0; num = Integer.parseInt(br.readLine()); for (int i = 1;i<=num;i++){ String buf = br.readLine(); String[] bufarray = buf.split(" "); int n = Integer.parseInt(bufarray[0]); int s = Integer.parseInt(bufarray[1]); int p = Integer.parseInt(bufarray[2]); int numgood = 0; for (int j = 3;j<bufarray.length;j++){ int now = Integer.parseInt(bufarray[j]); int div = now/3; int mod = now%3; switch(mod){ case 0: if (div >= p){ numgood++; }else if (s > 0 && div > 0 && div+1 >= p){ numgood++; s--; } break; case 1: if (div >= p || div+1 >= p){ numgood++; } break; case 2: if (div >= p || div+1 >= p){ numgood++; }else if (s > 0 && div+2 >= p){ numgood++; s--; } break; } } String out = "Case #"+i+": "+numgood; wr.write(out); if (i != num) wr.newLine(); } br.close(); wr.close(); }catch (IOException e){ System.out.println("IO failure"); } } public static void main(String[] args) { DancingWithTheGooglers sp = new DancingWithTheGooglers("B-small-attempt2.in","B-small-attempt2.out"); } }
0
86
A12852
A10155
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; public class CodeJam { private static BufferedReader reader; private static BufferedWriter writer; public static void main(String args[]) throws Exception { prepareFiles("B-small-attempt2"); int T = Integer.parseInt(reader.readLine()); for(int i = 0; i < T; i++) { String[] line = reader.readLine().split(" "); int N = Integer.parseInt(line[0]); // # of googlers int S = Integer.parseInt(line[1]); // # of suprising triplets int p = Integer.parseInt(line[2]); // best result of at least p int maxTopScorers = 0; ArrayList<Case> surprisingCases = calulate(N, line, p, true); ArrayList<Case> normalCases = calulate(N, line, p, false); ArrayList<ArrayList<Case>> permutations = new ArrayList<ArrayList<Case>>(); permutate(new ArrayList<Case>(), surprisingCases, permutations); for(int j = 0; j < permutations.size(); j++) { int topScorers = 0; HashSet<Case> topScorersCases = new HashSet<Case>(); ArrayList<Case> suprisingPermutation = permutations.get(j); for(int k = 0; k < suprisingPermutation.size() && k < S; k++) { topScorersCases.add(suprisingPermutation.get(k)); topScorers ++; } for(int k = 0; k < normalCases.size(); k++) { if(!topScorersCases.contains(normalCases.get(k))) { topScorers ++; } } if(topScorers > maxTopScorers) { maxTopScorers = topScorers; } } print(getCase(i + 1)); print(maxTopScorers); //print(" " + Arrays.toString(line)); print("\n"); } putAwayFiles(); } private static void permutate(ArrayList<Case> head, List<Case> tail, ArrayList<ArrayList<Case>> permutations) throws Exception { if(tail.size() == 0) { permutations.add(head); return; } else { for(int i = 0; i < tail.size(); i++) { ArrayList<Case> newHead = new ArrayList<Case>(); newHead.addAll(head); newHead.add(tail.get(i)); permutate(newHead, joinLists(tail.subList(0, i), tail.subList(i + 1, tail.size())), permutations); } } } private static List<Case> joinLists(List<Case> list1, List<Case> list2) { ArrayList<Case> list = new ArrayList<>(); list.addAll(list1); list.addAll(list2); return list; } private static ArrayList<Case> calulate(int N, String[] line, int p, boolean surprising) { ArrayList<Case> cases = new ArrayList<Case>(); for(int j = 0; j < N; j++) { boolean actuallySurprising = false; int t = Integer.parseInt(line[3 + j]); // total points for this googler int basePoints = t/3; int extraPoints = t%3; int maxPoints = 0; if(surprising) { if(extraPoints == 0 && basePoints > 0) { maxPoints = basePoints + 2; actuallySurprising = true; } else if(extraPoints > 0) { maxPoints = basePoints + extraPoints; if(extraPoints == 2) { actuallySurprising = true; } } else { maxPoints = basePoints; } if(actuallySurprising && maxPoints >= p) { Case pointCase = new Case(j, maxPoints, true); cases.add(pointCase); } } else { if(extraPoints > 0) { maxPoints = basePoints + 1; } else { maxPoints = basePoints; } if(maxPoints >= p) { Case pointCase = new Case(j, maxPoints, false); cases.add(pointCase); } } } Collections.sort(cases, new Comparator<Case>() { @Override public int compare(Case arg0, Case arg1) { return arg1.maxPoints - arg0.maxPoints; } }); return cases; } private static void prepareFiles(String fileName) throws IOException { reader = new BufferedReader(new FileReader(new File(fileName + ".in"))); writer = new BufferedWriter(new FileWriter(new File(fileName + ".out"))); } private static void putAwayFiles() throws IOException { reader.close(); writer.flush(); writer.close(); } private static String getCase(int i) { return "Case #" + i + ": "; } private static void print(Object object) throws IOException { System.out.print(object.toString()); writer.write(object.toString()); } private static class Case { private int caseNumber; private int maxPoints; private boolean surprising; public Case(int caseNumber, int maxPoints, boolean surprising) { this.caseNumber = caseNumber; this.maxPoints = maxPoints; this.surprising = surprising; } @Override public boolean equals(Object o) { return ((Case)o).caseNumber == caseNumber; } @Override public int hashCode() { return caseNumber; } @Override public String toString() { return caseNumber + ":" + maxPoints; } } }
0
87
A12852
A12122
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Main { /** * @param args */ public static void main(String[] args) { try{ // Open the file that is the first // command line parameter // FileInputStream fstream = new FileInputStream("C-small-practice.in"); FileInputStream fstream = new FileInputStream("B-small-attempt0 (1).in"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; FileWriter foutstream = new FileWriter("output.out"); BufferedWriter out = new BufferedWriter(foutstream); System.out.println (br.readLine()); int Case = 0; while ((strLine = br.readLine()) != null) { Case+=1; out.write("Case #" + Case + ": "); System.out.println (strLine); String str[] = strLine.split(" "); int N = Integer.parseInt(str[0]); int S = Integer.parseInt(str[1]); int p = Integer.parseInt(str[2]); int g[] = new int[str.length-3]; int y = 0; for (int i = 3;i<str.length;i++) { g[i-3]=Integer.parseInt(str[i]); //System.out.println(g[i-3]); } //Quicksort(g,0,g.length-1); bubbleSort1(g); for (int i=0;i<g.length;i++) { if (S==-1) S=0; System.out.print(g[i] + ", p=" + p + ", S=" + S + " ,y="); if (((g[i]-p)+2>=2*p)) y++; else if (g[i]==0) ; else if (((g[i]-p)+4>=2*p)) { if (S>0) { y++; S--; } } System.out.println(y); //if (((g[i]-p)+4>=2*p)); } out.write(Integer.toString(y)); out.newLine(); } out.close(); //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage() + " " + e.getCause()); } System.exit(-1); } public static void swap (int A[], int x, int y) { int temp = A[x]; A[x] = A[y]; A[y] = temp; } // Reorganizes the given list so all elements less than the first are // before it and all greater elements are after it. public static int partition(int A[], int f, int l) { int pivot = A[f]; while (f < l) { // if (A[f] == pivot || A[l] == pivot) { // System.out.println("Only distinct integers allowed - C321"); // System.out.println("students should ignore this if statement"); } while (A[f] < pivot) f++; while (A[l] > pivot) l--; swap (A, f, l); } if (A[f]==A[l]) return f--; return f; } public static void Quicksort(int A[], int f, int l) { if (f >= l) return; int pivot_index = partition(A, f, l); Quicksort(A, f, pivot_index); Quicksort(A, pivot_index+1, l); } public static void bubbleSort1(int[] x) { int n = x.length; for (int pass=1; pass < n; pass++) { // count how many times // This next loop becomes shorter and shorter for (int i=0; i < n-pass; i++) { if (x[i] < x[i+1]) { // exchange elements int temp = x[i]; x[i] = x[i+1]; x[i+1] = temp; } } } } }
0
88
A12852
A11111
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 JuanjeProblemaB { /* * Juan Jesus Gutierrez * Solucion al problema - B */ public static void main(String[] args) { //lector de la entrada Scanner in = new Scanner(System.in); //in.nextLine(); //numero de frases en Googlerese int T = in.nextInt(); in.nextLine(); for(int con = 1; con <=T; con++) { String concurso = in.nextLine(); int result = tratarConcurso(concurso); System.out.format("Case #%d: %d\n", con, result); } } public static int tratarConcurso(String concurso) { int result = 0; //System.out.println(concurso); String[] datos = concurso.split(" "); int N = Integer.parseInt(datos[0]); int s = Integer.parseInt(datos[1]); int p = Integer.parseInt(datos[2]); int[] puntuaciones = new int[N]; for(int i = 3; i<datos.length; i++) { puntuaciones[i-3] = Integer.parseInt(datos[i]); } int[] Pmax = new int[N]; int[] PmaxS = new int[N]; for(int i = 0; i<N; i++) { Pmax[i] = maximoPosible(puntuaciones[i]); PmaxS[i] = maximoPosibleConSorpresa(puntuaciones[i]); } for(int i = 0; i<N; i++) { if(Pmax[i] >= p) { result++; } else { if(PmaxS[i] >= p && s>0) { result++; s--; } } } return result; } public static int maximoPosible(int total) { if(total == 0) return 0; if(total == 30) return 10; int d = (int) total / 3; int resto = total % 3; if(resto == 0) return d; return d+1; } public static int maximoPosibleConSorpresa(int total) { if(total == 0) return 0; if(total == 30) return 10; int d = (int) total / 3; int resto = total % 3; if(resto == 2) return d+2; return d+1; } }
0
89
A12852
A10051
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.awt.*; import java.awt.event.*; import java.awt.geom.*; import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class B { static StringTokenizer st; static BufferedReader br; static PrintWriter pw; public static void main(String[] args) throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter( System.out))); int qq = readInt(); for(int casenum = 1; casenum <= qq; casenum++) { int n = readInt(); int s = readInt(); int max = readInt(); int ret = 0; while(n-- > 0) { int curr = readInt(); boolean awesome = false; boolean semiawesome = false; for(int a = 0; a <= 10; a++) { for(int b = a; b <= 10; b++) { for(int c = b; c <= a+2; c++) { if(a+b+c == curr && c-a <= 1 && c >= max) awesome = true; else if(a+b+c == curr && c >= max) semiawesome = true; } } } if(awesome) ret++; else if(semiawesome && s > 0) { s--; ret++; } } pw.println("Case #" + casenum + ": " + ret); } pw.close(); } public static long readLong() throws IOException { return Long.parseLong(nextToken()); } public static double readDouble() throws IOException { return Double.parseDouble(nextToken()); } public static int readInt() throws IOException { return Integer.parseInt(nextToken()); } public static String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { if (!br.ready()) { pw.close(); System.exit(0); } st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }
0
90
A12852
A10485
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.Scanner; public class codejam_B_small { public static void main(String[] args) throws IOException { FileUtil.Timer.start(); Scanner scanner = new Scanner(System.in); int numOfTest = scanner.nextInt(); scanner.nextLine(); String[] testCases = new String[numOfTest]; for (int i = 0; i < numOfTest; i++) { testCases[i] = scanner.nextLine(); } String[] finalResult = new String[numOfTest]; for (int i = 0; i < numOfTest; i++) { String testCase = testCases[i]; String result = runTestCase(testCase); finalResult[i] = FileUtil.formatTestResult(i, result); System.out.println(finalResult[i]); } FileUtil.Timer.stop(); } private static String runTestCase(String testCase) { String[] splits = testCase.split(" "); int numOfGoogler = Integer.valueOf(splits[0]); int numOfSurpring = Integer.valueOf(splits[1]); int bestResult = Integer.valueOf(splits[2]); if (numOfGoogler <= 0) { return "0"; } // int maxResult = 3 * bestResult; int count = 0; // check best result for (int i = 3; i < splits.length; i++) { int point = Integer.valueOf(splits[i]); int avg = point / 3; int reminder = point % 3; int diff = bestResult - avg; if (avg >= bestResult || diff == 0) { count++; continue; } else if (point < bestResult) { continue; } if (reminder >= 1 && diff <= 1) { count++; continue; } else if (reminder >= 2 && diff == 2 && numOfSurpring > 0) { numOfSurpring--; count++; continue; } else if (reminder == 0 && diff == 1 && numOfSurpring > 0) { numOfSurpring--; count++; continue; } } return String.valueOf(count); } }
0
91
A12852
A10810
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 DancingWithTheGoogler { public static void main(String[] args) { try { FileInputStream fstream = new FileInputStream(args[0]); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; int count = 0; int noCases = 0; while ((strLine = br.readLine()) != null) { if (count > noCases) break; if (count == 0) { noCases = Integer.valueOf(strLine); } else { compute(count, strLine); } count++; } in.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } private static void compute(int caseNo, String str) { String[] tokens = str.split(" "); int N = Integer.valueOf(tokens[0]); int S = Integer.valueOf(tokens[1]); int P = Integer.valueOf(tokens[2]); int count = 0; for (int i = 3; i < N + 3; i++) { int candidate = Integer.valueOf(tokens[i]); int top = getCommonDigit(candidate, false); if (top >= P) { count++; } else { if (S > 0) { if (getCommonDigit(candidate, true) >= P) { count++; S--; } } } } System.out.println(String.format("Case #%s: %s", caseNo, count)); } private static int getCommonDigit(int no, boolean special) { if (no == 0) return 0; int initialDigits = no / 3; int toShare = no % 3; if (special == false) { if (toShare == 0) return initialDigits; else return initialDigits + 1; } else { if (toShare == 2) return initialDigits + 2; else { return initialDigits + 1; } } } }
0
92
A12852
A12766
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.evolve.codejam2012.qualification; import java.io.BufferedReader; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Dancing { private static final String TEST_FILE = "B-small-attempt0.in"; private PrintWriter pw = null; private BufferedReader br = null; Dancing(boolean skip) throws IOException { String outFile = TEST_FILE.replace(".in", ".out"); System.out.println(outFile); this.pw = new PrintWriter(new FileWriter(outFile)); if (skip) return; File file = new File(TEST_FILE); if (file.exists()) { br = new BufferedReader(new java.io.FileReader(TEST_FILE)); } else { br = new BufferedReader(new InputStreamReader(System.in), 1 << 16); } } void doit() throws NumberFormatException, IOException { int testsNumber = Integer.parseInt(br.readLine()); System.out.println(testsNumber); for (int i = 1; i <= testsNumber; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); StringBuilder sb = new StringBuilder(); int N = Integer.parseInt( st.nextToken() ); // number of googlers 1 <= N <= 3. int S = Integer.parseInt( st.nextToken() ); // number of surprising triplets of scores 0 <= S <= N. int p = Integer.parseInt( st.nextToken() ); // minimal result 0 <= p <= 10. int[] scores = new int[N]; for (int j = 0; j < N; j++) { scores[j] = Integer.parseInt( st.nextToken() ); // 0 <= ti <= 30. } // non surprising boolean[] nonsurpising = new boolean[N]; int counter = 0; for (int score : scores) { //nonsurpising[counter] = false; if (score % 3 == 0) { int a = score / 3; if (a >= p) { nonsurpising[counter] = true; } } if (score >= 1 && (score-1) % 3 == 0) { int a = (score-1) / 3 + 1; if (a >= p) { nonsurpising[counter] = true; } } if (score >= 2 && (score-2) % 3 == 0) { int a = (score-2) / 3 + 1; if (a >= p) { nonsurpising[counter] = true; } } counter++; } // surprising boolean[] surpising = new boolean[N]; if (S > 0) { // tylko gdy sa jakies // zakladamy ze kazdy jest surprising counter = 0; for (int score : scores) { //surpising[counter] = false; if (score >= 3 && (score-3) % 3 == 0) { int a = (score-3) / 3 + 2; if (a >= p) { surpising[counter] = true; } } if (score >= 2 && (score-2) % 3 == 0) { int a = (score-2) / 3 + 2; if (a >= p) { surpising[counter] = true; } } if (score >= 4 && (score-4) % 3 == 0) { int a = (score-4) / 3 + 2; if (a >= p) { surpising[counter] = true; } } counter++; } } System.out.println("nonsurprising: " + Arrays.toString(nonsurpising)); System.out.println("surprising: " + Arrays.toString(surpising)); int max = 0; for (int k = 0; k < N; k++) { if (nonsurpising[k]) { max++; } else if (S > 0 && surpising[k]) { max++; S--; } } pw.println("Case #" + i + ": " + max); } pw.flush(); pw.close(); } public static void main(String[] args) throws NumberFormatException, IOException { new Dancing(false).doit(); } }
0
93
A12852
A11207
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Dancer { public static void main(String[] args) { Scanner in = new Scanner(new BufferedInputStream(System.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 minTotal = p*3-4; int minTotalnoS = p*3-2; if(p <= 1) { minTotal = p; minTotalnoS = p; } int surprises = 0; int dancers = 0; //int[] scores = new int[N]; for(int j = 0; j < N; j++) { // scores[j] = in.nextInt(); int score = in.nextInt(); if(score >= minTotal) { dancers++; if(score < minTotalnoS) surprises++; } } if(S < surprises) dancers -= (surprises - S); System.out.printf("Case #%d: %d\n",i+1,dancers); } } }
0
94
A12852
A10762
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.rahul.codejam; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.lang.reflect.Array; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; /** * Hello world! * */ public class App { private int inputlength; private int counter; public App(String filename) { fFileName = filename; } public static void main( String[] args ) throws IOException { String fileName = args[0]; String encoding = "utf-8"; App test = new App(fileName); test.process(); } protected void process() throws IOException { log("Reading from file."); StringBuilder text = new StringBuilder(); String NL = System.getProperty("line.separator"); Scanner scanner = new Scanner(new FileInputStream(fFileName), fEncoding); try { while (scanner.hasNextLine()) { if (inputlength == 0) { inputlength = Integer.parseInt(scanner.nextLine()); } else { counter++; String output = String.format("Case #%d: %s", counter,processLine(scanner.nextLine())); System.out.println(output); text.append(output + NL); } //text.append(scanner.nextLine() + NL); } log("Writing to file named " + fFileName+".out" + ". Encoding: " + fEncoding); Writer out = new OutputStreamWriter(new FileOutputStream(fFileName + ".out"), fEncoding); try { out.write(text.toString()); } finally { out.close(); } } finally { scanner.close(); } log("Text read in: " + text); } protected String processLine(String s) { //Logic goes here String comp[] = s.split(" "); int googlers = Integer.parseInt(comp[0]); int maxsurprises = Integer.parseInt(comp[1]); int surprises = 0; int chasingScore = Integer.parseInt(comp[2]); int googlersGotChasingScores = 0; String scores[] = Arrays.copyOfRange(comp, 3, comp.length); System.out.println("scores length: " + scores.length); for(int i = 0; i < scores.length && i < googlers; i++) { if(checkChasingScore(Integer.parseInt(scores[i]), chasingScore)) { googlersGotChasingScores++; } else if(surprises < maxsurprises) { if(checkChasingScoreWithSurprise(Integer.parseInt(scores[i]), chasingScore)) { surprises++; googlersGotChasingScores++; } } } System.out.print(googlersGotChasingScores); return googlersGotChasingScores+""; } protected boolean checkChasingScore(int totalScore, int chasingScore) { boolean gotScore = false; switch (totalScore %3) { case 0: gotScore = totalScore/3 >= chasingScore; break; case 1: case 2: if(totalScore/3 + 1 <= totalScore) gotScore = (totalScore/3 + 1) >= chasingScore; break; } return gotScore; } protected boolean checkChasingScoreWithSurprise(int totalScore, int chasingScore) { boolean gotScore = false; switch (totalScore % 3) { case 0: case 1: if(totalScore/3 + 1 <= totalScore) gotScore = (totalScore/3 + 1) >= chasingScore; break; case 2: if(totalScore/3 + 2 <= totalScore) gotScore = (totalScore/3 + 2) >= chasingScore; break; } return gotScore; } // PRIVATE private final String fFileName; private final String fEncoding = "utf-8"; private void log(String aMessage) { System.out.println(aMessage); } }
0
95
A12852
A10984
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.moriraaca.codejam; import java.io.InputStream; import java.util.Scanner; public abstract class AbstractDataParser { protected Scanner scanner; protected TestCase[] testCases; public AbstractDataParser(InputStream input) { scanner = new Scanner(input); parse(); } abstract protected void doParse(); protected void parse() { doParse(); } public TestCase[] getTestCases() { return testCases; } }
0
96
A12852
A11793
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) { int cases = 0, googlers = 0, suprs = 0, max = 0, point = 0; String in = "B-small-attempt0"; try { BufferedReader br = readFile(new FileReader(in + ".in")); FileWriter fstream = new FileWriter(in + ".out"); BufferedWriter out = new BufferedWriter(fstream); String inline; while ((inline = br.readLine()) != null) { int i = 0; String[] input = inline.trim().split(" "); while (i < input.length) { if (i == 0) { googlers = Integer.parseInt(input[i++]); } else if (i == 1) { suprs = Integer.parseInt(input[i++]); } else if (i == 2) { max = Integer.parseInt(input[i++]); } else { String result = "Case #" + (++cases) + ": "; int num = 0; while (i < input.length) { point = Integer.parseInt(input[i++]); //acceptable values int minNotSuprs = (max + ((max - 1) * 2)); int minSuprs = (max + ((max - 2) * 2)); if (point >= minNotSuprs) { num++; } else if (point > 0) { if (point >= minSuprs && suprs > 0) { num++; suprs--; } } } result += String.valueOf(num); writeOutput(result, out); } } } out.close(); } catch(Exception e) { e.printStackTrace(); } } private static BufferedReader readFile(FileReader in) throws FileNotFoundException { return new BufferedReader(in); } private static void writeOutput(String text, BufferedWriter out) throws IOException { out.write(text); out.write("\n"); } }
0
97
A12852
A11340
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.*; import java.nio.*; import java.nio.file.*; import java.nio.charset.*; public class danzig { //arrays store each Googler's score info private static int[] total; private static int[] max; private static int[] modulo; private static int[] results; public static void main(String args[]) { //int linesRead=0; //fileRead(); Path file = Paths.get("C:\\Users\\Elena\\Documents\\george\\code jam\\B-small-attempt0.in"); Charset cs = Charset.forName("US-ASCII"); try(BufferedReader reader = Files.newBufferedReader(file, cs)){ //#test cases setup int T = Integer.valueOf(reader.readLine()); results = new int[T]; //the 'main' loop for(int i=0; i<T; i++) { String lineStr = reader.readLine(); //System.out.println(lineStr); String strAry[] = lineStr.split(" "); int N = Integer.valueOf(strAry[0]); //#Googlers int S = Integer.valueOf(strAry[1]); //#surprising scores int p = Integer.valueOf(strAry[2]); //target value //set array size total = new int[N]; max = new int[N]; modulo = new int[N]; for(int j=0; j<N; j++) total[j] = Integer.valueOf(strAry[j+3]); Arrays.sort(total); //max and remainder for(int j=0; j<N; j++){ modulo[j] = total[j]%3; if(modulo[j]==0) max[j] = total[j]/3; else max[j] = total[j]/3+1; } //System.out.println(S+"..."+Arrays.toString(max)); //finds largest max values < p int n=0; //number of surprisings selected so far for(int j=N-1; j>=0; j--){ if(n>=S) //do not exceed break; if(max[j]<p){ if(modulo[j]!=1 && total[j]>=2){ //if remainder 0|2 then can increase n++; max[j]++; } } } /*System.out.println(Arrays.toString(total)); System.out.println(p+"..."+Arrays.toString(max)); System.out.println(Arrays.toString(modulo));*/ //count number of matches tally(i,p); //System.out.print("\n"); } } catch(IOException x) { System.out.println("oops read"); } //System.out.println(Arrays.toString(results)); fileWrite(); } public static void tally(int pos, int target){ int instances=0; for(int i=0; i<max.length; i++){ if(max[i]>=target) instances++; } results[pos]=instances; } public static void fileWrite(){ Path file = Paths.get("C:\\Users\\Elena\\Documents\\george\\code jam\\dancing.out"); Charset cs = Charset.forName("US-ASCII"); try(BufferedWriter writer = Files.newBufferedWriter(file, cs)){ for(int i=0; i<results.length; i++){ String line = "Case #" + (i+1) + ": " + results[i]; writer.write(line); writer.newLine(); } } catch(IOException x){ System.out.println("oops write"); } } /*public static void fileRead() { Path file = Paths.get("C:\\Users\\Elena\\Documents\\george\\code jam\\dancingsample.in"); Charset cs = Charset.forName("US-ASCII"); try(BufferedReader reader = Files.newBufferedReader(file, cs)){ int T = Integer.valueOf(reader.readLine()); //parses lines for meaningful numbers for(int i=0; i<T; i++) { String str = reader.readLine(); String strAry = str.split() } } catch(IOException x) { System.out.println("oops read"); } }*/ }
0
98
A12852
A12982
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.unitedcoders.examples.codejam; import java.io.File; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new File("/Users/nh/b.in")); PrintStream out = new PrintStream(new File("/Users/nh/b.out")); int testcases = scanner.nextInt(); scanner.nextLine(); for (int casenr = 1; casenr <= testcases; casenr++) { int googlers = scanner.nextInt(); int surprises = scanner.nextInt(); int minScore = scanner.nextInt(); ArrayList<Integer> scores = new ArrayList<Integer>(); for(int i=0; i<googlers; i++){ scores.add(scanner.nextInt()); } int p = solve(googlers, surprises, minScore, scores); System.out.printf("Case #%d: %d\n", casenr, p); out.printf("Case #%d: %d\n", casenr, p); } } public static int solve(int googlers, int surprises, int minScore, ArrayList<Integer> scores){ Collections.sort(scores); Collections.reverse(scores); int save = minScore + 2*(minScore-1); int min = minScore +2*(minScore-2); int p = 0; for(int i : scores){ if(i>=save){ p++; continue; }else{ if((i>=min && surprises >0) && (i>0)){ p++; surprises--; } } } return p; } }
0
99