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
A12353
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; /** * @author: Ignat Alexeyenko * Date: 4/14/12 */ public class DancingWithGooglersMain { public static final int MAX_LENGTH = 80; public static void main(String[] args) { DancingWithGooglersMain main = new DancingWithGooglersMain(); main.runConsoleApp(System.in, System.out); } public void runConsoleApp(InputStream inputStream, OutputStream outputStream) { final String s = readLn(inputStream, MAX_LENGTH); Integer cases = Integer.valueOf(s); Writer writer = new OutputStreamWriter(outputStream); for (int i= 0; i < cases; i++) { String rawLine = readLn(inputStream, MAX_LENGTH); try { writer.write("Case #" + (i + 1) + ": " + runFunction(rawLine) + "\n"); } catch (IOException e) { throw new RuntimeException(e); } } try { writer.flush(); } catch (IOException e) { throw new RuntimeException(e); } } private long runFunction(String rawLine) { String[] edgesArr = rawLine.split(" "); int numOfGooglers = Integer.valueOf(edgesArr[0]); int surprises = Integer.valueOf(edgesArr[1]); int minScoreP = Integer.valueOf(edgesArr[2]); List<Integer> marksT = new ArrayList<Integer>(numOfGooglers); for (int t = 0; t < numOfGooglers; t++) { marksT.add(Integer.valueOf(edgesArr[t + 3])); } return caclulateAmountOfGooglersThatExceedScoreP(surprises, minScoreP, marksT); } private int caclulateAmountOfGooglersThatExceedScoreP(int surprises, int minScoreP, List<Integer> marksT) { Map<Integer, Set<Mark>> sumToPermutations = new HashMap<Integer, Set<Mark>>(marksT.size()); for (Integer theSum : marksT) { Set<Mark> allPossiblePermutations = getAllPossiblePermutations(theSum, minScoreP); sumToPermutations.put(theSum, allPossiblePermutations); } int exceedsWithoutSurprises = 0; int exceedsOnlyWithSurprises = 0; for (Integer theSum : marksT) { Set<Mark> marksPermutations = sumToPermutations.get(theSum); boolean exceeded = false; boolean needSurprise = true; for (Mark marksPermutation : marksPermutations) { if (marksPermutation.exceedsScore) { exceeded = true; if (!marksPermutation.surprise && needSurprise) { needSurprise = false; } } } if (exceeded && needSurprise) { exceedsOnlyWithSurprises++; } if (exceeded && !needSurprise) { exceedsWithoutSurprises++; } } return exceedsWithoutSurprises + Math.min(exceedsOnlyWithSurprises, surprises); } Set<Mark> getAllPossiblePermutations(int sum, int minScoreP) { Set<Mark> markList = new LinkedHashSet<Mark>(5); final int start = Math.max(sum / 3 - 2, 0); final int stop = sum / 3 + 2; for (int i = start; i <= stop; i++) { for (int j = start; j <= stop; j++) { for (int k = start; k <= stop; k++) { final int divergence = Math.abs(max(i, j, k) - min(i, j, k)); if ((i + j + k == sum) && divergence <= 2) { boolean exceedsScore = i >= minScoreP || j >= minScoreP || k >= minScoreP; markList.add(new Mark(i, j, k, divergence == 2, exceedsScore)); } } } } return markList; } private static int min(int a, int b, int c) { return Math.min(Math.min(a, b), c); } private static int max(int a, int b, int c) { return Math.max(Math.max(a, b), c); } private String readLn(InputStream inputStream, int maxLength) { // utility function to read from stdin, // Provided by Programming-challenges, edit for style only byte line[] = new byte[maxLength]; int length = 0; int input = -1; try { while (length < maxLength) {//Read untill maxlength input = inputStream.read(); if ((input < 0) || (input == '\n')) break; //or untill end of line ninput line[length++] += input; } if ((input < 0) && (length == 0)) return null; // eof return new String(line, 0, length); } catch (IOException e) { return null; } } static class Mark { // array represents marks, always are sorted private List<Integer> marks; private boolean surprise; private boolean exceedsScore; Mark(int m0, int m1, int m2, boolean surprise, boolean exceedsScore) { this.marks = new ArrayList<Integer>(3); this.marks.add(m1); this.marks.add(m0); this.marks.add(m2); this.surprise = surprise; this.exceedsScore = exceedsScore; // todo: possibly just put elements in the list in a right order Collections.sort(this.marks); Collections.reverse(this.marks); } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Mark mark = (Mark) o; if (exceedsScore != mark.exceedsScore) return false; if (surprise != mark.surprise) return false; if (marks != null ? !marks.equals(mark.marks) : mark.marks != null) return false; return true; } @Override public int hashCode() { int result = marks != null ? marks.hashCode() : 0; result = 31 * result + (surprise ? 1 : 0); result = 31 * result + (exceedsScore ? 1 : 0); return result; } @Override public String toString() { return "Mark{" + "marks=" + marks + ", surprise=" + surprise + ", exceedsScore=" + exceedsScore + '}'; } } }
0
100
A12852
A12183
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.StringTokenizer; public class GoogleDancers{ public static void main(String[] args) throws Exception{ FileReader fr = new FileReader("C:\\java projects\\learn\\src\\B-small-attempt0.in"); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter("C:\\java projects\\learn\\src\\BSmallOut.txt"); int N = new Integer(br.readLine()); for (int cases = 1; cases <= N; cases++) { String str = br.readLine(); StringTokenizer st = new StringTokenizer(str); int numberParticipants = Integer.parseInt(st.nextToken()); int surprise = Integer.parseInt(st.nextToken()); int goodScore = Integer.parseInt(st.nextToken()); int a[] = new int[numberParticipants]; for(int i=0; i< numberParticipants; i++) { a[i] = Integer.parseInt(st.nextToken()); } int count = 0; int possibility = 0; int minToGetGoodScore = Math.max(((3 * goodScore) - 2), 1); System.out.println("minToGetGoodScore" + minToGetGoodScore); int surpriseRange = Math.max(((3* goodScore) - 4), 1); if (goodScore > 0 ) { for (int i = 0; i < numberParticipants; i++) { if (a[i] >= minToGetGoodScore) { count++; System.out.println("Count" + count); } else if (a[i] >= surpriseRange && a[i] < minToGetGoodScore) { possibility++; } }System.out.println("Count" + count); count = count + Math.min(possibility, surprise); System.out.println("Count" + count); } else { count = numberParticipants; } fw.write("Case #" + cases + ": " + count + "\n"); } fw.flush(); fw.close(); } }
0
101
A12852
A10932
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.problemb; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ProblemB { private class Data { private int surpricing; private int minPoints; private List<Integer> points = new ArrayList<Integer>(); public int getSurpricing() { return surpricing; } public void setSurpricing(int surpricing) { this.surpricing = surpricing; } public int getMinPoints() { return minPoints; } public void setMinPoints(int minPoints) { this.minPoints = minPoints; } public List<Integer> getPoints() { return points; } public void setPoints(List<Integer> points) { this.points = points; } } private List<Data> readFile(File f) { String nextLine = null; List<Data> result = null; try { BufferedReader reader = new BufferedReader(new FileReader(f)); while ((nextLine = reader.readLine()) != null) { if (result == null) { result = new ArrayList<Data>(); } else { String[] line = nextLine.split(" "); Data d = new Data(); d.setSurpricing(Integer.parseInt(line[1])); d.setMinPoints(Integer.parseInt(line[2])); List<Integer> points = new ArrayList<Integer>(); for(int i = 0; i < Integer.parseInt(line[0]); i++) { d.getPoints().add(Integer.parseInt(line[i + 3])); } result.add(d); } } reader.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return result; } private List<Integer> solve(List<Data> data) { List<Integer> winners = new ArrayList<Integer>(); for(Data d : data) { winners.add(getMaxWinnerForList(d)); } return winners; } private int getMaxWinnerForList(Data data) { int winners = 0; int surpricing = 0; for(int point : data.getPoints()) { if(point < data.getMinPoints()) { continue; } if(point >= 3 * data.getMinPoints() - 2) { winners++; } else if(point >= 3 * data.getMinPoints() - 4) { surpricing++; } } winners += Math.min(data.getSurpricing(), surpricing); return winners; } private void writeToDisk(List<Integer> output) { File f = new File("outputBsmall.txt"); try { BufferedWriter writer = new BufferedWriter(new FileWriter(f)); int counter = 1; for(int s : output) { writer.write("Case #" + counter + ": " + s + "\n"); counter++; } writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void main(String[] args) { ProblemB c = new ProblemB(); List<Data> structures = c.readFile(new File(args[0])); List<Integer> longs = c.solve(structures); c.writeToDisk(longs); } }
0
102
A12852
A12719
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.dancing; import java.util.Scanner; import com.google.util.FileUtil; /* * * */ public class Dancing { public static void main(String[] args) { String orgFilePath = "E:\\Google_Jam\\Dancing\\B-small-attempt6.in"; Scanner scanner = FileUtil.openFile(orgFilePath); StringBuilder sb = new StringBuilder(); int caseNum = Integer.valueOf(scanner.nextLine()); for (int i = 0; i < caseNum; i++) { sb.append("Case #" + (i + 1) + ": "); String line = scanner.nextLine(); String[] numbers = line.split(" "); // String[] numbers = {"15"}; int n = 0;// ´ïµ½×î´óÖµµÄ¸öÊý int googlers = Integer.valueOf(numbers[0]);// Ñ¡ÊÖ¸öÊý int suprising = Integer.valueOf(numbers[1]);// µÃ·Ö²î´óÓÚ2 int max = Integer.valueOf(numbers[2]);// ÆÚÍûÖµ /* * int googlers = 1; int suprising =1; int max = 3; */ for (int j = 0; j < googlers; j++) { int temp = Integer.valueOf(numbers[j + 3]);// µ±Ç°Ñ¡ÊÖËùµÃ×Ü·Ö // int temp = Integer.valueOf(numbers[0]); if (temp / 3 >= max) { n++; } else if ((max - (temp / 3) == 1) && ((temp / 3) + (temp % 3)) >= max) { n++; } else if ((max - (temp / 3)) > 1 && ((temp / 3) + (temp % 3)) >= max && suprising > 0) { n++; suprising--; } else if (temp != 0 && max - temp / 3 == 1 && suprising > 0 && temp % 3 == 0) { n++; suprising--; } } sb.append(n); sb.append("\n"); } FileUtil.writeFile(sb, "Dancing\\small1.in"); } }
0
103
A12852
A12465
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.DataOutputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; public class Dancing { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileOutputStream ostream = new FileOutputStream("Output.txt"); DataOutputStream out = new DataOutputStream(ostream); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out)); int count = Integer.parseInt(br.readLine()); for (int i = 0; i < count; i++) { String lineString = br.readLine(); String [] arrayLineString = lineString.split(" "); int googlersCount = Integer.parseInt(arrayLineString[0]); if (googlersCount > 0 && googlersCount <= 100); else break; int surprisingResultsCount = Integer.parseInt(arrayLineString[1]); if (surprisingResultsCount >= 0 && surprisingResultsCount <= googlersCount); else break; int maxNumber = Integer.parseInt(arrayLineString[2]); if (maxNumber >= 0 && maxNumber <= 10); else break; int maxSumForSurprisngResults = maxNumber + (maxNumber - 2) * 2; if (maxSumForSurprisngResults >=2); else maxSumForSurprisngResults = 2; int maxSumForNormalResults = maxNumber + (maxNumber - 1) * 2; int scoresArray [] = convertArrayStringToNumbers(arrayLineString, googlersCount); Arrays.sort(scoresArray); int answerCount = 0; for (int j = (scoresArray.length - 1); j >= 0; j--){ if (scoresArray[j] >= 0 && scoresArray[j] <= 30); else break; if (scoresArray[j] >= maxSumForNormalResults){ answerCount++; } else if (scoresArray[j] >= maxSumForSurprisngResults){ if (surprisingResultsCount > 0){ surprisingResultsCount--; answerCount++; } else break; } else break; } bw.write("Case #" + (i+1) + ": " + answerCount); bw.newLine(); bw.flush(); } //Close the input stream in.close(); out.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } private static int [] convertArrayStringToNumbers(String[] arrayLineString, int count) { // TODO Auto-generated method stub int array [] = new int[count]; for (int i = 3; i < arrayLineString.length; i++){ array[i-3] = Integer.parseInt(arrayLineString[i]); } return array; } }
0
104
A12852
A12696
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 es.saspelo.codejam.dancingwiththegooglers; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.Queue; import java.util.Scanner; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.martiansoftware.jsap.FlaggedOption; import com.martiansoftware.jsap.JSAP; import com.martiansoftware.jsap.JSAPResult; import es.saspelo.codejam.commons.CodeJamProblem; public class DancingWithTheGooglers implements CodeJamProblem { private static final Logger log = LoggerFactory.getLogger(DancingWithTheGooglers.class); private static class DancingWithTheGooglersData { private int googlers = 0; private int surprisingTriplets = 0; private int score = 0; private List<Integer> points = null; public int getGooglers() { return googlers; } public void setGooglers(int googlers) { this.googlers = googlers; } public int getSurprisingTriplets() { return surprisingTriplets; } public void setSurprisingTriplets(int surprisingTriplets) { this.surprisingTriplets = surprisingTriplets; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } public List<Integer> getPoints() { return points; } public void setPoints(List<Integer> points) { this.points = points; } @Override public String toString() { return "DancingWithTheGooglersData [googlers=" + googlers + ", surprisingTriplets=" + surprisingTriplets + ", score=" + score + ", points=" + points + "]"; } } public void execute(InputStream in, OutputStream out) throws IOException { int testCases = 1; final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); final List<DancingWithTheGooglersData> problemDatas = readInput(in); if (log.isDebugEnabled()) { log.debug("==== starting problem '{}' ====", DancingWithTheGooglers.class.getSimpleName()); } try { for (DancingWithTheGooglersData data : problemDatas) { int bestResultReached = 0; Collections.sort(data.getPoints()); Collections.reverse(data.getPoints()); log.debug("points: '{}' | score: '{}' | surprising: '{}'", new Object[] { data.getPoints(), data.getScore(), data.getSurprisingTriplets() }); int surprising = data.getSurprisingTriplets(); List<int[]> tripletList = new ArrayList<int[]>(); for (int i = 0; i < data.getGooglers(); i++) { int[] triplet = new int[3]; int div = data.getPoints().get(i) / 3; int rest = data.getPoints().get(i) % 3; triplet[0] = div; triplet[1] = div; triplet[2] = div; int t = 0; while (rest > 0) { triplet[t++]++; rest--; } Arrays.sort(triplet); // adjust points to max if (triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 && ((triplet[2] + 1) - (triplet[0] - 1) < 2)) { triplet[2]++; triplet[0]--; } if (triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 && ((triplet[2] + 1) - (triplet[1] - 1) < 2)) { triplet[2]++; triplet[1]--; } boolean nothingToDoIn1 = false; boolean nothingToDoIn2 = false; while (surprising > 0 && !nothingToDoIn1 && !nothingToDoIn2) { if ((triplet[2] < data.getScore()) && triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 && (((triplet[2] + 1) - (triplet[0] - 1)) == 2)) { triplet[2]++; triplet[0]--; surprising--; nothingToDoIn1 = false; } else { nothingToDoIn1 = true; } nothingToDoIn2 = true; if (surprising > 0) { if ((triplet[2] < data.getScore()) && triplet[2] <= 9 && triplet[1] > 0 && triplet[0] > 0 && (((triplet[2] + 1) - (triplet[1] - 1)) == 2)) { triplet[2]++; triplet[1]--; surprising--; nothingToDoIn2 = false; } } } tripletList.add(triplet); log.debug("googler '{}'-> triplet: '{}'", new Object[] { i, triplet }); } for (int[] triplet : tripletList) { if (triplet[2] >= data.getScore()) { bestResultReached++; } } writer.write("Case #" + testCases + ": " + bestResultReached + "\n"); writer.flush(); testCases++; } } finally { writer.close(); } } private List<DancingWithTheGooglersData> readInput(InputStream in) { final Scanner sc = new Scanner(in); int testCases = sc.nextInt(); if (log.isDebugEnabled()) { log.debug("testCases: '{}'", testCases); } List<DancingWithTheGooglersData> problemData = new ArrayList<DancingWithTheGooglersData>(testCases); for (int i = 0; i < testCases; i++) { DancingWithTheGooglersData data = new DancingWithTheGooglersData(); data.setGooglers(sc.nextInt()); data.setSurprisingTriplets(sc.nextInt()); data.setScore(sc.nextInt()); List<Integer> points = new ArrayList<Integer>(); for (int j = 0; j < data.getGooglers(); j++) { points.add(sc.nextInt()); } data.setPoints(points); if (log.isDebugEnabled()) { log.debug("data: '{}'", data); } problemData.add(data); } sc.close(); return problemData; } public static void main(String[] args) throws Exception { final JSAP jsap = new JSAP(); final FlaggedOption inputFileName = new FlaggedOption("input").setStringParser(JSAP.STRING_PARSER) .setShortFlag('i').setLongFlag(JSAP.NO_LONGFLAG); final FlaggedOption outputFileName = new FlaggedOption("output").setStringParser(JSAP.STRING_PARSER) .setShortFlag('o').setLongFlag(JSAP.NO_LONGFLAG); inputFileName.setHelp("File name with input for the problem"); outputFileName.setHelp("File name for problem output file"); jsap.registerParameter(inputFileName); jsap.registerParameter(outputFileName); final JSAPResult config = jsap.parse(args); if (!config.success()) { System.err.println(); // print out specific error messages describing the problems // with the command line, THEN print usage, THEN print full // help. This is called "beating the user with a clue stick." for (Iterator<?> errs = config.getErrorMessageIterator(); errs.hasNext();) { System.err.println("Error: " + errs.next()); } System.err.println(); System.err.println("Usage: java " + DancingWithTheGooglers.class.getName()); System.err.println(" " + jsap.getUsage()); System.err.println(); System.err.println(jsap.getHelp()); System.exit(1); } InputStream in = System.in; OutputStream out = System.out; if (config.getString("input") != null) { in = new FileInputStream(new File(config.getString("input"))); } if (config.getString("output") != null) { out = new FileOutputStream(new File(config.getString("output"))); } DancingWithTheGooglers problem = new DancingWithTheGooglers(); problem.execute(in, out); } }
0
105
A12852
A13238
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner readStuff = new Scanner(System.in); int numCases, numGooglers, numSurprises, numTarget; int scores, results = 0; numCases = readStuff.nextInt(); for (int i = 0; i< numCases; i++) { numGooglers = readStuff.nextInt(); numSurprises = readStuff.nextInt(); numTarget = readStuff.nextInt(); for (int j=0; j<numGooglers; j++) { scores = readStuff.nextInt(); if (scores >= (3*numTarget - 2) && scores > 0) { results++; } else if (scores >= (3*numTarget-4) && scores > 0 && numSurprises > 0) { results++; numSurprises--; } if (scores == 0 && numTarget == 0) { results++; } } System.out.println("Case #" + (i+1) + ": " + results); results = 0; } } }
0
106
A12852
A11465
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.ArrayList; public class Googler { private String total; private ArrayList<Triplet> triplets; public Googler(String _total,ArrayList<Triplet> _triplets){ total=_total; triplets = _triplets; } public void setTriplets(ArrayList<Triplet> triplets) { this.triplets = triplets; } public ArrayList<Triplet> getTriplets() { return triplets; } public void setTotal(String total) { this.total = total; } public String getTotal() { return total; } }
0
107
A12852
A13131
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; /** * * @author akila */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { // TODO code application logic here ArrayList<String> testCases = new ArrayList<String>(); boolean isCaseNo = true; int testCount = 0; FileReader fr = new FileReader("B-small-attempt0.in"); BufferedReader br = new BufferedReader(fr); String s; while ((s = br.readLine()) != null) { if (isCaseNo) { testCount = Integer.parseInt(s); isCaseNo = false; } else { testCases.add(s); } } fr.close(); Solve(testCount, testCases); } public static void Solve(int testCount, ArrayList<String> testCases) throws IOException { FileWriter fstream = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream); for (int i = 0; i < testCount; i++) { ArrayList<Googler> googlers = new ArrayList<Googler>(); String s = testCases.get(i); String[] ar = s.split(" "); int noOfGooglers = 0, sup = 0, min = -1, count = 0; noOfGooglers = Integer.parseInt(ar[0]); sup = Integer.parseInt(ar[1]); min = Integer.parseInt(ar[2]); for (int j = 3; j < noOfGooglers + 3; j++) { Googler g = new Googler(); googlers.add(g); for (int a = 0; a <= 10; a++) { if (a > Integer.parseInt(ar[j])) { break; } for (int b = 0; b <= 10; b++) { if (a + b > Integer.parseInt(ar[j])) { break; } for (int c = 0; c <= 10; c++) { if (a + b + c == Integer.parseInt(ar[j])) { if ((Math.abs(a - b) <= 2) && (Math.abs(a - c) <= 2) && (Math.abs(b - c) <= 2)) { if ((Math.abs(a - b) == 2) || (Math.abs(a - c) == 2) || (Math.abs(b - c) == 2)) { Scores sc = new Scores(); sc.A = a; sc.B = b; sc.C = c; g.sup.add(sc); g.hasSup = true; } else { Scores sc = new Scores(); sc.A = a; sc.B = b; sc.C = c; g.normal.add(sc); } } } else if (a + b + c > Integer.parseInt(ar[j])) { break; } } } } } ArrayList<Googler> removed = new ArrayList<Googler>(); for (int j = 0; j < googlers.size(); j++) { Googler googler = googlers.get(j); if (googler.hasSup && googler.normal.isEmpty() && sup > 0) { if (googler.hasMinInSup(min)) { count++; } sup--; removed.add(googler); } } googlers.removeAll(removed); for (int j = 0; j < googlers.size(); j++) { Googler googler = googlers.get(j); if (googler.hasMinInNorm(min)) { count++; } else if (sup > 0 && googler.hasMinInSup(min)) { count++; sup--; } } out.write("Case #" + (i + 1) + ": " + count + "\n"); } out.close(); } } class Scores { public int A = -1, B = -1, C = -1; public boolean hasMin(int min) { return A >= min || B >= min || C >= min; } } class Googler { public ArrayList<Scores> normal = new ArrayList<Scores>(); public ArrayList<Scores> sup = new ArrayList<Scores>(); public boolean hasSup = false; public boolean hasMinInSup(int min) { for (int i = 0; i < sup.size(); i++) { if (sup.get(i).hasMin(min)) return true; } return false; } public boolean hasMinInNorm(int min) { for (int i = 0; i < normal.size(); i++) { if (normal.get(i).hasMin(min)) return true; } return false; } }
0
108
A12852
A12238
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.Scanner; import java.io.BufferedWriter; public class D { public static void main(String[] args) throws IOException { int n; InputStreamReader reader = new InputStreamReader(new FileInputStream( args[0])); BufferedReader read = new BufferedReader(reader); BufferedWriter write = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(args[1]))); // Scanner scan = new Scanner(System.in); n = Integer.parseInt(read.readLine()); // n = scan.nextInt(); for (int i = 0; i < n; i++) { String p = read.readLine(); write.write("Case #" + (i + 1) + ": " + holy(p, read)); write.newLine(); } write.flush(); write.close(); } static int holy(String s, BufferedReader read) throws IOException { int [] value = new int [103]; String p = s; int i = 0; int min_score = 0; int result = 0; while (p.indexOf(" ") != -1){ int pemisah = p.indexOf(" "); int a = Integer.parseInt(p.substring(0 , pemisah)); value [i] = a; i++; p = p.substring(pemisah+1); } value [i] = Integer.parseInt(p); i++; switch (value[2]) { case 0 : min_score = 0 ; break; case 1 : min_score = 1 ; break; case 2 : min_score = 2 ; break; case 3 : min_score = 5 ; break; case 4 : min_score = 8 ; break; case 5 : min_score = 11 ; break; case 6 : min_score = 14 ; break; case 7 : min_score = 17 ; break; case 8 : min_score = 20 ; break; case 9 : min_score = 23 ; break; case 10 : min_score = 26 ; break; } int surprising = value [1]; if (value[2] == 0) { for (int j = 3; j < i; j++) { result++; } } else { for (int j = 3; j < i; j++) { if ((value[j] == min_score) || (value[j] == min_score + 1)) { if (surprising > 0) { result++; surprising--; } } if (value[j] > min_score + 1) { result++; } } } return result; } }
0
109
A12852
A11658
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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_with_the_googlers { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int input = sc.nextInt(); for (int i = 1; i <= input; i++){ int googlers = sc.nextInt(); int surprises = sc.nextInt(); int min = sc.nextInt(); int results = 0; for (int j = 0; j < googlers; j++){ int googler = sc.nextInt(); int avg = googler / 3; int mod = googler % 3; if (avg >= min || ((avg + 1 == min) && mod > 0)){ results++; }else if (surprises > 0 && (avg + 1 == min) && avg != 0){ results++; surprises--; }else if (surprises > 0 && (avg + 2 == min) && mod > 1) { results++; surprises--; } } System.out.println("Case #"+i+": "+results); } } }
0
110
A12852
A11959
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.sql.SQLOutput; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class ProblemB { int[][] resultset = new int[3][3]; int googlersCount = 3; int surprising = 1; int winners=0; int count = 0; int p = 0; FileWriter fstream; BufferedWriter out; public static void main(String[] args) throws IOException { ProblemB p1 = new ProblemB(); p1.fstream = new FileWriter("outB.txt"); p1.out = new BufferedWriter(p1.fstream); p1.readFile("B-small-attempt0.in"); } public void readFile(String filePath) { String[] result = null; try { FileReader input = new FileReader(filePath); BufferedReader bufRead = new BufferedReader(input); Scanner scan = new Scanner(input); this.count = scan.nextInt(); for (int i = 0; i < count; i++) { winners = 0; this.googlersCount = scan.nextInt(); this.surprising = scan.nextInt(); this.p = scan.nextInt(); int a[] = new int[googlersCount]; for (int j=0; j<googlersCount;j++){ a[j] = scan.nextInt(); } resultset = new int[googlersCount][3]; for (int h = 0; h < a.length; h++) resultset[h]=getCombinations(a[h],p); int[] g = new int[0]; recursion(g); System.out.println(winners); out.write("Case #" + (i + 1) + ": "+winners); if (i<count-1) out.write("\n"); } bufRead.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } public int[] getCombinations(int a, int p) { int[] result = new int[3]; // System.out.println("----" + a + ":"); for (int i = 0; i <= 10; i++) { for (int j = i; j <= 10; j++) { for (int k = j; k <= 10; k++) { if ((i + j + k) == a) { int diff1 = Math.abs(i - j); int diff2 = Math.abs(k - j); int diff3 = Math.abs(i - k); if (diff1 <= 2 && diff2 <= 2 && diff3 <= 2) { // System.out.println(i + "-" + j + "-" + k); Integer[] res = {i, j, k}; if (isSurprising(i, j, k) && ((i >= p) || (j >= p) || (k >= p))) { result[0] = 1; } else if (isSurprising(i, j, k)) { result[1] = 1; } else if ((i >= p) || (j >= p) || (k >= p)) { result[2] = 1; } } } } } } return result; } public void check() { for (int i=0; i<googlersCount; i++); } public boolean isSurprising(int a, int b, int c) { int diff1 = Math.abs(a - b); int diff2 = Math.abs(b - c); int diff3 = Math.abs(a - c); if (diff1 == 2 || diff2 == 2 || diff3 == 2) { return true; } return false; } public void recursion(int[] a){ if (a.length<googlersCount-1){ int[] b = new int[a.length+1]; for (int rec=0;rec<a.length;rec++){ b[rec]=a[rec]; } for (int i=0; i<=2; i++){ b[b.length-1]=0; if(resultset[b.length-1][i]==1 && i==0){ b[b.length-1]=1; } if(resultset[b.length-1][i]==1 && i==1){ b[b.length-1]=2; } if(resultset[b.length-1][i]==1 && i==2){ b[b.length-1]=3; } recursion(b); } } else { int[] b = new int[a.length+1]; for (int rec=0;rec<a.length;rec++){ b[rec]=a[rec]; } for (int i=0; i<=2; i++){ b[b.length-1]=0; if(resultset[b.length-1][i]==1 && i==0){ b[b.length-1]=1; } if(resultset[b.length-1][i]==1 && i==1){ b[b.length-1]=2; } if(resultset[b.length-1][i]==1 && i==2){ b[b.length-1]=3; } int surpCount=0; int winCount=0; for (int j=0; j<b.length;j++){ if (b[j]==1){ surpCount++; winCount++; } if(b[j]==2){ surpCount++; } if(b[j]==3){ winCount++; } } if (this.winners<=winCount && surpCount==this.surprising){ winners=winCount; } } } } }
0
111
A12852
A12964
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package mgg.utils; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; /** * @author manolo * @date 13/04/12 */ public class FileUtil { FileReader reader; FileWriter writer; public FileUtil(String input, String output) { try { reader = new FileReader(input); writer = new FileWriter(output); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public String getLine(){ try { StringBuilder builder = new StringBuilder(); char c = (char) reader.read(); while (c != '\n') { builder.append(c); //System.out.println("\t\t\t> char: '" + c + "'"); c = (char) reader.read(); } ; System.out.println("\t\t\t----------> line: '" + builder.toString() + "'"); return builder.toString(); } catch (IOException e) { e.printStackTrace(); } return null; } public void printLine(int lineNumber, String line){ try { writer.write("Case #" + lineNumber + ": " + line + "\n"); } catch (IOException e) { e.printStackTrace(); } } public void closeFiles(){ try { reader.close(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }
0
112
A12852
A13088
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.jedruch.dancing; import java.util.Arrays; import java.util.LinkedList; import java.util.List; import com.jedruch.utils.Files; import com.jedruch.utils.Files.LineReader; public class Dancing { public static void main(String[] args) { if (args.length == 0) { System.out.println("missing file name"); return; } String fileName = args[0]; Files.readFileByLine(fileName, new LineReader() { Dancing gt = new Dancing(); @Override public void onNewLine(String line, int lineNumber) { if ( lineNumber > 1) { int max = gt.getMaximumGooglers(line); String output = String.format("Case #%d: %d", lineNumber - 1, max); System.out.println(output); } } }); } public int getMaximumGooglers(String line) { Object[] params = parseInput(line); return getMaximumGooglers((int)params[0], (int)params[1], (int[])params[2]); } public Object[] parseInput(String line) { String[] tokens = line.split(" "); int arraySize = Integer.valueOf(tokens[0]); int surprsingS = Integer.valueOf(tokens[1]); int betScore = Integer.valueOf(tokens[2]); int[] scores = new int[arraySize]; int count = 0; for (int i = 3; i < tokens.length; i++) { scores[i - 3] = Integer.valueOf(tokens[i]); count++; } if (arraySize != count) { throw new IllegalStateException( "Given number of scores do not match"); } return new Object[] { surprsingS, betScore, scores }; } /** * * @param surprisingScores * - ti ( i = N) * @param maxBestScore * - p * @param results * @return */ public int getMaximumGooglers(int surprisingScores, int maxBestScore, int[] results) { List<Score> scores = new LinkedList<>(); for (int s : results) { scores.add(new Score(s)); } makeSurprsingScores(surprisingScores, maxBestScore, scores); return calculateWithScoreMoreThenGiven(scores, maxBestScore); } public void makeSurprsingScores(int noOfSurprisingScores, int bestScore, List<Score> scores) { int count = 0; for (Score s : scores) { if (count == noOfSurprisingScores) { break; } if (s.getBestScore() >= bestScore) continue; // ignore this case; boolean result = makeSuprisingOnlyIfWorth(s, bestScore); if (result) { count++; } } if (count > noOfSurprisingScores) throw new IllegalStateException( "Make more surprsing then exptecated"); } private boolean makeSuprisingOnlyIfWorth(Score s, int bestScore) { int tmp = s.getTotal(); s.makeSurprising(); if (s.getBestScore() >= bestScore) { return true; } else { s.initScores(tmp); // rollback return false; } } public int calculateWithScoreMoreThenGiven(List<Score> scores, int maxBestScore) { int count = 0; for (Score s : scores) { if (s.getBestScore() >= maxBestScore) { count++; } } return count; } public int calculateWithTheBestScore(List<Score> scores) { int max = -1; int count = 0; for (Score s : scores) { if (s.getBestScore() > max) { count = 1; max = s.getBestScore(); } else if (s.getBestScore() == max) { count++; } } return count; } public void makeSurprsingScores(int noOfSurprisingScores, List<Score> scores) { int count = 0; for (Score s : scores) { if (count == noOfSurprisingScores) { break; } boolean result = s.makeSurprising(); if (result) { count++; } } if (count > noOfSurprisingScores) throw new IllegalStateException( "Make more surprsing then exptecated"); } } class Score { private int[] scores = new int[3]; private int moduloType = -1; public Score(int score) { initScores(score); } void initScores(int total) { moduloType = total % 3; int div = total / 3; Arrays.fill(scores, div); if (moduloType == 1) { scores[0] += 1; } else if (moduloType == 2) { scores[0] += 1; scores[1] += 1; } } void initScores(int first, int second, int third) { scores[0] = first; scores[1] = second; scores[2] = third; } public boolean makeSurprising() { if (moduloType == -1) { throw new IllegalStateException("Can not be -1"); } if (moduloType == 1 || getTotal() == 0) return false; if (moduloType == 0) { scores[0] += 1; scores[2] -= 1; } else if (moduloType == 2) { scores[0] += 1; scores[1] -= 1; } return true; } @Override public String toString() { return "Score [scores=" + Arrays.toString(scores) + "]"; } public boolean isSurprising() { int first = scores[0]; int second = scores[1]; int third = scores[2]; boolean surprsing = false; surprsing |= checkSurprising(first, second); surprsing |= checkSurprising(first, third); surprsing |= checkSurprising(second, third); return surprsing; } private boolean checkSurprising(int int1, int int2) { int diff = Math.abs(int1 - int2); if (diff > 2) throw new IllegalStateException("Some problem with judges"); return diff == 2; } public int[] getScores() { return scores; } public int getTotal() { int sum = 0; for (int s : scores) { sum += s; } return sum; } public int getBestScore() { int max = -1; for (int s : scores) { max = Math.max(max, s); } return max; } }
0
113
A12852
A13163
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package tr0llhoehle.cakemix.utility.googleCodeJam; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.text.ParseException; import java.util.ArrayList; import java.util.LinkedList; import java.util.Scanner; /** * {@link IOManager} is used to manage all input and output operations needed * for your java-solution of a Google codejam problem. * * It uses the class/interface {@link Problem} and {@link Solver}. * * @author Cakemix * * @param <S> * The type of your concrete Solver-implementation which solves the * Problem P. * @param <P> * The type of your concrete Problem. * @see Problem * @see Solver */ public class IOManager<S extends Solver<P>, P extends Problem> { private S solver; private Class<P> clazz; private LinkedList<P> problems; /** * Creates a new IOManager. * * @param solver * The solver-instance which is to be used for solving the * problems. * @param clazz * A Class object of one exemplary concrete Problem P. This is * needed to correctly instantiate new concrete Problems. */ public IOManager(S solver, Class<P> clazz) { this.clazz = clazz; this.solver = solver; } private P createProblem() throws InstantiationException, IllegalAccessException { return clazz.newInstance(); } /** * Starts the IO-operations and solves the Problems contained in the file * pointed to by the filePath. * * @param filePath * A String describing the location of an input-file (usually * *.in) * @throws IOException * @throws ParseException */ public void start(String filePath) throws IOException, ParseException { int amountOfProblems; File out; Scanner lineScanner; File in = new File(filePath); Scanner scanner; FileWriter writer; System.out.print("Creating files... "); if (filePath.length() >= 3 && filePath.substring(filePath.length() - 3).equals(".in")) { filePath = filePath.substring(0, filePath.length() - 3); } filePath += ".out"; out = new File(filePath); out.createNewFile(); System.out.println("Done!"); System.out.print("Creating file reader and writers... "); scanner = new Scanner(in); writer = new FileWriter(out); System.out.println("Done!"); System.out.print("Parsing the input file... "); amountOfProblems = scanner.nextInt(); scanner.nextLine(); problems = new LinkedList<P>(); for (int probID = 0; probID < amountOfProblems; probID++) { P problem = null; try { problem = createProblem(); SupportedTypes[] probTypes = problem.getTypes(); for (SupportedTypes t : probTypes) { switch (t) { case INT: lineScanner = new Scanner(scanner.nextLine()); problem.addValue(lineScanner.nextInt()); break; case DOUBLE: lineScanner = new Scanner(scanner.nextLine()); problem.addValue(lineScanner.nextDouble()); break; case BOOLEAN: lineScanner = new Scanner(scanner.nextLine()); problem.addValue(lineScanner.nextBoolean()); break; case STRING: problem.addValue(scanner.nextLine()); break; case LIST_INT: lineScanner = new Scanner(scanner.nextLine()); ArrayList<Integer> ints = new ArrayList<Integer>(); while (lineScanner.hasNext()) { ints.add(lineScanner.nextInt()); } problem.addValue(ints); break; case LIST_DOUBLE: lineScanner = new Scanner(scanner.nextLine()); ArrayList<Double> doubles = new ArrayList<Double>(); while (lineScanner.hasNext()) { doubles.add(lineScanner.nextDouble()); } problem.addValue(doubles); break; case LIST_BOOLEAN: lineScanner = new Scanner(scanner.nextLine()); ArrayList<Boolean> booleans = new ArrayList<Boolean>(); while (lineScanner.hasNext()) { booleans.add(lineScanner.nextBoolean()); } problem.addValue(booleans); break; case LIST_STRING: lineScanner = new Scanner(scanner.nextLine()); ArrayList<String> strings = new ArrayList<String>(); while (lineScanner.hasNext()) { strings.add(lineScanner.next()); } problem.addValue(strings); break; default: System.err .print("Default case! This is not a good sign... "); } } } catch (IllegalAccessException e) { System.err.println("Couldn't instantiate the problem!"); e.printStackTrace(); } catch (InstantiationException e) { System.err.println("Couldn't instantiate the problem!"); // TODO Auto-generated catch block e.printStackTrace(); } if (problem != null) { problems.add(problem); } } System.out.println("Done!"); System.out.print("Closing the input file... "); scanner.close(); System.out.println("Done!"); System.out.print("Solving the problems... "); for (int i = 0; i < problems.size(); i++) { writer.append("Case #" + (i+1) + ": " + solver.solve(problems.get(i)) + System.getProperty("line.separator")); } System.out.println("Done!"); System.out.print("Closing the writer... "); writer.close(); System.out.println("Done!"); System.out.println("Shutting down, output lies here:"); System.out.println(filePath); } }
0
114
A12852
A12947
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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. */ /** * * @author Madu */ import java.io.*; public class Ex2 { public static void main(String[] args) { try{ FileInputStream fstream = new FileInputStream("C:/Users/Madu/Documents/NetBeansProjects/CodeJamR1Ex1/input/A-small-attempt0.in"); FileOutputStream fout = new FileOutputStream ("C:/Users/Madu/Documents/NetBeansProjects/CodeJamR1Ex1/output/out.txt"); PrintStream printStream = new PrintStream(fout); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String inputIlne; br.readLine(); //printStream.println ("Output"); //Read File Line By Line int lineNum = 1; while ((inputIlne = br.readLine()) != null) { // Print the content on the console //########## String[] marks = inputIlne.split(" "); int peopleCount = Integer.parseInt(marks[0].toString()); int s = Integer.parseInt(marks[1].toString()); int p = Integer.parseInt(marks[2].toString()); int ans = 0; for (int i = 3; i < marks.length; i++) { System.out.println(marks[i]); int total = Integer.parseInt(marks[i].toString()); int value = total/3; int reminder = total%3; if(total==0){ if(p==0){ans++;} continue;} if(reminder==0){ if(value>=p){ans++;} else if(value+1>=p){ if(s>=1){ans++; s--; } } } else if(reminder==1){ if(value>=p){ans++;} else if(value+1>=p){ans++;} } else if(reminder==2){ if(value>=p){ans++;} else if(value+1>=p){ans++;} else if(value+2>=p){ if(s>=1){ans++; s--;} } } } printStream.print ("Case #"+lineNum+": "+ans);lineNum++; //########### printStream.println(""); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.toString()); } } // public static void main(String[] args) { // // String test = "2 1 1 8 0"; // int peopleCount = Integer.parseInt(test.substring(0, 1)); // int s = Integer.parseInt(test.substring(2, 3)); // int p = Integer.parseInt(test.substring(4, 5)); // // int ans = 0; // // //System.out.println(p); // // String[] marks = (test.substring(6)).split(" "); // // // // for (int i = 0; i < marks.length; i++) { // // System.out.println(marks[i]); // int total = Integer.parseInt(marks[i].toString()); // // int value = total/3; // int reminder = total%3; // // if(total==0){continue;} // // if(reminder==0){ // // if(value>=p){ans++;} // else if(value+1>=p){ // // if(s>=1){ans++; s--; // } // // } // // } // // else if(reminder==1){ // // if(value>=p){ans++;} // else if(value+1>=p){ans++;} // // } // // else if(reminder==2){ // // if(value>=p){ans++;} // else if(value+1>=p){ans++;} // else if(value+2>=p){ // // if(s>=1){ans++; s--;} // } // // } // // } // // // // System.out.println("Answer :"+ans); // // } }
0
115
A12852
A11087
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package Qual; import java.io.*; import java.math.*; import java.util.*; public class B { static void start() throws IOException { new B().run1(); } private final String dir = "D:\\contest\\gcj\\2012\\" + getClass().getPackage().toString().split(" ")[1] + "\\" + getClass().getSimpleName(); // private final String inputFileName = "sample.txt"; private final String inputFileName = "B-small-attempt2.in"; private final String outputFileName = "res.txt"; void run() throws IOException { int T = IOFast.nextInt(); while(T-- != 0) { final int n = IOFast.nextInt(); int S = IOFast.nextInt(); final int p = IOFast.nextInt(); int res = 0; for(int i = 0; i < n; i++) { final int x = IOFast.nextInt(); if((x + 2) / 3 >= p) { res++; } else if(S > 0 && x != 0) { if(x % 3 != 1 && (x + 2) / 3 + 1 >= p) { res++; S--; } } } printCase(); IOFast.out.println(res); } } void run1() throws IOException { IOFast.setReader(new FileReader(dir + "\\" + inputFileName)); IOFast.setWriter(new FileWriter(dir + "\\" + outputFileName)); run(); } private static int CASE; private static void printCase() { IOFast.out.print("Case #" + ++CASE + ": "); } public static void main(String[] args) throws IOException { start(); IOFast.out.flush(); IOFast.in.close(); IOFast.out.close(); } static public class IOFast { private static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); private static PrintWriter out = new PrintWriter(System.out); // private static final int BUFFER_SIZE = 50 * 200000; private static final StringBuilder buf = new StringBuilder(); private static boolean[] isDigit = new boolean[256]; private static boolean[] isSpace = new boolean[256]; static { for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; } isDigit['-'] = true; isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true; } static boolean endInput; public static void setReader(Reader r) { in = new BufferedReader(r); } public static void setWriter(Writer w) { out = new PrintWriter(w); } private static int nextInt() throws IOException { boolean plus = false; int ret = 0; while(true) { final int c = in.read(); if(c == -1) { endInput = true; return Integer.MIN_VALUE; } if(isDigit[c]) { if(c != '-') { plus = true; ret = c - '0'; } break; } } while(true) { final int c = in.read(); if(c == -1 || !isDigit[c]) { break; } ret = ret * 10 + c - '0'; } return plus ? ret : -ret; } private static long nextLong() throws IOException { boolean plus = false; long ret = 0; while(true) { final int c = in.read(); if(c == -1) { endInput = true; return Integer.MIN_VALUE; } if(isDigit[c]) { if(c != '-') { plus = true; ret = c - '0'; } break; } } while(true) { final int c = in.read(); if(c == -1 || !isDigit[c]) { break; } ret = ret * 10 + c - '0'; } return plus ? ret : -ret; } private static String next() throws IOException { buf.setLength(0); while(true) { final int c = in.read(); if(c == -1) { endInput = true; return "-1"; } if(!isSpace[c]) { buf.append((char)c); break; } } while(true) { final int c = in.read(); if(c == -1 || isSpace[c]) { break; } buf.append((char)c); } return buf.toString(); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
0
116
A12852
A10353
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class Submission { public static final int numJudges = 3; public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); int numCases = Integer.parseInt(in.readLine()); for (int i=0; i<numCases; i++) { if (i != 0) { out.println(); } out.print("Case #"+(i+1)+": "); String s = in.readLine(); String[] tokens = s.split(" "); if (tokens.length < 3) { throw new IllegalArgumentException("Bad input!"); } int remainingScoreRaises = Integer.parseInt(tokens[1]); final int requiredScore = Integer.parseInt(tokens[2]); int highScoringGooglers = 0; for (int j=3; j<tokens.length; j++) { final int totalScore = Integer.parseInt(tokens[j]); //maxScore = ceil (totalScore / numJudges) final int maxScore = (totalScore + numJudges - 1) / numJudges; if (maxScore >= requiredScore) { highScoringGooglers++; } else if (maxScore == requiredScore - 1 && totalScore%numJudges != 1 && remainingScoreRaises != 0 && maxScore >= 1 && maxScore <= 9) { highScoringGooglers++; remainingScoreRaises--; } } out.print (highScoringGooglers); } out.close(); } catch (IOException e) { System.out.println ("Problem with file!"); } } }
0
117
A12852
A12617
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 aao; import java.io.*; import java.util.regex.Pattern; /** * @author aoboturov */ public class DansingWithGooglers { public LineNumberReader lineNumberReader; public DansingWithGooglers(final String inputFileName) throws Exception { lineNumberReader = new LineNumberReader( new BufferedReader( new InputStreamReader( getClass().getClassLoader().getResourceAsStream(inputFileName) ) )); } public int readNumberOfTestCases() throws Exception { return Integer.parseInt(lineNumberReader.readLine()); } public void solve(final String outputFileName) throws Exception { final FileOutputStream fos = new FileOutputStream(new File(outputFileName)); final int numberOfTestCases = readNumberOfTestCases(); final Pattern pattern = Pattern.compile("[\\s]+"); for ( int caseNumber = 1; caseNumber <= numberOfTestCases; caseNumber++) { // Init of counters. int guaranteedNumberOfGooglersHavingBestResult = 0; int holdOutNumberOfGooglersHavingBestResult = 0; // Init of base parameters. final String[] splitInput = pattern.split(lineNumberReader.readLine()); final int numberOfGooglers = Integer.parseInt(splitInput[0]); final int numberOfSurprises = Integer.parseInt(splitInput[1]); final int requiredBestResult = Integer.parseInt(splitInput[2]); // Compute required values. for ( int googler = 0; googler < numberOfGooglers; googler++) { final int googlerScore = Integer.parseInt(splitInput[3 + googler]); // Filter evident cases: if ( googlerScore >= 3*requiredBestResult) { guaranteedNumberOfGooglersHavingBestResult++; continue; } if ( googlerScore <= (3*requiredBestResult - 5)) { continue; } // case p=k,k,k if ( googlerScore == (3*requiredBestResult - 0)) { guaranteedNumberOfGooglersHavingBestResult++; continue; } // case p=k,k+1,k+1 if ( googlerScore == (3*requiredBestResult - 1) && (googlerScore - 2) >= 0) { guaranteedNumberOfGooglersHavingBestResult++; continue; } // case p=k,k,k+1 if ( googlerScore == (3*requiredBestResult - 2) && (googlerScore - 1) >= 0) { guaranteedNumberOfGooglersHavingBestResult++; continue; } // case p=k,k+1,k+2 if ( googlerScore == (3*requiredBestResult - 3) && (googlerScore - 3) >= 0) { holdOutNumberOfGooglersHavingBestResult++; continue; } // case p=k,k+2,k+2 if ( googlerScore == (3*requiredBestResult - 4) && (googlerScore - 2) >= 0) { holdOutNumberOfGooglersHavingBestResult++; continue; } } final StringBuilder sb = new StringBuilder("Case #").append(caseNumber).append(": ") .append(guaranteedNumberOfGooglersHavingBestResult+Math.min(holdOutNumberOfGooglersHavingBestResult, numberOfSurprises)) .append("\n"); System.out.print(sb.toString()); fos.write(sb.toString().getBytes()); } } public static void main(String args[]) throws Exception { new DansingWithGooglers("B-small-attempt0.in.txt").solve("output.xml"); } }
0
118
A12852
A12269
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; public class B { public static void main(String[] args) throws FileNotFoundException, IOException { Scanner sc = new Scanner(new FileReader("input.txt")); PrintWriter pw = new PrintWriter(new FileWriter("output.txt")); int noOfCases = sc.nextInt(); for (int caseNum = 0; caseNum < noOfCases; caseNum++){ int noOfGooglers = sc.nextInt(); int supprizing = sc.nextInt(); int bestScore = sc.nextInt(); int scores[] = new int[noOfGooglers]; int result = 0; for (int i = 0; i < noOfGooglers; i++) { scores[i] = sc.nextInt(); } int suppLowest = ((bestScore-1)*3)-1; int normLowest = (bestScore*3)-2; for (int i = 0; i < scores.length; i++) { if(scores[i]==0){ if(bestScore==0){ result++; } } else if(scores[i]>=normLowest){ result++; } else if(scores[i]>=suppLowest){ if(supprizing>0){ result++; supprizing--; } } } pw.print("Case #" + (caseNum + 1) + ": " + result); if(caseNum < noOfCases-1) pw.println(""); } pw.flush(); pw.close(); sc.close(); } }
0
119
A12852
A11878
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; import java.util.InputMismatchException; import java.io.FileOutputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.FileInputStream; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Egor Kulikov (egor@egork.net) */ public class Main { public static void main(String[] args) { InputStream inputStream; try { inputStream = new FileInputStream("taskb.in"); } catch (IOException e) { throw new RuntimeException(e); } OutputStream outputStream; try { outputStream = new FileOutputStream("taskb.out"); } catch (IOException e) { throw new RuntimeException(e); } InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); TaskB solver = new TaskB(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } } class TaskB { public void solve(int testNumber, InputReader in, OutputWriter out) { int count = in.readInt(); int surprising = in.readInt(); int required = in.readInt(); int[] scores = IOUtils.readIntArray(in, count); int answer = 0; for (int i : scores) { if (i < required) continue; if (i >= 3 * required - 2) answer++; else if (i >= 3 * required - 4 && surprising > 0) { answer++; surprising--; } } out.printLine("Case #" + testNumber + ":", answer); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuffer res = new StringBuffer(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(outputStream); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } } class IOUtils { public static int[] readIntArray(InputReader in, int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = in.readInt(); return array; } }
0
120
A12852
A10170
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class CodeJam { public static void main(String a[]){ try { FileReader f = new FileReader("B-small-attempt1.in"); BufferedReader in = new BufferedReader(f); FileWriter fwrite = new FileWriter("output"); BufferedWriter out = new BufferedWriter(fwrite); int n = Integer.parseInt(in.readLine().toString()); int i = 0; int j=0; int numOfGooglers = 0; int numOfSurprise = 0; int bestResult = 0; String line = null; int[] sums = new int[100]; triplet [] goo = new triplet[100]; int surpDone=0; boolean curSurp = false; int count = 0; while(i<n){ count = 0; line = in.readLine(); out.write("Case #"+(i+1)+": "); numOfGooglers = Integer.parseInt(line.substring(0,line.indexOf(" "))); line =line.substring(line.indexOf(" ")+1); numOfSurprise = Integer.parseInt(line.substring(0,line.indexOf(" "))); line =line.substring(line.indexOf(" ")+1); bestResult = Integer.parseInt(line.substring(0,line.indexOf(" "))); // System.out.print(numOfGooglers+" "+numOfSurprise+" "+bestResult+"|"); line =line.substring(line.indexOf(" ")+1); j=0; surpDone =0; curSurp=false; while(j<numOfGooglers){ curSurp = false; if(j<numOfGooglers-1){ sums[j]=Integer.parseInt(line.substring(0,line.indexOf(" "))); line = line.substring(line.indexOf(" ")+1); // System.out.println(sums[j]); } else sums[j] = Integer.parseInt(line); if(sums[j] <=28 && sums[j]>=2 && surpDone < numOfSurprise){ if(test(setScore(sums[j],false,bestResult), bestResult)==true) curSurp = false; else if(test(setScore(sums[j], true, bestResult),bestResult)==true){ surpDone+=1; curSurp = true; } else if(test(setScore(sums[j], true, bestResult),bestResult)==false){ curSurp = false; } else { curSurp = true; // System.out.print("here"); surpDone++;} } goo[j] = setScore(sums[j], curSurp,bestResult); if(goo[j].one >= bestResult || goo[j].two >= bestResult|| goo[j].three >= bestResult) count++; // System.out.print(sums[j]+" "+goo[j].one+" "+goo[j].two+" "+goo[j].three+" "+goo[j].surprise+" "); j++; } // System.out.println(count); out.write(String.valueOf(count)); out.newLine(); i++; } in.close(); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static boolean test(triplet t,int best){ if(t.one>=best||t.two>=best||t.three>=best){ // System.out.print("positive"); return true; } // System.out.print("negative"); return false; } public static triplet setScore(int sum, boolean surp, int best){ triplet score = new triplet(); int a,b,c; int div = sum/3; int mod = sum%3; a=b=c=div; if(mod==1){ if(surp ==false) a=a+1; else{ a=a+1 ; b=b+1; c=c-1; if(a>=best||b>=best||c>=best){ score.flag=true; // System.out.println("here"+a+b+c+best); } } }else if(mod==2){ if(surp ==false ){ a=a+1; b=b+1; } else{ a=a+2; if(a>=best||b>=best||c>=best){ score.flag=true; // System.out.println("here"); } } }else { if(surp==true){ a=a+1; b=b-1; if(a>=best||b>=best||c>=best){ score.flag=true; // System.out.println("here"); } } } score.one=a; score.two=b; score.three=c; score.surprise=surp; return score; } }
0
121
A12852
A13120
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.weiwei.googlejam; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * Created with IntelliJ IDEA. * User: ding * Date: 12-4-14 * Time: 上午11:37 * To change this template use File | Settings | File Templates. */ public class Dancing { List<Integer> scores; int surp; int p; public Dancing(List<Integer> scores, int surp, int p){ this.scores = scores; this.surp = surp; this.p = p; } public static Dancing loadFromString(String input){ String[] elems = input.trim().split(" "); int surp = Integer.parseInt(elems[1].trim()); int p = Integer.parseInt(elems[2].trim()); int total = Integer.parseInt(elems[0].trim()); List<Integer> scores = new ArrayList<Integer>(); for (int i =0; i < total; i++){ scores.add(Integer.parseInt(elems[3+i].trim())); } return new Dancing(scores, surp, p); } public int getNumber(){ int number = 0; Collections.sort(scores, Collections.reverseOrder()); for(int score : scores){ if(score >= 3*p -2 ){ number++; } else if(surp > 0){ if(score >=3*p-4 && p >= 2) { number++; surp--; } else { break; } } else break; } return number; } }
0
122
A12852
A10116
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class Googlers { /** * @param args */ public static void main(String[] args) { Scanner scanner = null; int caseNumber = 0; Googlers a = new Googlers(); try { scanner = new Scanner(new FileInputStream(args[0])); while (scanner.hasNextLine()) { if (caseNumber == 0) { scanner.nextLine(); } else { String pairs = scanner.nextLine(); String[] numbers = pairs.split(" "); System.out.println("Case #" + caseNumber + ": " + a.resolve(numbers)); } caseNumber++; } } catch (FileNotFoundException e) { e.printStackTrace(); } finally { scanner.close(); } } private Integer resolve(String[] data) { int googlersNumber = Integer.parseInt(data[0]); int surprices = Integer.parseInt(data[1]); int p = Integer.parseInt(data[2]); int total = 0; ArrayList<Integer> googlers = new ArrayList<Integer>(); for (int i = 0; i < googlersNumber; i++) { googlers.add(Integer.parseInt(data[3 + i])); } // create the triadas ArrayList<Integer[]> scores = createTriada(googlers); if (surprices > 0) { // Count number surpricing Integer totalSuprising = countNumberSurprising(scores); if (totalSuprising == surprices) { // Count p total = countP(p, scores); } else { // Create missing surprises scores = createMissingSurprices(surprices - totalSuprising, p, scores, false); Integer totalSuprisingB = countNumberSurprising(scores); if (totalSuprisingB != surprices) { scores = createMissingSurprices(surprices - totalSuprising, p, scores, true); } // check p total = countP(p, scores); } } else { total = countP(p, scores); } return total; } private ArrayList<Integer[]> createTriada(ArrayList<Integer> g) { ArrayList<Integer[]> scores = new ArrayList<Integer[]>(); for (Integer number : g) { Integer[] score = new Integer[3]; for (int i = 3; i > 0; i--) { float resultPrecise = number / i; int resultInteger = number / i; int calification = 0; if (resultPrecise > resultInteger) { calification = resultInteger + 1; } else { calification = resultInteger; } score[i - 1] = calification; number = number - calification; } scores.add(score); } return scores; } private Boolean checkSurprising(Integer[] scores) { Boolean found = false; int a = scores[0] - scores[1]; int b = scores[0] - scores[2]; int c = scores[1] - scores[2]; if (a == 2 || b == 2 || c == 2) { found = true; } return found; } private int countNumberSurprising(ArrayList<Integer[]> c) { Boolean found = false; int surpriseN = 0; for (Integer[] integers : c) { if (checkSurprising(integers)) { surpriseN++; } } return surpriseN; } private ArrayList<Integer[]> createMissingSurprices(int missing, int p, ArrayList<Integer[]> s, Boolean forced) { for (int i = 0; i < s.size(); i++) { if (missing > 0) { if (!checkP(p, s.get(i)) || forced) { if (s.get(i)[1] > 0) { if ((s.get(i)[0] < p && s.get(i)[0] + 1 >= p) || forced) { Integer[] newTripleta = (Integer[])s.get(i).clone(); newTripleta[0] = newTripleta[0]+1; newTripleta[1] = newTripleta[1]-1; if (validTripleta(newTripleta)) { s.set(i, newTripleta); missing--; } } } } } } return s; } private Boolean validTripleta(Integer[] scores) { Boolean found = true; int a = scores[0] - scores[1]; int b = scores[0] - scores[2]; int c = scores[1] - scores[2]; if (a > 2 || b > 2 || c > 2) { found = false; } return found; } private Boolean checkP(int p, Integer[] scores) { Boolean found = false; for (Integer integer : scores) { if (integer >= p) { found = true; break; } } return found; } private Integer countP(int p, ArrayList<Integer[]> scores) { Integer total = 0; for (Integer[] integer : scores) { for (Integer integer2 : integer) { if (integer2 >= p) { total++; break; } } } return total; } }
0
123
A12852
A11448
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package de.hg.codejam.tasks.dance.domain; public class Case { private final byte[] totalPoints; private final int numberOfSurprisingTriplets; private final int numberOfGooglers; private final short bestResult; public Case(short bestResult, int numberOfSurprisingTriplets, byte[] totalPoints) { this.totalPoints = totalPoints; this.numberOfSurprisingTriplets = numberOfSurprisingTriplets; this.bestResult = bestResult; numberOfGooglers = totalPoints.length; } public byte[] getTotalPoints() { return totalPoints; } public int getNumberOfSurprisingTriplets() { return numberOfSurprisingTriplets; } public int getNumberOfGooglers() { return numberOfGooglers; } public short getBestResult() { return bestResult; } public static Case parse(String inputString) { String[] splitted = inputString.split(" "); int numberOfGooglers = Integer.parseInt(splitted[0]); int numberOfSurprisingTriplets = Integer.parseInt(splitted[1]); short bestResult = Short.parseShort(splitted[2]); byte[] totalPoints = new byte[numberOfGooglers]; for (int i = 0; i < numberOfGooglers; i++) totalPoints[i] = Byte.parseByte(splitted[i + 3]); return new Case(bestResult, numberOfSurprisingTriplets, totalPoints); } @Override public String toString() { String s = "CASE[Number of Googlers: " + numberOfGooglers + ", Number of surprising Scores: " + numberOfSurprisingTriplets + ", Best result at least: " + bestResult + ", Scores: "; for (int i = 0; i < totalPoints.length; i++) s += totalPoints[i] + (i < (numberOfGooglers - 1) ? " " : ""); s += "]"; return s; } }
0
124
A12852
A10630
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; import java.util.TreeSet; public class GoogleDancers { private static final List<Case> cases = new ArrayList<Case>(); public static void main(String[] args) throws IOException { // sanityCheck(); readInFile("src/resources/dancers/B-small-attempt0.in"); FileWriter fstream = new FileWriter("src/resources/dancers/B-small-attempt0.ou"); BufferedWriter out = new BufferedWriter(fstream); for (int i = 0; i < cases.size(); i++) { String msg = "Case #" + (i + 1) + ": " + cases.get(i).getResult() + "\n"; out.write(msg); System.out.print(msg); } out.close(); } protected static void readInFile(String path) throws NumberFormatException, IOException { DataInputStream in = new DataInputStream(new FileInputStream(path)); BufferedReader br = new BufferedReader(new InputStreamReader(in)); int lines = Integer.parseInt(br.readLine()); for (int i = 0; i < lines; i++) { cases.add(new Case(br.readLine())); } in.close(); } } class Case { protected int N; protected int S; protected int p; protected TreeSet<Dancer> dancers = new TreeSet<Dancer>(); public Case(String line) { StringTokenizer tokenizer = new StringTokenizer(line); N = Integer.parseInt(tokenizer.nextToken()); S = Integer.parseInt(tokenizer.nextToken()); p = Integer.parseInt(tokenizer.nextToken()); for (int i = 0; i < N; i++) { dancers.add(new Dancer(Integer.parseInt(tokenizer.nextToken()))); } } public int getResult() { System.out.println(this); int ctr = 0; for (Dancer d : dancers) { if (d.expected.max() >= p) { ctr += 1; } else if ((d.surprising != null) && (d.surprising.max() >= p) && (d.surprising.max() >= d.expected.max()) && (S > 0)) { ctr += 1; S -= 1; } System.out.println(d); } return ctr; } @Override public String toString() { return "N=" + N + ", S=" + S + ", p=" + p; } } class Dancer implements Comparable<Dancer> { Triplet expected; Triplet surprising; protected Dancer(int score) { expected = Triplet.expected(score); surprising = Triplet.surprising(score); } protected int max() { if (surprising == null) { return expected.max(); } else { return Math.max(expected.max(), surprising.max()); } } @Override public int compareTo(Dancer arg0) { if (max() < arg0.max()) { return 1; } else { return -1; } } @Override public String toString() { return expected.toString() + ", " + surprising; } } /** * "Note: this class has a natural ordering that is inconsistent with equals." */ class Triplet implements Comparable<Triplet> { protected boolean isSurprising = false; protected int t1, t2, t3; protected Triplet(int t1, int t2, int t3) { this.t1 = t1; this.t2 = t2; this.t3 = t3; isSurprising = (Math.abs(t1 - t2) >= 2) || (Math.abs(t2 - t3) >= 2) || (Math.abs(t1 - t3) >= 2); } protected static Triplet expected(int score) { if (score == 0) { return new Triplet(0, 0, 0); } else if (score % 3 == 0) { return new Triplet(score / 3, score / 3, score / 3); } else if (score % 3 == 1) { return new Triplet(score / 3, score / 3, score / 3 + 1); } else { return new Triplet(score / 3, score / 3 + 1, score / 3 + 1); } } protected static Triplet surprising(int score) { if (score < 2) { return null; } else if (score % 3 == 0) { return new Triplet(score / 3 - 1, score / 3, score / 3 + 1); } else if (score % 3 == 1) { return new Triplet(score / 3 - 1, score / 3 + 1, score / 3 + 1); } else { return new Triplet(score / 3, score / 3, score / 3 + 2); } } public int max() { return Math.max(t1, Math.max(t2, t3)); } @Override public int compareTo(Triplet arg0) { if (max() < arg0.max()) { return 1; } else { return -1; } } @Override public String toString() { return String.format("(%s, %s, %s) %s [Total=%s]", t1, t2, t3, ((isSurprising) ? "*" : " "), (t1 + t2 + t3)); } }
0
125
A12852
A12250
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codeJam; import java.io.*; import java.util.ArrayList; import java.util.Arrays; /** * Created by IntelliJ IDEA. * User: vsaurabh * Date: 4/14/12 * Time: 6:10 AM * To change this template use File | Settings | File Templates. */ public class DancingWithTheGooglers { public static void main(String args[]) throws Exception { String inputPath = "C:\\myTestProj\\src\\codeJam\\B-small-attempt0.in"; String outputPath = "C:\\myTestProj\\src\\codeJam\\B-small-attempt0.out"; DancingWithTheGooglers dwg = new DancingWithTheGooglers(); String[] str = dwg.readFromFile(inputPath); str = dwg.solution(str); dwg.writeToFile(outputPath, str); } private String[] solution(String[] str){ String[] strNew = new String[str.length-1]; for(int i=0; i<strNew.length; i++){ strNew[i] = "Case #" +(i+1)+ ": " + find(str[i + 1]); } return strNew; } public int find(String str){ String s1[] = str.split(" "); int n = Integer.parseInt(s1[0]); int s = Integer.parseInt(s1[1]); int p = Integer.parseInt(s1[2]); int y=0; int[] t = new int[n]; for(int i=0; i<n; i++){ t[i] = Integer.parseInt(s1[i+3]); } Arrays.sort(t); for(int x : t){ int max1=0; int max2=0; if(x < 2){ max1=max2=x; } else if(x==2){ max1=1; if(s > 0){ max2=2; } if(max2 >= p){ s--; } } else if(x%3 == 0){ max1 = x/3; if(s > 0 && max1<p){ max2 = x/3 + 1; if(max2 >= p){ s--; } } } else if(x%3 == 1){ max1 = x/3 + 1; } else{ max1 = x/3 + 1; if(s > 0 && (x/3 + 2) <= 10 && max1<p){ max2 = x/3 + 2; if(max2 >= p){ s--; } } } if(max1>=p || max2>=p){ y++; } } return y; } public String[] readFromFile(String inputPath) throws FileNotFoundException,IOException { FileInputStream fis = null; DataInputStream dis = null; BufferedReader br = null; ArrayList<String> strArrList = new ArrayList<String>(); try{ fis = new FileInputStream(inputPath); dis = new DataInputStream(fis); br = new BufferedReader(new InputStreamReader(dis)); String strLine; while ((strLine = br.readLine()) != null) { strArrList.add(strLine); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ try{ if (br != null) { br.close(); } if (dis != null) { dis.close(); } if (fis != null) { fis.close(); } } catch(IOException e) { e.printStackTrace(); } } return strArrList.toArray(new String[strArrList.size()]); } public void writeToFile(String outputPath, String[] strArr) { BufferedWriter bw = null; try { bw = new BufferedWriter(new FileWriter(outputPath)); for(int i=0; i<strArr.length; i++){ bw.write(strArr[i]); bw.newLine(); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (bw != null) { bw.flush(); bw.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
0
126
A12852
A10439
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class ProblemBB { static class State { boolean surprising, not; int max; State(boolean S, boolean n, int mx) { surprising = S; not = n; max = mx; } } private void solve() throws IOException { int T = nextInt(); while (T-- > 0) { int N = nextInt(); int S = nextInt(); int P = nextInt(); int[] a = new int[N]; State[] St = new State[N]; for (int i = 0; i < N; i++) a[i] = nextInt(); int res = 0; for (int i = 0; i < a.length; i++) { St[i] = new State(false, false, -1); for (int k1 = 0; k1 <= 10; k1++) { for (int k2 = 0; k2 <= 10; k2++) { for (int k3 = 0; k3 <= 10; k3++) { if (k1 + k2 + k3 == a[i]) { if (notValid(k1, k2, k3)) continue; if (surprise(k1, k2, k3)) { if (k1 >= P || k2 >= P || k3 >= P) { St[i].surprising = true; St[i].max = Math.max(St[i].max, Math.max(k1, Math.max(k2, k3))); } } else { if (k1 >= P || k2 >= P || k3 >= P) { St[i].not = true; St[i].max = Math.max(St[i].max, Math.max(k1, Math.max(k2, k3))); } } } } } } } boolean[] V = new boolean[N]; for (int i = 0; i < St.length && S > 0; i++) { if (St[i].surprising && !St[i].not) { res++; V[i] = true; S--; } } for (int i = 0; i < St.length && S > 0; i++) { if (!V[i] && St[i].surprising && St[i].not) { res++; V[i] = true; S--; } } for (int i = 0; i < St.length; i++) { if (!V[i] && St[i].not) { res++; } } pf(); pl(res); } } private boolean notValid(int k1, int k2, int k3) { if (Math.abs(k1 - k2) > 2 || Math.abs(k1 - k3) > 2 || Math.abs(k2 - k3) > 2) return true; return false; } private boolean surprise(int k1, int k2, int k3) { if (Math.abs(k1 - k2) == 2 || Math.abs(k1 - k3) == 2 || Math.abs(k2 - k3) == 2) return true; return false; } public static void main(String[] args) { new ProblemBB().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { reader = new BufferedReader(new FileReader("B.in")); // reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; // writer = new PrintWriter(System.out); writer = new PrintWriter("B.out"); solve(); reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } BigInteger nextBigInteger() throws IOException { return new BigInteger(nextToken()); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } void p(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.flush(); writer.print(objects[i]); writer.flush(); } } void pl(Object... objects) { p(objects); writer.flush(); writer.println(); writer.flush(); } int cc; void pf() { writer.printf("Case #%d: ", ++cc); writer.flush(); } }
0
127
A12852
A10382
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 DancingWithTheGooglers { /** * @param args */ public static void main(String[] args) { try { FileReader fileReader = new FileReader("B-small-attempt0.in.txt"); FileWriter fileWriter = new FileWriter("out.txt"); BufferedReader reader = new BufferedReader(fileReader); BufferedWriter writer = new BufferedWriter(fileWriter); String inputString; inputString = reader.readLine(); int cases = Integer.parseInt(inputString); for (int caseCount = 0; caseCount < cases; caseCount++) { inputString = reader.readLine(); String output = "Case #" + (caseCount+1) + ": "; String a[] = inputString.split(" "); int n = Integer.parseInt(a[0]); int s = Integer.parseInt(a[1]); int p = Integer.parseInt(a[2]); int ans = 0; int score[] = new int[n]; for (int i = 0; i < n; i++) score[i] = Integer.parseInt(a[i + 3]); Arrays.sort(score); for (int i = 0; i < n; i++) { if ((score[i] + 2) / 3 >= p) ans ++; else { if (s > 0 && score[i] >= 2 && ((score[i] + 4) / 3 >= p)) { s--; ans++; } } } output += ans; output += '\n'; writer.write(output); } reader.close(); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
128
A12852
A12020
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 googler; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("B-small-attempt0.in")))); br.readLine(); String temp; int nsurprise=0; int best; int googlers; int usedmin; int answer; int casenumber=1; FileWriter fstream = new FileWriter("output.txt"); BufferedWriter out = new BufferedWriter(fstream); while((temp=br.readLine())!=null) { String arr[] = temp.split(" "); usedmin=0; answer=0; googlers = Integer.parseInt(arr[0]); nsurprise = Integer.parseInt(arr[1]); best = Integer.parseInt(arr[2]); // System.out.println("best: " + best); // System.out.println("arrlength: " + arr.length); for(int j=arr.length-1;j>=3;j--) { int totalscore = Integer.parseInt(arr[j]); if(totalscore/3>=best) { answer++; } else if(totalscore!=0) { int eachscore = totalscore/3; int thirdscore = totalscore - eachscore*2; if(thirdscore>=best && (thirdscore-eachscore)==2 && usedmin<nsurprise) { answer++; usedmin++; } else if(thirdscore>=best && (thirdscore-eachscore)==1) { answer++; } else if(thirdscore==eachscore && usedmin<nsurprise) { int secondscore = eachscore+1; eachscore = eachscore-1; thirdscore+=1; if(thirdscore>=best) { answer++; usedmin++; } } else if(thirdscore-eachscore==2) { eachscore = eachscore+1; thirdscore = thirdscore-2; if(eachscore>=best) { answer++; } } } } out.write("Case #" + casenumber + ": " + answer); System.out.println("Case #" + casenumber + ": " + answer); out.newLine(); casenumber++; } out.close(); } }
0
129
A12852
A10876
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 sc = new Scanner(System.in); int testCases = sc.nextInt(); for (int i = 1; i <= testCases; i++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int[] points = new int[n]; int result = 0; boolean[] flags = new boolean[n]; for (int j = 0; j < n; j++) { int temp = sc.nextInt(); if (temp == 0) { points[j] = 0; flags[j] = false; } else if (temp % 3 == 0) { points[j] = temp / 3; flags[j] = true; } else if (temp % 3 == 1) { points[j] = temp / 3 + 1; flags[j] = false; } else { points[j] = temp / 3 + 1; flags[j] =true; } } for (int j = 0; j < n; j++) { if (points[j] >= p) { result += 1; flags[j] = false; } } int currentSurprising = 0; for (int j = 0; j < n && currentSurprising < s; j++) { if (flags[j] && points[j] + 1 >= p) { result += 1; currentSurprising += 1; } } System.out.println("Case #" + i + ": " + result); } } }
0
130
A12852
A11255
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Locale; import java.util.StringTokenizer; public class Solution implements Runnable { private BufferedReader in; private StringTokenizer st; private PrintWriter out; private void solve() throws IOException { int t = nextInt(); for (int test = 1; test <= t; test++) { int answer = readAndSolve(); out.println("Case #" + test + ": " + answer); } } private int readAndSolve() 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(); } int[] maxNorm = calcMaxNormal(t); int[] maxStrange = calcMaxStrange(t); int[][] a = new int[n + 1][n + 1]; for (int i = 0; i <= n; i++) { for (int j = 0; j <= n; j++) { a[i][j] = -1; } } a[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j <= i; j++) { if (a[i][j] >= 0) { int[] d = {maxNorm[i], maxStrange[i]}; for (int k = 0; k < d.length; k++) { if (d[k] >= 0) { a[i + 1][j + k] = Math.max(a[i + 1][j + k], a[i][j] + (d[k] >= p ? 1 : 0)); } } } } } return a[n][s]; } private int[] calcMaxNormal(int[] t) { int[] result = new int[t.length]; for (int i = 0; i < t.length; i++) { result[i] = calcMaxNormal(t[i]); } return result; } private int calcMaxNormal(int sum) { return (sum + 2) / 3; } private int[] calcMaxStrange(int[] t) { int[] result = new int[t.length]; for (int i = 0; i < t.length; i++) { result[i] = calcMaxStrange(t[i]); } return result; } private int calcMaxStrange(int sum) { int result; if (sum % 3 == 2) { result = sum / 3 + 2; } else { result = sum / 3 + 1; } if (result - 2 < 0 || result > 10) { return -1; } return result; } @Override public void run() { try { solve(); } catch (Throwable e) { apstenu(e); } finally { out.close(); } } private int nextInt() throws IOException { return Integer.parseInt(next()); } private String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } private void apstenu(Throwable e) { e.printStackTrace(); System.exit(1); } public Solution(String filename) { try { in = new BufferedReader(new FileReader(filename + ".in")); st = new StringTokenizer(""); out = new PrintWriter(new FileWriter(filename + ".out")); } catch (IOException e) { apstenu(e); } } public static void main(String[] args) { Locale.setDefault(Locale.US); new Solution("data").run(); } }
0
131
A12852
A12975
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package mgg.main; import mgg.problems.ProblemB; import mgg.utils.FileUtil; public class Main { // public final static String inFileName = ProblemA.EXAMPLE_IN; // public final static String outFileName = ProblemA.EXAMPLE_OUT; // public final static String inFileName = ProblemA.A_SMALL_IN; // public final static String outFileName = ProblemA.A_SMALL_OUT; // public final static String inFileName = ProblemB.EXAMPLE_IN; // public final static String outFileName = ProblemB.EXAMPLE_OUT; public final static String inFileName = ProblemB.B_SMALL_IN; public final static String outFileName = ProblemB.B_SMALL_OUT; // public final static String inFileName = ProblemB.B_LARGE_IN; // public final static String outFileName = ProblemB.B_LARGE_OUT; // public final static String inFileName = ProblemC.EXAMPLE_IN; // public final static String outFileName = ProblemC.EXAMPLE_OUT; // public final static String inFileName = ProblemC.C_SMALL_IN; // public final static String outFileName = ProblemC.C_SMALL_OUT; // public final static String inFileName = ProblemC.C_LARGE_IN; // public final static String outFileName = ProblemC.C_LARGE_OUT; public final static String delim = " "; public static void main(String[] args) { FileUtil util = new FileUtil(inFileName, outFileName); String firstLine = util.getLine(); //System.out.println("FIRST LINE: '" + firstLine + "'"); int numLines = Integer.parseInt(firstLine); //System.out.println("NUMBER OF LINES: " + numLines); String result; for (int i = 1; i <= numLines; i++) { //System.out.println("----------------------------------------------------"); System.out.println("Case #" + i); // result = ProblemA.solve(util); result = ProblemB.solve(util); // result = ProblemC.solve(util); // result = ProblemD.solve(util); util.printLine(i, result); } util.closeFiles(); } }
0
132
A12852
A10400
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; public class DancingWithThegooglers { private static Map<Integer, Points> pointMap = new HashMap<Integer, Points>(); public static void main(String[] args) { pointMap.put(0, new Points(0, 0)); pointMap.put(1, new Points(1, 1)); pointMap.put(2, new Points(4, 2)); pointMap.put(3, new Points(7, 5)); pointMap.put(4, new Points(10, 8)); pointMap.put(5, new Points(13, 11)); pointMap.put(6, new Points(16, 14)); pointMap.put(7, new Points( 19, 17)); pointMap.put(8, new Points( 22, 20)); pointMap.put(9, new Points( 25, 23)); pointMap.put(10, new Points( 28, 26)); try { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String str = ""; // Testcases str = in.readLine(); int cases = Integer.valueOf(str); List<String> output = new ArrayList<String>(); for(int i = 1; i <= cases; i++){ str = in.readLine(); String[] numbers = str.split(" "); int googlers = Integer.valueOf(numbers[0]); int surprising = Integer.valueOf(numbers[1]); int points = Integer.valueOf(numbers[2]); Integer[] results = new Integer[googlers]; for(int j = 3; j < 3 + googlers; j++){ results[j - 3] = Integer.valueOf(numbers[j]); } // sort the shit out of it Arrays.sort(results, Collections.reverseOrder()); output.add("Case #" + i+ ": " + calculate(googlers, surprising, points, results)); } for(String outputLine : output){ System.out.println(outputLine); } } catch (IOException e) { } } private static String calculate(int googlers, int surprising, int points, Integer[] results) { String res = googlers + " : " + surprising + " : " + points + " anz: " + results.length + " first: " + results[0] + " last: " + results[results.length - 1]; Points p = pointMap.get(points); int result = 0; int surleft = surprising; for(int i = 0; i < results.length; i++){ if(results[i] >= p.minPoints){ result++; continue; } if(results[i] >= p.surPoints && surleft > 0) { result++; surleft--; continue; } break; } return String.valueOf(result); } }
0
133
A12852
A13064
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package qualification_round; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.*; public class DancingWithGooglers { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("input2.txt"))); int inputSize = Integer.parseInt(br.readLine()); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output2.txt"))); for(int x = 1 ; x <= inputSize ; x++ ) { String line = br.readLine(); String[] lineArray = line.split(" "); int n = Integer.parseInt(lineArray[0]); int s = Integer.parseInt(lineArray[1]); int p = Integer.parseInt(lineArray[2]); int array[] = new int[n]; for (int i = 0 ; i< n ; i++) { array[i] = Integer.parseInt(lineArray[i + 3]); } bw.write("Case #"+x+": "+findP(n,s,p,array)+"\n"); } bw.flush(); bw.close(); br.close(); int j[] = {15, 13, 11}; int i = findP(3,1,5,j); System.out.println(i); } public static int findP(int numberOfGooglers, int surprisingTriplets, int p, int totalScores[]) { int answer = 0; int border0 = 0; int border1 = 0 ; int border2 = 0; int totalScore, best; if (p == 0) { return numberOfGooglers; } else { for(int i = 0 ; i < numberOfGooglers ; i ++) { totalScore = totalScores[i]; if (totalScore == 0) {/*do nothing*/} else if( totalScore % 3 == 0 ) { best = totalScore / 3; if (best >= p) answer += 1; else if(best == (p-1) ) border0 += 1; } else if( totalScore % 3 == 1 ) { best = ( totalScore + 2) / 3; if (best >= p) answer += 1; else if(best == (p-1) ) border1 += 1; } else { best = (totalScore + 1) / 3; if (best >= p) answer += 1; else if(best == (p-1) ) border2 += 1; } } } if(border0 >= surprisingTriplets) { border0 -= surprisingTriplets; answer += surprisingTriplets; surprisingTriplets = 0; } else { answer += border0; surprisingTriplets -= border0; border0 = 0; } if(border2 >= surprisingTriplets) { border2 -= surprisingTriplets; answer += surprisingTriplets; surprisingTriplets = 0; } else { answer += border2; surprisingTriplets -= border2; border2 = 0; } return answer; } }
0
134
A12852
A12314
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; public class dancing { private void go() throws Exception{ File infile = new File("B-small-attempt0.in"); BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); int num_of_cases = Integer.parseInt(br.readLine()); for(int i=1;i<=num_of_cases;i++){ String cur_str = br.readLine(); StringTokenizer stk = new StringTokenizer(cur_str); int num_of_emp = Integer.parseInt(stk.nextToken()); int num_of_surprise = Integer.parseInt(stk.nextToken()); int req_num = Integer.parseInt(stk.nextToken()); int surprise_not_needed = req_num*3 - 2; int surprise_needed = Math.max(req_num*3 -2 -2,1); int satisifed = 0; int scores[] = new int[num_of_emp]; for(int k=0;k<num_of_emp;k++) scores[k] = Integer.parseInt(stk.nextToken()); for(int k=0;k<num_of_emp;k++){ if(scores[k] >= surprise_not_needed){ satisifed++; continue; } else{ if(scores[k] >= surprise_needed && num_of_surprise>0){ satisifed++; num_of_surprise--; continue; } else continue; } } System.out.println("Case #"+i+": "+satisifed); } } public static void main(String[] args){ try { new dancing().go(); } catch (Exception ex) { ex.printStackTrace(); } } }
0
135
A12852
A10519
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; import java.util.StringTokenizer; public class habala { public static void main(String[] args) throws Exception { String s2; BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("input.in"))); PrintWriter out = new PrintWriter("output.out"); int testCases = Integer.parseInt(in.readLine()); for (int i = 1; i <= testCases; i++) { String s = in.readLine(); int Googlers, surprizes ,p; int winers = 0; StringTokenizer st = new StringTokenizer (s); s2 = ""; s2 = st.nextToken(); Googlers = Integer.parseInt(s2); surprizes = Integer.parseInt(st.nextToken()); p = Integer.parseInt(st.nextToken()); int minn = (3*p-2) < p ? p : (3*p-2) ; int mins = (3*p-4) < p? p : (3*p-4) ; for(int j = 1 ; j <= Googlers ; j++) { int scoure = Integer.parseInt(st.nextToken()); if (scoure >= minn ) winers++; else if(scoure >= mins && surprizes > 0){ winers++; surprizes--; } } out.println("Case #"+i+": "+winers); } out.close(); in.close(); } }
0
136
A12852
A12515
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 gdwg; import java.io.*; /** * * @author alexho */ public class GDWG { private static int [] result; private void readInput (String infn) throws FileNotFoundException, IOException { String line = null; int testCases = 0; BufferedReader bufRdr = null; String delimiter = " "; File file = new File(infn); bufRdr = new BufferedReader(new FileReader(file)); testCases = Integer.valueOf(bufRdr.readLine()); GDWG.result = new int [testCases]; int index=0; while ( (line = bufRdr.readLine()) != null ) { String [] temp; temp = line.split(delimiter); this.computeMax(temp, index); index++; } bufRdr.close(); } private void output (String outfn) throws IOException { PrintWriter out = new PrintWriter(new FileWriter(outfn)); for (int i=0;i<GDWG.result.length;i++) { out.println("Case #"+(i+1)+": "+GDWG.result[i]); } out.close(); } private void computeMax (String [] tempS, int index) { int N,S,p, max=0,Nti; N = Integer.valueOf(tempS[0]); S = Integer.valueOf(tempS[1]); p = Integer.valueOf(tempS[2]); for (int i=3;i<tempS.length;i++) { Nti = Integer.valueOf(tempS[i]); // 1st case if (p == 0) { max++; } else if (p > Nti) { // do nothing } else if (Nti/3 >= p) { max++; } else if (p - Nti/3 <=2 && p - Nti/3 > 0 ) { if ( 3*p == Nti) { max++; } else if (3*p+1 == Nti) { max++; } else if (3*p-1 == Nti) { max++; } else if (3*p-2 == Nti) { max++; } else if (3*p+2 == Nti) { max++; } else if (3*p-3 == Nti && S > 0) { S--; max++; } else if (3*p+3 == Nti && S > 0) { S--; max++; } else if (3*p-4 == Nti && S > 0) { S--; max++; } else if (3*p+4 == Nti && S > 0) { S--; max++; } } else { } } GDWG.result[index]=max; } public GDWG () { } /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { String infn = args[0]; String outfn = args[1]; GDWG gdwg = new GDWG(); gdwg.readInput(infn); gdwg.output(outfn); for (int i=0;i<GDWG.result.length;i++) { System.out.println(GDWG.result[i]); } } }
0
137
A12852
A10880
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.nigel.codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; public class GoogleDance { public static int[][] gudjedScores(int a){ int div=a/3; int[][] tempArray=new int[1][3]; if(a==0) { tempArray[0][0]=0; tempArray[0][1]=0; tempArray[0][2]=0; } else {tempArray[0][0]=div; tempArray[0][1]=div; tempArray[0][2]=div; if(tempArray[0][0]+tempArray[0][1]+tempArray[0][2]==a){} else {tempArray[0][0]=tempArray[0][0]+1;} if(tempArray[0][0]+tempArray[0][1]+tempArray[0][2]==a){} else {tempArray[0][1]=tempArray[0][1]+1;} } return tempArray; } public static int[][] supriseArray(int a,int b,int[][] c){ int surprisesAllowed=a; int bestNo=b; int [][] googlerScores=c; if(surprisesAllowed==0 || bestNo==0 || bestNo==1) return googlerScores; else{ int surprisesDone=0; for(int i=0;i<googlerScores.length;i++){ int[][] tempArray=new int[1][3]; tempArray[0][0]=googlerScores[i][0]; tempArray[0][1]=googlerScores[i][1]; tempArray[0][2]=googlerScores[i][2]; int flag=0; if(tempArray[0][0]>=bestNo) {flag=1;} else if(tempArray[0][1]>=bestNo) {flag=1;} else if(tempArray[0][2]>=bestNo) {flag=1;} else if(flag==0){ tempArray[0][0]=tempArray[0][0]+1; tempArray[0][1]=tempArray[0][1]-1; if(tempArray[0][0]-tempArray[0][1]>2 || tempArray[0][0]-tempArray[0][1]<-2 || tempArray[0][0]-tempArray[0][2]>2 || tempArray[0][0]-tempArray[0][2]<-2){ tempArray[0][0]=tempArray[0][0]-1; tempArray[0][1]=tempArray[0][1]+1; } else{ if(tempArray[0][0]==bestNo) {flag=1;} else {tempArray[0][0]=tempArray[0][0]-1; tempArray[0][1]=tempArray[0][1]+1; } } if(flag==0){ tempArray[0][0]=tempArray[0][0]+1; tempArray[0][1]=tempArray[0][2]-1; if(tempArray[0][0]-tempArray[0][1]>2 || tempArray[0][0]-tempArray[0][1]<-2 || tempArray[0][0]-tempArray[0][2]>2 || tempArray[0][0]-tempArray[0][2]<-2){ tempArray[0][0]=tempArray[0][0]-1; tempArray[0][2]=tempArray[0][2]+1; } else{ if(tempArray[0][0]==bestNo) flag=1; else {tempArray[0][0]=tempArray[0][0]-1; tempArray[0][2]=tempArray[0][2]+1;} } } if(flag==0){ tempArray[0][0]=tempArray[0][0]+2; tempArray[0][1]=tempArray[0][1]-1; tempArray[0][2]=tempArray[0][2]-1; if(tempArray[0][0]-tempArray[0][1]>2 || tempArray[0][0]-tempArray[0][1]<-2 || tempArray[0][0]-tempArray[0][2]>2 || tempArray[0][0]-tempArray[0][2]<-2){ tempArray[0][0]=tempArray[0][0]-2;tempArray[0][1]=tempArray[0][1]+1; tempArray[0][2]=tempArray[0][2]+1; } else{ if(tempArray[0][0]==bestNo) flag=1; else{ tempArray[0][0]=tempArray[0][0]-2; tempArray[0][1]=tempArray[0][1]+1; tempArray[0][2]=tempArray[0][2]+1;} } } //---------------------------------- if(flag==0){ tempArray[0][1]=tempArray[0][1]+1; tempArray[0][0]=tempArray[0][0]-1; if(tempArray[0][1]-tempArray[0][0]>2 || tempArray[0][1]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ tempArray[0][1]=tempArray[0][1]-1;tempArray[0][0]=tempArray[0][0]+1; } else{ if(tempArray[0][1]==bestNo) flag=1; else {tempArray[0][1]=tempArray[0][1]-1;tempArray[0][0]=tempArray[0][0]+1;} } } if(flag==0){ tempArray[0][1]=tempArray[0][1]+1; tempArray[0][2]=tempArray[0][2]-1; if(tempArray[0][1]-tempArray[0][0]>2 || tempArray[0][1]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ tempArray[0][1]=tempArray[0][1]-1;tempArray[0][2]=tempArray[0][2]+1; } else{ if(tempArray[0][1]==bestNo) flag=1; else {tempArray[0][1]=tempArray[0][1]-1;tempArray[0][2]=tempArray[0][2]+1;} } } if(flag==0){ tempArray[0][1]=tempArray[0][1]+2; tempArray[0][0]=tempArray[0][0]-1;tempArray[0][2]=tempArray[0][2]-1; if(tempArray[0][1]-tempArray[0][0]>2 || tempArray[0][1]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ tempArray[0][1]=tempArray[0][1]-2; tempArray[0][0]=tempArray[0][0]+1;tempArray[0][2]=tempArray[0][2]+1; } else{ if(tempArray[0][1]==bestNo) flag=1; else {tempArray[0][1]=tempArray[0][1]-2;tempArray[0][0]=tempArray[0][0]+1;tempArray[0][2]=tempArray[0][2]+1;} } } //---------------------------------- if(flag==0){ tempArray[0][2]=tempArray[0][2]+1; tempArray[0][0]=tempArray[0][0]-1; if(tempArray[0][2]-tempArray[0][0]>2 || tempArray[0][2]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1; } else{ if(tempArray[0][2]==bestNo) flag=1; else {tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1;} } } if(flag==0){ tempArray[0][2]=tempArray[0][2]+1; tempArray[0][1]=tempArray[0][1]-1; if(tempArray[0][2]-tempArray[0][0]>2 || tempArray[0][2]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ tempArray[0][2]=tempArray[0][2]-1;tempArray[0][1]=tempArray[0][1]+1; } else{ if(tempArray[0][2]==bestNo) flag=1; else {tempArray[0][2]=tempArray[0][2]-1;tempArray[0][1]=tempArray[0][1]+1;} } } if(flag==0){ tempArray[0][2]=tempArray[0][2]+1;tempArray[0][0]=tempArray[0][0]-1;tempArray[0][1]=tempArray[0][1]-1; if(tempArray[0][2]-tempArray[0][0]>2 || tempArray[0][2]-tempArray[0][0]<-2 || tempArray[0][1]-tempArray[0][2]>2 || tempArray[0][1]-tempArray[0][2]<-2){ tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1;tempArray[0][1]=tempArray[0][1]+1; } else{ if(tempArray[0][2]==bestNo) flag=1; else {tempArray[0][2]=tempArray[0][2]-1;tempArray[0][0]=tempArray[0][0]+1;tempArray[0][1]=tempArray[0][1]+1;} } } if(flag==1) surprisesDone=surprisesDone+1; } googlerScores[i][0]=tempArray[0][0]; googlerScores[i][1]=tempArray[0][1]; googlerScores[i][2]=tempArray[0][2]; if(surprisesDone==surprisesAllowed){return googlerScores;} } } return googlerScores; } public static int checkResult(){ return 0; } public static void main(String args[]) throws Exception{ BufferedReader reader = new BufferedReader(new FileReader(new File("E:/DOWNLOADS/B-small-attempt3.in"))); BufferedWriter writer = new BufferedWriter(new FileWriter(new File("E:/DOWNLOADS/B-small-attempt3.out"))); String line = reader.readLine(); int k = Integer.parseInt(line); int count=1; for(int i = 0 ; i < k ; i ++){ line = reader.readLine(); // System.out.println("11"); //line=line.replaceAll(" ",""); String[] newLine=line.split(" "); //char[] cArray = line.toCharArray(); System.out.println(count); count++; int noOfGooglers=Integer.parseInt(newLine[0]); System.out.println("noOfGooglers "+noOfGooglers); int surprises=Integer.parseInt(newLine[1]); int bestNo=Integer.parseInt(newLine[2]); int[] totalScores=new int[noOfGooglers]; for(int j=3,n=0;j<newLine.length;j++,n++){ totalScores[n]=Integer.parseInt(newLine[j]); System.out.println("totalScores "+totalScores[n]); } int [][] googlerScores=new int[noOfGooglers][3]; for(int j=0;j<totalScores.length;j++){ int[][] tempArray=gudjedScores(totalScores[j]); googlerScores[j][0]=tempArray[0][0]; googlerScores[j][1]=tempArray[0][1]; googlerScores[j][2]=tempArray[0][2]; System.out.println(googlerScores[j][0]+""+googlerScores[j][1]+""+googlerScores[j][2]); } googlerScores=supriseArray(surprises,bestNo,googlerScores); int result=0; for(int h=0;h<googlerScores.length;h++){ System.out.println(googlerScores[h][0]+""+googlerScores[h][1]+""+googlerScores[h][2]); if(googlerScores[h][0]>=bestNo || googlerScores[h][0]>=bestNo || googlerScores[h][0]>=bestNo ){ result++; } } int Case=i+1; writer.write("Case #" + Case + ": "); writer.write(Integer.toString(result)); if(Case==k){} else{writer.write("\n"); } } reader.close(); writer.close(); } }
0
138
A12852
A12327
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; public class DancingWithTheGooglers { static final String input_path = "data/input.b.txt"; private static int solve(int N, int S, int p, int[] t) { int ans = 0; int candidate = 0; for (int i = 0; i < N; i++) { int point = t[i]; int base = point / 3; int residule = point % 3; if (base >= p) { ans += 1; continue; } if (base == p - 1) { if (residule > 0) ans += 1; else if (base > 0) candidate += 1; continue; } if (base == p - 2 && residule == 2) candidate += 1; } if (S >= candidate) ans += candidate; else ans += S; // System.out.println(String.format("%d\t%d", ans, candidate)); return ans; } /** * Good luck, Wash :) * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader(input_path)); String intext = in.readLine(); int T = Integer.parseInt(intext); for (int caseIter = 0; caseIter < T; caseIter ++) { intext = in.readLine(); System.out.print(String.format("Case #%d: ", caseIter + 1)); String[] parts = intext.split(" "); int N = Integer.parseInt(parts[0]); int S = Integer.parseInt(parts[1]); int p = Integer.parseInt(parts[2]); int[] t = new int[N]; for (int i = 0; i < N; i ++) t[i] = Integer.parseInt(parts[3 + i]); System.out.println(solve(N,S,p,t)); } in.close(); } }
0
139
A12852
A11546
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 B { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try{ FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; strLine = br.readLine(); int T = Integer.valueOf(strLine); // System.out.println(T); int N[] = new int[T]; int S[] = new int[T]; int p[] = new int[T]; int t[][] = new int[T][100]; int j = 0; while ((strLine = br.readLine()) != null) { // N[j]=Integer.valueOf(strLine); // strLine = br.readLine(); String[] ss = strLine.split(" "); // System.out.println(N[j]+ "-"); N[j] = Integer.valueOf(ss[0]); S[j] = Integer.valueOf(ss[1]); p[j] = Integer.valueOf(ss[2]); for (int i = 0; i < N[j]; i++) { t[j][i] = Integer.valueOf(ss[i+3]); // System.out.println(a[j][i]); } j++; } for (int k=0; k<T; k++) { int possible = 0; int count = 0; int res=0; for (int i=0; i<N[k];i++){ Float f = new Float(t[k][i])/3; int rounded = Math.round(f); if (t[k][i] % 3 == 1){ if (rounded+1 >= p[k]) count++; } else{ if (rounded >= p[k]) count++; else if ((rounded+1 >= p[k]) && (t[k][i]>0)) possible ++; } if (possible < S[k]) { res = count + possible; } else { res = count + S[k]; } } System.out.print("Case #"); System.out.print(k+1); System.out.print(": "); System.out.print(res); System.out.println(); } //Close the input stream in.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
140
A12852
A11713
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; /** * Created by IntelliJ IDEA. * User: tanin * Date: 4/14/12 * Time: 9:22 AM * To change this template use File | Settings | File Templates. */ public class Dancing { public static void main(String[] args) throws Exception { String filename = "dancing"; String outFilename = filename + "_out"; FileInputStream fis = new FileInputStream(new File(filename)); Scanner input = new Scanner(new BufferedInputStream(fis)); FileOutputStream fOut = new FileOutputStream(new File(outFilename)); BufferedOutputStream bOut = new BufferedOutputStream(fOut); DataOutputStream out = new DataOutputStream(bOut); int numCases = input.nextInt(); input.nextLine(); for (int caseNumber=0;caseNumber<numCases;caseNumber++) { int n = input.nextInt(); int s = input.nextInt(); int p = input.nextInt(); int[] g = new int[n]; for (int i=0;i<n;i++) { g[i] = input.nextInt(); } out.writeBytes("Case #" + (caseNumber+1) + ": " + solve(n, s, p, g) + "\n"); } out.flush(); out.close(); bOut.flush(); bOut.close(); fOut.flush(); fOut.close(); } public static int solve(int n, int s, int p, int[] g) { int count = 0; for (int i=0;i<n;i++) { int maxUnsurprised = -1; if ((g[i]%3) == 0) maxUnsurprised = g[i] / 3; else if ((g[i]%3) == 1) maxUnsurprised = (g[i] / 3) + 1; else if ((g[i]%3) == 2) maxUnsurprised = (g[i] / 3) + 1; if (maxUnsurprised >= p) { count++; } else { int maxSurprised = -1; if ((g[i]%3) == 0 && ((g[i] / 3) - 1) >= 0) maxSurprised = (g[i] / 3) + 1; else if ((g[i]%3) == 1) maxSurprised = (g[i] / 3) + 1; else if ((g[i]%3) == 2) maxSurprised = (g[i] / 3) + 2; if (maxSurprised >= p && s > 0) { count++; s--; } } } return count; } }
0
141
A12852
A12186
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
//Edwin Lunando template for online algorithm contest import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.StringTokenizer; public class Main { // class node implements Comparable<node> { // // public int a; // public int b; // // public int compareTo(node a) { // if (a.b == this.b) { // return a.a - this.a; // } else { // return a.b - this.b; // } // } // // public node(int a, int b) { // this.a = a; // this.b = b; // } // } private void solve() throws IOException { int n = nextInt(); for (int x = 0; x < n; x++) { int count = 0; int N = nextInt(), s = nextInt(), p = nextInt(); int[] t = new int[N]; for (int y = 0; y < N; y++) { t[y] = nextInt(); if (t[y] >= p * 3) { count++; } else if (t[y] >= (p * 3) - 2 && t[y] != 0) { count++; } else if (t[y] >= (p * 3) - 4 && s > 0 && t[y] != 0 ) { count++; s--; } } System.out.println("Case #" + (int) (x + 1) + ": " + count); } } public static void main(String[] args) { try { br = new BufferedReader(new InputStreamReader(System.in)); //br = new BufferedReader(new FileReader("input.txt")); out = new PrintWriter(System.out); //out = new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))); new Main().solve(); out.close(); } catch (Throwable e) { System.out.println(e); System.exit(239); } } static BufferedReader br; static StringTokenizer st; static PrintWriter out; static String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = br.readLine(); if (line == null) { return null; } st = new StringTokenizer(line); } return st.nextToken(); } static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } static long nextLong() throws IOException { return Long.parseLong(nextToken()); } static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } static int[] nextIntArray(int n) throws IOException { int[] temp = new int[n]; for (int x = 0; x < n; x++) { temp[x] = nextInt(); } return temp; } static long[] nextLongArray(int n) throws IOException { long[] temp = new long[n]; for (int x = 0; x < n; x++) { temp[x] = nextLong(); } return temp; } static String[] nextArray(int n) throws IOException { String[] temp = new String[n]; for (int x = 0; x < n; x++) { temp[x] = nextToken(); } return temp; } }
0
142
A12852
A10694
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codeJam2012; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.RandomAccessFile; public class B { public static void main(String[] args) throws IOException { RandomAccessFile raf = new RandomAccessFile("input.in", "r"); PrintWriter raf2 = new PrintWriter("output.txt"); int testCases = Integer.parseInt(raf.readLine()); for(int i=0;i<testCases;i++) { String[] caseI = raf.readLine().split(" "); int N = Integer.parseInt(caseI[0]); int S = Integer.parseInt(caseI[1]); int p = Integer.parseInt(caseI[2]); int least = 3*p; int counter=0; for(int j=0;j<N;j++) { int currentScore = Integer.parseInt(caseI[j+3]); if(currentScore >= least - 2) counter++; else if(currentScore >= least - 4 && least-4>0 && S > 0) { counter++; S--; } } raf2.write("Case #"+(i+1)+": "+counter); if(i!=testCases-1) raf2.println(); } raf.close(); raf2.close(); } }
0
143
A12852
A11249
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/** * Copyright 2012 Christopher Schmitz. All Rights Reserved. */ package com.isotopeent.codejam.lib; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class InputReader<T> extends BufferedReader { private final InputConverter<T> converter; public InputReader(File file, InputConverter<T> converter) throws FileNotFoundException { super(new FileReader(file)); this.converter = converter; } public T readInput() { String data; try { do { data = readLine(); if (data == null) { return null; } } while (converter.readLine(data)); } catch (IOException e) { // do nothing } return converter.generateObject(); } }
0
144
A12852
A11258
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; public class DancingWiththeGooglers { /** * @param args * @throws Exception */ public static void main(String[] args) throws Exception { // TODO Auto-generated method stub System.setIn(new FileInputStream("dancing.in")); BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); int Case = Integer.parseInt(bf.readLine()); int cCase = 1; while(Case > 0){ String line = bf.readLine(); String [] parts = line.trim().split("[ ]+"); int [][] t = new int[Integer.parseInt(parts[0])][2]; int S = Integer.parseInt(parts[1]); int p = Integer.parseInt(parts[2]); for (int i = 3; i < parts.length; i++){ int sum = Integer.parseInt(parts[i]); if(sum == 0){ t[i-3][0] = 0; t[i-3][1] = 0; } else if(sum == 1){ t[i-3][0] = 1; t[i-3][1] = 1; } else if(sum == 2){ t[i-3][0] = 1; t[i-3][1] = 2; } else{ int caso = 0; if((sum-1)%3 == 0)caso = 1; double h = sum/3.0; int x = (int) Math.ceil(h); t[i-3][0] = x; if(caso == 1 || x == 10)t[i-3][1] = x; else t[i-3][1] = x+1; } } int count = 0; for(int i = 0; i < Integer.parseInt(parts[0]);i++){ if(t[i][0] >= p)count++; else if(t[i][1] >= p && S>0){ S--; count++; } } System.out.println("Case #"+cCase+": "+count); cCase++; Case--; } } }
0
145
A12852
A11892
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.StringTokenizer; public class Dancers { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader(new File("B-small-attempt0.in"))); BufferedWriter out = new BufferedWriter(new FileWriter(new File("output0"))); String line = in.readLine(); int T = Integer.parseInt(line); for(int i = 0; i < T && in.ready(); i++) { line = in.readLine(); StringTokenizer tokenizer = new StringTokenizer(line); int N = Integer.parseInt(tokenizer.nextToken()); int S = Integer.parseInt(tokenizer.nextToken()); int p = Integer.parseInt(tokenizer.nextToken()); int numReg = 0; int numSurprise = 0; int min = 3*p - 2; int max = 3*p + 2; int sMin = min - 2; int sMax = max + 2; for(int j = 0; j < N && tokenizer.hasMoreTokens(); j++) { int score = Integer.parseInt(tokenizer.nextToken()); if (score == 0) { if (p == 0) numReg++; continue; } if (score == 1) { if (p <= 1) numReg++; continue; } if (score >= min) { numReg++; continue; } if (score >= sMin) numSurprise++; } numSurprise = Math.min(numSurprise, S); int num = numReg + numSurprise; System.out.println("Case #" + (i+1) + ": " + num + ", reg: " + numReg + ", surp: " + numSurprise); out.write("Case #" + (i+1) + ": " + num); out.newLine(); } out.close(); } }
0
146
A12852
A10474
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.File; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import com.google.common.base.Charsets; import com.google.common.io.Closeables; import com.google.common.io.Files; public class Dancing { public static final int MIN_SCORE = 0, MAX_SCORE = 10, COUNT_JUDGES = 3; private static Map<Integer, Set<Triplet>> scoreCache = createScoreCache(); public static void main(String[] args) throws IOException { File cwd = new File("C:\\Users\\TaG\\workspace\\CodeJam\\"); File inputFile = new File(cwd, "input.txt"); File outputFile = new File(cwd, "output.txt"); if (outputFile.exists()) outputFile.delete(); PrintStream out = null; try { out = new PrintStream(outputFile); List<String> lines = Files.readLines(inputFile, Charsets.UTF_8); int cases = Integer.parseInt(lines.remove(0)); int caseNo = 1; for (String line : lines) { String[] tokens = line.split("\\s"); List<String> list = new ArrayList<String>(Arrays.asList(tokens)); int nDancers = Integer.parseInt(list.remove(0)); int surprising = Integer.parseInt(list.remove(0)); int p = Integer.parseInt(list.remove(0)); int max = 0; while (!list.isEmpty()) { int score = Integer.parseInt(list.remove(0)); if (surprising > 0 && shouldApplySurprise(score, p)) { surprising--; max++; continue; } int high = calcHighestScore(score); if (high >= p) { max++; } } out.printf("Case #%d: %d\n", caseNo, max); System.out.printf("Case #%d: %d\n", caseNo, max); caseNo++; } // end for-each lines } finally { Closeables.closeQuietly(out); } } private static boolean shouldApplySurprise(int total, int p) { Set<Triplet> set = scoreCache.get(total); for (Triplet triplet : set) { if (!triplet.isSurprising() && triplet.getHigh() >= p) { return false; } } for (Triplet triplet : set) { if (triplet.isSurprising() && triplet.getHigh() >= p) { return true; } } return false; } private static int calcHighestScore(int total) { Set<Triplet> set = scoreCache.get(total); int max = 0; for (Triplet triplet : set) { if (!triplet.isSurprising()) { max = Math.max(max, triplet.getHigh()); } } return max; } public static Map<Integer, Set<Triplet>> createScoreCache() { Map<Integer, Set<Triplet>> list = new HashMap<Integer, Set<Triplet>>(); for (int score = MIN_SCORE; score <= (MAX_SCORE * COUNT_JUDGES); score++) { Set<Triplet> set = calcPossibleCombos(score); list.put(score, set); // System.out.println(score + ":"); // for (Triplet triplet : set) { // System.out.println(triplet.getLow() + ", " + triplet.getMid() // + ", " + triplet.getHigh() + " ? " + triplet.isSurprising()); // } } return list; } private static Set<Triplet> calcPossibleCombos(int score) { // I am too tired to think this through // so I'll brute-force it Set<Triplet> set = new HashSet<Triplet>(); for (int a = MIN_SCORE; a <= MAX_SCORE; a++) { for (int b = MIN_SCORE; b <= MAX_SCORE; b++) { for (int c = MIN_SCORE; c <= MAX_SCORE; c++) { int total = a + b + c; if (total == score) { Triplet triplet = new DefaultTriplet(a, b, c); if (triplet.isPossible()) { set.add(triplet); } } } } } return set; } private static interface Triplet { int getLow(); int getMid(); int getHigh(); boolean isSurprising(); boolean isPossible(); } private static class DefaultTriplet implements Triplet { private int[] ints; private boolean isSurprising, isPossible; public DefaultTriplet(int score1, int score2, int score3) { super(); ints = new int[] { score1, score2, score3 }; Arrays.sort(ints); int diff = ints[2] - ints[0]; switch (diff) { case 2: isSurprising = true; case 1: case 0: isPossible = true; break; default: isPossible = false; } } private void validate() { if (!isPossible()) throw new IllegalStateException("this should never happen"); } @Override public int getLow() { validate(); return ints[0]; } @Override public int getMid() { validate(); return ints[1]; } @Override public int getHigh() { validate(); return ints[2]; } @Override public boolean isSurprising() { validate(); return this.isSurprising; } @Override public boolean isPossible() { return this.isPossible; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + Arrays.hashCode(ints); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; DefaultTriplet other = (DefaultTriplet) obj; if (!Arrays.equals(ints, other.ints)) return false; return true; } } }
0
147
A12852
A12347
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; import java.io.*; class Caso{ int n; int s; int p; int[]t; public void leer(Scanner s){ n=s.nextInt(); this.s=s.nextInt(); p=s.nextInt(); t=new int[n]; for(int i=0;i<t.length;i++){ t[i]=s.nextInt(); } } public Caso(){ } public String obtenerRespuesta(){ int ps=0; int mx=0; int c=s; for(int i=0;i<t.length;i++){ ps=(int)Math.ceil(t[i]/3.); if(ps>=p){ mx++; }else{ if(t[i]<=28&&t[i]>1&&c>0){ if(ps+1>=p&&t[i]%3!=1){ mx++; c--; } } } } return mx+""; } } public class Caso1{ public void iniciar(){ Scanner s=null; PrintStream ps=null; try{ ps=new PrintStream(new FileOutputStream(new File("output.txt"))); s=new Scanner(new FileReader("input.txt")); StringBuffer entrada=new StringBuffer(); while(s.hasNextLine()){ entrada.append(s.nextLine()+"\n"); } s=new Scanner(entrada+""); }catch(Exception e){ e.printStackTrace(); } int numeroCasos=s.nextInt(); Caso[]casos=new Caso[numeroCasos]; for(int i=0;i<numeroCasos;i++){ casos[i]=new Caso(); } for(int k=0;k<numeroCasos;k++){ casos[k].leer(s); } for(int i=0;i<casos.length;i++){ ps.println("Case #"+(i+1)+": "+casos[i].obtenerRespuesta()); } } public static void main(String[]args){ (new Caso1()).iniciar(); } }
0
148
A12852
A10097
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.math.*; public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; try { inputStream = new FileInputStream("a.in"); outputStream = new FileOutputStream("a.out"); } catch (FileNotFoundException e) { System.err.println("File not found"); return; } InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solver solver = new Solver(); solver.solve(in, out); out.close(); } } class Solver { public void solve(InputReader in, PrintWriter out) { int t = in.nextInt(); for (int i = 0; i < t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int ans = 0; for (int j = 0; j < n; j++) { int a = in.nextInt(); if (a == 0) { if (p == 0) ans++; continue; } if ((a + 2) / 3 >= p) { ans++; continue; } if (s > 0) if (a % 3 != 1 && ((a + 2) / 3 + 1 >= p)) { ans++; s--; } } out.print("Case #"); out.print(i + 1); out.print(": "); out.println(ans); } } } class InputReader { private BufferedReader reader; private StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public long nextLong() { return Long.parseLong(next()); } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } }
0
149
A12852
A10055
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package google.code.jam.dancing.with.the.googlers; import java.io.*; import java.util.ArrayList; /** * * @author Lucas */ public class Utils { public ArrayList<ArrayList> parse(String file) { BufferedReader in = null; ArrayList<ArrayList> list = new ArrayList<ArrayList>(); int size; try { in = new BufferedReader(new InputStreamReader(new DataInputStream(new FileInputStream(file)))); size = Integer.parseInt(in.readLine()); for (int n = 0; n < size; n++) { String[] stringCases = in.readLine().split("\\s+"); ArrayList<Integer> cases = new ArrayList<Integer>(); cases.add(Integer.parseInt(stringCases[0])); cases.add(Integer.parseInt(stringCases[1])); cases.add(Integer.parseInt(stringCases[2])); for (int m = 0; m < cases.get(0); m++) { cases.add(Integer.parseInt(stringCases[3 + m])); } list.add(cases); } } catch (IOException e) { e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } } return list; } public void write(ArrayList<Integer> output, String file) { BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(file)); for (int n = 0; n < output.size() - 1; n++) { out.write("Case #" + (n + 1) + ": " + output.get(n)); out.newLine(); } out.write("Case #" + output.size() + ": " + output.get(output.size() - 1)); } catch (IOException e) { e.printStackTrace(); } finally { try { if (out != null) { out.flush(); out.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } }
0
150
A12852
A10676
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class B { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { // TODO Auto-generated method stub Scanner S = new Scanner(new File("B-small-attempt2.in")); //Scanner S = new Scanner(System.in); int t = S.nextInt(); for (int i = 1; i <= t; i++) { int n = S.nextInt(); int surprise = S.nextInt(); int p = S.nextInt(); int cases =0; for (int j = 0; j < n; j++) { int score = S.nextInt(); int base = (int)score /3; if(base*3 == score&& base>=p) cases++; else if(base*3 == score && surprise!=0 && base+1>=p && score > p){ cases++; surprise--; } else if(score - (base*3) == 1 && base+1 >=p) cases++; else if((score - (base*3) == 2) && (base>=p || base+1>=p)){ cases++; }else if((score - (base*3) == 2) && base+2 >=p && surprise!=0){ cases++; surprise--; } } System.out.println("Case #"+i+": "+cases); } } }
0
151
A12852
A12094
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.InputStream; import java.io.InputStreamReader; import java.io.FileInputStream; import java.util.Arrays; import java.util.Scanner; public class B { public static int gao(int s, int p , int[] ss) { int p1 = p + Math.max(0,p-1) * 2; int p2 = p + Math.max(0,p-2) * 2; Arrays.sort(ss); int ret = 0; for (int i = ss.length - 1; i >=0; --i) { int n = ss[i]; if (n >= p1) { ret ++; } else if (n >= p2 && s > 0) { ret ++; s--; } } return ret; } public static void main(String[] args) throws Exception { //InputStream in = System.in; InputStream in = new FileInputStream("c:\\B-small-attempt0.in"); Scanner scanner = new Scanner(in); //BufferedReader r = new BufferedReader(new InputStreamReader(in)); /* for (;;) { String l = r.readLine(); if (l == null) { break; } } */ int n; n = scanner.nextInt(); for (int i = 1; i <= n; ++i) { int m = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); int[] ss = new int[m]; for (int j = 0; j < m; ++j) { ss[j] = scanner.nextInt(); } System.out.println("Case #" + i + ": " + gao(s, p, ss)); } } }
0
152
A12852
A11329
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; public class Main { /** * @param args */ // public static void main(String[] args) // { // try // { // Map<Character, Character> m = new HashMap<Character, Character>(); // start_googlerese("ejp mysljylc kd kxveddknmc re jsicpdrysi","our language is impossible to understand",m); // start_googlerese("rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd","there are twenty six factorial possibilities",m); // start_googlerese("de kr kd eoya kw aej tysr re ujdr lkgc jv","so it is okay if you want to just give up",m); // // m.put('z','q'); // m.put('q','z'); // // int a=0; // a= a+1; // // char letter; // for (letter='a'; letter <= 'z'; letter++) // { // if(m.containsKey(letter)) // System.out.println(letter+" "+m.get(letter)); // else // System.out.println(letter+" "+"!!!"); // } // // googlerese(m); // // } // catch (IOException e) // { // // TODO Auto-generated catch block // e.printStackTrace(); // } // } public static void main(String[] args) { try { dancing(); //recycled(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static void dancing() throws IOException { ArrayList<String[]> input = Tools.getInput("C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\B-small.in"); ArrayList<String> output = new ArrayList<String>(); int num_cases = Integer.parseInt(input.get(0)[0]); for (int i=1;i<=num_cases;i++) { int result=0; int N=Integer.parseInt(input.get(i)[0]); int S=Integer.parseInt(input.get(i)[1]); int p=Integer.parseInt(input.get(i)[2]); int a,b,c; for(int j=0;j<N;j++) { int goog = Integer.parseInt(input.get(i)[3+j]); a = goog/3; b = (goog-a)/2; c = goog-a-b; if( a>=p || b>=p || c>=p ) result++; else { if(S>0 && ( (a==b && a==p-1 && a>0) || (a==c && a==p-1 && a>0) || (b==c && b==p-1 && b>0) ) ) { S--; result++; } } } StringBuilder sbO = new StringBuilder(); sbO.append("Case #"+(i)+": "); sbO.append(result); output.add(sbO.toString()); } Tools.saveOutputSingle("C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\B-small.out", output); } public static void recycled() throws IOException { ArrayList<String[]> input = Tools.getInput("C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\C-small.in"); ArrayList<String> output = new ArrayList<String>(); int num_cases = Integer.parseInt(input.get(0)[0]); Set<Integer> done = new HashSet<Integer>(); //!!!!!!!!!!!!!!!!!!! num_cases for (int i=0;i<num_cases;i++) { int length = input.get(i+1)[0].length(); int lower = Integer.parseInt(input.get(i+1)[0]); int upper = Integer.parseInt(input.get(i+1)[1]); int result=0; for (int n=lower;n<=upper;n++) { int m=n; for(int j=0;j<length-1; j++) { int mult = (int) Math.pow(10,length-1); int initial = m/mult; m = m-mult*initial; m = m*10 + initial; if(m>n && m<=upper && !done.contains(m)) { System.out.println(n+" "+m); result++; // done.add(m); done.add(n); } } } StringBuilder sbO = new StringBuilder(); sbO.append("Case #"+(i+1)+": "); sbO.append(result); output.add(sbO.toString()); } Tools.saveOutputSingle("C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\C-small.out", output); } public static void start_googlerese(String input, String output, Map<Character, Character> m) throws IOException { if(input.length()!=output.length()) throw new IOException(); for(int i=0;i<input.length();i++) { m.put(input.charAt(i),output.charAt(i)); } } public static void googlerese(Map<Character, Character> m) throws IOException { ArrayList<String> input = Tools.getInputSingle("C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\A-small.in"); ArrayList<String> output = new ArrayList<String>(); int num_cases = Integer.parseInt(input.get(0)); for (int i=0;i<num_cases;i++) { String strI = input.get(i+1); StringBuilder sbO = new StringBuilder(); sbO.append("Case #"+(i+1)+": "); for(int j=0; j<strI.length();j++) { sbO.append(m.get(strI.charAt(j))); } output.add(sbO.toString()); } Tools.saveOutputSingle("C:\\Users\\Yannick\\Dropbox\\GCJ_JAVA\\Q_2012\\A-small.out", output); } public static void minimum_scalar_product() throws IOException { ArrayList<String[]> input = Tools.getInput("D:\\Documents\\Dropbox\\GCJ_JAVA\\1A_2008\\A-large-practice.in"); ArrayList<String[]> output = new ArrayList<String[]>(); int T = Integer.parseInt(input.get(0)[0]); for (int i=0;i<T;i++) { int pointer = i*3+1; int n = Integer.parseInt(input.get(pointer)[0]); ArrayList<Integer> vectorA = new ArrayList<Integer>(); ArrayList<Integer> vectorB = new ArrayList<Integer>(); for(int j=0;j<n;j++) { vectorA.add(Integer.parseInt(input.get(pointer+1)[j])); vectorB.add(Integer.parseInt(input.get(pointer+2)[j])); } Collections.sort(vectorA); Collections.sort(vectorB); long sum=0; for (int j=0;j<n;j++) sum += ((long) vectorA.get(j))*vectorB.get(n-j-1); String[] output_line = new String[1]; output_line[0] = "Case #"+(i+1)+": "+sum; output.add(output_line); } Tools.saveOutput("D:\\Documents\\Dropbox\\GCJ_JAVA\\1A_2008\\A-large-practice.out", output); } }
0
153
A12852
A11274
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Solution { public static void main(String[] args) { Scanner s = new Scanner(System.in); int size = s.nextInt(); for (int count = 1; count <= size; count++){ int dancerNum = s.nextInt(); int surpNum = s.nextInt(); int score = s.nextInt(); int[] dancerScore = new int[dancerNum]; char[] marks = new char[dancerNum]; for (int i = 0; i < dancerNum; i++){ dancerScore[i] = s.nextInt(); } int highB = score * 3 - 2; int lowB = (score - 1) * 3 - 1; int output = 0; int sup = surpNum; int markIdx = 0; if (score < 2) { for (Integer i : dancerScore){ if (i >= score) { marks[markIdx] = '+'; output++; }else{ marks[markIdx] = '-'; } markIdx++; } } else { for (Integer i : dancerScore){ if (i >= highB){ output++; marks[markIdx] = '+'; }else if (i< highB && i >= lowB && sup > 0){ //if (){ output++; sup--; marks[markIdx] = '*'; // }else{ // // marks[markIdx] = '-'; // } } else{ marks[markIdx] = '-'; } markIdx++; } } // System.out.print("Case #"+count+": " + dancerNum + " " + surpNum + " "+ score + " "); // for (Integer i: dancerScore) // { // System.out.print(i+" "); // } System.out.println("Case #"+count+": "+output); // for (Character mark: marks) // { // System.out.print(mark+" "); // } // System.out.println(); } } }
0
154
A12852
A10546
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 practice; import java.util.*; public class GoogleDance { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int cases = Integer.parseInt(sc.nextLine()); for(int i = 0; i<cases; i++){ //Case starts here int caseCounter = i+1; String caseLine = sc.nextLine(); String[] caseArray = caseLine.split(" "); int googlers = Integer.parseInt(caseArray[0]); int surprising = Integer.parseInt(caseArray[1]); int passing = Integer.parseInt(caseArray[2]); List<Integer> scores = new ArrayList<Integer>(); for(int j = 3; j<caseArray.length;j++){ scores.add(Integer.parseInt(caseArray[j])); } //Finding individual scores int result = 0; for(Integer score:scores){ if(score%3==0){ int individual = score/3; if(individual==0){ if(individual>=passing){ result++; } }else{ if(individual>=passing){ result++; }else if(surprising>0){ individual++; if(individual>=passing){ result++; surprising--; } } } } if(score%3==1){ int individual = score/3+1; if(individual>=passing){ result++; } } if(score%3==2){ int individual = score/3+1; if(individual>=passing){ result++; }else if(surprising>0){ individual++; if(individual>=passing){ result++; surprising--; } } } } System.out.println("Case #"+caseCounter+": " + result); //Case ends here } } }
0
155
A12852
A11783
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { String inputName = "B-small-attempt0"; FileReader fr = new FileReader(inputName+".in"); Scanner sc = new Scanner(fr); FileWriter fstream = new FileWriter(inputName+".out"); BufferedWriter out = new BufferedWriter(fstream); int T = sc.nextInt(); for(int i = 0; i < T; i++){ int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int t[] = new int[N]; for(int j = 0; j < N; j++){ t[j] = sc.nextInt(); } int ans = 0; //System.out.println(N + " " + S + " " + p); for(int j = 0; j < N; j++){ int leftover = t[j] - p; //System.out.println(leftover + " " + leftover/2); if(leftover < 0){ continue; } if(leftover/2 >= p-1){ ans++; } else if(S > 0 && leftover/2 >= p-2){ ans++; S--; } } out.write("Case #" + (i+1) + ": " + ans); out.newLine(); System.out.println("Case #" + (i+1) + ": " + ans); } fr.close(); out.close(); } }
0
156
A12852
A12085
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.List; import java.util.Locale; import java.util.Scanner; import java.util.Set; public class QuestionB { //final static String FNAME = "C:\\CodeJam\\GoogleDancers"; final static String FNAME = "C:\\CodeJam\\B-small-attempt0"; //final static String FNAME = "C:\\CodeJam\\A-large-practice"; public static Scanner in; public static PrintWriter out; public static List<Integer> listA = new ArrayList<Integer>(3); public static List<Integer> listB = new ArrayList<Integer>(3); static void open() throws IOException { Locale.setDefault( Locale.US ); in = new Scanner( new File( FNAME + ".in" ) ); out = new PrintWriter( new File( FNAME + ".out" ) ); } static void close() throws IOException { out.close(); } static class Triplet implements Comparable<Triplet>{ int a, b, c; public Triplet(int a, int b, int c){ this.a = a; this.b = b; this.c = c; } public int getBestScore(){ int best = 0; if(a >= b && a >= c) best = a; else if(b >= a && b >= c) best = b; else if(c >= a && c >= b) best = c; return best; } public boolean isBest(int bestVal){ if(getBestScore()>=bestVal) return true; return false; } public boolean isSuprise(){ int difAB = this.a - this.b; int difBC = this.b - this.c; int difAC = this.a - this.c; if ( (Math.abs(difAB)==2) || (Math.abs(difBC)==2) || (Math.abs(difAC)==2) ) return true; return false; } @Override public int compareTo(Triplet arg0) { if(this.equals(arg0)) return 0; return 1; } @Override public int hashCode(){ return a + b + c; } @Override public boolean equals(Object obj){ listA.clear(); listB.clear(); listA.add(this.a);listA.add(this.b);listA.add(this.c); Triplet t = (Triplet)obj; listB.add(t.a);listB.add(t.b);listB.add(t.c); Collections.sort(listA); Collections.sort(listB); if(listA.get(0).equals(listB.get(0)) && listA.get(1).equals(listB.get(1)) && listA.get(2).equals(listB.get(2))) return true; return false; } } public static void main(String[] args)throws IOException { open(); int T = in.nextInt();//Number of test cases /* -------- Main code ---------- */ List<Integer> scores = new ArrayList<Integer>(); List<List<Triplet>> tripletGridList = new ArrayList<List<Triplet>>(); int[] digit1 = new int[3]; int[] digit3 = new int[3]; int[] digit2 = new int[3]; for(int i = 0 ; i < T ; i++){ //Read Data int numberOfGooglers = in.nextInt(); int surprises = in.nextInt(); final int minBestScore = in.nextInt(); scores.clear(); for(int j = 0 ; j<numberOfGooglers ; j++){ scores.add(in.nextInt()); } //Process tripletGridList.clear(); int possibleSurpriseCount = 0; for(Integer score : scores){ Set<Triplet> set = new HashSet<Triplet>(); //generate triplets for(int a = 0, b = 1, c = 2 ; c <=10 ; a++, b++, c++){ if(c*3 < score) continue; digit1[0]=a;digit1[1]=b;digit1[2]=c; digit2[0]=a;digit2[1]=b;digit2[2]=c; digit3[0]=a;digit3[1]=b;digit3[2]=c; for(int m : digit1){ for(int n : digit2){ for(int o : digit3){ if(m+n+o == score){ Triplet t =new Triplet(m,n,o); if(set.add(t)){ if(t.isSuprise()) possibleSurpriseCount++; //if(t.getBestScore() >= minBestScore) //possibleBestScores++; //System.out.println(t.a + ":" + t.b + ":" + t.c); } } } } } } //triplet generation done //Convert Set to list and sort list with triplets that are best and surprising appearing first ArrayList<Triplet> tList = new ArrayList<QuestionB.Triplet>(set); /*Collections.sort(tList, new Comparator<Triplet>(){ @Override public int compare(Triplet t1, Triplet t2) { if(t1.isBest(minBestScore) && t1.isSuprise()) return -1; else if(t2.isBest(minBestScore) && t2.isSuprise()) return -1; else if (t1.isBest(minBestScore)) return -1; else if (t2.isBest(minBestScore)) return -1; else if (t1.isSuprise()) return -1; else if (t2.isSuprise()) return -1; return 1; } });*/ tripletGridList.add(tList); //System.out.println("Set contents for Score :: "+ score);= } //System.out.println("Possible number of surprises : "+ possibleSurpriseCount); //System.out.println("Possible number of ALL BEstScores : "+ possibleBestScores); Collections.sort(tripletGridList, new Comparator<List<Triplet>>(){ @Override public int compare(List<Triplet> set1, List<Triplet> set2) { if(set1.size() > set2.size()) return -1; else if(set1.size() < set2.size()) return 1; else return 0; } }); if(possibleSurpriseCount == surprises){ int maxPosGooglers = 0; for(List<Triplet> list : tripletGridList){ for(Triplet t : list){ if(t.isBest(minBestScore)){ maxPosGooglers++; break; } } } //System.out.println("Case #" + (i+1) + ": "+maxPosGooglers); out.println("Case #" + (i+1) + ": "+maxPosGooglers); }else{ int maxPosGooglers = generateGroups(tripletGridList,0, new ArrayList<Triplet>(), minBestScore, surprises ); //System.out.println("Case #" + (i+1) + ": "+maxPosGooglers); out.println("Case #" + (i+1) + ": "+maxPosGooglers); } //Print to file //System.out.println( "Case #" + (i+1) + ": "+count); //out.println( "Case #" + (i+1) + ": "+""); } close(); } public static int generateGroups(List<List<Triplet>> tripletGridList, int gridIndexToProcess, List<Triplet> group, int minBestScore, int surprises){ if(gridIndexToProcess > tripletGridList.size()-1){ int groupSurprises = 0; int bestScores = 0; for(Triplet t : group){ if(t.isBest(minBestScore)) bestScores++; if(t.isSuprise()) groupSurprises++; } if(groupSurprises!=surprises) return 0; else return bestScores; } List<Triplet> tlist = tripletGridList.get(gridIndexToProcess); int max = 0; for(Triplet t : tlist){ group.add(t); int retMax = generateGroups(tripletGridList, gridIndexToProcess+1, group, minBestScore, surprises); group.remove(t); max = (max > retMax) ? max : retMax ; } return max; } }
0
157
A12852
A12685
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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_Dancing { static boolean enoughNonSurprising(int p, int score) { return score >= 3*p-2; } static boolean enoughSurprising(int p, int score) { return score >= 3*p-4; } public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); boolean firstline = true; for (int cas = 1; cas <= T; cas++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int enoughNS = 0; int enoughS = 0; for (int i = 0; i < N; i++) { int score = in.nextInt(); if (enoughNonSurprising(p,score)) enoughNS++; else if (p > 1 && enoughS < S && enoughSurprising(p,score)) enoughS++; } if (firstline) firstline = false; else System.out.println(); System.out.print("Case #"+cas+": "+(enoughNS+enoughS)); } } }
0
158
A12852
A11239
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class B { Map<String, String> mapLenguaje; public static void main(String arg[]) { try { StringBuffer line; File file = new File("C:/Documents and Settings/jjmamby/Mis documentos/Descargas/B-small-attempt1.in"); int T = 0, N = 0, S = 0, maxP, t, bestResult, p; StringBuilder output = new StringBuilder(); if (file.exists()) { BufferedReader input = new BufferedReader(new FileReader(file)); T = Integer.valueOf((input.readLine())); for (int i = 0; i < T; i++) { line = new StringBuffer(input.readLine()); StringTokenizer st = new StringTokenizer(line.toString(), " "); N = Integer.valueOf(st.nextToken()); S = Integer.valueOf(st.nextToken()); maxP = Integer.valueOf(st.nextToken()); p = 0; for(int j = 0; j < N; j++){ t = Integer.valueOf(st.nextToken()); int aux1 = t / 3 ; bestResult = aux1; int aux2 = (t - aux1) / 2 ; if(aux2>bestResult){ bestResult = aux2; } int aux3 = (t - aux1 - aux2) ; if(aux3>bestResult){ bestResult = aux3; } if(maxP<=aux3){ p++; }else if (t > 2 && t < 28){ aux2--; aux3++; if(maxP<=aux3&& S>0 ){ S--; p++; } } } output.append("Case #"); output.append((i+1)); output.append(": "); output.append(p); output.append("\n"); } System.out.println(output.toString()); }else{ output.append("No hay Archivo"); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
159
A12852
A13132
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class B { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); int N, S, p; for (int x = 1; x <= T; x++) { N = in.nextInt(); S = in.nextInt(); p = in.nextInt(); int[] t = new int[N]; int y = 0; for (int i = 0; i < N; i++) { t[i] = in.nextInt(); int k = t[i] / 3; int j1 = -1, j2 = -1, j3 = -1; // not surprising triplets if ((k + 1) + (k + 1) + k == t[i]) { j1 = k + 1; j2 = k + 1; j3 = k; } else if ((k + 1) + k + k == t[i]) { j1 = k + 1; j2 = k; j3 = k; } else if (3 * k == t[i]) { j1 = k; j2 = k; j3 = k; } if (j1 >= p || j2 >= p || j3 >= p) { y++; continue; } if(S==0) continue; // surprising triplets if (k != 9 && (k + 2) + k + k == t[i]) { j1 = k + 2; j2 = k; j3 = k; } else if (k != 0 && ((k + 1) + (k + 1) + (k - 1) == t[i])) { j1 = k + 1; j2 = k + 1; j3 = k - 1; } else if (k != 0 && ((k + 1) + k + (k - 1) == t[i])) { j1 = k + 1; j2 = k; j3 = k - 1; } if (j1 >= p || j2 >= p || j3 >= p) { y++; S--; continue; } } System.out.println("Case #" + x + ": " + y); } } }
0
160
A12852
A11666
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dancinggooglers; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; /** * * @author Alfred */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { try { FileInputStream fstream = new FileInputStream("B-small-attempt3.in"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter outFile = new FileWriter("out.txt"); PrintWriter out = new PrintWriter(outFile); String line; HashMap<Integer,Integer[]> map = new HashMap<Integer,Integer[]>(); map.put(0, new Integer[] {0, 0, 0}); map.put(1, new Integer[] {1, 0, 0}); map.put(2, new Integer[] {1, 1, 0}); map.put(3, new Integer[] {1, 1, 1}); map.put(4, new Integer[] {2, 1, 1}); map.put(5, new Integer[] {2, 2, 1}); map.put(6, new Integer[] {2, 2, 2}); map.put(7, new Integer[] {3, 2, 2}); map.put(8, new Integer[] {3, 3, 2}); map.put(9, new Integer[] {3, 3, 3}); map.put(10, new Integer[] {4, 3, 3}); map.put(11, new Integer[] {4, 4, 3}); map.put(12, new Integer[] {4, 4, 4}); map.put(13, new Integer[] {5, 4, 4}); map.put(14, new Integer[] {5, 5, 4}); map.put(15, new Integer[] {5, 5, 5}); map.put(16, new Integer[] {6, 5, 5}); map.put(17, new Integer[] {6, 6, 5}); map.put(18, new Integer[] {6, 6, 6}); map.put(19, new Integer[] {7, 6, 6}); map.put(20, new Integer[] {7, 7, 6}); map.put(21, new Integer[] {7, 7, 7}); map.put(22, new Integer[] {8, 7, 7}); map.put(23, new Integer[] {8, 8, 7}); map.put(24, new Integer[] {8, 8, 8}); map.put(25, new Integer[] {9, 8, 8}); map.put(26, new Integer[] {9, 9, 8}); map.put(27, new Integer[] {9, 9, 9}); map.put(28, new Integer[] {10, 9, 9}); map.put(29, new Integer[] {10, 10, 9}); map.put(30, new Integer[] {10, 10, 10}); line = br.readLine(); int cases = Integer.parseInt(line); for (int i=1; i<=cases;i++){ line = br.readLine(); String[] values = line.split(" "); int N = Integer.parseInt(values[0]); int S = Integer.parseInt(values[1]); int p = Integer.parseInt(values[2]); Integer[] scores = new Integer[N]; for (int j = 0; j< N; j++){ scores[j] = Integer.parseInt(values[3+j]); } Arrays.sort(scores, Collections.reverseOrder()); int total=0; for (int j = 0; j< N; j++){ Integer[] triplet = map.get(scores[j]).clone(); if(triplet[0]>=p){ total++; } else{ if (S > 0){ if(surprising(triplet,scores[j])){ if(triplet[0]>=p){ S--; total++; } } } } } out.println("Case #"+i+": "+total); } in.close(); out.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } } private static boolean surprising(Integer[] triplet, int score) { if(score < 2 || score> 27) return false; else{ if(triplet[0]==triplet[1]){ triplet[0]++; triplet[1]--; Arrays.sort(triplet,Collections.reverseOrder()); return true; } else{ triplet[1]++; triplet[2]--; Arrays.sort(triplet,Collections.reverseOrder()); return true; } } } }
0
161
A12852
A10095
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 googlecodejam; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; /** * * @author Tobi */ public class GoogleCodeJam { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner s = new Scanner(System.in); int T = s.nextInt(); for(int t = 1; t <= T; t++) { int N = s.nextInt(); //number of googlers int S = s.nextInt(); //number of surprising results int p = s.nextInt(); //number of target-best result int[] points = new int[N]; for(int i = 0; i < N; i++) points[i] = s.nextInt(); int matches = 0; for(int i = 0; i < N; i++) { if((points[i] / 3) + 2 < p) //skip results that are too low continue; int a = points[i] / 3; int b = (points[i] - a) / 2; int c = (points[i] - a - b); int max = Math.max(Math.max(a, b), c); int delta = Math.max(Math.max(Math.abs(b - c), Math.abs(a - b)), Math.abs(a - c)); if(max >= p) { if(delta == 2 && S > 0) { //enough points, but surprising, surprises left? S--; matches++; continue; } else if (delta < 2) { //enough points, no surprise matches++; continue; } } if((max + 1 >= p) && (delta < 2)) { if((S > 0) && (delta == 0) && max > 0) { //can shift one point up and one down -> delta == 2 -> surprise left? S--; matches++; } else if (S > 0 && delta == 1 && ((a == b && a == max) || (a == c && a == max) || (b == c && b == max))) { //can shift one point up, one down, but delta S--; matches++; } } } System.out.println("Case #" + t + ": " + matches); } } }
0
162
A12852
A11644
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package me.mevrad.codejam; import java.util.ArrayList; public class DataTemplate { public int numberOfGooglers; public int surprisingScores; int p; public ArrayList<Integer> scores; public DataTemplate(){ scores = new ArrayList<Integer>(); } }
0
163
A12852
A11776
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.ArrayList; import java.util.Collections; import java.util.List; public class Dancing { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int cases = Integer.parseInt(in.readLine()); for (int i = 1; i <= cases; i++) { String[] inp = in.readLine().trim().split(" "); int N = Integer.parseInt(inp[0]); int S = Integer.parseInt(inp[1]); int p = Integer.parseInt(inp[2]); List<Integer> scores = new ArrayList<Integer>(); for (int j = 3; j < N+3; j++) { scores.add(Integer.parseInt(inp[j])); } int out = 0; Collections.sort(scores); Collections.reverse(scores); int j=0; while(j<N && scores.get(j)>=(3*p-2)) { out++; j++; } if(p>1) while(j<N && scores.get(j)>=(3*p-4) && S>0) { out++; j++; S--; } System.out.println("Case #"+i+": "+out); } } }
0
164
A12852
A12738
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class Main { public static void main(String[] args) throws Exception { PrintWriter out = new PrintWriter(new FileOutputStream(new File("output.txt")), true); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(new File("input.txt")))); // StringTokenizer st = new StringTokenizer(in.readLine()); // Scanner s = new Scanner(System.in); int t = Integer.parseInt(in.readLine()); for(int a = 0;a < t;a++) { StringTokenizer st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); Map<Integer,ArrayList<Decompose>> map = new TreeMap<>(); ArrayList<Integer> scores = new ArrayList<>(); for(int m = 0;m < n;m++) { int g = Integer.parseInt(st.nextToken()); scores.add(g); map.put(g, dec(g)); //out.println(dec(g).toString()); } int colSurpWinAndWin = 0; int colSurpWin = 0; int colWin = 0; for(int i = 0;i < n;i++) { if(isDecomposeThere(map.get(scores.get(i)),p,true) && isDecomposeThere(map.get(scores.get(i)),p,false)) { colSurpWinAndWin++; }else if(isDecomposeThere(map.get(scores.get(i)),p,true)) { colSurpWin++; }else if(isDecomposeThere(map.get(scores.get(i)),p,false)) { colWin++; } } //out.println(colSurpWinAndWin+" "+colSurpWin+" "+colWin); if(colSurpWin >= s) { out.println("Case #"+(a+1)+": "+(s+colWin+colSurpWinAndWin)); }else{ s -= colSurpWin; out.println("Case #"+(a+1)+": "+(colSurpWin+colSurpWinAndWin+colWin)); } } } public static boolean isDecomposeThere(ArrayList<Decompose> decomposes, int p, boolean surprise) { for(Decompose dec : decomposes) { if(dec.a >= p && dec.surprise == surprise) return true; } return false; } public static ArrayList<Decompose> dec(int n) { ArrayList<Decompose> list = new ArrayList<>(); for(int i = 0;i <= 10;i++) { for(int j = 0;j <= i;j++) { for(int k = 0;k <= j;k++) { if(i - j <= 2 && j - k <= 2 && i - k <= 2 && i+j+k == n) { boolean surprise = (i-j == 2 || j-k == 2 || i-k == 2); list.add(new Decompose(i,j,k,surprise)); } } } } return list; } } class Decompose { int a, b, c; boolean surprise; public Decompose(int a, int b, int c, boolean surprise) { this.a = a; this.b = b; this.c = c; this.surprise = surprise; } @Override public String toString() { return ""+a+" "+b+" "+c+" "+surprise; } }
0
165
A12852
A12809
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileInputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Scanner; /** * @author Max Loewenthal */ public class B { public void solve(Scanner input, StringBuilder buffer) { int N = input.nextInt(); int surprisingScores = input.nextInt(); int p = input.nextInt(); int candidates = 0; int surprisingCandidates = 0; for (int i = 0; i <N; i++) { int total = input.nextInt(); if (total >= 3*p - 2 && total >= p) { candidates = candidates + 1; } else if (total >= 3*p - 4 && total >= p) { surprisingCandidates = surprisingCandidates + 1; } } buffer.append(Integer.toString(candidates + Math.min(surprisingCandidates, surprisingScores))); } public static void main(String[] args) { try { InputStream input = System.in; OutputStream output = System.out; if (args.length > 0) { input = new FileInputStream(new File(args[0])); } if (args.length > 1) { File outputFile = new File(args[1]); if (outputFile.exists()) { throw new Exception("Output file already exists"); } output = new FileOutputStream(new File(args[1])); } Scanner scanner = new Scanner(input); PrintWriter writer = new PrintWriter(output); B a = new B(); int count = scanner.nextInt(); scanner.nextLine(); for (int i = 0; i < count; i++) { StringBuilder result = new StringBuilder(); a.solve(scanner, result); writer.println("Case #" + (i + 1) + ": " + result.toString()); } writer.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
166
A12852
A12555
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package main; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.HashSet; public class ProblemC { public static void main(String args[]){ try{ FileInputStream fileInputStream = new FileInputStream(args[0] + ".in"); DataInputStream in = new DataInputStream(fileInputStream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter fstream = new FileWriter(args[0] + ".out"); BufferedWriter out = new BufferedWriter(fstream); String strLine; strLine = br.readLine(); int T = Integer.parseInt(strLine); for(int i = 1; i <= T; i++){ strLine = br.readLine(); String[] input = strLine.split(" "); int N = Integer.parseInt(input[0]); int S = Integer.parseInt(input[1]); int p = Integer.parseInt(input[2]); int count = 0; for(int j = 0; j < N; j++){ int t = Integer.parseInt(input[3 + j]); if(t / 3 >= p){ count++; } else if(p > t){ continue; } else if(t / 3 == p - 1){ if(t % 3 == 0){ if(S > 0){ count++; S--; } } else if(t % 3 == 1){ count++; } else{ count++; } } else if(t / 3 == p - 2){ if(t % 3 == 0){ } else if(t % 3 == 1){ } else{ if(S > 0){ count++; S--; } } } } System.out.println("Case #" + i + ": " + count); out.write("Case #" + i + ": " + count + "\n"); } out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
167
A12852
A11114
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.googlecode.codejam.contest.gcj2012.round_q; import java.util.Arrays; import java.util.Iterator; import java.util.concurrent.Callable; import com.googlecode.codejam.model.JamCaseResolver; import com.googlecode.codejam.model.JamCaseResolverFactory; import com.googlecode.codejam.model.JamResolver; public class B extends JamCaseResolver { private final int s; // surprising private final int p; // score limit private final int[] scores; public B(final int caseNumber, final Iterator<String> lineIterator) { super(caseNumber); int[] input = this.parseInt(lineIterator.next().split(" ")); s = input[1]; p = input[2]; scores = Arrays.copyOfRange(input, 3, input.length); } @Override protected String resolve() { int surprisingUsed = s; int result = 0; for (int score : scores) { if(score < 2) { if(score >= p) result++; continue; } double avg = Math.ceil(score / 3.0); if(avg >= p) { result++; } else if (surprisingUsed > 0 && avg + 1 >= p && (score - 1) % 3 != 0) { result++; surprisingUsed--; } } return String.valueOf(result); } public static void main(String[] args) throws Exception { final JamCaseResolverFactory factory = new JamCaseResolverFactory() { @Override public Callable<String> newJamCaseResolver(int caseNumber, Iterator<String> lineIterator) { return new B(caseNumber, lineIterator); } }; final JamResolver jamResolver = new JamResolver(factory, "gcj2012/round_q", "B-small-attempt0.in"); jamResolver.resolve(); } }
0
168
A12852
A12814
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 gcj2012.qr; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class DancingWithTheGooglers { public static int getMax(int s, int p, int[] scores) { int numHigh = 0; int numPotential = 0; int score = 0; int best = 0; for (int i = 0; i < scores.length; i++) { score = scores[i]; best = (score + 2) / 3; if (best >= p) { numHigh++; } else if ((score > 1) && (score < 29) && (best == p - 1) && (score % 3 != 1)) { numPotential++; } } return numHigh + Math.min(numPotential, s); } public static void main(String[] args) throws NumberFormatException, IOException { DancingWithTheGooglers sit = new DancingWithTheGooglers(); if (args.length < 1 ) { System.out.println("File name not given"); System.exit(1); } BufferedReader br = new BufferedReader(new FileReader(args[0])); int t = Integer.parseInt(br.readLine()); for (int i = 1; i <= t; i++) { String[] test = br.readLine().split(" "); int n = Integer.parseInt(test[0]); int s = Integer.parseInt(test[1]); int p = Integer.parseInt(test[2]); int[] scores = new int[n]; for (int j = 0; j < n; j++) { scores[j] = Integer.parseInt(test[3 + j]); } System.out.printf("Case #%d: %d\n", i, getMax(s, p, scores)); } br.close(); } }
0
169
A12852
A12707
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Exception { File f = new File(args[0]); File out = new File(f.getParentFile(), f.getName()+".out"); BufferedWriter w = new BufferedWriter(new FileWriter(out)); Scanner s = new Scanner(f); int T = s.nextInt(); s.nextLine(); for (int t=1;t<=T;t++) { int N = s.nextInt(); int S = s.nextInt(); int p = s.nextInt(); int[] totals = new int[N]; for (int x=0; x<N; x++) { totals[x] = s.nextInt(); } println(w, "Case #"+t+": "+solve(S, p, totals)); } s.close(); w.close(); } private static String solve(int s, int p, int[] totals) { int min = p + Math.max(0,(p-1)) + Math.max(0,(p-1)); int floor = p + Math.max(0,p-2) + Math.max(0,p-2); int num = 0; for (int x=0; x<totals.length; x++) { if (totals[x] >= min) { num++; } else if (totals[x] < floor) { continue; } else if (s > 0) { s--; num++; } } return String.valueOf(num); } static void println(BufferedWriter w, String s) throws IOException { System.out.println(s); w.write(s+"\n"); } }
0
170
A12852
A10627
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Problem2 { private static int [] MAX_NO_SURPRISE; private static int [] MAX_WITH_SURPRISE; public static void main(String[] args) throws IOException { MAX_NO_SURPRISE = calcArray(1); MAX_WITH_SURPRISE = calcArray(2); Scanner scanner = new Scanner(new File(args[0])); int cases = scanner.nextInt(); PrintWriter printWriter = new PrintWriter(new File(args[1])); for (int i = 0; i < cases; i++) { int n = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); int t[] = new int[n]; for (int k = 0; k < n; k++) { t[k] = scanner.nextInt(); } printWriter.write("Case #" + (i + 1) + ": " + solve(n,s,p,t) + "\n"); } printWriter.close(); scanner.close(); } private static int[] calcArray(int d) { int t[] = new int[31]; for (int i = 0; i <= 30; i++) { int max = 0; for (int a1=0;a1<=10;a1++) { for (int a2=0;a2<=10;a2++) { for (int a3=0;a3<=10;a3++) { if (a1+a2+a3 == i && Math.abs(a1-a2) <= d && Math.abs(a2-a3) <= d && Math.abs(a1-a3) <= d) { if (a1 > max) { max = a1; } if (a2 > max) { max = a2; } if (a3 > max) { max = a3; } } } } } t[i] = max; } return t; } private static int solve(int n, int s, int p, int[] t) { int r[][] = new int[n + 1][s + 1]; for (int i = 0; i <= s; i++) { r[0][i] = 0; } for (int i = 1; i <= n; i++) { r[i][0] = ((MAX_NO_SURPRISE[t[i - 1]] >= p) ? 1 : 0) + r[i - 1][0]; } for (int i = 1; i <= n; i++) { for (int j = 1; j <= s; j++) { r[i][j] = Math.max( r[i - 1][j] + ((MAX_NO_SURPRISE[t[i - 1]] >= p) ? 1 : 0), r[i - 1][j - 1] + ((MAX_WITH_SURPRISE[t[i - 1]] >= p) ? 1 : 0)); } } return r[n][s]; } }
0
171
A12852
A10340
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.ArrayList; import java.util.StringTokenizer; public class B implements Runnable { private static BufferedReader reader; private static StreamTokenizer st; private static PrintWriter writer; public static void main(String[] args) { new Thread(new B()).start(); } @Override public void run() { try { solve(); } catch (IOException e) {} } private void solve() throws IOException { reader = new BufferedReader(new FileReader("b.in")); st = new StreamTokenizer(reader); writer = new PrintWriter(new FileWriter("b.out")); int n = nextInt(); for (int i = 1; i <= n; i++) { int temp = countAns(); writer.println("Case #" + i + ": " + temp); } reader.close(); writer.close(); } static String nextToken() throws IOException { st.nextToken(); return st.sval; } static int nextInt() throws NumberFormatException, IOException { st.nextToken(); return (int)st.nval; } private static int countAns() throws IOException{ int n = nextInt(); int s = nextInt(); int p = nextInt(); //writer.print(String.valueOf(n) + " " + String.valueOf(s) + " " + String.valueOf(p) + " "); ArrayList<Integer> num = new ArrayList<Integer>(n); int nonSurprisingNum = 0; for (int i = 0; i < n; i++) { int temp = nextInt(); //writer.print(String.valueOf(temp) + " "); num.add(temp); } if (p == 0) return n; int nonSurprisingFrame = p + 2 * (p - 1); for (int i = 0; i < num.size(); i++) { int curNum = num.get(i); if (curNum >= nonSurprisingFrame) { nonSurprisingNum++; num.remove(i); i--; } } if (s == 0) return nonSurprisingNum; int surprisingFrame = Math.max(0, p + 2 * (p - 2)); int len = num.size(); int cnt = 0; while (s > 0 && cnt < len) { int curNum = num.get(cnt); if (curNum > 0 && curNum >= surprisingFrame) { s--; nonSurprisingNum++; } cnt++; } return nonSurprisingNum; } }
0
172
A12852
A10760
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for(int zz = 1; zz <= T;zz++){ int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int x = 0; for(int i = 0; i < N;i++){ int score = in.nextInt(); int best = score/3; int mod = score%3; int diff = p-best; if(diff<1){ x++; }else if(diff<2){ if(mod==0 && score !=0){ if(S!=0){ S--;x++; } }else if(score!=0){ x++; } }else if(diff<3){ if(mod==2){ if(S!=0){ S--;x++; } } } } System.out.format("Case #%d: %d\n", zz, x); } } }
0
173
A12852
A12407
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class B { public static void main(String[] args) throws IOException { int[][] arr = new int[31][11]; for(int[] a : arr) { Arrays.fill(a, 1000); } for(int i = 0; i <= 10; i++) { for(int j = i; j <= 10 && j <= i+2; j++) { for(int k = j; k <= 10 && k <= i+2; k++) { int sum = i+j+k; if(k-i <= 1) { for(int l = k; l >= 0; l--) { arr[sum][l] = 1; } } else { for(int l = k; l >= 0; l--) { arr[sum][l] = Math.min(arr[sum][l], 2); } } } } } PrintWriter out = new PrintWriter(new File("B.out")); Scanner in = new Scanner(System.in); int cases = in.nextInt(); for(int caseOn = 1; caseOn <= cases; caseOn++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int ans = 0; for(int i = 0; i < n; i++) { int t = in.nextInt(); if(arr[t][p]==1000) continue; if(arr[t][p]==2) { if(s>0) { s--; ans++; } } if(arr[t][p]==1) { ans++; } } out.printf("Case #%d: %d\n",caseOn,ans); } out.close(); } } /* 7 3 1 5 15 13 11 3 0 8 23 22 21 2 1 1 8 0 6 2 8 29 20 8 18 18 21 3 1 5 5 5 5 3 1 5 11 11 11 3 1 5 15 15 15 */
0
174
A12852
A12036
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package jp.funnything.competition.util; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import org.apache.commons.io.IOUtils; public class AnswerWriter { private static final String DEFAULT_FORMAT = "Case #%d: %s\n"; private final BufferedWriter _writer; private final String _format; public AnswerWriter( final File output , final String format ) { try { _writer = new BufferedWriter( new FileWriter( output ) ); _format = format != null ? format : DEFAULT_FORMAT; } catch ( final IOException e ) { throw new RuntimeException( e ); } } public void close() { IOUtils.closeQuietly( _writer ); } public void write( final int questionNumber , final Object result ) { write( questionNumber , result.toString() , true ); } public void write( final int questionNumber , final String result ) { write( questionNumber , result , true ); } public void write( final int questionNumber , final String result , final boolean tee ) { try { final String content = String.format( _format , questionNumber , result ); if ( tee ) { System.out.print( content ); System.out.flush(); } _writer.write( content ); } catch ( final IOException e ) { throw new RuntimeException( e ); } } }
0
175
A12852
A10914
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileNotFoundException; import java.io.FileReader; import java.io.PrintWriter; import java.util.Scanner; public class Dancing { private static String fileName = "dancing-small"; private static String inputFileName = fileName + ".in"; private static String outputFileName = fileName + ".out"; private static Scanner in; private static PrintWriter out; private void solve() { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int allGood = (3 * p) - 2; int almostGood = allGood - 2; int sureGood = 0; int maybeGood = 0; for (int i = 0; i < N; i++) { int value = in.nextInt(); if (value < p) { continue; } if (value >= allGood) { sureGood++; continue; } if (value >= almostGood) { maybeGood++; continue; } } int maxP = sureGood + (maybeGood > S ? S : maybeGood); out.print(maxP); } /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { in = new Scanner(new FileReader(inputFileName)); out = new PrintWriter(outputFileName); int tests = in.nextInt(); in.nextLine(); for (int t = 1; t <= tests; t++) { out.print("Case #" + t + ": "); new Dancing().solve(); out.println(); } in.close(); out.close(); } }
0
176
A12852
A12264
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam2012; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Hashtable; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws Exception { Scanner scanner = new Scanner(new BufferedReader(new FileReader( "A-large-practice.in.txt"))); Output out = new Output("A.out"); int T = scanner.nextInt(); for (int t = 1; t <= T; t++) { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int[] scores = new int[N]; for (int i = 0; i < N; i++) { scores[i] = scanner.nextInt(); } Arrays.sort(scores); int count = 0; int num_s = 0; int[] roundUp = { 0, 2, 1 }; int[] makeUp = { 1, 0, 1 }; int[] makeDown = { 1, 1, 0 }; for (int i = scores.length - 1; i >= 0; i--) { int score = scores[i]; int mod = score % 3; int hi = (score + roundUp[mod]) / 3; int low = score / 3 - makeDown[mod]; if (hi >= p) { count++; } else if (num_s < S && (hi + makeUp[mod]) >= p && low >= 0) { count++; num_s++; } else { //break; } } out.format("Case #%d: %d\n", t, count); } scanner.close(); out.close(); } static class Output { PrintWriter pw; public Output(String filename) throws IOException { pw = new PrintWriter(new BufferedWriter(new FileWriter(filename))); } public void print(String s) { pw.print(s); System.out.print(s); } public void println(String s) { pw.println(s); System.out.println(s); } public void format(String format, Object... args) { pw.format(format, args); System.out.format(format, args); } public void close() { pw.close(); } } }
0
177
A12852
A10948
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; import java.util.*; public class trie { public static void main(String[] args) throws IOException { int i,j,nog,nos,p,n,count; int[] t=new int[10]; String s1="",p1="",m1=""; solver h1=new solver(); Scanner fin=new Scanner(new File("A.txt")); s1=fin.nextLine(); n=Integer.parseInt(s1); FileWriter fstream=new FileWriter("out.txt"); BufferedWriter out=new BufferedWriter(fstream); for(i=0;i<n;i++) { j=0; s1=""; s1=fin.nextLine(); out.write("Case #"); out.write(Integer.toString(i+1)); out.write(": "); while(s1.charAt(j)!=' ') { p1=p1+s1.charAt(j); j++; } System.out.println(p1); nog=Integer.parseInt(p1); j++; p1=""; while(s1.charAt(j)!=' ') { p1=p1+s1.charAt(j); j++; } // System.out.println(p1); nos=Integer.parseInt(p1); j++; p1=""; while(s1.charAt(j)!=' ') { p1=p1+s1.charAt(j); j++; } // System.out.println(p1); p=Integer.parseInt(p1); j++; p1=""; count=0; while(j<s1.length()) { if(s1.charAt(j)==' ') { t[count++]=Integer.parseInt(p1); // System.out.println(p1); p1=""; } else p1=p1+s1.charAt(j); j++; } t[count++]=Integer.parseInt(p1); // System.out.println(p1); p1=""; m1=Integer.toString(h1.solve(nog,nos,p,t)); out.write(m1); m1=""; out.write("\n"); } out.close(); } }
0
178
A12852
A11034
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package fixjava; import java.util.Collection; import java.util.Comparator; /** * Typed 3-tuple */ public class Tuple4<A, B, C, D> { private final A field0; private final B field1; private final C field2; private final D field3; public A getField0() { return field0; } public B getField1() { return field1; } public C getField2() { return field2; } public D getField3() { return field3; } public Tuple4(final A field0, final B field1, final C field2, final D field3) { this.field0 = field0; this.field1 = field1; this.field2 = field2; this.field3 = field3; } /** Convenience method so type params of pair don't have to be specified: just do Tuple4.make(a, b, c, d) */ public static <A, B, C, D> Tuple4<A, B, C, D> make(A field0, B field1, C field2, D field3) { return new Tuple4<A, B, C, D>(field0, field1, field2, field3); } // --------------------------------------------------------------------------------------------------- private static final boolean objEquals(Object p1, Object p2) { if (p1 == null) return p2 == null; return p1.equals(p2); } @Override public final boolean equals(Object o) { if (!(o instanceof Tuple4<?, ?, ?, ?>)) { return false; } else { final Tuple4<?, ?, ?, ?> other = (Tuple4<?, ?, ?, ?>) o; return objEquals(getField0(), other.getField0()) && objEquals(getField1(), other.getField1()) && objEquals(getField2(), other.getField2()) && objEquals(getField3(), other.getField3()); } } @Override public int hashCode() { int h0 = getField0() == null ? 0 : getField0().hashCode(); int h1 = getField1() == null ? 0 : getField1().hashCode(); int h2 = getField2() == null ? 0 : getField2().hashCode(); int h3 = getField3() == null ? 0 : getField3().hashCode(); return h0 + 53 * h1 + 97 * h2 + 131 * h3; } // --------------------------------------------------------------------------------------------------- public static <A extends Comparable<A>, B, C, D> Comparator<Tuple4<A, B, C, D>> comparatorOnField0(Collection<Tuple4<A, B, C, D>> tupleCollection) { return new Comparator<Tuple4<A, B, C, D>>() { @Override public int compare(Tuple4<A, B, C, D> o1, Tuple4<A, B, C, D> o2) { return o1.getField0().compareTo(o2.getField0()); } }; } public static <A, B extends Comparable<B>, C, D> Comparator<Tuple4<A, B, C, D>> comparatorOnField1(Collection<Tuple4<A, B, C, D>> tupleCollection) { return new Comparator<Tuple4<A, B, C, D>>() { @Override public int compare(Tuple4<A, B, C, D> o1, Tuple4<A, B, C, D> o2) { return o1.getField1().compareTo(o2.getField1()); } }; } public static <A, B, C extends Comparable<C>, D> Comparator<Tuple4<A, B, C, D>> comparatorOnField2(Collection<Tuple4<A, B, C, D>> tupleCollection) { return new Comparator<Tuple4<A, B, C, D>>() { @Override public int compare(Tuple4<A, B, C, D> o1, Tuple4<A, B, C, D> o2) { return o1.getField2().compareTo(o2.getField2()); } }; } public static <A, B, C, D extends Comparable<D>> Comparator<Tuple4<A, B, C, D>> comparatorOnField3(Collection<Tuple4<A, B, C, D>> tupleCollection) { return new Comparator<Tuple4<A, B, C, D>>() { @Override public int compare(Tuple4<A, B, C, D> o1, Tuple4<A, B, C, D> o2) { return o1.getField3().compareTo(o2.getField3()); } }; } // --------------------------------------------------------------------------------------------------- @Override public String toString() { return "(" + getField0() + ", " + getField1() + ", " + getField2() + ", " + getField3() + ")"; } }
0
179
A12852
A12177
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package hk.polyu.cslhu.codejam.lib; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.log4j.Logger; public class FileStream { public static Logger logger = Logger.getLogger(FileStream.class); /** * Read the content of file with the given file path * * @param filePath String The location of file * @return The content of file as an instance of list */ public static List<String> read(String filePath) { List<String> content = new ArrayList<String>(); try { BufferedReader br = new BufferedReader(new FileReader(filePath)); String line; while ((line = br.readLine()) != null) { content.add(line); } br.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block logger.error("File is not found with the path \"" + filePath + "\""); } catch (IOException e) { // TODO Auto-generated catch block logger.error(e.getMessage()); } return content; } /** * Save the content to a file * * @param filePath String The location of file to be saved * @param content String The content to be saved */ public static void save(String filePath, String content) { try { BufferedWriter bw = new BufferedWriter(new FileWriter(filePath)); bw.write(content); bw.flush(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block logger.error(e.getMessage()); } } }
0
180
A12852
A10334
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; public class problemB { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub int[] tab = new int[100]; String outputFile = "C:\\Users\\mejdi\\Documents\\A-small1.out"; String inputFile = "C:\\Users\\mejdi\\Documents\\B-small-attempt0.in"; BufferedWriter out = new BufferedWriter(new FileWriter(outputFile)); DataInputStream in = new DataInputStream(new FileInputStream(inputFile)); int T = Integer.valueOf(in.readLine()); for (int o = 0; o < T; o++) { String list = in.readLine(); int k = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); int s = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); int p = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); for (int j = 0; j < (k-1); j++) { tab[j] = Integer.valueOf(list.substring(0, list.indexOf(" "))); list = list.substring(list.indexOf(" ") + 1); } tab[k-1] = Integer.valueOf(list.substring(0)); int i = 0; int r = 0; while (i < k) { if (tab[i]==0 ) {if (p==0) {i=i+1; r=r+1; } else i=i+1;} else if ((tab[i] / 3) + 2 - p < 0) i = i + 1; else if ((tab[i] / 3) + 2 - p == 0) { if (tab[i] % 3 == 2) { if (s > 0) { s = s - 1; r = r + 1; i = i + 1; } else { i = i + 1; } } else { i = i + 1; } } else if ((tab[i] / 3) + 1 - p == 0) { if (tab[i] % 3 == 0) { if (s > 0) { s = s - 1; r = r + 1; i = i + 1; } else { i = i + 1; } } else { i = i + 1; r = r + 1; } } else { i = i + 1; r = r + 1; } } int x = o + 1; out.write("Case #" + x + ": " + r); out.newLine(); } in.close(); out.close(); } }
0
181
A12852
A11875
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package codejam2; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; /** * * @author Mahmoud */ public class CodeJam2 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here try { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); BufferedWriter writer = new BufferedWriter(new FileWriter("output.txt")); int n, s, p; String inStrLine = in.readLine(); if (inStrLine == null) { System.out.println("wrong format"); return; } int num = Integer.parseInt(inStrLine); for (int i = 0; i < num; i++) { writer.write("Case #" + (i + 1) + ": "); inStrLine = in.readLine(); if (inStrLine == null) { System.out.println("wrong format"); return; } String[] params = inStrLine.split(" "); n = Integer.parseInt(params[0]); s = Integer.parseInt(params[1]); p = Integer.parseInt(params[2]); int t,max, result = 0; for (int j = 0; j < n; j++) { t = Integer.parseInt(params[j + 3]); max = t==0?0:((t - 1) / 3) + 1; if (max >= p) { result++; } else if (s != 0) { max = t==0?0:((t - 2) / 3) + 2; if (max >= p) { result++; s--; } } } writer.write(String.valueOf(result)); if (i != num - 1) { writer.write('\n'); } } writer.flush(); } catch (Exception e) { System.err.println("cant open file"); } } }
0
182
A12852
A10082
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 qualificationRound; public class Dancing { /** * * @param N * Number of Googlers * @param S * number of surprising triplets of scores * @param P * * @param Ti * the total points of the Googlers * * @return what is the maximum number of Googlers that could have had a best * result of at least p */ public static int howMany(int N, int S, int P, int[] Ti) { if (0 == P) return N; int count = 0; int specials = 0; for (int t : Ti) { if (0 == t) continue; int mod = t % 3; int div = t / 3; int max = -1; int maxSpecial = -1; switch (mod) { case 0: max = div; maxSpecial = div + 1; break; case 1: max = div + 1; // same as 'maxSpecial' break; case 2: max = div + 1; maxSpecial = div + 2; break; } if (max >= P) count++; else if (maxSpecial >= P) specials++; } if (specials > S) count += S; else count += specials; return count; } }
0
183
A12852
A12082
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package qual; import java.util.Arrays; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) { new DancingWithTheGooglers().run(); } private void run() { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for (int testcase = 0; testcase < T; testcase++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int[] t = new int[N]; for (int i = 0; i < N; i++) { t[i] = sc.nextInt(); } int result = solve(N, S, p, t); System.out.printf("Case #%d: %d\n", testcase + 1, result); } } /** * * @param N the number of Googlers * @param S the number of surprising triplets of scores * @param p * @param t * @return */ public int solve(int N, int S, int p, int[] t) { int result = 0; Arrays.sort(t); for (int i = N - 1; i >= 0; i--) { int b = (t[i] + 2) / 3; if (b >= p) { result++; // System.out.printf("(1) %d : %d\n", t[i], b); } else if (t[i] > 1 && S > 0 && b == p - 1 && ((t[i] - 1) % 3) != 0) { result++; S--; // System.out.printf("(2) %d : %d (S=%d)\n", t[i], b, S); } } return result; } }
0
184
A12852
A10565
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.Arrays; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Scanner; import java.util.Set; import java.util.TreeSet; public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File("B-small-attempt0.in")); PrintWriter out = new PrintWriter("C:\\Users\\JiaKY\\Desktop\\out.txt"); //Scanner in = new Scanner(System.in); int t = Integer.valueOf(in.nextLine()); for(int ii=0;ii<t;ii++){ String line = in.nextLine(); String[] data = line.split(" "); int n = Integer.valueOf(data[0]); int s = Integer.valueOf(data[1]); int p = Integer.valueOf(data[2]); int[] score = new int[n]; for(int i=0;i<n;i++){ score[i] = Integer.valueOf(data[3+i]); } Arrays.sort(score); int ans = 0; for(int i=score.length-1;i>=0;i--){ int valid = 3*p-2; if(p<2) valid = p; int min = 3*p-4; if(p <= 2) min = p; if(score[i] >= valid) ans++; else if(s > 0){ if(score[i] >= min){ ans++; s--; if(s == 0) break; } } } out.printf("Case #%d: %d",ii+1,ans); out.println(); out.flush(); } } }
0
185
A12852
A11417
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.codejam.googlearse; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; public class Problem2 { public static void main(String arg[]) { try{ FileInputStream fstream = new FileInputStream("textfile.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileWriter foutstream = new FileWriter("test1.out"); BufferedWriter out = new BufferedWriter(foutstream); String strLine,copyStrLine=""; int caseCount = -1; strLine = br.readLine(); caseCount = Integer.parseInt(strLine); for(int j=0; j < caseCount; j++) //System.out.println (strLine); { strLine = br.readLine(); String[] splitStrings = strLine.split(" "); int countGooglers = Integer.parseInt(splitStrings[0]); int surprisingSet = Integer.parseInt(splitStrings[1]); int pValue = Integer.parseInt(splitStrings[2]); int pMaxCount = 0; for(int i = 0 ; i < countGooglers; i++ ) { int score = Integer.parseInt(splitStrings[3+i]); int n = score / 3; if(pValue > score){ continue; } if(score % 3 == 0){ if(n >= pValue){ pMaxCount++; } if(n == pValue - 1){ if(surprisingSet > 0){ pMaxCount++; surprisingSet--; } } } else if(score % 3 == 1){ if(n >= pValue - 1){ pMaxCount++; } } else{ if(n >= pValue - 1){ pMaxCount++; } if(n == pValue - 2){ if(surprisingSet > 0){ pMaxCount++; surprisingSet--; } } } } System.out.println("Case #" + (j + 1) + ": " + pMaxCount + "\n"); out.write("Case #" + (j + 1) + ": " + pMaxCount + "\n"); } out.close(); } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
186
A12852
A11520
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.math.*; import java.util.*; import java.io.*; import static java.lang.Math.*; public class DancingWiththeGooglers { public static void main (String [] args) throws IOException { String[]filename="test A-small A-large B-small B-large C-small C-large D-small D-large".split(" "); ////////////////// 0 1 2 3 4 5 6 7 8 String fn=filename[3]; f = new BufferedReader(new FileReader(fn+".in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(fn+".out"))); nl(); int t = ip(tk()); for (int i = 0; i < t; i++) { nl(); int n = ip(tk()),s=ip(tk()),p=ip(tk()); int res=0; int sp=0; for (int j = 0; j < n; j++) { int data=ip(tk()); int ans=data/3,rest=data%3; if(ans>=p)res++; else if(ans==p-1&&rest>0){res++;} else if(ans==p-1&&rest==0&&sp<s&&ans-1>=0){res++;sp++;} else if(ans==p-2&&rest==2&&sp<s){res++;sp++;} } out.println("Case #"+(i+1)+": "+res); } out.close(); System.exit(0); } static BufferedReader f; static StringTokenizer st; static void nl() throws IOException { st = new StringTokenizer(f.readLine()); } static String tk() { return st.nextToken(); } static void fill(Object array,int val){ if(array instanceof int[])Arrays.fill((int[])array,val); else for(Object o:(Object[])array)fill(o,val); } //static String min(String a,String b){return a.compareTo(b)<0?a:b;} static int ip(String s){return Integer.parseInt(s);} static long lp(String s){return Long.parseLong(s);} static int inf=Integer.MAX_VALUE/2; static int gcd(int a,int b){return b==0?a:gcd(b,a%b);} static boolean isPrime(int number) { if (number < 2) return false; if (number == 2) return true; if (number % 2 == 0) return false; for (int i = 3; i * i <= number; i += 2) if (number % i == 0) return false; return true; } static public class Comp implements Comparable<Comp> { public int compareTo(Comp other) {// myself first asc if (len == other.len) return str.compareTo(other.str);// myself first asc return other.len - len;// other first desc } int len; String str; public Comp(int len, String str) { super(); this.len = len; this.str = str; } } }
0
187
A12852
A12338
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 qualif2; import java.io.File; import java.util.Arrays; import java.util.Scanner; public class Qualif2 { public static void main(String[] args) throws Exception { Scanner scan = new Scanner(new File("input")); int num = Integer.parseInt(scan.nextLine()); for (int i = 1; i <= num; i++) { int googlers = scan.nextInt(); int surprising = scan.nextInt(); int score = scan.nextInt(); int[] totals = new int[googlers]; for (int j = 0; j < googlers; j++) { totals[j] = scan.nextInt(); } System.out.println("Case #" + i + ": " + solve(googlers, surprising, score, totals)); } } private static int solve(int googlers, int surprising, int score, int[] totals) { Arrays.sort(totals); int count = 0; if (score == 0) { return googlers; } for (int i = totals.length - 1; i >= 0; i--) { int total = totals[i]; if (total > 28) { count++; continue; } if (total == 0) { continue; } int base = total / 3; int r = total % 3; int n = base + (r > 0 ? 1 : 0); if (n >= score) { count++; } else if (surprising > 0) { surprising--; if (n + (r == 1 ? 0 : 1) >= score) { count++; } } else { break; } } return count; } }
0
188
A12852
A13078
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Dance { Scanner in; BufferedWriter out; Dance(String input, String output) throws Exception { in = new Scanner(new File(input)); FileWriter fstream = new FileWriter(output); out = new BufferedWriter(fstream); } public void solveAll() throws IOException { int T = in.nextInt(); int N, S, P; for (int test = 1; test <= T; test++) { N = in.nextInt(); S = in.nextInt(); P = in.nextInt(); int[] t = new int[N]; for(int i = 0; i < N; i++) { t[i] = in.nextInt(); } out.write("Case #" + test + ": " + solve(N, S, P, t)); out.newLine(); } } public int solve(int N, int S, int P, int[] t) { int count = 0; for(int i = 0; i < N; i++) { if(t[i] % 3 == 0) { if(t[i]/3 >= P) { count++; } else { if(S > 0 && t[i] != 0 && t[i]/3 + 1 >= P) { count++; S--; } } } else if(t[i] % 3 == 1) { if(t[i]/3 + 1 >= P) { count ++; } } else { if(t[i]/3 + 1 >= P) { count++; } else { if(S > 0 && t[i]/3 + 2 >= P) { count++; S--; } } } } return count; } public void close() throws IOException { in.close(); out.close(); } public static void main(String[] args) throws Exception { Dance pb = new Dance("input.txt", "output.txt"); pb.solveAll(); pb.close(); } }
0
189
A12852
A10121
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 code12.qualification; import java.io.File; import java.io.FileWriter; import java.util.Scanner; public class B { public static String solve(int N, int S, int p, int[] t) { // 3a -> (a, a, a), *(a - 1, a, a + 1) // 3a + 1 -> (a, a, a + 1), *(a - 1, a + 1, a + 1) // 3a + 2 -> (a, a + 1, a + 1), *(a, a, a + 2) int numPNoS = 0; int numPWithS = 0; for (int i = 0; i < N; i++) { int a = (int)Math.floor(t[i] / 3); int r = t[i] % 3; switch (r) { case 0: if (a >= p) { numPNoS++; } else if (a + 1 >= p && a - 1 >= 0) { numPWithS++; } break; case 1: if (a >= p || a + 1 >= p) { numPNoS++; } break; case 2: if (a >= p || a + 1 >= p) { numPNoS++; } else if (a + 2 >= p) { numPWithS++; } break; } } return "" + (numPNoS + Math.min(S, numPWithS)); } public static void main(String[] args) throws Exception { // file name //String fileName = "Sample"; String fileName = "B-small"; //String fileName = "B-large"; // file variable File inputFile = new File(fileName + ".in"); File outputFile = new File(fileName + ".out"); Scanner scanner = new Scanner(inputFile); FileWriter writer = new FileWriter(outputFile); // problem variable int totalCase; int N, S, p; int[] t; // get total case totalCase = scanner.nextInt(); for (int caseIndex = 1; caseIndex <= totalCase; caseIndex++) { // get input N = scanner.nextInt(); S = scanner.nextInt(); p = scanner.nextInt(); t = new int[N]; for (int i = 0; i < N; i++) { t[i] = scanner.nextInt(); } String output = "Case #" + caseIndex + ": " + solve(N, S, p, t); System.out.println(output); writer.write(output + "\n"); } scanner.close(); writer.close(); } }
0
190
A12852
A11341
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* Author: Gaurav Gupta Date: 14 Apr 2012 */ import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class Dancing { /** * TODO Put here a description of what this method does. * * @param args */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub. FileWriter fw = new FileWriter("Output2.txt"); PrintWriter pw = new PrintWriter(fw); Scanner sc = new Scanner(System.in); int T = sc.nextInt(); int N, S, p, t; for (int i = 0; i < T; i++) { N = sc.nextInt(); S = sc.nextInt(); p = sc.nextInt(); int avg = 3 * p; int sum = 0; for (int j = 0; j < N; j++) { t = sc.nextInt(); if (t >= (avg - 4)) { if (t < (avg - 2)) { if (S > 0 && t >= p) { sum++; S--; } } else { sum++; } } // System.out.print(t + ", "); } pw.println("Case #" + (i + 1) + ": " + sum); System.out.println("Case #" + (i + 1) + ": " + sum); } pw.close(); } public static boolean isBest(int t, int p) { return true; } }
0
191
A12852
A10765
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.io.PrintWriter; import java.io.Reader; public class Processor { public void process(TestCaseFactory factory, String filenameIn, String filenameOut) throws IOException, MalformedInputFileException { System.out.println("Started!"); final Reader in = new FileReader(filenameIn); final BufferedReader br = new BufferedReader(in); final PrintWriter out = new PrintWriter(new File(filenameOut)); final String str1 = br.readLine(); final int ncases = Integer.parseInt(str1); for (int i = 0; i < ncases; i++) { final TestCase item = factory.getInstance(i); item.readInput(br); item.solve(); item.writeOutput(out); } in.close(); out.close(); System.out.println("Finished!"); } }
0
192
A12852
A12603
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 googlecodequalificationround; import java.util.Scanner; /** * * @author LeongYan */ public class DancingWithGooglers { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); sc.nextLine(); int[] out = new int[t]; for (int i = 0; i < t; i++) { out[i] = 0; int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int[] scores = new int[n]; for (int j = 0; j < n; j++) { scores[j] = sc.nextInt(); } for (int j = 0; j < n; j++) { if(scores[j] > ((p * 3) - 3)){ out[i]++; } else if(scores[j] >= ((p * 3) - 4) && scores[j] <= ((p * 3) - 3) && s > 0){ if(scores[j] == 0){ } else{ out[i]++; s--; } } } } for (int i = 0; i < t; i++) { System.out.println("Case #" + (i + 1) + ": " + out[i]); } } }
0
193
A12852
A13151
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dancing { private static Reader in; private static PrintWriter out; public static final String NAME = "B-small-attempt1"; private static void main2() throws IOException { int N = in.nextInt(), S = in.nextInt(), p = in.nextInt(); int [] arr = new int [N + 1]; for (int i = 1; i <= N; i++) arr [i] = in.nextInt(); int [][] dp = new int [N + 1][S + 1]; dp [0][0] = 0; for (int i = 1; i <= N; i++) { int curscore = (arr [i] + 2) / 3, nscore = (arr [i] + 4) / 3; if (arr [i] == 0) curscore = nscore = 0; dp [i][0] = dp [i - 1][0]; if (curscore >= p) dp [i][0] = dp [i - 1][0] + 1; for (int j = 1; j <= S; j++) { dp [i][j] = Math.max (dp [i - 1][j - 1], dp [i - 1][j]); if (curscore >= p) dp [i][j] = Math.max (dp [i][j], dp [i - 1][j] + 1); if (nscore >= p) dp [i][j] = Math.max (dp [i][j], dp [i - 1][j - 1] + 1); } } out.println (dp [N][S]); } public static void main(String[] args) throws IOException { in = new Reader(NAME + ".in"); out = new PrintWriter(new BufferedWriter(new FileWriter(NAME + ".out"))); int numCases = in.nextInt(); for (int test = 1; test <= numCases; test++) { out.print("Case #" + test + ": "); main2(); } out.close(); System.exit(0); } /** Faster input **/ static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[1024]; int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; else return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; else return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') ret += (c - '0') / (div *= 10); } if (neg) return -ret; else return ret; } public char nextChar() throws IOException { char ret = 0; byte c = read(); while (c <= ' ') c = read(); return (char) c; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
0
194
A12852
A11863
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; /** * * @author Shubham */ public class Dancers { public static void main(String a[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for(int i=1;i<=t;i++) { String line = br.readLine(); String[] ints = line.split(" "); int n = Integer.parseInt(ints[0]); int s = Integer.parseInt(ints[1]); int l = Integer.parseInt(ints[2]); int c=0; for(int j=3;j<3+n;j++) { int sum = Integer.parseInt(ints[j]); int r = sum - 3*l; int r2 = (sum-l)/2; if(r2>=0) { if(r>=-2) { c++; } else if(r>=-4 && s>0) { c++; s--; } } } System.out.println("Case #"+i+": "+c); } } }
0
195
A12852
A11830
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package gcj; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class Dancing{ public static void main(String args[]) throws Exception { BufferedReader br=new BufferedReader(new FileReader("c:/b.in")); BufferedWriter out=new BufferedWriter(new FileWriter("c:/out.txt")); String s; int t=Integer.parseInt(br.readLine()); for(int i=0;i<t;i++) {s=br.readLine(); String s2[]=s.split(" "); int n=Integer.parseInt(s2[0]); int sub=Integer.parseInt(s2[1]); int p=Integer.parseInt(s2[2]); int arr[]=new int[n]; int res=0; for(int j=3;j<s2.length;j++) { // System.out.println("A"+s2[j]); arr[j-3]=Integer.parseInt(s2[j]); } for(int j=0;j<n;j++) { int v=arr[j]; if(v==0) { if(p==0) res++; continue; } if(v==1) { if(p==1||p==0) res++; continue; } if(v==2) { if(p==1) res++; else if(p==0&&sub>0) { sub--; res++; } continue; } // System.out.println(v+" "+res); if(v%3==0) { if(v/3-1>=p||v/3>=p) res++; else if(v/3+1>=p&&sub>0) { sub--; res++; } } if(v%3==1) { if(v/3>=p||v/3+1>=p) res++; } if(v%3==2) { if(v/3+1>=p||v/3>=p) res++; else if(v/3+2>=p&&sub>0) { sub--; res++; } } } out.write("Case #"+(i+1)+": "+res+"\n"); } out.close(); } }
0
196
A12852
A12704
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; public class Googlers { private static int testcases = 0; public static void main(String[] args) { String DataLine = ""; int line = 0; PrintWriter out; try { File inFile = new File("./config/B-small-attempt1.txt"); BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream(inFile))); out = new PrintWriter(new BufferedWriter(new FileWriter("./config/out3" + ".txt"))); while((DataLine = br.readLine()) != null) { if(line == 0) { testcases = Integer.parseInt(DataLine.trim()); line++; } else { if(line<=testcases) { String[] datas = DataLine.split(" "); int N = Integer.parseInt(datas[0]); int S = Integer.parseInt(datas[1]); int P = Integer.parseInt(datas[2]); int[] pnts = new int[N]; for(int i=0;i<N;i++) pnts[i] = Integer.parseInt(datas[2+i+1]); int reslt = getResult(N, S,P,pnts); out.write("Case #"+line+": "+reslt+"\n"); System.out.println("Case #"+line+": "+reslt+"\n"); line++; } } } br.close(); out.close(); } catch(FileNotFoundException fe) { fe.printStackTrace(); } catch(IOException ie) { ie.printStackTrace(); } } private static int getResult(int N,int S,int P,int[] pnts) { int resCount = 0; int temp = 0; System.out.println("N:S:P::"+N+":"+S+":"+P); if(P==0) return N; for(int j=0;j<N;j++) { int check = pnts[j]; if(temp < S && P > 1) { if(((P-2)*3)+2 <= check ) { resCount++; if(((P-2)*3)+2 == check || ((P-2)*3)+2 == check-1) temp++; } } else { if(((P-1)*3)+1 <= check ) resCount++; } } return resCount; } }
0
197
A12852
A11173
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 BSmall { public static void main(String[] args) throws IOException { Scanner in = new Scanner(new File("B-small-attempt1.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("B-Small.out"))); int T = Integer.parseInt(in.nextLine()); for (int i = 0; i < T; i++) { String[] Line = in.nextLine().split(" "); int counter = 0; int surprising = Integer.parseInt(Line[1]); int thresh = Integer.parseInt(Line[2]); int len = Line.length; for (int j = 3; j < len; j++) { int score = Integer.parseInt(Line[j]); if (score == 0) { if (score >= thresh) { counter++; } Line[j] = null; continue; } int mod3 = score % 3; switch (mod3) { case 2: if ((score/3) + 1>= thresh) { counter++; Line[j] = null; break; } case 1: if ((score/3) + 1 >= thresh) { counter++; Line[j] = null; break; } case 0: if ((score/3) >= thresh) { counter++; Line[j] = null; break; } } } for (int l = 3; l < len && surprising > 0; l++) { if (!(Line[l] == null)) { int score = Integer.parseInt(Line[l]); int mod3 = score % 3; switch (mod3) { case 2: if ((score/3) + 2 >= thresh) { counter++; surprising--; break; } case 1: if ((score/3) + 1 >= thresh) { counter++; surprising--; break; } case 0: if ((score/3) + 1 >= thresh) { counter++; surprising--; break; } } } } out.write("Case #"+ (i+1) +": " + counter); if (i != T-1) out.write("\n"); //System.out.println(counter); //System.out.println(Arrays.toString(Line)); } out.close(); System.exit(0); } }
0
198
A12852
A11766
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.util.Set; import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; public class B implements CodeJamCaseSolver { int n, s, p; int[] t; @Override public void input(Scanner in) { n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); t = new int[n]; for(int i=0;i<n;i++) t[i] = in.nextInt(); } @Override public String solve() { int count = 0; int remains = s; for(int i=0;i<n;i++) { int notallowed; int allowed; int v = t[i]; if(v%3 == 0) { notallowed = v/3; if(v/3 > 0) allowed = v/3+1; else allowed = notallowed; } else if(v%3 == 1) { notallowed = v/3+1; allowed = v/3+1; } else { notallowed = v/3+1; if(v/3+1 > 0) allowed = v/3+2; else allowed = notallowed; } if(notallowed >= p) { count++; } else if(allowed >= p && remains > 0) { count++; remains--; } } return count + ""; } public static void main(String[] args) throws Exception { CodeJamSolver.launch(8, "B-example.in", new CodeJamCaseSolverFactory() { @Override public CodeJamCaseSolver createSolver() { return new B(); } }); } } interface CodeJamCaseSolver { void input(Scanner in); String solve(); } interface CodeJamCaseSolverFactory { CodeJamCaseSolver createSolver(); } class CodeJamSolver { public static void launch(int threadNumber, String inputFileNameOnDesktop, CodeJamCaseSolverFactory factory, Integer... caseNumbers) throws Exception { if(!inputFileNameOnDesktop.endsWith(".in")) throw new RuntimeException("input filename should ends with '.in'"); String outputFileNameOnDesktop = inputFileNameOnDesktop.substring(0, inputFileNameOnDesktop.length()-3) + ".out"; String desktopDir = System.getProperty("user.home") + "/Desktop"; String inputFile = desktopDir + "/" + inputFileNameOnDesktop; String outputFile = desktopDir + "/" + outputFileNameOnDesktop; launch(inputFile, outputFile, threadNumber, factory, caseNumbers); } private static void launch(String inputFilePath, String outputFilePath, final int threadNumber, final CodeJamCaseSolverFactory factory, Integer... caseIndices) throws Exception { final Object lock = new Object(); final long startTime = System.currentTimeMillis(); final Scanner in = new Scanner(new File(inputFilePath)); final int casen = in.nextInt(); final int[] nextIndex = {0}; final String[] results = new String[casen]; final Set<Integer> caseIndexToSolve = createCaseIndicesToSolve(casen, caseIndices); ExecutorService executor = Executors.newFixedThreadPool(threadNumber); for(int i=0;i<casen;i++) { executor.execute(new Runnable() { @Override public void run() { int casei; String result = null; { CodeJamCaseSolver caseSolver = factory.createSolver(); synchronized(lock) { caseSolver.input(in); casei = nextIndex[0]++; } if(caseIndexToSolve.contains(casei+1)) result = caseSolver.solve(); } if(result != null) { synchronized(lock) { results[casei] = result; int solved = countNotNull(results); outputProgess(startTime, solved, caseIndexToSolve.size()); } } } }); } executor.shutdown(); executor.awaitTermination(Long.MAX_VALUE, TimeUnit.SECONDS); printLine(); outputResult(results, outputFilePath); printLine(); System.out.println("Output is written to " + outputFilePath); } private static Set<Integer> createCaseIndicesToSolve(int casen, Integer... caseIndices) { final Set<Integer> set = new TreeSet<Integer>(); if(caseIndices.length == 0) { for(int i=1;i<=casen;i++) set.add(i); } else { for(int v : caseIndices) { if(v < 1 || v > casen) throw new RuntimeException("invalid index : " + v); set.add(v); } } return set; } private static void printLine() { for(int i=0;i<100;i++) System.out.print("-"); System.out.println(); } private static int countNotNull(final String[] results) { int solved = 0; for(String s : results) if(s != null) solved++; return solved; } private static void outputProgess(long startTime, int solved, int caseNumberToSolve) { long duration = System.currentTimeMillis() - startTime; long estimation = (long)Math.round((double)duration * caseNumberToSolve / solved / 1000); System.out.printf("%.03fs : %d/%d solved (estimated : %dm %ds)\n", (double)duration / 1000, solved, caseNumberToSolve, estimation / 60, estimation % 60); } private static void outputResult(final String[] results, String outputFilePath) throws FileNotFoundException { PrintStream ps = new PrintStream(outputFilePath); for(int i=0;i<results.length;i++) { if(results[i] != null) { String line = String.format("Case #%d: %s", i+1, results[i]); System.out.println(line); ps.println(line); } } ps.close(); } }
0
199