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
A12824
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 TripletGenerator { private static Map<Integer, TripletPair> mapTotalScoreToGroup = new Hashtable<Integer, TripletPair> (); private int dancerScore[] = new int[] {15, 13, 11}; private int surpriseCount = 1; private int pointMark = 5; private int finalValue = 0; public TripletGenerator (int dancerScore[], int surpriseCount, int pointMark) { this.dancerScore = dancerScore; this.surpriseCount = surpriseCount; this.pointMark = pointMark; } public static void main (String arg[]) throws IOException { if (arg.length != 1) { System.out.println("Usage : java TripletGenerator <InputFile>"); System.exit(1); } TripletGenerator.processInput(new File(arg[0])); } public static void processInput (File fileName) throws IOException { BufferedReader in = new BufferedReader(new FileReader(fileName)); PrintWriter out = new PrintWriter ("output.txt"); TripletGenerator.populateMap(); TripletGenerator.displayScoreMap(); int caseCount = new Integer (in.readLine()); for (int i = 0; i < caseCount; ++i) { String currLine = in.readLine(); if (currLine == null) throw new IllegalArgumentException("Lesser Lines to complete case " + (i+1)); String token[] = currLine.split(" "); int num[] = new int [token.length]; for (int j= 0; j < token.length; ++j) num[j] = new Integer (token[j]); int dancerCount = num[0]; int dancerScore[] = new int [dancerCount]; int surpriseCount = num[1]; int pointMark = num[2]; System.arraycopy(num, 3, dancerScore, 0, dancerCount); TripletGenerator generator = new TripletGenerator(dancerScore, surpriseCount, pointMark); int finalValue = generator.getFinalValue(); out.println ("Case #" + (i+1) + ": " + finalValue); } in.close(); out.close(); } public int getFinalValue () { recurCombination (0, new boolean[dancerScore.length], 0); return finalValue; } private void recurCombination (int dancerIndex, boolean comb[], int currSurpriseCount) { if (currSurpriseCount > surpriseCount) return; if (dancerIndex == dancerScore.length) { if (currSurpriseCount != surpriseCount) return; int currValue = getCombinationValue(comb); if (currValue > finalValue) finalValue = currValue; return; } for (boolean isSurprise : new boolean [] {false, true}) { comb[dancerIndex] = isSurprise; if (isSurprise) recurCombination (dancerIndex + 1, comb, currSurpriseCount + 1); else recurCombination (dancerIndex + 1, comb, currSurpriseCount); } } private int getCombinationValue (boolean comb[]) { Triplet triplet [] = new Triplet [dancerScore.length]; System.out.println("---------------------------------"); System.out.println("Combination = " + Arrays.toString(comb)); int value = 0; for (int i = 0; i < dancerScore.length; ++i) { int currDancerScore = dancerScore [i]; TripletPair tripletPair = mapTotalScoreToGroup.get(currDancerScore); triplet[i] = (comb[i]) ? tripletPair.tripletSurprise : tripletPair.tripletRegular; if (triplet[i] == null) return 0; System.out.println(triplet[i].totalScore + " " + triplet[i]); if (triplet[i].maxScore >= pointMark) value++; } System.out.println("Value = " + value); return value; } private static void displayScoreMap () { for (int i = 0; i <= 30; ++i) { TripletPair tripletPair = mapTotalScoreToGroup.get(i); System.out.println(String.format("%2d %s", i, tripletPair)); } } public static void populateMap () { for (int i = 0; i <= 10; ++i) { for (int j = 0; j <= 10; ++j) { if (Math.abs(i-j) > 2) continue; for (int k = 0; k <= 10; ++k) { if (Math.abs(i-k) > 2 || Math.abs(j-k) > 2) continue; Triplet triplet = new Triplet(i, j, k); TripletPair tripletPair = mapTotalScoreToGroup.get(triplet.totalScore); if (tripletPair == null) tripletPair = new TripletPair(); tripletPair.set(triplet); mapTotalScoreToGroup.put(triplet.totalScore, tripletPair); } } } } private static Triplet max (Triplet tA, Triplet tB) { if (tA == null && tB == null) throw new IllegalStateException ("Both the triplets are null!"); if (tA == null) return tB; if (tB == null) return tA; return (tB.maxScore > tA.maxScore) ? tB : tA; } static class TripletPair { Triplet tripletSurprise = null; Triplet tripletRegular = null; public void set (Triplet triplet) { if (triplet.isSurprise) tripletSurprise = (tripletSurprise == null) ? triplet : TripletGenerator.max (tripletSurprise, triplet); else tripletRegular = (tripletRegular == null) ? triplet : TripletGenerator.max (tripletRegular , triplet); } public String toString () { String strRegular = (tripletRegular == null) ? "-" : tripletRegular.toString(); String strSurprise = (tripletSurprise == null) ? "-" : tripletSurprise.toString(); return String.format("%-20s %-20s", strRegular, strSurprise); } } static class Triplet { int x, y, z; boolean isSurprise = false; int maxScore, totalScore; public Triplet (int x, int y, int z) { this.x = x; this.y = y; this.z = z; this.totalScore = x + y + z; int min = Math.min (Math.min(x, y), z); int max = Math.max (Math.max(x, y), z); if (max - min < 0 || max - min > 2) throw new IllegalStateException ("Max=" + max + " Min=" + min); isSurprise = (max - min < 2) ? false : true; maxScore = max; } @Override public String toString () { return String.format("%d,%d,%d,%s,%d", x, y, z, "" + isSurprise, maxScore); } } }
0
600
A12852
A10958
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class Dancing { public static void main(String[] args) { int t, n, s, p, y; int[] ti; Scanner scan = new Scanner(System.in); t = scan.nextInt(); for(int i=1; i<=t; i++){ y = 0; int surprised = 0; n = scan.nextInt(); s = scan.nextInt(); p = scan.nextInt(); ti = new int[n]; for(int j=0; j<n; j++){ ti[j] = scan.nextInt(); } int limiteInf; if(p <= 1) limiteInf = p; else limiteInf = p + 2 * (p - 2); for(int j=0; j<ti.length; j++){ if(limiteInf == 0){ y++; }else if(ti[j] >= (limiteInf + 2)){ y++; //System.out.println("Entrou 1: " + ti[j]); }else if(ti[j] >= limiteInf && ti[j] < (limiteInf + 2) && surprised < s){ y++; surprised++; //System.out.println("Entrou 2: " + ti[j]); } } System.out.println("Case #" + i + ": " + y); } } }
0
601
A12852
A11732
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package de.johanneslauber.codejam; import java.io.IOException; /** * * @author Johannes Lauber - joh.lauber@googlemail.com * */ public class Main { /** * @author Johannes Lauber - joh.lauber@googlemail.com * @param Args */ public static void main(String[] Args) { // solveProblem("input/A-small-practice.in", "StoreCredit"); // solveProblem("input/A-large-practice.in", "StoreCredit"); // solveProblem("input/B-small-practice.in", "ReverseWords"); // solveProblem("input/B-large-practice.in", "ReverseWords"); // solveProblem("input/C-small-practice.in", "T9Spelling"); // solveProblem("input/C-large-practice.in", "T9Spelling"); // solveProblem("input/A-small-practice.in", "SpeakinginTongues"); solveProblem("input/B-small-attempt.in", "DancingGooglers"); } /** * * @author Johannes Lauber - joh.lauber@googlemail.com * @param fileName * @param problemName */ private static void solveProblem(String fileName, String problemName) { CaseProvider caseProvider = new CaseProvider(); try { try { caseProvider.importFile( fileName, Class.forName("de.johanneslauber.codejam.model.impl." + problemName + "Case")); caseProvider.solveCases(Class .forName("de.johanneslauber.codejam.model.impl." + problemName + "Problem")); } catch (ClassNotFoundException e) { System.out.println("Error finding implemented Case: " + e.getMessage()); } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } catch (IOException e) { System.out.println("Error reading file: " + e.getMessage()); } } }
0
602
A12852
A12791
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.DataInputStream; import java.io.DataOutputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class danceGooglers { private static void readFile () { String str, temp[]; int T, n, i, s, p, totals[]; try { FileInputStream fistream = new FileInputStream("src/qualification_round/B-small-attempt1.in"); DataInputStream dis = new DataInputStream(fistream); BufferedReader br = new BufferedReader(new InputStreamReader(dis)); // Read the number of test cases str = br.readLine(); T = Integer.parseInt(str); System.out.println ("Number of test cases:" + T); // Read the test cases for (int tCtr = 0; tCtr < T; tCtr++) { System.out.print("Case #" + (tCtr+1) + ": "); // Read each line of input file str = br.readLine(); // processInput(str); writeFile((tCtr+1), processInput(str)); } dis.close(); } catch (FileNotFoundException fnfe) { System.out.println ("File is not found"); } catch (IOException ioe) { System.out.println ("IO Error"); } } private static int processInput (String str) { int n, s, p, total, quo, rem; int res = 0, sur = 0; String temp[] = str.split(" "); n = Integer.parseInt(temp[0]); s = Integer.parseInt(temp[1]); p = Integer.parseInt(temp[2]); for (int i = 0; i < n; i++) { total = Integer.parseInt(temp[i+3]); if (total >= p) { quo = total / 3; rem = total % 3; if (quo >= p) { res++; } else if (rem == 2) { if ((quo + 1) >= p) { res++; } else if ((quo + 2) >= p && sur < s) { sur++; res++; } } else if (rem == 1) { if ((quo + 1) >= p) { res++; } } else if (rem == 0) { if ((quo + 1) >= p && sur < s) { sur++; res++; } } } } System.out.println(res); return res; } private static void writeFile (int n, int Res) { try { FileOutputStream fostream = new FileOutputStream("src/qualification_round/B-small-attempt1.out", true); DataOutputStream dos = new DataOutputStream(fostream); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(dos)); bw.write("Case #" + n + ": " + Res); bw.newLine(); bw.close(); } catch (FileNotFoundException fnfe) { System.out.println ("File is not found"); } catch (IOException ioe) { System.out.println ("IO Error"); } } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub readFile(); } }
0
603
A12852
A11894
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 testC { public static void main(String args[]){ int arrayInt[]; String str=""; int numbersOfGooglers=0; int S=0; int P=0; int index=0; int count=0; int arrResults[]; try{ FileReader fr = new FileReader("2.txt"); BufferedReader br = new BufferedReader(fr); int size = Integer.parseInt(br.readLine()); for(int loop=0;loop<size;loop++){ str= br.readLine(); char arraychar[] = str.toCharArray(); // = new int[100]; arrayInt = new int[100]; index=0; count=0; String s; s=""; for(int i=0;i<str.length();i++){ if(arraychar[i] != ' '){ s+=arraychar[i]; }else{ arrayInt[index++] = Integer.parseInt(s); s=""; } } arrayInt[index++] = Integer.parseInt(s); s=""; numbersOfGooglers = arrayInt[0]; S = arrayInt[1]; P = arrayInt[2]; arrResults = new int[numbersOfGooglers]; index=3; for(int i=0;i<numbersOfGooglers;i++){ arrResults[i] = arrayInt[index++]; } int SS=S; int PP=P; int check=0; S=SS; for(int i=0;i<numbersOfGooglers;i++){ P=PP; while(P<30) { if(!(P-1<0 || P-2<0)){ if(P*3==arrResults[i] || P+(P-1)+(P-1)==arrResults[i] || P+(P+1)+(P+1)==arrResults[i] || P+(P)+(P+1)==arrResults[i] || P+(P)+(P-1)==arrResults[i]) { count++; break; } else if(S>0 && ( P+(P-1)+(P+1)==arrResults[i] || P+(P+2)+(P+2)==arrResults[i] || P+(P-2)+(P-2)==arrResults[i] || P+(P-1)+(P-2)==arrResults[i] || P+(P+1)+(P+2)==arrResults[i])) { count++; S--; break; } }else if((P-1<0)){ if(P*3==arrResults[i] || P+(P+1)+(P+1)==arrResults[i] || P+(P)+(P+1)==arrResults[i] ) { count++; break; } else if(S>0 && ( P+(P+2)+(P+2)==arrResults[i] || P+(P+1)+(P+2)==arrResults[i])) { count++; S--; break; } }else if((P-2<0)){ if(P*3==arrResults[i] || P+(P-1)+(P-1)==arrResults[i] || P+(P+1)+(P+1)==arrResults[i] || P+(P)+(P+1)==arrResults[i] || P+(P)+(P-1)==arrResults[i]) { count++; break; } else if(S>0 && ( P+(P-1)+(P+1)==arrResults[i] || P+(P+2)+(P+2)==arrResults[i] || P+(P+1)+(P+2)==arrResults[i])) { count++; S--; break; } } P++; } /* if(arrResults[i]/P<4){ if(arrResults[i]%P < 2){ count++; break; }else if(arrResults[i]%P == 2 && S>0){ count++; S--; break; } } P++; */ } System.out.println("Case #"+(loop+1)+": "+count); /* for(int j=0;j<numbersOfGooglers;j++) System.out.print(arrResults[j]+" "); System.out.println();*/ } br.close(); fr.close(); }catch(IOException ex){ ex.printStackTrace(); } } }
0
604
A12852
A11573
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 ProbB { public static void main(String[] args) throws FileNotFoundException, IOException { ProbB p = new ProbB(); p.solveAll(); } int tests = 0; Scanner in; BufferedWriter out; public ProbB() throws FileNotFoundException, IOException { out = new BufferedWriter(new FileWriter("b.out")); in = new Scanner(new File("b.in")); tests = in.nextInt(); in.nextLine(); //System.out.println(tests); } public void solveAll() throws IOException { for(int i = 0; i < tests; i++) { solve(i+1); } out.close(); in.close(); } public void solve(int casenr) throws IOException { int n, s, p, gar = 0, may = 0; n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); for(int i = 0; i < n; i++) { int tot = in.nextInt(); int tmay = 3*p-4; int tgar = 3*p-2; if(tmay < 0) tmay = p; if(tot >= tgar) { gar++; } else if(tot >= tmay) { may++; } } out.write("Case #"+casenr+": "); out.write(new Integer(gar+Math.min(s, may)).toString()); out.write('\n'); } }
0
605
A12852
A12131
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qualification; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class DancingWithTheGooglers { static String dir="/home/casatta/Scaricati/"; // static String dir="data/"; static String fname="B-small-attempt0.in"; // static String fname="DancingWithTheGooglers"; public void test(Scanner input, PrintWriter out, Long i) { int n=input.nextInt(); int surprising=input.nextInt(); int p=input.nextInt(); int max=p*3; int notSurprising=max-2; int isSurprising=max-4; int count=0; int current; System.out.println("n=" + n + " surprising=" + surprising + " p=" + p ); System.out.println("max=" + max + " notSurprising=" + notSurprising + " isSurprising=" + isSurprising ); for(int j=0;j<n;j++) { current=input.nextInt(); System.out.print(" " + current); if(current>=notSurprising) count++; else if(current>=isSurprising && surprising>0 && current>=p) { count++; surprising--; } } System.out.println(); String result = "Case #" + (i+1) + ": " +count; out.println(result); System.out.println(result); System.out.println(); } public void run() { try { String inputPath = dir + fname; Scanner input =new Scanner(new File(inputPath)); FileWriter outFile = new FileWriter(inputPath + ".out"); PrintWriter out = new PrintWriter(outFile); try { Long testCases = input.nextLong(); input.nextLine(); for(Long i=0L ; i < testCases ; i++) test(input,out,i); } finally { input.close(); out.close(); } } catch (IOException ex){ ex.printStackTrace(); } } public static void main(String[] args) { DancingWithTheGooglers template = new DancingWithTheGooglers(); template.run(); } }
0
606
A12852
A11723
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int no = sc.nextInt(); for (int s = 1; s <= no; s++) { int players = sc.nextInt(); int stars = sc.nextInt(); int best = sc.nextInt(); int count = 0; int k; for (int i = 0; i < players; i++) { int j = sc.nextInt(); k = (int) Math.floor(j / 3); if (k >= best) { count++; } else if (k < best) { int diff = j - (k * 3); if (diff == 1 && (diff + k) == best) { count++; continue; } else if (diff == 2) { if ((k + 1) == best) { count++; continue; } else if (stars > 0 && (k + diff) == best) { count++; stars--; continue; } } else if (diff == 0) { int first = k - 1; int second = k; int third = k + 1; if ((stars > 0) && (third == best) && first > 0) { stars--; count++; continue; } } } } System.out.println("Case #" + s + ": " + count); } } }
0
607
A12852
A11072
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.Scanner; public class Problem2 { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("input.txt")); PrintStream output = new PrintStream(new FileOutputStream(new File("output.txt"))); int T = input.nextInt(); input.nextLine(); for(int i=1; i <= T; ++i) { Scanner line = new Scanner(input.nextLine()); int N = line.nextInt(); int S = line.nextInt(); int p = line.nextInt(); System.out.printf("Case:%d, N:%d, S:%d, p:%d\n", i,N,S,p); int result = 0; for(int j=0; j < N; ++j) { int points = line.nextInt(); int threshold,special_threshold; if (p==0) { threshold = 0; special_threshold = 0; } if (p==1) { threshold = 1; special_threshold = 1; } else { threshold = 3*p-2; special_threshold = 3*p-4; } if(points >= threshold) { result++; } else if( (S>0) && (points >= special_threshold)) { S--; result++; } } output.println("Case #" + i + ": " + result); } } }
0
608
A12852
A10882
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
public interface Solver { public String solve(); }
0
609
A12852
A12618
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.code.jam; 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.Scanner; public class B { public static int Case,N,S,p; public static int[] Ti = new int[102]; // public static final String inputfileName = "B-small.in"; // public static final String outputfileName = "B-small.out"; public static final String inputfileName = "B-small-attempt6.in"; public static final String outputfileName = "B-small-attempt6.out"; // public static final String inputfileName = "B-large-attempt0.in"; // public static final String outputfileName = "B-large-attempt0.out"; /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner s = null; PrintWriter outputStream = null; try{ s = new Scanner(new BufferedReader( new FileReader(inputfileName))); outputStream = new PrintWriter( new BufferedWriter(new FileWriter(outputfileName))); Case = s.nextInt(); for(int i=0;i<Case;i++){ N=s.nextInt(); S=s.nextInt(); p=s.nextInt(); for(int j=0;j<N;j++){ Ti[j] = s.nextInt(); } int rst = solve(); System.out.format("Case #%d: %d\n" , i+1, rst); outputStream.format("Case #%d: %d\n" , i+1,rst); } }finally{ if (s != null) { s.close(); } if (outputStream != null) { outputStream.close(); } } } private static int solve() { // TODO Auto-generated method stub int cntS,rst; cntS=0; rst=0; for(int i=0;i<N;i++){ int tmp = Ti[i]/3; if(tmp==0){ if(Ti[i]>=p){ if(p==2){ cntS++;rst++; } else if(p<2){ rst++; } } continue; } if(Ti[i]==5){ if(p<=2){ rst++; } else if(p==3){ rst++;cntS++; } continue; } if(Ti[i]==4){ if(p<=2){ rst++; } continue; } if(Ti[i]==3){ if(p<=1){ rst++; } else if(p==2){ rst++;cntS++; } continue; } if(Ti[i]%tmp==0){ if(tmp>=p){ rst++; } else if(tmp+1==p){ rst++;cntS++; } } else if(Ti[i]%tmp==1){ if(tmp+1>=p){ rst++; } }else{ if(tmp+1>=p){ rst++; } else if(tmp+2>=p){ rst++;cntS++; } } } //System.out.println(N); if(cntS-S>0){ rst -= cntS-S; } return rst; } }
0
610
A12852
A13051
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class B { HashMap<Integer, HashSet<ArrayList<Integer>>> pre = new HashMap<Integer, HashSet<ArrayList<Integer>>>(); { for(int a = 0; a <= 10; a++) for(int b = 0; b <= a; b++) for(int c = 0; c <= b; c++){ ArrayList<Integer> tmp = new ArrayList<Integer>(); tmp.add(a); tmp.add(b); tmp.add(c); Integer sum = a + b + c; if(a - c > 2) continue; if(pre.get(sum) == null) pre .put(sum, new HashSet<ArrayList<Integer>>()); pre.get(sum).add(tmp); } } /* * 18 = 6 6 6, 5 6 7 * 19 = 5 7 7, 6 6 7 * 20 = 6 7 7 * 21 = 7 7 7, 6 7 8 * 28 = 8 10 10 */ private boolean isSurprize(ArrayList<Integer> a){ return (a.get(0) - a.get(2)) == 2; } private boolean canBeSurprize(int a) { for(ArrayList<Integer> t: pre.get(a)) if(isSurprize(t)) return true; return false; } private int getBestScore(int a, boolean surprize){ int best = -1; for(ArrayList<Integer> t: pre.get(a)) { if(surprize != isSurprize(t)) continue; if(best < t.get(0)) best = t.get(0); } return best; } private void printState(int a){ for(ArrayList<Integer> t: pre.get(a)){ for(Integer i: t) System.out.print(i + " "); System.out.print(", "); } System.out.println(); } private void run() throws FileNotFoundException { Scanner sc = new Scanner(new FileInputStream("B-small-attempt0.in")); System.setOut(new PrintStream(new FileOutputStream("b.out"))); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int arr[] = new int[n]; for (int j = 0; j < n; j++) { arr[j] = sc.nextInt(); // printState(arr[j]); } Arrays.sort(arr); int bes[] = new int[n]; for(int j = n - 1; j >= 0; j--){ int bestS = getBestScore(arr[j], true); int bestNS = getBestScore(arr[j], false); if(bestNS >= p){ bes[j] = bestNS; continue; } if(s > 0 && bestS >= p) { bes[j] = bestS; s--; continue; } bes[j] = bestNS; } int res = 0; for(int j = 0; j < bes.length; j++) if(bes[j] >= p) res++; System.out.println("Case #" + (i + 1) + ": " + res); } } public static void main(String[] args) throws FileNotFoundException { B b = new B(); b.run(); } }
0
611
A12852
A12847
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Dancing { static int n; static int[] score; static int solve( int surp, int p ) { int notPossible = 0; int cutOff = 3*p - 4; int surCutOff = 3*p-2; Arrays.sort( score ); if( p == 0 ) return n; if( p==1 ) // only score of zero is invalid { for( int i=0; i<n; i++ ) { if( score[ i ] == 0 ) notPossible++; else break; } return n-notPossible; } for( int i=0; i<n; i++ ) { /* if( score[ i ] <= p ) { notPossible++; continue; } */ if( score[ i ]< cutOff ) { notPossible++; continue; } // check if surprising else if(score[i] < surCutOff) // surprising possible { if( surp > 0 ) { surp--; continue; } else { notPossible++; } } else if( score[ i ] >= surCutOff ) { break; } else break; } return n-notPossible; } public static void main( String[] args ) throws IOException { FileWriter fr= new FileWriter("/home/gowri/Desktop/out.txt"); BufferedWriter out = new BufferedWriter( fr ); BufferedReader br = new BufferedReader( new InputStreamReader( System.in )); int T = Integer.parseInt( br.readLine() ); String s; StringTokenizer tok; for( int i=0; i<T; i++ ) { s = br.readLine(); tok = new StringTokenizer( s ); n = Integer.parseInt( tok.nextToken() ); score = new int[ n ]; int surp = Integer.parseInt( tok.nextToken() ); int p = Integer.parseInt( tok.nextToken() ); for( int j=0; j<n; j++ ) { score[ j ] = Integer.parseInt( tok.nextToken() ); } String res = String.format( "Case #%d: ", i+1 ); out.write( res ); out.write( ( "" + solve( surp, p ) ) ); out.newLine(); } out.close(); } }
0
612
A12852
A12856
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; public class B { class Solver implements Runnable { int testId; boolean failed = false; int result = 0; Solver(int testId) { this.testId = testId; } String in, out = ""; ArrayList<String> text = new ArrayList<String>(); int N,S, p; private void readInput() { N = nextInt(); S = nextInt(); p = nextInt(); } int res; public void run() { for (int i=0; i<N; i++){ int t = nextInt(); if (t >= (3*p-2) && t >=p) {//3*points_goal-2 is enough to reach goal for normal score result++; } else if (S>0 && t>=(3*p-4) && t >=p) { //3*pg-4 is enough to reach for surprising score result++; S--; } } } private void printOutput() { if (failed) { writer.println("0"); System.out.println("FAILURE!!!"); } else { writer.println(String.format("Case #%d: %d", testId, result)); } } } // solve the problem here private void solve(){ int numTests = nextInt(); for (int testId = 1; testId <= numTests; testId++) { Solver solver = new Solver(testId); solver.readInput(); solver.run(); solver.printOutput(); } } BufferedReader reader; StringTokenizer tokenizer = null; PrintWriter writer; String encrypted = "ejp mysljylc kd kxveddknmc re jsicpdrysi"+ "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd"+ "de kr kd eoya kw aej tysr re ujdr lkgc jvq"; String output = "our language is impossible to understand"+ "there are twenty six factorial possibilities"+ "so it is okay if you want to just give upz"; char[] code = new char[256]; private void preparehalfcode() { for (int i = 0; i<encrypted.length(); i++) { code[encrypted.charAt(i)] = output.charAt(i); } } private void prepare() { preparehalfcode(); encrypted = encrypted.toUpperCase(); output = output.toUpperCase(); preparehalfcode(); } public void run() { try { long now = System.currentTimeMillis(); String problemfilename = this.getClass().getSimpleName(); reader = new BufferedReader(new FileReader(problemfilename + ".in")); writer = new PrintWriter(problemfilename + ".out"); prepare(); solve(); reader.close(); writer.close(); System.out.println(System.currentTimeMillis() - now + "ms"); } catch (Exception e) { throw new RuntimeException(e); } } int nextInt() { return Integer.parseInt(nextToken()); } double nextDouble() { return Double.parseDouble(nextToken()); } long nextLong() { return Long.parseLong(nextToken()); } String nextToken() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } /** * @param args */ public static void main(String[] args) { new B().run(); } }
0
613
A12852
A11371
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 { public static void main(String[] args) throws IOException { Kattio io = new Kattio(System.in, new FileOutputStream("dance.out")); int T = io.getInt(); for (int test = 1; test <= T; test++) { int N = io.getInt(); int S = io.getInt(); int p = io.getInt(); int res = 0; for (int i = 0; i < N; i++) { int t = io.getInt(); int h = t/3; boolean surprise = t >= 2 && t <= 28; if (t % 3 != 0) h++; if (h >= p) { res++; } else if (surprise && h+1 >= p && S > 0 && t%3 != 1) { res++; S--; } } io.println("Case #"+test+": "+res); } io.close(); } static class Kattio extends PrintWriter { public Kattio(InputStream i) { super(new BufferedOutputStream(System.out)); r = new BufferedReader(new InputStreamReader(i)); } public Kattio(InputStream i, OutputStream o) { super(new BufferedOutputStream(o)); r = new BufferedReader(new InputStreamReader(i)); } public boolean hasMoreTokens() { return peekToken() != null; } public int getInt() { return Integer.parseInt(nextToken()); } public double getDouble() { return Double.parseDouble(nextToken()); } public long getLong() { return Long.parseLong(nextToken()); } public String getWord() { return nextToken(); } private BufferedReader r; private String line; private StringTokenizer st; private String token; private String peekToken() { if (token == null) try { while (st == null || !st.hasMoreTokens()) { line = r.readLine(); if (line == null) return null; st = new StringTokenizer(line); } token = st.nextToken(); } catch (IOException e) { } return token; } private String nextToken() { String ans = peekToken(); token = null; return ans; } } }
0
614
A12852
A10364
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qvark.codejam.dancinggooglers; import java.util.Scanner; public class DancingGooglers { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int i = 1; i <= t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int r = 0; for (int j = 0; j < n; j++) { int total = in.nextInt(); int score = total / 3; int mod = total % 3; if (total == 0) { if (p == 0) r++; } else if (score >= p || (score+1>=p && mod>=1)) { r++; } else if (score + 1 >= p && mod < 1 && s > 0) { r++; s--; } else if (score + 2 >= p && mod == 2 && s > 0) { r++; s--; } } System.out.format("Case #%d: %d\n", i, r); } } }
0
615
A12852
A12438
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class dance { public static void main(String... args){ Scanner in = new Scanner(System.in); int cases = in.nextInt(); int[] counts = new int[cases]; for(int i = 0;i<cases;i++){ int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int sUsed = 0; // special cases used int[] nums = new int[n]; int[][] scores = new int[n][3]; for(int k=0;k<n;k++){ nums[k] = in.nextInt(); int mod = nums[k] % 3; int div = nums[k] /3; if (mod == 2 && sUsed < s && div + 2 == p){ scores[k][0] = div + 2; scores[k][1] = div; scores[k][2] = div; sUsed +=1; } else if(mod == 0 && div + 1 == p && sUsed <s && div > 0){ scores[k][0] = div+ 1; scores[k][1] = div; scores[k][2] = div-1; sUsed += 1; }else if (mod == 2){ scores[k][0] = div + 1; scores[k][1] = div + 1; scores[k][2] = div; } else { scores[k][0] = div + mod; scores[k][1] = div; scores[k][2] = div; } } //count int count = 0; for(int k = 0;k<n;k++){ if(scores[k][0] >= p){ count++; } } counts[i] = count; } for(int i = 0;i<cases;i++){ System.out.printf("Case #%d: %d\n",i+1,counts[i]); } } }
0
616
A12852
A13061
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; import java.io.*; public class DancingGooglers { private static Scanner inFile; private static PrintWriter outFile; private static final String FILE_NAME = "B-small-attempt0"; /* Copy & Paste: VARIABLES */ private static int numCases, numGooglers, surpriseScores, bestScore, totalScore, trio, score1, score2, score3, answer; private static boolean trioFound; /* Copy & Paste: VARIABLES */ public static void main(String[] args) throws IOException { inFile = new Scanner(new File(FILE_NAME + ".in")); outFile = new PrintWriter(FILE_NAME + ".out"); numCases = inFile.nextInt(); for (int caseNum = 0; caseNum < numCases; caseNum++) { numGooglers = inFile.nextInt(); surpriseScores = inFile.nextInt(); bestScore = inFile.nextInt(); answer = 0; for (int googlerNum = 0; googlerNum < numGooglers; googlerNum++) { totalScore = inFile.nextInt(); trioFound = false; if (bestScore > 0) { trio = 28 - (27 - ((bestScore - 1) * 3)); score1 = bestScore; score2 = bestScore - 1; score3 = score2; } else { trio = 0; score1 = 0; score2 = 0; score3 = 0; } for (trio = trio; trio < 31 && !trioFound; trio++) { if (score1 + score2 + score3 == totalScore) { answer++; trioFound = true; } else { if (trio % 3 == 0) { score1++; } else if (trio % 3 == 1) { score2++; } else { score3++; } } } if (bestScore >= 2 && (totalScore - 1) % 3 != 0 && !trioFound) { score1 = bestScore; score2 = bestScore - 2; score3 = score2; for (trio = (bestScore - 2) * 2; trio < 18 && !trioFound && surpriseScores > 0; trio++) { if (score1 + score2 + score3 == totalScore) { answer++; surpriseScores--; trioFound = true; } else { if (trio % 2 == 0) { score2++; } else { score1++; score3++; } } } } } outFile.printf("Case #%d: %d\n", caseNum + 1, answer); } inFile.close(); outFile.close(); System.out.println("Succesfully written to " + FILE_NAME + ".out."); } }
0
617
A12852
A10326
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Saransh */ import java.io.*; import java.util.*; import java.math.*; import java.lang.*; public class Main { static int pts[]; static int n,s,p; static int memo[][]; static boolean marked[][]; public static void main(String[] args) { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); int test=1; while(t-->0) { n=sc.nextInt(); s=sc.nextInt(); p=sc.nextInt(); pts=new int[n]; memo=new int[n+1][s+1]; marked=new boolean[n+1][s+1]; for(int i=0;i<n;i++)pts[i]=sc.nextInt(); System.out.println("Case #"+test+": "+find(0,s)); test++; } } catch(Exception e) { e.printStackTrace(); } } public static int find(int pos,int sur) { if(pos==n) { if(sur==0)return 0; return -10000; } if(marked[pos][sur])return memo[pos][sur]; marked[pos][sur]=true; int max=-10000; for(int p1=0;p1<=10;p1++) { for(int p2=0;p2<=10;p2++) { int p3=pts[pos]-p1-p2; if(p3>=0&&p3<=10) { int arr[]=new int[3]; arr[0]=p1; arr[1]=p2; arr[2]=p3; Arrays.sort(arr); if(arr[2]-arr[0]==2&&sur>0) { if(arr[2]>=p) { max=Math.max(max,1+find(pos+1,sur-1)); } else { max=Math.max(max,find(pos+1,sur-1)); } } else if(arr[2]-arr[0]<2) { if(arr[2]>=p) { max=Math.max(max,1+find(pos+1,sur)); } else { max=Math.max(max,find(pos+1,sur)); } } } } } memo[pos][sur]=max; return max; } }
0
618
A12852
A10404
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam; import java.util.Hashtable; public class RecycledNumbers { @SuppressWarnings("unchecked") Hashtable h1; @SuppressWarnings("unchecked") RecycledNumbers(){ h1 = new Hashtable(); } @SuppressWarnings("unchecked") long noOfPairs(long min, long max, long num){ String sMin = ""+min; String sMax = ""+max; String sNum = ""+num; long countPairs = 0; int nod = sMin.length(); int i = 0; char fd = sNum.charAt(0); for( i = 1; i < nod ; i++){ String block = sNum.substring(i); if( block.charAt(0)=='0' || (block.charAt(0)> sMax.charAt(0)) || block.charAt(0)<fd) continue; else if( block.charAt(0)== sMax.charAt(0)){ int j = 2; boolean can = true; for( ; j<= block.length() ;j++){ String sTemp = block.substring(0,j); long temp = Long.parseLong(sTemp); temp *= (long)Math.pow(10, nod - j); if( temp > max){ can = false; break; } } if( !can ){ continue; } } String sPair = block + sNum.substring(0,i); long pair = Long.parseLong(sPair); boolean contains = h1.containsKey(sNum+" "+sPair); if( pair > num && pair<=max && !contains){ h1.put(sNum+" "+sPair, countPairs); countPairs ++; } } return countPairs; } public static void main(String[]args){ long i = 0; long count = 0; RecycledNumbers r1 = new RecycledNumbers(); FileRead fr = new FileRead("C-small-attempt0.in"); FileWrite fw = new FileWrite("C-small-ouput.txt"); //FileRead fr = new FileRead("C-large-attempt0.in"); //FileWrite fw = new FileWrite("C-large-ouput.txt"); int t = fr.readNextInt(); int j = 0; long A,B; for( ; j< t; j++){ count = 0; String nextLine = fr.readNextLine(); A = Long.parseLong(nextLine.split(" ")[0]); B = Long.parseLong(nextLine.split(" ")[1]); for( i = A; i < B; i++){ count += r1.noOfPairs(A,B,i); } fw.writeLine("Case #"+(j+1)+": "+count); } fr.close(); fw.close(); } }
0
619
A12852
A11932
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 CodeJamB { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 1; i <= t; i++) { int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); int a = 0; int b = 0; for (int j = 0; j < n; j++) { int x = scan.nextInt(); if ((x + 2) / 3 >= p) a++; else if ((x % 3 == 0 && x >= 3 || x % 3 != 0) && (x + 4) / 3 >= p) b++; } System.out.printf("Case #%d: %d%n", i, a + Math.min(b, s)); } } }
0
620
A12852
A12268
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileNotFoundException; import java.io.InputStreamReader; public class Dancing { /** * @param args */ public static void main(String[] args) { try { System.setIn(new FileInputStream("../B-small-attempt0.in")); } catch (FileNotFoundException e) { e.printStackTrace(); System.exit(0); } InputStreamReader inp = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(inp); String line = ""; int inputs = 0; try{ line = br.readLine(); inputs = Integer.parseInt( line ); } catch(Exception x){ System.err.println(x); System.exit(1); } String[] stringdata = {}; for(int i=0; i < inputs; i++){ try{ line = br.readLine(); stringdata = line.split(" "); } catch(Exception x){ System.err.println(x); System.exit(1); } int[] data = new int[stringdata.length]; for(int j=0; j < stringdata.length; j++){ data[j] = Integer.parseInt(stringdata[j]); } int n = data[0]; int s = data[1]; int p = data[2]; int count = 0; for(int k=3; k < data.length; k++){ int score = data[k]; //double x = Math.ceil(score / 3.0); if(score >= p && score >= (p*3)-2){ count++; } else if(score >= p && score >= (p*3)-4 && s > 0){ s--; count++; } } System.out.println("Case #" + (i+1) + ": " + count); } } }
0
621
A12852
A12701
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.IOException; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); int counter = 1; while (T-- > 0) { int returned = 0; int N = scan.nextInt(); int surp = scan.nextInt(); int theMax = scan.nextInt(); double[] array = new double[N]; for (int i = 0; i < array.length; i++) { array[i] = scan.nextDouble(); } for (int i = 0; i < array.length; i++) { if (Math.ceil((double) array[i] / 3) >= theMax) { returned++; } else if (array[i] >= theMax) { double temp = array[i] - theMax; double first = theMax; double second = Math.ceil((double) temp / 2); double third = temp - second; double diff1 = Math.abs(first - second); double diff2 = Math.abs(second - third); double diff3 = Math.abs(first - third); if (diff1 <= 2 && diff2 <= 2 && diff3 <= 2) { if (diff1 == 2 || diff2 == 2 || diff3 == 2) { if (surp > 0 && (first >= theMax || second >= theMax || third >= theMax)) { surp--; returned++; } } } } } System.out.println("Case #" + counter++ + ": " + returned); } } }
0
622
A12852
A12703
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dancers; import java.io.BufferedReader; import java.io.FileReader; public class Dancing { static int solve(int N, int S, int p, int[] ts) { int good = 0, improveable = 0; for (int i = 0; i < ts.length; ++i) { int total = ts[i]; int simple=0, special=0; if (total % 3 == 0) { simple = total/3; if (simple > 0 && simple < 10) special = simple+1; } else if (total % 3 == 1) { simple = total/3+1; if (total/3 > 0) special = simple; } else if (total % 3 == 2) { simple = total/3+1; special = simple+1; } if (simple >= p) ++good; else if (special >= p) ++improveable; } return good + Math.min(improveable,S); } public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new FileReader(args[0])); String line = in.readLine(); int X = Integer.parseInt(line); for (int i = 0; i < X; ++i) { line = in.readLine(); String[] toks = line.split(" "); int N = Integer.parseInt(toks[0]); int S = Integer.parseInt(toks[1]); int p = Integer.parseInt(toks[2]); int[] ts = new int[N]; for (int j = 0; j < N; ++j) { ts[j] = Integer.parseInt(toks[3+j]); } System.out.println("Case #"+(i+1)+": "+solve(N,S,p,ts)); } } }
0
623
A12852
A10418
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package qualification.taskC; public class Task { private int a; private int b; private boolean[][] table; public Task(int a, int b, boolean[][] table) { this.a = a; this.b = b; this.table = table; } public String execute() { int result = 0; for (int i = a; i <= b; i++){ for(int p = a; p <= b; p++){ if(table[i][p]){ result++; } } } return result/2 + ""; } }
0
624
A12852
A11823
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 prob2; import com.bertramtruong.utils.BT; import com.bertramtruong.utils.DataReader; /** * * @author Bertram */ public class Prob2 { /** * @param args the command line arguments */ public static void main(String[] args) { DataReader dr = new DataReader("input.in"); try { int nLines = dr.readInt(); for (int i = 0; i < nLines; i++) { //BT.db("==================== case ", (i + 1), " ================="); System.out.print("Case #" + (i + 1) + ": "); int nGooglers = dr.readInt(); int nSurprising = dr.readInt(); int bestRes = dr.readInt(); //BT.db("nGooglers: ", nGooglers); //BT.db("nSurprising: ", nSurprising); //BT.db("bestRes: ", bestRes); int np = 0; for (int j = 0; j < nGooglers; j++) { // triplets, take a number divide by 3, int totalScore = dr.readInt(); int triplet = totalScore / 3; if (triplet >= bestRes) { //BT.db("bestres: ", triplet); np++; } else { /** * double remaindar = triplet % 3; // can we do it with * 1? if (triplet + 1 >= bestRes) { if (remaindar == 0 * && nSurprising == 0) { } else { nSurprising--; np++; * } } * * if (triplet + 2 >= bestRes) { BT.db("triplet: ", * triplet); // can you do it with 1? if (triplet + 1 >= * bestRes) { // good np++; } else { if (nSurprising > * 0) { //BT.db("after: ", triplet + 2); nSurprising--; * triplet += 2; } } } * * if (triplet >= bestRes) { np++; } */ int rem = totalScore % 3; if (triplet + 1 >= bestRes && rem >= 1) { np++; } else { if (totalScore != 0) { switch (rem) { case 0: if (nSurprising > 0 && triplet + 1 >= bestRes) { triplet++; nSurprising--; } break; case 1: triplet++; break; case 2: if (nSurprising > 0 && triplet + 2 >= bestRes) { triplet += 2; nSurprising--; } break; } if (triplet >= bestRes) { np++; } } } } } System.out.print(np); System.out.println(); } } catch (Exception x) { } } }
0
625
A12852
A10846
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 static java.lang.System.*; class B{ static public void main(String[] args){ Scanner sc = new Scanner(System.in); int cases = Integer.parseInt(sc.nextLine()); for(int c = 1; c<=cases; c++){ String[] s = sc.nextLine().split(" "); int n = Integer.parseInt(s[0]); int sur = Integer.parseInt(s[1]); int p = Integer.parseInt(s[2]); int[] score = new int[n]; int cz = 0; for(int i = 0; i<n; i++){ score[i] = Integer.parseInt(s[3+i]); if(score[i] == 0) cz ++; } if(p == 1){ out.println("Case #"+c+": "+(n-cz)); continue; } if(p == 0){ out.println("Case #"+c+": "+(n)); continue; } int cnt = 0; int pot = 0; for(int i:score){ if(i <= 1) continue; int nsur = (i-1)/3+1; if(nsur >=p) cnt++; else{ if(nsur == (p-1)){ if(i%3 != 1) pot++; } } } cnt += Math.min(pot, sur); out.println("Case #"+c+": "+cnt); } } }
0
626
A12852
A13106
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qualification; import com.qualification.ScoreCombo.Score; import java.io.*; import java.util.ArrayList; import java.util.List; public class Three { public static void main(String[] args) throws FileNotFoundException, IOException { FileReader fr = new FileReader("/Users/minerva/Desktop/input.txt"); FileWriter fw = new FileWriter("/Users/minerva/Desktop/output.txt"); BufferedReader br = new BufferedReader(fr); PrintWriter pr = new PrintWriter(fw); int numInputs = Integer.valueOf(br.readLine()); for(int i=0;i<numInputs;i++) { String str = br.readLine(); String values[] = str.split(" "); int[] numValues = new int[values.length]; for (int j=0;j<values.length;j++) numValues[j] = Integer.parseInt(values[j]); pr.println("Case #" + (i + 1) + ": " + compute(numValues)); } pr.flush(); } public static int compute(int[] inputs) { int numInputs = inputs[0]; int surprising = inputs[1]; int best = inputs[2]; List<Score> scores = new ArrayList<Score>(); for (int indx = 3;numInputs > 0; numInputs--,indx++) { Score result = new ScoreCombo(inputs[indx]).testBest(best); if (result != null) scores.add(result); } int supCount = 0; int num = scores.size(); for(Score item:scores) if (item.isSurprising()) supCount++; if (supCount > surprising) { num -= (supCount - surprising); } return num; } } class ScoreCombo { private Score normalScore; private Score surprisingScore; public ScoreCombo(int total) { int rem = total % 3; int avg = total / 3; if (total == 0) { normalScore = new Score(0,false); } else if (total == 1) { normalScore = new Score(1,false); } else if (total == 2) { normalScore = new Score(1,false); surprisingScore = new Score(2,true); } else { if(rem == 0) { normalScore = new Score(avg,false); surprisingScore = new Score(avg + 1,true); } else if(rem == 1) { normalScore = new Score(avg + 1,false); surprisingScore = new Score(avg + 1,true); } else if(rem == 2) { normalScore = new Score(avg + 1,false); surprisingScore = new Score(avg + 2,true); } } } public class Score { private int maxScore; private boolean flag; private Score(int maxScore, boolean flag) { this.maxScore = maxScore; this.flag = flag; } public boolean isSurprising() { return flag; } public boolean testBest(int testValue) { return maxScore >= testValue; } } public Score testBest(int minScore) { if (normalScore.testBest(minScore)) return normalScore; else if (surprisingScore != null && surprisingScore.testBest(minScore)) return surprisingScore; else return null; } }
0
627
A12852
A10378
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* Problem You're watching a show where Googlers (employees of Google) dance, and then each dancer is given a triplet of scores by three judges. Each triplet of scores consists of three integer scores from 0 to 10 inclusive. The judges have very similar standards, so it's surprising if a triplet of scores contains two scores that are 2 apart. No triplet of scores contains scores that are more than 2 apart. For example: (8, 8, 8) and (7, 8, 7) are not surprising. (6, 7, 8) and (6, 8, 8) are surprising. (7, 6, 9) will never happen. The total points for a Googler is the sum of the three scores in that Googler's triplet of scores. The best result for a Googler is the maximum of the three scores in that Googler's triplet of scores. Given the total points for each Googler, as well as the number of surprising triplets of scores, what is the maximum number of Googlers that could have had a best result of at least p? For example, suppose there were 6 Googlers, and they had the following total points: 29, 20, 8, 18, 18, 21. You remember that there were 2 surprising triplets of scores, and you want to know how many Googlers could have gotten a best result of 8 or better. With those total points, and knowing that two of the triplets were surprising, the triplets of scores could have been: 10 9 10 6 6 8 (*) 2 3 3 6 6 6 6 6 6 6 7 8 (*) The cases marked with a (*) are the surprising cases. This gives us 3 Googlers who got at least one score of 8 or better. There's no series of triplets of scores that would give us a higher number than 3, so the answer is 3. Input The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of a single line containing integers separated by single spaces. The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores. The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers. Output For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum number of Googlers who could have had a best result of greater than or equal to p. Limits 1 = T = 100. 0 = S = N. 0 = p = 10. 0 = ti = 30. At least S of the ti values will be between 2 and 28, inclusive. Small dataset 1 = N = 3. Large dataset 1 = N = 100. Sample Input Output 4 3 1 5 15 13 11 3 0 8 23 22 21 2 1 1 8 0 6 2 8 29 20 8 18 18 21 Case #1: 3 Case #2: 2 Case #3: 1 Case #4: 3 */ import java.io.*; import java.util.logging.Level; import java.util.logging.Logger; public class Dancing { BufferedReader read; BufferedWriter write; public static void main(String args[]) { try { new Dancing().init("B-small-attempt0"); } catch (Exception ex) { //Logger.getLogger(Dancing.class.getName()).log(Level.SEVERE, null, ex); } } void init(String name) throws Exception { read=new BufferedReader(new FileReader(new File(name+".in"))); write=new BufferedWriter(new FileWriter(new File(name+".out"))); String x=""; try { x = read.readLine(); int nos = Integer.parseInt(x); for(int i=0;i<nos;i++) { x = read.readLine(); String ss[]=x.split(" "); int[] num = new int[ss.length]; for(int z=0;z<ss.length;z++) num[z] = Integer.parseInt(ss[z]); int n = num[0]; int s = num[1]; int p = num[2]; int[] t = new int[n]; for(int j=0;j<n;j++) t[j] = num[j+3]; int sum =0,count=0,j=0; for(int r1=0;r1<n;r1++) { int c=0; for(j =0;j<=10;j++) { int m=0; for(int k=j;k<=j+1;k++) { if(k==11) {k=10;m++;} int s1 = j+k+k; int s2 = j+j+k; if((s1== t[r1])||(s2== t[r1])) { if(((j>=p)||(k>=p))&& c==0) { c++; count+=1; break ; } } if(m==1) k=11; } } if(c==0 && s>0) { for(int k=2;k<=4;k++) { if(t[r1]==0 && p!=0) break; if((t[r1]==(3*p)-k) || (t[r1]==(3*p)+k)) { count+=1; s--; break; } } } } write.write("Case #"+(i+1)+":"+" "+count+"\n"); System.out.println("Case #"+(i+1)+":"+" "+count+"\n"); } write.flush(); write.close(); read.close(); // System.out.println(a+" "+b); } catch (Exception ex) { System.exit(0); } } }
0
628
A12852
A11174
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class ProblemB { public static void main(String[] args) { System.out.println("Enter input for case:"); Scanner sc = new Scanner(System.in); int T = sc.nextInt(); sc.nextLine(); int[] nt = new int[T]; int[] st = new int[T]; int[] pt = new int[T]; int[][] ni = new int[T][]; for (int t = 0; t < T; t++) { nt[t] = sc.nextInt(); st[t] = sc.nextInt(); pt[t] = sc.nextInt(); ni[t] = new int[nt[t]]; for (int j = 0; j < nt[t]; j++) ni[t][j] = sc.nextInt(); sc.nextLine(); } for (int t = 1; t <= T; t++) { int n = nt[t-1]; //number of Googlers int s = st[t-1]; //number of surprising triplets of scores int p = pt[t-1]; //minimum best result int sUsedUp = 0; int result = 0; for (int totalPoints : ni[t-1]) { if (totalPoints >= p*3 - 2) result++; if (p > 1) if (totalPoints == p*3 - 4 || totalPoints == p*3 - 3) if (sUsedUp < s) { result++; sUsedUp++; } } System.out.println("Case #" + t +": " + result); } } }
0
629
A12852
A11213
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.InputStreamReader; import java.util.ArrayList; public class IOGoogleCodeJam{ public static ArrayList<String> fileInput(String fileName){ File file = null; FileReader fr = null; BufferedReader br = null; ArrayList<String> inputs= new ArrayList<String>(); int lines; try { // Apertura del fichero y creacion de BufferedReader para poder // hacer una lectura comoda (disponer del metodo readLine()). file= new File (fileName); fr = new FileReader (file); br = new BufferedReader(fr); // Lectura del fichero while(br.ready()){ inputs.add(br.readLine()); } }catch(Exception e){ e.printStackTrace(); }finally{ // En el finally cerramos el fichero, para asegurarnos // que se cierra tanto si todo va bien como si salta // una excepcion. try{ if( null != fr ){ fr.close(); } }catch (Exception e2){ e2.printStackTrace(); } } return inputs; } public static void resultsOutput(ArrayList<String> args, int argsPerLine){ int numArg=0; int maxNumber= args.size()/argsPerLine; for(int caseNumber=1;caseNumber<=maxNumber;caseNumber++){ System.out.print("Case #"+caseNumber+": "); for(int i=1;i<=argsPerLine;i++){ System.out.print(args.get(numArg)+" "); numArg++; } System.out.println(); } } }
0
630
A12852
A13076
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedInputStream; import java.util.Scanner; public class ProblemB { public static void main(final String[] args) { Scanner scanner = new Scanner(new BufferedInputStream(System.in)); int T = scanner.nextInt(); for(int i = 0; i < T; i++) { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int res = 0; for(int j = 0; j < N; j++) { double t = (double)(scanner.nextInt()); if(t >= 0) { if(t/3 >= p) res++; else if(t >= 1) { if((t-1)/3 + 1 >= p) res++; else if(t >= 2) { if((t-2)/3 + 1 >= p) res++; else if((t-2)/3 + 2 >= p && S > 0) {res++; S--;} else if(t >= 3) { if((t-3)/3 + 2 >= p && S > 0) {res++; S--;} else if(t >= 4 && (t-4)/3 + 2 >= p && S > 0) {res++; S--;} } } } } } System.out.println("Case #"+(i+1)+": "+res); } } }
0
631
A12852
A10311
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.eduardcapell.gcj2012.qualification; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.util.List; import java.util.Vector; public class B { public static void main(String[] args) throws Exception { B a = new B(); a.run(); } public void run() throws Exception { String fileName = "/Users/edu/Dropbox/google_code_jam/2012/B-small-attempt0.in"; File f = new File(fileName); List<String> rows = getLines(f); for (int i=1; i < rows.size(); i++) { String line = rows.get(i); int result = processLine(line); print("Case #" + i + ": " + result); } } private int processLine(String line) { String[] values = line.split(" "); int n = Integer.parseInt(values[0]); int surprising = Integer.parseInt(values[1]); int p = Integer.parseInt(values[2]); int[] scores = new int[n]; for (int i=0; i < n; i++) { scores[i] = Integer.parseInt(values[i + 3]); } int could = 0; int mustBeSurprising = 0; for (int i=0; i < scores.length; i++) { int score = scores[i]; if (score < p) { continue; } int exact = p * 3; int diff = score - exact; if (diff >= 0) { could++; } else if (diff >= -2) { could++; } else if (diff >= -4) { mustBeSurprising++; could++; } } if (mustBeSurprising < surprising) { // Set as surprising the cases that originally were not flagged as such. mustBeSurprising = surprising; } could = could - (mustBeSurprising - surprising); return could; } private void print(Object o) { System.out.println(o); } public List<String> getLines(File f) throws Exception { List<String> lines = new Vector<String>(); BufferedReader in = new BufferedReader(new FileReader(f)); String line = null; while ((line = in.readLine()) != null) { lines.add(line); } return lines; } }
0
632
A12852
A10742
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Queue; class GoogleCodeJam2 { static BufferedReader br ; static PrintWriter pw; static String line; static HashSet<String> hs; public static void main (String [] args) throws IOException { try { br = new BufferedReader(new InputStreamReader(new FileInputStream(new File("C:\\Code\\google\\in.txt")))); pw = new PrintWriter(new File("C:\\Code\\google\\out.out")); start(); // // do { // present = func(present, start); // if (present != null) { // for (int i : present) // { // System.out.print(i+","); // } // } // System.out.println(); // }while (present!= null); // Integer input[] = {1,2,3,8,9}; // System.out.println(convert(input)); // for (int i: convert(12389)) { // System.out.print(i+","); // } pw.flush(); pw.close(); br.close(); } catch (NumberFormatException t) { //throw t; } } static void start() throws IOException { int n=0; int n1=0; int s=0; int p=0; String firstLine = br.readLine().trim(); n = Integer.parseInt(firstLine.trim()); for( int i=0; i<n; i++) { int finalSum=0; int sDone=0; String tLine = br.readLine().trim(); String tLineArray[] = tLine.split(" "); n1 = Integer.parseInt(tLineArray[0].trim()); s = Integer.parseInt(tLineArray[1].trim()); p = Integer.parseInt(tLineArray[2].trim()); int limit= ((p-1)*3); for (int j=3;j<n1+3;j++) { int t = Integer.parseInt(tLineArray[j].trim()); if (p>1) { if (t>limit) { finalSum++; } else if (t == limit || t==limit-1) { if (sDone<s) { finalSum++; sDone++; } } } else if (p==1) { if (t>=1) { finalSum++; } } else if (p<=0) { finalSum++; } // else if (p==2) { // if (t==1||t==0){ // // } else if (t==2 || t==3) { // if (sDone<s) { // finalSum++; // sDone++; // } // } // else { // finalSum++; // } // } } pw.println("Case #"+(i+1)+": "+finalSum); } } }
0
633
A12852
A12586
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import com.sun.org.apache.bcel.internal.generic.AALOAD; import java.io.IOException; import java.util.HashSet; import java.util.List; import java.util.Set; public class RecycledNum extends JamProblem { public static void main(String[] args) throws IOException { RecycledNum p = new RecycledNum(); p.go(); } @Override String solveCase(JamCase jamCase) { RecNCase ca = (RecNCase) jamCase; int res = 0; for (int n = ca.A; n < ca.B; n++) { String m = ""; //print("n "+n); Set<Integer> bag = new HashSet<>(); int length = intLength(n); for (int t = 1; t < length; t++) { int pow = (int) Math.pow(10, t); int pow2 = (int) Math.pow(10,length-t); int f = (n / pow); int s = n - (pow * f); int cand = f + (pow2 * s); //print("m " + cand); if (cand < ca.A || cand > ca.B || cand <= n) { continue; } if (bag.contains(cand)) { continue; } if (intLength(cand) != intLength(n)) { continue; } res++; bag.add(cand); //print(""+ n+ " " + cand); } } return "" + res; } private void print(String m) { System.out.println(m); } private int intLength(int n) { return Integer.toString(n).length(); } @Override JamCase parseCase(List<String> file, int line) { RecNCase ca = new RecNCase(); ca.lineCount = 1; String s = file.get(line); int[] ints = JamUtil.parseIntList(s, 2); ca.A = ints[0]; ca.B = ints[1]; return ca; } } class RecNCase extends JamCase { int A, B; }
0
634
A12852
A11172
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.PrintStream; public class B { public static void main(String[] args) throws NumberFormatException, IOException { // Use scanner! Good for reading in bigints too. // Arrays.fill for initialising arrays // Look up cumulative frequency tables (only for dynamic querying with new numbers coming in) BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("in.in"))); PrintStream writer = new PrintStream(new FileOutputStream("out.out")); int cases = Integer.parseInt(reader.readLine()); for (int i = 1; i <= cases; i++) { String[] tokens = reader.readLine().split(" "); int googlers = Integer.parseInt(tokens[0]); int surprising = Integer.parseInt(tokens[1]); int target = Integer.parseInt(tokens[2]); int maxReached = 0; for (int j = 3; j < googlers + 3; j++) { int total = Integer.parseInt(tokens[j]); if ((total / 3 + Math.min(total % 3, 1) >= target) || ((total / 3 + Math.max(total % 3, 1) >= target) && (surprising-- > 0) && ((total >= 1) || (total % 3 != 0)))) { maxReached++; } } writer.printf("Case #%d: %d\n", i, maxReached); } } }
0
635
A12852
A12034
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package jp.funnything.competition.util; import java.math.BigInteger; /** * Utility for BigInteger */ public class BI { public static BigInteger ZERO = BigInteger.ZERO; public static BigInteger ONE = BigInteger.ONE; public static BigInteger add( final BigInteger x , final BigInteger y ) { return x.add( y ); } public static BigInteger add( final BigInteger x , final long y ) { return add( x , v( y ) ); } public static BigInteger add( final long x , final BigInteger y ) { return add( v( x ) , y ); } public static int cmp( final BigInteger x , final BigInteger y ) { return x.compareTo( y ); } public static int cmp( final BigInteger x , final long y ) { return cmp( x , v( y ) ); } public static int cmp( final long x , final BigInteger y ) { return cmp( v( x ) , y ); } public static BigInteger div( final BigInteger x , final BigInteger y ) { return x.divide( y ); } public static BigInteger div( final BigInteger x , final long y ) { return div( x , v( y ) ); } public static BigInteger div( final long x , final BigInteger y ) { return div( v( x ) , y ); } public static BigInteger mod( final BigInteger x , final BigInteger y ) { return x.mod( y ); } public static BigInteger mod( final BigInteger x , final long y ) { return mod( x , v( y ) ); } public static BigInteger mod( final long x , final BigInteger y ) { return mod( v( x ) , y ); } public static BigInteger mul( final BigInteger x , final BigInteger y ) { return x.multiply( y ); } public static BigInteger mul( final BigInteger x , final long y ) { return mul( x , v( y ) ); } public static BigInteger mul( final long x , final BigInteger y ) { return mul( v( x ) , y ); } public static BigInteger sub( final BigInteger x , final BigInteger y ) { return x.subtract( y ); } public static BigInteger sub( final BigInteger x , final long y ) { return sub( x , v( y ) ); } public static BigInteger sub( final long x , final BigInteger y ) { return sub( v( x ) , y ); } public static BigInteger v( final long value ) { return BigInteger.valueOf( value ); } }
0
636
A12852
A10714
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; public class B { static BufferedReader br; static PrintWriter pw; static StringTokenizer st; static int k, ch, v = 0; static int t, n, s, p, tmp; static String str; static String[] stray = new String[110]; static int[] intray = new int[100]; String nextToken() throws IOException { while (st == null || !st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } char nextChar() throws IOException { return (char) br.read(); } public static void main(String[] args) throws IOException { br = new BufferedReader(new FileReader("input.in")); pw = new PrintWriter("output.out"); t = Integer.parseInt(br.readLine()); for (int i = 1; i <= t; i++) { str = br.readLine(); st = new StringTokenizer(str, " \t\n\r,."); while (st.hasMoreTokens()) { stray[k] = st.nextToken(); k++; } n = Integer.parseInt(stray[0]); s = Integer.parseInt(stray[1]); p = Integer.parseInt(stray[2]); for (int j = 3; j < k; j++) { intray[j - 3] = Integer.parseInt(stray[j]); } for (int j = 0; j < n; j++) { if (intray[j] == 0) { if (p == 0) { continue; } else { ch++; continue; } } if (intray[j] % 3 == 0) { tmp = intray[j] / 3; if (tmp >= p) { continue; } else { if (p - tmp <= 1) { if (s != 0) { s--; continue; } else { ch++; continue; } } else { ch++; continue; } } } else { tmp = (int) (intray[j] / 3 + 0.5); if (intray[j] % 3 == 1) { if (tmp + 1 >= p) { continue; } else { ch++; continue; } } else { if (tmp + 1 >= p) { continue; } if (tmp + 2 >= p) { if (s != 0) { s--; continue; } else { ch++; continue; } } else { ch++; continue; } } } } v++; pw.println("Case #" + v + ": " + (n - ch)); ch = 0; k = 0; } br.close(); pw.close(); } }
0
637
A12852
A10124
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.lang.reflect.Array; import java.math.BigInteger; import java.util.Arrays; import java.util.Comparator; import java.util.StringTokenizer; public class B implements Runnable { private static final String PROBLEM_ID = "B"; private class TestCaseRunner { class Triple { int a, b, c; public Triple(int a, int b, int c) { this.a = a; this.b = b; this.c = c; } int worst() { return Math.min(Math.min(a, b), c); } int best() { return Math.max(Math.max(a, b), c); } int total() { return a + b + c; } boolean isValid() { return best() - worst() <= 2; } boolean isSurprising() { return best() - worst() == 2; } } int[] bestSurprising, bestNonSurprising; private void precalc() { bestSurprising = new int[31]; Arrays.fill(bestSurprising, -1); bestNonSurprising = new int[31]; Arrays.fill(bestNonSurprising, -1); for (int a = 0; a <= 10; a++) for (int b = 0; b <= 10; b++) for (int c = 0; c <= 10; c++) { Triple t = new Triple(a, b, c); if (!t.isValid()) { continue; } if (t.isSurprising()) { bestSurprising[t.total()] = t.best(); } else { bestNonSurprising[t.total()] = t.best(); } } } public void handleCase() throws IOException { precalc(); int n = nextInt(); int s = nextInt(); int p = nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } int[][] d = new int[n + 1][s + 2]; for (int[] v : d) { Arrays.fill(v, -1); } d[0][0] = 0; for (int i = 0; i < n; i++) for (int j = 0; j <= s; j++) if (d[i][j] >= 0) { // use a non-surprising triple { if (bestNonSurprising[a[i]] >= 0) { int v = bestNonSurprising[a[i]] >= p ? 1 : 0; d[i + 1][j] = Math.max(d[i + 1][j], d[i][j] + v); } } // take a surprising triple { if (bestSurprising[a[i]] >= 0) { int v = bestSurprising[a[i]] >= p ? 1 : 0; d[i + 1][j + 1] = Math.max(d[i + 1][j + 1], d[i][j] + v); } } } out.print(Math.max(d[n][s], 0)); } } BufferedReader in; PrintWriter out; StringTokenizer tokenizer = new StringTokenizer(""); public static void main(String[] args) { new Thread(new B()).start(); } public void run() { File[] all = new File(".").listFiles(); Arrays.sort(all, new Comparator<File>() { public int compare(File a, File b) { return a.getName().toLowerCase().compareTo(b.getName().toLowerCase()); } }); int processed = 0; for (File inFile : all) if (inFile.isFile()) { String name = inFile.getName().toLowerCase(); if (name.startsWith(PROBLEM_ID.toLowerCase()) && name.endsWith(".in")) { try { runFile(inFile); processed++; } catch (Throwable t) { throw new IllegalStateException("Fatal error", t); } } } if (processed > 0) { System.out.println("Processed " + processed + " files for problem " + PROBLEM_ID); } else { System.err.println("No input files found for problem " + PROBLEM_ID); } } private void runFile(File inFile) throws IOException { in = new BufferedReader(new FileReader(inFile)); out = new PrintWriter(new FileWriter(inFile.getName() + ".out")); long startTime = System.currentTimeMillis(); System.out.println("Processing file: " + inFile.getName()); int tc = nextInt(); for (int p = 0; p < tc; p++) { long nowTime = System.currentTimeMillis(); System.out.print("Running test case #" + (p + 1) + " out of " + tc); if (p > 0) { System.out.print(" (remaining time: " + remainingTime(p, tc, startTime, nowTime) + ")"); } System.out.println(); out.print("Case #" + (p + 1) + ": "); new TestCaseRunner().handleCase(); out.println(); } in.close(); out.close(); } private String remainingTime(int p, int tc, long startTime, long nowTime) { double secondsPerTestCase = 1.0e-3 * (nowTime - startTime) / p; double secondsRemaining = (tc - p) * secondsPerTestCase; double minutesRemaining = secondsRemaining / 60; int minutes = (int) Math.floor(minutesRemaining); int seconds = (int) Math.round(secondsRemaining - minutes * 60); return minutes + " min " + seconds + " sec"; } private String nextToken() throws IOException { while (!tokenizer.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } tokenizer = new StringTokenizer(line); } return tokenizer.nextToken(); } private int nextInt() throws IOException { return Integer.parseInt(nextToken()); } private BigInteger nextBigInt() throws IOException { return new BigInteger(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } }
0
638
A12852
A12588
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.lang.reflect.Array; import java.util.*; public class ArrayUtil { static<T> T[] revers (T[] t){ List<T> list = Arrays.asList(t); Collections.reverse(list); return (T[]) list.toArray(); } static<T> Map<T,Integer> listToMap(List<T> list) { HashMap<T, Integer> map = new HashMap<>(); for (int i = 0; i < list.size(); i++) { T t = list.get(i); map.put(t,i); } return map; } static <T> List<T> fromIndexList(List<Integer> inds, List<T> values) { ArrayList<T> ts = new ArrayList<>(); for (Integer ind : inds) { ts.add(values.get(ind)) ; } return ts; } }
0
639
A12852
A11686
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
public class Result { public String output; public int i; public Result(int i) { this.i = i; } @Override public String toString() { return "Case #"+i+": " + output; } }
0
640
A12852
A12734
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.Arrays; 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 i = 0; i < t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int ans = 0; int a[] = new int[n]; int b[] = new int[n]; for (int j = 0; j < n; j++) { a[j] = in.nextInt(); if (a[j] % 3 == 0) { b[j] = a[j] / 3; } else if ((a[j] > 0) && (a[j] - 1) % 3 == 0) { b[j] = (a[j] - 1) / 3 + 1; } else if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { b[j] = (a[j] - 2) / 3 + 1; } } for (int j = 0; j < n && s > 0; j++) { if (a[j] >= 0 && b[j] < p) { int x = -1; if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { x = (a[j] - 2) / 3 + 2; } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { x = (a[j] - 3) / 3 + 2; } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { x = (a[j] - 4) / 3 + 2; } if (x >= p) { ans++; a[j] = -1; s--; } } } for (int j = 0; j < n && s > 0; j++) { if (a[j] >= 0 && b[j] < p) { int x = -1; if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { x = (a[j] - 2) / 3 + 2; } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { x = (a[j] - 3) / 3 + 2; } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { x = (a[j] - 4) / 3 + 2; } if (x != -1) { a[j] = -1; s--; } } } for (int j = 0; j < n && s > 0; j++) { if (a[j] >= 0 && b[j] >= p) { int x = -1; if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { x = (a[j] - 2) / 3 + 2; } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { x = (a[j] - 3) / 3 + 2; } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { x = (a[j] - 4) / 3 + 2; } if (x >= p) { ans++; a[j] = -1; s--; } } } for (int j = 0; j < n && s > 0; j++) { if (a[j] >= 0 && b[j] >= p) { int x = -1; if ((a[j] > 1) && (a[j] - 2) % 3 == 0) { x = (a[j] - 2) / 3 + 2; } else if ((a[j] > 2) && (a[j] - 3) % 3 == 0) { x = (a[j] - 3) / 3 + 2; } else if ((a[j] > 3) && (a[j] - 4) % 3 == 0) { x = (a[j] - 4) / 3 + 2; } if (x != -1) { ans--; a[j] = -1; s--; } } } for (int j = 0; j < n; j++) { if (a[j] >= 0 && b[j] >= p) { ans++; } } System.out.println("Case #"+(i+1)+": "+ans); } } }
0
641
A12852
A10919
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.ArrayList; import java.util.Scanner; public class B { public static void readFile() throws FileNotFoundException { File f = new File("B-small.in"); Scanner in = new Scanner(f); PrintWriter out = new PrintWriter(new File("B-small.out")); int T, S, p, N; T = in.nextInt(); //System.out.println(T); ArrayList<int[]> L = new ArrayList<int[]>(); int found, q, r; for (int i = 0; i < T; i++) { found = 0; N = in.nextInt(); //System.out.print(N + " "); S = in.nextInt(); //System.out.print(S + " "); p = in.nextInt(); //System.out.println(p); int[] totalPoints = new int[N]; for (int j = 0; j < N; j++) { totalPoints[j] = in.nextInt(); q = totalPoints[j] / 3; r = totalPoints[j] % 3; // //System.out.println(q + "--" + r); if (r == 0) L.add(new int[] { q, q, q }); else if (r == 1) L.add(new int[] { q, q, q + 1 }); else L.add(new int[] { q, q + 1, q + 1 }); int lastIndex = L.size() - 1; if (L.get(lastIndex)[0] >= p || L.get(lastIndex)[1] >= p || L.get(lastIndex)[2] >= p) { //System.out.println("1111111111"); found++; continue; } else { if (L.get(lastIndex)[0] + L.get(lastIndex)[1] + L.get(lastIndex)[2] < 3 * p - 4) { //System.out.println("2222222222"); continue; } if (S > 0 && q > 1) { //System.out.println("333333333333"); L.get(lastIndex)[1]--; L.get(lastIndex)[2]++; S--; found++; } } } //System.out.println("Found : " + found); if (i < T - 1) out.println("Case #"+ (i + 1) + ": " + found); else out.print("Case #"+ (i + 1) + ": " + found); } // //System.out.println(L.get(3)[0]); out.close(); } public static void main(String[] args) throws FileNotFoundException { readFile(); } }
0
642
A12852
A11269
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.InputStream; import java.io.PrintStream; import java.util.Scanner; public abstract class AbstractCodeJam { public void solveProblems(InputStream in, PrintStream out) { Scanner scan = new Scanner(in); int nb = scan.nextInt(); scan.nextLine(); for (int i = 1; i <= nb; i++) { Problem problem = readProblem(scan); // problem.print(); problem.solve(); out.println("Case #" + i + ": " + problem.getSolution()); } } protected abstract Problem readProblem(Scanner scan); }
0
643
A12852
A10145
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package dancing; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class Dancing { public static int numDancer(double[] a, double numtoget, int s) { int iter = 0; for(int i = 0; i < a.length; i++) { a[i] = a[i] - numtoget; double c = Math.floor(a[i]/2); if(a[i] < 0) { } else if(c > numtoget || c == numtoget || c == numtoget - 1) { iter = iter + 1; } else if (c == numtoget - 2 && s != 0) { s = s - 1; iter = iter + 1; } } return iter; } public static void main(String[] args) throws FileNotFoundException, IOException { FileReader theFileID = new FileReader("B-small-attempt0.in"); BufferedReader inFile = new BufferedReader(theFileID); FileWriter fw = new FileWriter("output.txt"); PrintWriter output = new PrintWriter(fw); String line; int numCases = 0; if((line = inFile.readLine()) != null) numCases = Integer.parseInt(line); String[] x = null; int n = 0, s = 0; double numtoget = 0; for(int i = 0; (line = inFile.readLine()) != null && i < numCases; i++) { x = line.split(" "); n = Integer.parseInt(x[0]); s = Integer.parseInt(x[1]); numtoget = Integer.parseInt(x[2]); double[] a = new double[n]; for(int j = 3; j < x.length; j++) { a[j-3] = Integer.parseInt(x[j]); } int y = numDancer(a, numtoget, s); output.write("Case #"+ (i + 1) + ": " + y); output.println(); } inFile.close(); output.close(); fw.close(); double[] b = {15, 13, 11}; System.out.println(numDancer(b, 5, 1)); double[] c = {23, 22, 21}; System.out.println(numDancer(c, 8, 0)); double[] e = {8, 0}; System.out.println(numDancer(e, 1, 1)); double[] d = {29, 20, 8, 18, 18, 21}; System.out.println(numDancer(d, 8, 2)); } }
0
644
A12852
A11542
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.Arrays; import java.util.Scanner; public class B { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // BufferedReader read = new BufferedReader(new InputStreamReader( // new FileInputStream( // "C:/Users/Ortiga/Downloads/B-small-attempt0.in"))); BufferedWriter write = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("C:/Users/Ortiga/Downloads/outputB.txt"))); Scanner sc = new Scanner(new InputStreamReader(new FileInputStream( "C:/Users/Ortiga/Downloads/B-small-attempt1.in"))); byte length = sc.nextByte(); for (byte i = 0; i < length; i++) { byte t = sc.nextByte(), s = sc.nextByte(), p = sc.nextByte(), max = 0, getDuringSurp = 0; String rit = "Case #" + (i + 1) + ": "; byte[] t_i = new byte[t]; for (byte j = 0; j < t; j++) t_i[j] = sc.nextByte(); Arrays.sort(t_i); int sCounter = 0; for (byte j = 0; j < t; j++) { byte currT_i = t_i[j]; if (currT_i == 0 && p > 0) continue; if (sCounter < s) { if ((currT_i - 2) % 3 == 0) { if ((((currT_i - 2) / 3) + 2 >= p)) { max++; getDuringSurp++; } sCounter++; continue; } else if ((currT_i - 3) % 3 == 0) { if ((((currT_i - 3) / 3) + 2 >= p)) { max++; getDuringSurp++; } sCounter++; continue; } } if ((currT_i - 1) % 3 == 0) { if ((((currT_i - 1) / 3) + 1 >= p)) max++; else if (currT_i + 4 / 3 >= p && getDuringSurp < sCounter) { sCounter--; j--; } } else if ((currT_i - 2) % 3 == 0) { if ((((currT_i - 2) / 3) + 1 >= p)) max++; else if (currT_i + 4 / 3 >= p && getDuringSurp < sCounter) { sCounter--; j--; } } else { if (currT_i / 3 >= p) max++; else if (currT_i + 4 / 3 >= p && getDuringSurp < sCounter) { sCounter--; j--; } } } rit += max; write.write(rit); if (i < length - 1) write.newLine(); } sc.close(); write.close(); } }
0
645
A12852
A12286
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; //1 //3 1 5 15 13 11 // public class DancingWiththeGooglersCodeJam2012Q { public int solves(int N,int S,int P,int scores[]){ int i = 0 ; int sol = 0 ; Arrays.sort(scores); int TT = scores.length ; for ( i = 0 ; i < TT ;i++){ if ( scores[i] <P){ scores[i]=-1; continue;} else break; } //total score itself is < P not possible case; if( i == TT && S ==0 ) return 0; // solve for combination without surprise case for ( i = 0 ; i < TT ;i++){ if ( scores[i] !=-1 && scores[i]>= P){ for ( int j = 0 ; j <=10 ;j++){ for (int k = 0 ; k <=10 ;k++){ for (int l = 0 ; l <=10;l++){ if( l+j+k != scores[i] ) continue; if( l+j+k == scores[i] && ( Math.abs(j-k) < 2 && Math.abs(k-l) < 2 && Math.abs(l-j) < 2 ) && ( l >= P || j >= P || k >= P ) ){ //System.out.println(j + " " + k + " " + l + " " + scores[i] + " " + sol ); scores[i]= -1 ; ++sol; } } } } } } for ( i = 0 ; i < TT && S>0 ;i++){ if ( scores[i] !=-1 && scores[i]>= P){ for ( int j = 0 ; j <=10 ;j++){ for (int k = 0 ; k <=10 ;k++){ for (int l = 0 ; l <=10;l++){ if( l+j+k != scores[i] ) continue; if( l+j+k == scores[i] && ( ( Math.abs(j-k) ==2 && Math.abs(k-l) <= 2 && Math.abs(l-j) <=2 ) || ( Math.abs(j-k) <=2 && Math.abs(k-l) == 2 && Math.abs(l-j) <=2 ) || ( Math.abs(j-k) <=2 && Math.abs(k-l) <= 2 && Math.abs(l-j) ==2 ) ) && ( l >= P || j >= P || k >= P ) ){ //System.out.println(" FF" + j + " " + k + " " + l + " " + scores[i] + " " + sol ); scores[i]= -1 ; --S; ++sol; } } } } } } //System.out.println(" sol3 : " + sol); return sol; } public static void main(String[] args) throws IOException { DancingWiththeGooglersCodeJam2012Q si = new DancingWiththeGooglersCodeJam2012Q(); int T ; String CurLine = ""; InputStreamReader converter = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(converter); CurLine = in.readLine(); T= Integer.parseInt(CurLine); String s[] = new String[T]; for(int i = 0 ; i < T;i++) { CurLine = in.readLine(); String []input = CurLine.split(" "); int N = Integer.parseInt(input[0]); int S = Integer.parseInt(input[1]); int P = Integer.parseInt(input[2]); int scores[] = new int [N]; for( int j = 0 ; j < N;j++){ scores[j] = Integer.parseInt(input[j+3]); } System.out.println("Case #"+ (i+1)+": "+si.solves(N,S,P,scores)); } } }
0
646
A12852
A10033
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.code; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.Writer; public class ReadWriteInputFile { public BufferedReader readInputFile(String filePath) { try { FileInputStream fstream = new FileInputStream(filePath); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); return br; } catch (Exception e) { e.printStackTrace(); return null; } } public Writer writeOutputFile(String filePath) { try { File file = new File(filePath); Writer outWriter = new BufferedWriter(new FileWriter(file)); return outWriter; } catch (Exception e) { e.printStackTrace(); return null; } } public void closeObjects(Writer outWriter) { try { outWriter.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
647
A12852
A10943
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.LinkedList; public class Dancers { static LinkedList<Integer> scores; static int googlers = 0; static int surprising = 0; static int p; public static void main(String[] args) { String text = ""; int tests = 0; int test_index=0; int result; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); try{ tests = Integer.parseInt(br.readLine()); while ((text = br.readLine()) != null && test_index < tests){ test_index++; String[] testcase = text.split(" "); googlers = Integer.parseInt(testcase[0]); surprising = Integer.parseInt(testcase[1]); p = Integer.parseInt(testcase[2]); int i = 3; scores = new LinkedList<Integer>(); while(i<testcase.length){ scores.add(Integer.parseInt(testcase[i])); i++; } result = calc(); System.out.println("Case #" + test_index + ": " + result); } } catch (Exception e) {e.printStackTrace();} } private static int calc() { int result = 0; for(int x : scores){ if(p == 0) { result = scores.size(); break; } if(x == 0 && p == 0) { result++; continue; } if(x == 0 && p != 0) { continue; } int surpriseLimit = Math.max(p+(p-2)+(p-2),0); int okLimit = Math.max(p+(p-1)+(p-1),0); if(x >= okLimit) { result++; } if(x >= surpriseLimit && x < okLimit && surprising > 0){ surprising--; result++; } } return result; } }
0
648
A12852
A10408
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 in = new Scanner(System.in); int T = in.nextInt(); in.nextLine(); int N, S, p, sure, av, note, result; for(int zz = 1; zz <= T;zz++){ result=0; N = in.nextInt(); S = in.nextInt(); p = in.nextInt(); sure = p + (p-1) + (p-1); if (sure < p) sure =p; av = p + (p-2) + (p-2); if (av < p) av = p; for (int i = 1; i <= N; i++){ note = in.nextInt(); if (note >= sure){ result++; } else if (( note < sure ) && (note >= av)){ if (S > 0){ S--; result++; } } } in.nextLine(); System.out.format("Case #%d: %d\n",zz, result); } } }
0
649
A12852
A12171
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package hk.polyu.cslhu.codejam.solution.impl; public class AlienLanguage { }
0
650
A12852
A13206
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.Scanner; public final class ReadWriteTextFile { /** Constructor. */ ReadWriteTextFile(){ try { out =new BufferedWriter(new FileWriter("output.in")); scanner = new Scanner(new FileInputStream("input.in")); } catch (FileNotFoundException ex) { }catch (IOException ex) { } } /** Write fixed content to the given file. */ void writeNextLine(int text) { try { out.write("Case #"+lineNumber +": "+text+"\r\n"); System.out.println("Case #"+lineNumber +": "+text); } catch (IOException ex) { } lineNumber++; } String readLine() { String output = scanner.nextLine(); return output; } int readIntLine(){ String output = scanner.nextLine(); return Integer.decode(output).intValue(); } int readInt(){ return scanner.nextInt(); } public void close() { try { out.close(); } catch (IOException ex) { } scanner.close(); } // PRIVATE private int lineNumber = 1; private BufferedWriter out = null; private Scanner scanner = null; }
0
651
A12852
A11856
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package dancing.gogglers; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; import speaking.tongues.WordMap; /** * * @author Raveesh */ public class Googlers { private static int inputSurpriseCount = 0; private static int inputPointLimit = 0; private static int inputGooglerCount = 0; private static int surpriseCount = 0; private static int outputCount = 0; private static HashMap playerMap = new HashMap(); private static void printMap() { Iterator iter = playerMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry e = (Map.Entry) iter.next(); Integer player = (Integer) e.getKey(); List comboList = (ArrayList) e.getValue(); Iterator listIter = comboList.iterator(); System.out.println("Player combo :: " + player); while (listIter.hasNext()) { StringBuffer str = (StringBuffer) listIter.next(); System.out.println("Str : " + str.toString()); } } } private static ArrayList getInputList(BufferedReader stdin) throws IOException { ArrayList stringList = new ArrayList<String>(); String line; int inputLineCount = 0; Integer testCaseCount = 0; while ((line = stdin.readLine()) != null && line.length() != 0 && inputLineCount <= testCaseCount.intValue()) { // System.out.println("line :: " + line); if (inputLineCount == 0) { try { testCaseCount = Integer.valueOf(line); } catch (NumberFormatException pe) { System.out.println("Invalid input for # of test cases"); System.exit(0); } inputLineCount++; continue; } stringList.add(line); inputLineCount++; if (inputLineCount == testCaseCount + 1) { break; } } return stringList; } public static void main(String[] args) throws FileNotFoundException, IOException { String filePath = "C:\\Users\\Raveesh\\Downloads\\B-small-attempt0.in"; String filePathOutput = filePath + "_out"; BufferedReader stdin = new BufferedReader(new FileReader(new File(filePath))); FileWriter fileWriter = new FileWriter(filePathOutput); ArrayList stringList = Googlers.getInputList(stdin); inputSurpriseCount = 1; inputPointLimit = 1; int count = 1; Iterator iter = stringList.iterator(); while (iter.hasNext()) { String inputStr = (String) iter.next(); System.out.println("Str :: " + inputStr); String[] inputStrArr = inputStr.split("\\ "); inputGooglerCount = Integer.valueOf(inputStrArr[0]); inputSurpriseCount = Integer.valueOf(inputStrArr[1]); inputPointLimit = Integer.valueOf(inputStrArr[2]); surpriseCount = 0; outputCount = 0; playerMap = new HashMap(); System.out.println("c : " + inputGooglerCount + "c : " + inputSurpriseCount + "c : " + inputPointLimit); for (int i = 0; i < inputGooglerCount; i++) { System.out.println("Doing for :: " + (inputStrArr[i + 3])); List comboListA = Googlers.getCombibations(Integer.valueOf(inputStrArr[i + 3])); playerMap.put(i, comboListA); } Googlers.printMap(); /** String[] atrArr = new String[inputGooglerCount]; for (int i = 0;i < inputGooglerCount ; i++) { atrArr[i] = "0"; } String a= Integer.toBinaryString(000000); String b= Integer.toBinaryString(000001); System.out.println("Sum " + Integer.toBinaryString(10+ 1)); int counter = inputGooglerCount-1; for (int i = 0;i < atrArr.length ; i++) { String index = atrArr[i]; String str = new String(); for (int j = 0;j < inputGooglerCount ; j++) { StringBuffer sb = (StringBuffer) ((ArrayList)playerMap.get(j)).get(Integer.parseInt(atrArr[j])); str = str + sb.toString(); if (j == counter) { atrArr[counter] = "1"; counter--; } } System.out.println("Str :: " + str); } **/ int maxCount = 0; List li1 = (ArrayList) playerMap.get(0); for (int i = 0; i < li1.size(); i++) { StringBuffer str = (StringBuffer) li1.get(i); String newStr = new String(); List li2 = (ArrayList) playerMap.get(1); if (inputGooglerCount > 1) { for (int k = 0; k < li2.size(); k++) { StringBuffer str1 = (StringBuffer) li2.get(k); if (inputGooglerCount > 2) { List li3 = (ArrayList) playerMap.get(2); for (int m = 0; m < li3.size(); m++) { StringBuffer str2 = (StringBuffer) li3.get(m); newStr = str.toString() + "," +str1 + "," + str2; String[] arr = newStr.split(","); System.out.println(":: " + newStr); int sur = 0; int out = 0; for ( int p = 0 ; p < arr.length ;p=p+4) { int a = Integer.parseInt(arr[p]); int b = Integer.parseInt(arr[p+1]); int c = Integer.parseInt(arr[p+2]); if (arr[p+3].equalsIgnoreCase("Y")) { sur++; } if (Googlers.checkLimit(a, b, c)) { out++; } } if(sur == inputSurpriseCount && maxCount < out) { maxCount = out; } } } else { newStr = str.toString() + "," + str1; String[] arr = newStr.split(","); System.out.println(":: " + newStr); int sur = 0; int out = 0; for ( int p = 0 ; p < arr.length ;p=p+4) { int a = Integer.parseInt(arr[p]); int b = Integer.parseInt(arr[p+1]); int c = Integer.parseInt(arr[p+2]); if (arr[p+3].equalsIgnoreCase("Y")) { sur++; } if (Googlers.checkLimit(a, b, c)) { out++; } } if(sur == inputSurpriseCount && maxCount < out) { maxCount = out; } System.out.println(":: " + newStr); } } } else { newStr = str.toString(); String[] arr = newStr.split(","); System.out.println(":: " + newStr); int sur = 0; int out = 0; for ( int p = 0 ; p < arr.length ;p=p+4) { int a = Integer.parseInt(arr[p]); int b = Integer.parseInt(arr[p+1]); int c = Integer.parseInt(arr[p+2]); if (arr[p+3].equalsIgnoreCase("Y")) { sur++; } if (Googlers.checkLimit(a, b, c)) { out++; } } if(sur == inputSurpriseCount && maxCount < out) { maxCount = out; } System.out.println(":: " + newStr); } } outputCount = maxCount; /*while (iter2.hasNext()) { Map.Entry e2 = (Map.Entry)iter2.next(); Iterator iter3 = ((ArrayList)e2.getValue()).iterator(); boolean found = false; boolean mul = false; int remove = 0; while (iter3.hasNext()) { StringBuffer str = (StringBuffer)iter3.next(); String[] strArr = str.toString().split(","); if(Googlers.checkLimit(Integer.valueOf(strArr[0]), Integer.valueOf(strArr[1]) , Integer.valueOf(strArr[2]))) { if (mul) { remove ++; } mul = true; outputCount++; if (strArr[3].equalsIgnoreCase("Y") && !found) { surpriseCount++; found = true; } else if (strArr[3].equalsIgnoreCase("Y") && found) { outputCount--; } } outputCount = outputCount - remove; } } /**HashMap toBeComparedMap = (HashMap) playerMap.clone(); Set toBeCamparedSet = toBeComparedMap.keySet(); while (iter1.hasNext()) { Map.Entry e = (Map.Entry) iter1.next(); Integer player = (Integer) e.getKey(); toBeCamparedSet.remove(player); List comboList = (ArrayList) e.getValue(); Iterator listIter = comboList.iterator(); while (listIter.hasNext()) { StringBuffer str = (StringBuffer) listIter.next(); Iterator comparedIter = toBeCamparedSet.iterator(); while(comparedIter.hasNext()) { Integer comparedPlayer = (Integer)comparedIter.next(); List comStr = (List)toBeComparedMap.get(comparedPlayer); Iterator comStrListIter = comStr.iterator(); while(comStrListIter.hasNext()) { str.append(":"); str.append((StringBuffer)comStrListIter.next()); comStrListIter.remove(); continue; } System.out.println("str ::" + str.toString()); } } } **/ String out = "Case #" + count + ": " + outputCount; fileWriter.write(out); fileWriter.write("\n"); count++; } fileWriter.close(); // Googlers.printMap(); System.out.println("outputCount : " + outputCount); } private static boolean checkLimit(int a, int b, int c) { if (a >= inputPointLimit || b >= inputPointLimit || c >= inputPointLimit) { // outputCount++; return true; } return false; } private static List getCombibations(int num) { int n = num / 3; int a; int b; int c; int offset = 0; List listStr = new ArrayList(); StringBuffer str = null; if (num % 3 == 0) { offset = 0; str = new StringBuffer(); a = b = c = n; if (a >= 0 && b >= 0 && c >= 0) { str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N"); listStr.add(str); } a = n + 1; b = n; c = n - 1; str = new StringBuffer(); if (a >= 0 && b >= 0 && c >= 0) { str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N"); listStr.add(str); } } else if (num % 3 == 1) { offset = 1; a = n; b = n; c = n + 1; str = new StringBuffer(); if (a >= 0 && b >= 0 && c >= 0) { str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N"); listStr.add(str); } a = n - 1; b = n + 1; c = n + 1; str = new StringBuffer(); if (a >= 0 && b >= 0 && c >= 0) { str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N"); listStr.add(str); } } else if (num % 3 == 2) { offset = 2; a = n; b = n + 1; c = n + 1; str = new StringBuffer(); if (a >= 0 && b >= 0 && c >= 0) { str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N"); listStr.add(str); } a = n; b = n; c = n + 2; str = new StringBuffer(); if (a >= 0 && b >= 0 && c >= 0) { str.append(a).append(",").append(b).append(",").append(c).append(",").append(Googlers.checkSurprise(a, b, c) ? "Y" : "N"); listStr.add(str); } } return listStr; } private static boolean checkSurprise(int a, int b, int c) { boolean flag = false; if ((a - b) >= 2 || (b - a) >= 2) { flag = true; } else if ((b - c) >= 2 || (c - b) >= 2) { flag = true; } else if ((c - a) >= 2 || (a - c) >= 2) { flag = true; } return flag; } }
0
652
A12852
A12312
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 gcodejam2012; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Scanner; /** * @author alei */ public class B { public static void main(String[]Args) throws FileNotFoundException{ Scanner sn = new Scanner(new FileInputStream("B.in")); System.setOut(new PrintStream("B.out")); int nCases = sn.nextInt(); for(int i=0;i<nCases;i++){ sn.nextLine(); int N = sn.nextInt(); int S = sn.nextInt(); int P = sn.nextInt(); int[]totalPoints = new int[N]; for(int j=0;j<N;j++){ totalPoints[j] = sn.nextInt(); } int result = solve(totalPoints,S,P); System.out.println("Case #"+(i+1)+": "+result); } } public static int solve(int[]totalPoints,int S,int P){ int m = 0; int min = 3*P-4; min = min<0?P:min+0; //the right //min = min<0?0:min+0; int max = 3*P+4; //System.out.println("["+min+";"+max+"]"); int c=0,a=0,ssp=0,sns=0; int gigants = 0; int s1 = 3*P-4; int s2 = 3*P-3; int s3 = 3*P+3; int s4 = 3*P+4; for(int i=0;i<totalPoints.length;i++){ int point = totalPoints[i]; if(point<=max && point>=min){ m++; if(point==s1 || point==s2||point==s3||point==s4){ int n1 = (point+2)/3; if(n1>=P){ //System.out.println("sns++->"+point); sns++; } c++; } else{ int n1 = (point+2)/3; if(n1>=P){ ssp++; } } } else if(point >max){ gigants++; m++; } else{ a++; } } //System.out.println("m->"+m+"->gig->"+gigants+"->a->"+a+"->S->"+S+"->c->"+c+"<->nsp->"+ssp); if(S>c){ S-=c; if(S>0){ S-=gigants; if(S>0){ S-=a; if(S>0){ // System.out.println("finalSubst->"+m+"-s:"+S); int reaNsp = Math.min(S, ssp); m = m-S+reaNsp; } } } } else{ //sns = Math.min(S, sns); int fns = c-S; //System.out.println("fns->"+fns+"<->sns->"+sns); if(sns>=fns){ } else{ m = m - fns + sns; } } return m; } }
0
653
A12852
A10006
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class DancingWithGooglers { public int max(int s, int q, int[] score){ int pass = 0, fail = 0, pos = 0; for(int sc : score){ if(sc == 0){ if(q == 0) pass++; else fail++; } else if(sc == 1){ if(q <= 1) pass++; else fail++; } else if( (sc + 2) / 3 >= q) pass++; else if( (sc +1) / 3 +1 < q) fail++; else pos++; } return pass + Math.min(pos, s); } public static void main(String[] args) throws FileNotFoundException { DancingWithGooglers d = new DancingWithGooglers(); // int[] c1 = {15,13,11}; // System.out.println(d.max(1,5,c1)); // // int[] c2 = {23,22,21}; // System.out.println(d.max(0,8,c2)); // // int[] c3 = {8, 0}; // System.out.println(d.max(1,1,c3)); // // int[] c4 = {29,20, 8, 18, 18, 21}; // System.out.println(d.max(2,8,c4)); File f = new File(args[0]); Scanner sc = new Scanner(f); int l = Integer.parseInt(sc.nextLine()); for(int i = 1; i <= l ;i++){ String[] line = sc.nextLine().split(" "); int[] c = new int[Integer.parseInt(line[0])]; int s = Integer.parseInt(line[1]); int q = Integer.parseInt(line[2]); for(int j = 0; j < c.length; j++) c[j] = Integer.parseInt(line[j+3]); System.out.printf("Case #%d: %s\n", i, d.max(s, q, c)); } } }
0
654
A12852
A12608
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; public class B { public static void main(String[] Args) throws IOException { Scanner sc = new Scanner(new FileReader("B-small.in")); PrintWriter pw = new PrintWriter(new FileWriter("output.txt")); int caseCnt = sc.nextInt(); System.out.println(caseCnt); for (int caseNum=1; caseNum <= caseCnt; caseNum++) { System.out.println(caseNum); int N=sc.nextInt(); int S=sc.nextInt(); int p=sc.nextInt(); int[] score = new int[N]; int total=0; System.out.print(p+" "); for(int i=0;i<N;i++) { score[i]=sc.nextInt(); if(score[i]>=3*p-2) { total++; } else if(score[i]>=3*p-4 && S>0 && score[i]>=p) { total++; S--; } } System.out.println(total); pw.println("Case #" + caseNum + ": " + total); } pw.flush(); pw.close(); sc.close(); } }
0
655
A12852
A12546
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Round0; import custom.Output; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.StringTokenizer; /** * * @author shyam */ public class B { static String inputfile="./src/Small.in"; static String outputfile="./src/Small.out"; //static String inputfile="./src/Large.in"; //static String outputfile="./src/Large.out"; public static void main(String args[])throws Exception{ BufferedReader br=new BufferedReader(new FileReader(inputfile)); PrintWriter pw = new PrintWriter(new FileWriter(outputfile)); String row=""; StringTokenizer st; // first line to count no of records row=br.readLine(); int T=Output.ipri(row); // initial variables for(int count=1;count<=T;count++){ row=br.readLine(); // read each record // tokenize: default space st=new StringTokenizer(row); int N = Output.ipri(st.nextToken()); int S = Output.ipri(st.nextToken()); int p = Output.ipri(st.nextToken()); // variables int GT; int x,y,z; int sup=0; int[][] G = new int[N][3]; // operations for(int i=0;i<N;i++){ GT = Output.ipri(st.nextToken()); x = Math.min(GT, GT/3 + Math.max(GT%3, 1)); if(x==11) x=10; y = GT/3; z = GT-x-y; G[i][0] = x; G[i][1] = y; G[i][2] = z; if(x-z == 2) sup++; //Output.sopl(x+" "+y+" "+z); } java.util.Arrays.sort(G, new java.util.Comparator<int[]>() { public int compare(int[] a, int[] b) { return b[0] - a[0]; } }); int max_G = 0; for(int i=N-1;i>=0;i--){ if( G[i][0] == p ) break; if(sup > S && (G[i][0]-Math.min(G[i][1],G[i][2]))==2){ G[i][0]--; G[i][2]++; sup--; } } for(int i=0;i<N;i++){ if(sup > S && (G[i][0]-Math.min(G[i][1],G[i][2]))==2){ G[i][0]--; G[i][2]++; sup--; } if(G[i][0] >= p) max_G++; } // printing output //Output.sopl("Case #"+count+": "+max_G); pw.println("Case #"+count+": "+max_G); // reset variables } br.close(); pw.close(); } }
0
656
A12852
A12648
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 codejam2012; import java.util.Scanner; /** * * @author Matt */ public class ProbB { public static void main(String[] args){ Scanner scan = new Scanner(System.in); Integer cases = scan.nextInt(); for(int i = 0; i < cases; i++){ Integer contestants = scan.nextInt(); Integer surprising = scan.nextInt(); Integer num = scan.nextInt(); Integer count = 0; //System.out.print(surprising); for(int j = 0; j < contestants; j++){ Integer current = scan.nextInt(); Double average = current/3.0; if(average >= num){ count++; }else if(average == 0 || average == 10){ }else if(average.intValue() == average.doubleValue()){ if(surprising > 0 && (average+1) >= num){ count++; surprising--; //System.out.print(surprising); } }else if(average.intValue()+1 >= num) { count++; }else if(average > 0.5 && surprising > 0 && average.intValue()+2 >= num) { count++; surprising--; //System.out.print(surprising); } } //System.out.print(surprising); System.out.println("Case #"+(i+1)+": "+count); } } }
0
657
A12852
A11372
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.InputStreamReader; import java.io.OutputStreamWriter; public class googler { public static void main(String[] args) throws Exception { int n; int res; int threshold; int cheat; int goo; int test; int div; int rem; String[] temp; BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); BufferedWriter write = new BufferedWriter(new OutputStreamWriter(System.out)); n = Integer.parseInt(read.readLine()); for (int j=1; j<=n; j++) { temp = read.readLine().split(" "); res = 0; goo = Integer.parseInt(temp[0]); cheat = Integer.parseInt(temp[1]); threshold = Integer.parseInt(temp[2]); for (int i=0; i<goo; i++) { test = Integer.parseInt(temp[i+3]); div = test/3; rem = test%3; if (div >= threshold) { res++; } else if (threshold - div == 1) { if (rem > 0){ res++; } else if (cheat > 0 && div > 0) { cheat--; res++; } } else if ((threshold - div == 2) && rem == 2 && cheat > 0) { cheat--; res++; } } write.write(String.format("Case #%d: %d\n", j, res)); } write.flush(); } }
0
658
A12852
A10747
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.twelve; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ProbB { public static void main(String[] args) throws IOException { FileReader fr = new FileReader( "D:\\Dev\\Workspaces\\Android\\codejam\\io\\qualification\\B-small-attempt0.in"); FileWriter fw = new FileWriter( "D:\\Dev\\Workspaces\\Android\\codejam\\io\\qualification\\B-small-attempt0.out"); BufferedReader br = new BufferedReader(fr); BufferedWriter bw = new BufferedWriter(fw); int t = Integer.parseInt(br.readLine()); for (int i = 1; i <= t; i++) { String s = br.readLine(); bw.append("Case #" + i + ": "); String ss[] = s.split(" "); int nn[] = new int[ss.length]; for (int j = 0; j < ss.length; j++) { nn[j] = Integer.parseInt(ss[j]); } int N = nn[0]; int S = nn[1]; int P = nn[2]; int sa=0; int na=0; for (int j = 0; j < N; j++) { int trip = nn[3+j]; int remain = trip-P; if(remain<0) continue; int other = P-(remain/2); if(other==2){ sa++; } else if(other<2){ na++; } } if(sa>=S) sa=S; bw.append(""+(na+sa)); bw.newLine(); } bw.flush(); bw.close(); br.close(); } }
0
659
A12852
A11983
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package codejam; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; /** * * @author Luis Carlos */ public class DancingGooglers { private static String caseString = "Case #%d: %s"; private static int max; private static int count; public static void main(String[] args) throws FileNotFoundException, IOException { BufferedReader bf = new BufferedReader(new FileReader("small.in")); int testCase = Integer.parseInt(bf.readLine()); for (int i = 1; i <= testCase; i++) { String[] parameters = bf.readLine().split(" "); int N = Integer.parseInt(parameters[0]); int S = Integer.parseInt(parameters[1]); int p = Integer.parseInt(parameters[2]); int[][][] detailedPosibleScores = new int[N][][]; for (int j = 3; j < N + 3; j++) { for (int k = 0; k < detailedPosibleScores.length; k++) { detailedPosibleScores[k] = getPossibleTripplets(Integer.parseInt(parameters[k + 3])); } } int[] combination = new int[N]; visitar(0, combination, detailedPosibleScores, S, 0, p); System.out.println(String.format(caseString, i, count)); count = 0; } } public static int[][] getPossibleTripplets(int score) { if (score == 0) { return new int[][]{{0, 0, 0}, {0, 0, 0}}; } if (score == 1) { return new int[][]{{0, 0, 1}, {0, 0, 1}}; } int m = score / 3; int r = score % 3; if (r == 0) { return new int[][]{{m - 1, m, m + 1}, {m, m, m}}; } if (r == 1) { return new int[][]{{m, m, m + 1}, {m + 1, m + 1, m - 1}}; } if (m + 2 > 10) { return new int[][]{{m + 1, m + 1, m}, {m + 1, m + 1, m}}; } return new int[][]{{m, m, m + 2}, {m + 1, m + 1, m}}; } public static boolean isSurprising(int[] tripplet) { return Math.abs(tripplet[0] - tripplet[1]) == 2 || Math.abs(tripplet[0] - tripplet[2]) == 2 || Math.abs(tripplet[1] - tripplet[2]) == 2; } public static void visitar(int pos, int[] comb, int[][][] combs, int S, int s, int p) { if (pos < comb.length) { for (int i = 0; i < 2; i++) { comb[pos] = i; visitar(pos + 1, comb, combs, S, s, p); } } else { mostrar(comb, combs, p, S); } } public static void mostrar(int[] combination, int[][][] combs, int p, int S) { int s = 0, countTmp = 0; for (int i = 0; i < combination.length; i++) { int[] tripplet = combs[i][combination[i]]; if(isSurprising(tripplet)){ if(++s>S){ return; } } max = max(tripplet); if (max >= p) { countTmp++; } } if(countTmp > count){ count = countTmp; } } public static int max(int... number) { int max = 0; for (int i : number) { if (i == 10) { return 10; } if (i > max) { max = i; } } return max; } }
0
660
A12852
A12593
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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(); in.nextLine(); //build auxiliary arrays int[] without = new int[31]; int[] with = new int[31]; for (int i = 0; i <= 30; i++) { without[i] = (int)Math.ceil((double)i/3.0); if (i == 0) with[i] = 0; else with[i] = (int)Math.min(10, Math.ceil(((double)i+2.0)/3.0)); } //for each test case for (int i = 1; i <= T; i++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int result = 0; for (int j = 0; j < N; j++) { int tp = in.nextInt(); if (without[tp] >= p) result++; else if (with[tp] >= p && S > 0) { result++; S--; } } System.out.format("Case #%d: %d\n", i, result); } } }
0
661
A12852
A11313
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 static java.lang.System.*; public class B { // non-surprising public static int best1(int x) { if (x%3 == 0) return x/3; else return x/3+1; } // surprising public static int best2(int x) { if (x == 0) return 0; return (x+1)/3+1; } public static void main(String[] args) { Scanner sc = new Scanner(in); int t = sc.nextInt(); for (int c = 1; c <= t; c++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int[] arr = new int[31]; for (int i = 0; i < n; i++) arr[sc.nextInt()]++; int ctr = 0; for (int i = 30; i >= 0; i--) { if (best1(i) >= p) { ctr += arr[i]; } else { if (i > 1 && best2(i) >= p) { ctr += Math.min(s, arr[i]); if (s > arr[i]) s -= arr[i]; else s = 0; } } } out.printf("Case #%d: %d\n", c, ctr); } } }
0
662
A12852
A11439
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.io.Reader; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Set; public class Main { public static HashMap<Character,Character> mapp = new HashMap<Character,Character>(); public static void main(String[] args) throws Exception { PrintWriter writer = new PrintWriter(new FileWriter("output.txt")); BufferedReader input = new BufferedReader(new FileReader("B-small-attempt0.in")); int size=Integer.parseInt(input.readLine()); for(int i=0; i<size; i++) { String testCase = input.readLine(); String tokens[] = testCase.split(" "); int N = Integer.parseInt(tokens[0]); int S = Integer.parseInt(tokens[1]); int p = Integer.parseInt(tokens[2]); int count=0; //ArrayList<Integer> google = new ArrayList<Integer>(); for(int j=3; j<N+3; j++) { int testNum = Integer.parseInt(tokens[j]); if((testNum - p) >= 2*(p-1) && (testNum-p)>=0) { count++; } else if((testNum - p) < 2*(p-1) && (testNum-p)>=0) { if(S!=0 && (testNum - p) >= 2*(p-2) ) { count++; S--; } } } writer.println("Case #"+(i+1)+": "+count); } writer.close(); input.close(); } }
0
663
A12852
A10443
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; import java.io.*; public class Prob2 { public static void main(String[] args) throws IOException{ Scanner in = new Scanner(new File("D:/B-small-attempt0.in")); PrintStream out = new PrintStream(new File("D:/outputProb2.txt")); int lineAmount = Integer.parseInt(in.nextLine()); for (int n = 1; n <= lineAmount; n++) { int m = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int y = 0, spare = 0; for (int i = 0; i < m; i++) { int a = in.nextInt(); if (a == 0) { if (p == 0) y++; } else if (a % 3 == 0) { int k = a / 3; if (p <= k) y++; else if (p == k + 1) spare++; } else if (a % 3 == 1) { int k = (a - 1) / 3; if (p <= k + 1) y++; } else { int k = (a - 2) / 3; if (p <= k + 1) y++; else if (p == k + 2) spare++; } } if (s <= spare) y += s; else y += spare; out.println("Case #"+n+": "+y); } in.close(); out.close(); } }
0
664
A12852
A12812
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package ru.guredd.codejam; import java.io.*; import java.util.ArrayList; import java.util.List; public class Main { protected static List<String> inputData = new ArrayList<String>(); protected static List<String> outputData = new ArrayList<String>(); public static void loadInputData(String fileName) throws IOException { BufferedReader in = null; try { inputData.clear(); String line; in = new BufferedReader(new FileReader(fileName)); if (!in.ready()) throw new IOException(); while ((line = in.readLine()) != null) inputData.add(line); } finally { if(in != null) { in.close(); } } } public static void saveOutputData(String fileName) throws IOException { BufferedWriter out = null; try { out = new BufferedWriter(new FileWriter(fileName)); for (String anOutputData : outputData) { out.write(anOutputData); out.newLine(); } } finally { if(out != null) { out.close(); } } } public static void main (String [] argv) throws IOException { loadInputData(argv[0]); Qualification2012B QB = new Qualification2012B(); QB.solve(); saveOutputData(argv[1]); } }
0
665
A12852
A11123
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.PrintStream; import java.util.HashMap; import java.util.Map; public class B { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("b.in"))); PrintStream out = new PrintStream(new FileOutputStream("b.out")); long count = readInt(in); for (int i = 0; i < count; i++) { String[] data = in.readLine().split(" "); int n = Integer.parseInt(data[0]); int s = Integer.parseInt(data[1]); int p = Integer.parseInt(data[2]); int goodLimit = 3 * p - 2; if (p == 0) { goodLimit = 0; } int sLimit = 3 * p - 4; if (p == 1) { sLimit = 1; } System.out.println(goodLimit + " " + sLimit); int good = 0; int sur = 0; for (int j = 0; j < n; j++) { int v = Integer.parseInt(data[3 + j]); if (v >= goodLimit) { good++; } else if (v >= sLimit) { sur++; } } System.out.println(good + " " + sur); out.println("Case #" + (i + 1) + ": " + (good + Math.min(s, sur))); } out.flush(); out.close(); } private static long readInt(BufferedReader in) { try { return Long.parseLong(in.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } private static void loadCode(String s1, String t1, Map<Character, Character> m) { for (int i = 0; i < s1.length(); i++) { m.put(s1.charAt(i), t1.charAt(i)); } } }
0
666
A12852
A11997
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; import java.io.*; public class Dancing { public static void main(String [ ] args) throws Exception{ Scanner in = new Scanner(new File(args[0])); PrintStream Output = new PrintStream(new FileOutputStream("soluzione.txt")); int n = in.nextInt(); for(int i = 1; i <= n; i++){ int tot, a, b, c; int contatore = 0; int partecipanti = in.nextInt(); int triplSorp = in.nextInt(); int punteggio = in.nextInt(); for(int j = 0; j < partecipanti; j++){ tot = in.nextInt(); a = tot/3; b = a; c = a; if (a > punteggio) contatore++; else{ if (tot == (a + b + c)){ // solo in questo caso si puo avere un risultato sorpreendente if (a >= punteggio) contatore++; else if (triplSorp != 0 && a > 1){ a++; if (a >= punteggio){ contatore++; triplSorp--; } } } else { b++; if (tot == (a + b + c)){ if (a >= punteggio) contatore++; else if (b >= punteggio) contatore++; } else{ c++; if (tot == (a + b + c)){ if (a >= punteggio) contatore++; else if (b >= punteggio) contatore++; else if(triplSorp != 0) { c--; b++; if (tot == (a + b + c)){ if (b >= punteggio) { triplSorp--; contatore++; } } } } } } } } String x = "Case #" + i + ": "+ contatore; Output.println(x); } } }
0
667
A12852
A10023
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; public class InputReader { private BufferedReader br = null; public InputReader(String fileName) { try { br = new BufferedReader(new FileReader(fileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public ArrayList<String> loadLines() { ArrayList<String> lines = new ArrayList<String>(); String[] arrLines = null; String tmp = null; try { while ((tmp = br.readLine()) != null) { lines.add(tmp); } br.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return lines; } }
0
668
A12852
A12207
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintStream; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class DancingGooglers{ private static final int NUMBEROFJUDGES = 3; public static void main(String[] args) throws IOException { BufferedReader br = null; try { br = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintStream out = new PrintStream(new File("B-Small.out")); int testcases = Integer.parseInt(br.readLine()); for (int casenr = 1; casenr <= testcases; casenr++) { String line = br.readLine(); Scanner scanner= new Scanner(line); int numOfGoogler = scanner.nextInt(); int numOfSurprising = scanner.nextInt(); int bestResult = scanner.nextInt(); ArrayList<Integer> totalPoints =new ArrayList<Integer> (); for (int i=0;i<numOfGoogler ;i++){ totalPoints.add(scanner.nextInt()); } Collections.sort(totalPoints, Collections.reverseOrder()); int numberOfBestGoogler = 0; for (int i= 0;i<numOfGoogler ;i++){ double averagePoint = ((totalPoints.get(i)*1.0)/ NUMBEROFJUDGES); if ( averagePoint > (bestResult-1) ){ numberOfBestGoogler++; } else { if ((Math.max((bestResult-2),0)*(NUMBEROFJUDGES-1) <= (totalPoints.get(i)-bestResult) ) && (numOfSurprising>0)) { numOfSurprising--; numberOfBestGoogler++; } } } System.out.printf("Case #%d: %d\n", casenr, numberOfBestGoogler); out.printf("Case #%d: %s\n", casenr, numberOfBestGoogler); } } catch(FileNotFoundException fe) { fe.printStackTrace(); } catch(IOException ie) { ie.printStackTrace(); } finally { try { if(br != null) { br.close(); } } catch (IOException ex) { ex.printStackTrace(); } } } }
0
669
A12852
A12778
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Texter { public static void writeText(String text) { String fileName = "output.txt"; try { BufferedWriter writer = new BufferedWriter(new FileWriter(fileName, true)); writer.write(text); writer.newLine(); writer.close(); } catch (IOException e) { e.printStackTrace(); } } public static String readFile() { String fileName = "test.txt"; String LS = System.getProperty("line.separator"); StringBuffer fileContent = new StringBuffer(); try { FileReader fr = new FileReader(fileName); BufferedReader reader = new BufferedReader(new FileReader(fileName)); String line; while ((line = reader.readLine()) != null) { fileContent.append(line).append(LS); } } catch (IOException e) { e.printStackTrace(); } return fileContent.toString(); } static FileReader fr; static BufferedReader reader; public static void setupReader() { String fileName = "input.txt"; try { fr = new FileReader(fileName); reader = new BufferedReader(new FileReader(fileName)); } catch (IOException e) { e.printStackTrace(); } } public static String readLine() { String fileName = "test.txt"; String LS = System.getProperty("line.separator"); //StringBuffer fileContent = new StringBuffer(); String line = null; try { //FileReader fr = new FileReader(fileName); // BufferedReader reader = new BufferedReader(new FileReader(fileName)); line = reader.readLine(); } catch (IOException e) { e.printStackTrace(); } //Will return null at end of file return line; } public static ArrayList<Integer> parseNumberList(String input) { int length = input.length(); ArrayList<Integer> numbersArray = new ArrayList<Integer>(); int numberCount = 0; //Index to start current number at int noStart = 0; //First one shouldn't be a space so start ahead for (int i = 1; i < length; i++) { //If character is a space that means a number just ended if (input.charAt(i) == ' ') { //Get that number //Substring from startIndex to endIndex -1 int number = Integer.parseInt(input.substring(noStart, i)); //Add it to array numbersArray.add(number); //Increment count numberCount++; //Set new number start index to one after the space we just had noStart = i + 1; } //Add last number if (i == length - 1) { //Get that number //Substring from startIndex to endIndex -1 int number = Integer.parseInt(input.substring(noStart, length)); //Add it to array numbersArray.add(number); } } return numbersArray; } }
0
670
A12852
A12525
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileWriter; import java.io.IOException; import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.FileReader; import java.io.PrintStream; import java.io.PrintWriter; import java.io.FileWriter; import java.io.PrintWriter; import java.io.IOException; public class Googlers { public static void main(String args[]) throws IOException { int totalValid; int surp, numGooglers, maxNum, calcSurp; try { PrintWriter wt= new PrintWriter("C:\\Documents and Settings\\windows\\workspace\\test\\src\\file.out.txt"); Scanner I = new Scanner(new File("C:\\Documents and Settings\\windows\\workspace\\test\\src\\B-small-attempt2.in")); String num = I.nextLine(); int numTests = Integer.parseInt(num); for(int x=0; x<numTests; x++) { int i = 0; String[] str = I.nextLine().split(" "); int inputs[] = new int[150]; for(int y = 0; y <str.length; y++ ) { inputs[y] = Integer.parseInt(str[y]); } numGooglers = inputs[0]; surp = inputs[1]; maxNum = inputs[2]; totalValid = 0; calcSurp = 0; for( i = 3; i < numGooglers + 3 ; i++) { if (isGoogler(inputs[i], maxNum) == 1) { totalValid++; } else if(isGoogler(inputs[i], maxNum) == 2) { calcSurp++; } else {} } // match surp numbers if (calcSurp > surp) { totalValid = totalValid + surp; } else { totalValid = totalValid + calcSurp; } //logic to write totalValid to file String finalResult = "Case #"+(x+1)+": "+totalValid; wt.println(finalResult); finalResult = ""; } wt.close(); I.close(); } catch(FileNotFoundException e) { e.printStackTrace(); } catch(IOException e) { System.out.println(e); } } // Replacement algorithm public static int isGoogler (int num,int max) { if (max == 0 && max <= num) return 1; else if (num <= 0) return 0; else if (num >= ((max * 3)-2 )) return 1; else if (num >= ((max * 3)-4 )) return 2; else return 0; } }
0
671
A12852
A11358
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /** * * @author Igor */ public class Dancing { public static void main(String[] args) throws Exception { Scanner in = new Scanner(new File("input.txt")); PrintWriter out = new PrintWriter("output.txt"); int testCount = in.nextInt(); for (int test = 0; test < testCount; test++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int[] score = new int[n]; for (int i = 0; i < n; i++) { score[i] = in.nextInt(); } Arrays.sort(score); int res = 0; for (int i = n - 1; i >= 0; i--) { if (3 * p <= score[i]) { res++; } else { if (s > 0) { if (3 * p - 2 <= score[i]) { res++; } else { if (3 * p - 4 <= score[i] && 3 * p - 4 >= 0) { res++; s--; } } } else { if (3 * p - 2 <= score[i]) { res++; } } } } out.println("Case #" + (test + 1) + ": " + res); } out.close(); } }
0
672
A12852
A10743
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package Dancing; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Dancing { public static int[] result = new int[3]; public static List<ArrayList<Integer[]>> lstScore = new ArrayList<ArrayList<Integer[]>>(); public static ArrayList<Integer[]> lst; public static int numCase = 0; public static int max = -1; //Number of googler public static int N; public static int p; //Number of surprising public static int S; public static void main(String[] args) throws NumberFormatException, IOException { readFile(); } public static void readFile() throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader( new FileInputStream("B-small-attempt1.in"))); numCase = Integer.parseInt(br.readLine()); for (int i = 0; i < numCase; i++) { String[] arrStr = br.readLine().split(" "); N = Integer.valueOf(arrStr[0]); S = Integer.valueOf(arrStr[1]); p = Integer.valueOf(arrStr[2]); int n = arrStr.length; int[] total = new int[N]; for (int j = 3; j < n; j++) { total[j - 3] = Integer.valueOf(arrStr[j]); } lstScore = new ArrayList<ArrayList<Integer[]>>(); for (int k = 0; k < total.length; k++) { result[0] = (int)Math.floor(total[k] / 3) - 1; if (result[0] < 0) { result[0] = 0; } lst = new ArrayList<Integer[]>(); process(0, total[k]); lstScore.add(lst); //boolean[] mark = new boolean[] } if (S == 0) { ArrayList<Integer[]> lstInt = new ArrayList<Integer[]>(); int numLstScore = lstScore.size(); for (int j = 0; j < numLstScore; j++) { lstInt.add(lstScore.get(j).size() == 2 ? lstScore.get(j).get(1) : lstScore.get(j).get(0)); } writeOut(i + 1, count(lstInt, p)); } else { boolean[] mark = new boolean[N]; Arrays.fill(mark, false); max = -1; select(0, mark, 0); writeOut(i + 1, max); } } } public static int select(int indexSurprise, boolean[] markSurprise, int surprise) { if (surprise == S) { ArrayList<Integer[]> lstInt = new ArrayList<Integer[]>(); int numLstScore = lstScore.size(); for (int j = 0; j < numLstScore; j++) { lstInt.add(markSurprise[j] ? lstScore.get(j).get(0) : lstScore.get(j).size() == 2 ? lstScore.get(j).get(1) : lstScore.get(j).get(0)); } if (count(lstInt, p) > max) { max = count(lstInt, p); } } else { int n = lstScore.size(); for (int i = indexSurprise; i < n; i++) { if (lstScore.get(i).size() > 1) { markSurprise[i] = true; select(i + 1, markSurprise, surprise + 1); markSurprise[i] = false; } } } return 0; } public static int count(ArrayList<Integer[]> lstCount, int atLeast) { int n = lstCount.size(); int c = 0; for (int i = 0; i < n; i++) { Integer[] t = lstCount.get(i); for (int j = 0; j < 3; j++) { if (t[j] >= atLeast) { c++; break; } } } return c; } public static void writeOut(int order, int result) { System.out.format("Case #%d: %d\n", order, result); } public static void process(int n, int total) { if (n == 3) { if (result[0] + result[1] + result[2] == total) { if (result[1] - result[0] <= 2 && result[2] - result[1] <= 2 && result[2] - result[0] <= 2) { lst.add(new Integer[]{result[0], result[1], result[2]}); //System.out.println(result[0] + "," + result[1] + "," + result[2]); } } return; } int startNumber = 0; if (n > 0) { startNumber = result[n - 1]; } else { startNumber = result[0]; } for (int i = startNumber; i <= 10; i++) { if (i <= total) { result[n] = i; process(n + 1, total); } } } }
0
673
A12852
A11262
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner sc = null; BufferedWriter bw = null; try{ sc = new Scanner(new File("input.txt")); bw = new BufferedWriter(new FileWriter("gcj2a.txt")); int T = sc.nextInt(); int N, p, s, x; int minNormal=0, minSur=0, totNor=0, totSur=0; for(int i=0;i<T;i++){ totNor = 0; totSur = 0; N = sc.nextInt(); s = sc.nextInt(); p = sc.nextInt(); minNormal = 3*p-2;minSur = 3*p-4; minSur = (minSur>p)?minSur:p; for(int j=0;j<N;j++){ x = sc.nextInt(); if(x>=minNormal) totNor++; else if(x>=minSur) totSur++; } totNor += s>totSur?totSur:s; bw.write("Case #"+(i+1)+": "+totNor);bw.newLine(); } }catch(Exception e){} finally{ try{ sc.close();bw.close(); }catch(Exception e){} } } }
0
674
A12852
A12725
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 DancingWithGooglers { public static void main(String[] args) { Scanner in = new Scanner(System.in); int numberOfTests = Integer.parseInt(in.nextLine()); for(int i = 0; i < numberOfTests; i++) { int googlers = in.nextInt(), suprises = in.nextInt(), query = in.nextInt(); int numberSatisfyingQuery = 0, numberNeedingSuprises = 0; for(int j = 0; j < googlers; j++) { int total = in.nextInt(); if(total % 3 == 0) { int high = total / 3; if(high >= query) { numberSatisfyingQuery++; } else if(high + 1 >= query && high >= 1) { numberNeedingSuprises++; } } else if(total % 3 == 1) { int high = total / 3 + 1; if(high >= query) { numberSatisfyingQuery++; } // Surprise not possible } else if(total % 3 == 2) { int high = total / 3 + 1; if(high >= query) { numberSatisfyingQuery++; } else if(high + 1 >= query && high >= 1) { numberNeedingSuprises++; } } } int result = numberSatisfyingQuery + Math.min(numberNeedingSuprises, suprises); System.out.println("Case #" + (i + 1) + ": " + result); } } }
0
675
A12852
A10575
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qualification.b; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.ArrayListMultimap; public final class Memory { private static Logger log = LoggerFactory.getLogger(Memory.class); public ArrayListMultimap<Integer, Triplet> data = ArrayListMultimap.create(); private static int startFor(int a) { return a < 2 ? 0 : a - 2; } private static int endFor(int a) { return a > 8 ? 10 : a + 2; } public void init() { log.debug("init: start"); for (int a = 0; a <= 10; ++a) { int bStart = startFor(a); int bEnd = endFor(a); for (int b = bStart; b <= bEnd; ++b) { int cStart = startFor(b); int cEnd = endFor(b); for (int c = cStart; c <= cEnd; ++c) { int total = a + b + c; data.put(total, Triplet.of(a, b, c, total)); } } } log.debug("init: finished"); } }
0
676
A12852
A12423
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithTheGooglers { private String solve(Scanner in) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int p3 = 3*p; if (p >10) return "" + 0; int result = 0; int strange = 0; for (int i=0; i<N; i++) { int score = in.nextInt(); if (p3 <= score) result++; else { int diff = p3 - score; if (diff <= 2) { if (p - 1 >= 0) result++; } else if (diff <= 4) { if (p - 2 >= 0) { strange++; if (strange <= S) result++; } } } } return "" + result; } /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new File("C:\\Users\\User\\Desktop\\dane\\data.in")); PrintWriter out = new PrintWriter("C:\\Users\\User\\Desktop\\dane\\output"); int T = in.nextInt(); in.nextLine(); for (int i = 0; i < T; i++) { String s = "Case #" + (i + 1) + ": " + new DancingWithTheGooglers().solve(in); out.println(s); System.out.println(s); } out.close(); } }
0
677
A12852
A10273
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package problemB; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.Writer; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) throws Exception { Writer write = new FileWriter(new File("out.txt")); Writer writer = new BufferedWriter(write); Scanner scan = new Scanner(new File("B-small-attempt0.in.txt")); int t = scan.nextInt(); for(int i = 1; i<=t; i++) { int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); Score[] score = new Score[n]; for(int j = 0; j<score.length; j++) { score[j] = new Score(scan.nextInt()); } int count = 0; for(int j = 0; j<n; j++) { if(score[j].bestScore(p)) { count++; score[j] = null; } } int surprising = 0; for(int j = 0; j<n && surprising<s; j++) { if(score[j]!=null) { if(score[j].bestScoreOther(p)) { count++; surprising++; } } } writer.write("Case #"+i+": "+count+"\n"); } writer.close(); write.close(); } private static class Score { int[] not; int[] surprising; public Score(int num) { not = new int[3]; buildScores(num); } public boolean bestScore(int score) { for(int i : not) { if(i>=score) return true; } return false; } public boolean bestScoreOther(int score) { if(surprising==null) return false; for(int i : surprising) { if(i>=score) return true; } return false; } private void buildScores(int num) { int i = 0; while(i<num) { if(i<num) { not[0]++; i++; } if(i<num) { not[1]++; i++; } if(i<num) { not[2]++; i++; } } buildSurprising(); } private void buildSurprising() { int increment = -1; int decrement = -1; if(not[0]==not[1]) { if(not[0]!=10) increment = 0; if(not[1]!=0) decrement = 1; } else if (not[0]==not[2]) { if(not[0]!=10)increment = 0; if(not[0]!=0)decrement = 2; } else if (not[1]==not[2]) { if(not[0]!=10)increment = 1; if(not[0]!=0)decrement = 2; } if(increment!=-1 && decrement!=-1) { surprising = new int[]{not[0], not[1], not[2]}; surprising[increment]++; surprising[decrement]--; } } } }
0
678
A12852
A11141
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 CodeJam2; import java.io.*; import java.util.HashMap; import java.util.Scanner; /** * * @author Ivan du Toit <s29363412> */ public class CodeJam2 { /** * @param args the command line arguments */ public static void main(String[] args) { BufferedReader fIn = null; PrintWriter fOut = null; try { fIn = new BufferedReader(new FileReader("in.txt")); fOut = new PrintWriter(new FileWriter("out.txt")); } catch (IOException e) { System.out.println("Invalid file given for output."); System.exit(200); } Scanner in = new Scanner(fIn); int numberOfCases = Integer.parseInt(in.nextLine()); for (int c=0; c<numberOfCases; c++) { fOut.print("Case #" + (c+1) + ": "); int numGoogs = in.nextInt(); int numSuprises = in.nextInt(); int bestScore = in.nextInt(); int result = 0; for (int pos=0; pos<numGoogs; pos++) { int total = in.nextInt(); int num = (int) Math.floor(total/3); int res = total % 3; //res = (res > 1) ? 1 : res; //boolean resBiggerThan1 = (res > 1); boolean resLessThan1 = (res < 1); if (num >= bestScore) result++; else if ((!resLessThan1) && (num + 1 >= bestScore)) result++; else if ((numSuprises > 0) && (num > 0) && ((resLessThan1 && (num + 1 >= bestScore)) || (!resLessThan1 && (num + res >= bestScore)))) { numSuprises--; result++; } else if ((numSuprises > 0) && (!resLessThan1 && (num + res >= bestScore))) { numSuprises--; result++; } } in.nextLine(); fOut.println(result); } fOut.flush(); } }
0
679
A12852
A10818
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package quals; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class Dancing { public static void main(String args[]) { try { System.setIn(new FileInputStream("B-small-attempt0.in")); Scanner scanner = new Scanner(System.in); int testCases = scanner.nextInt(); scanner.nextLine(); for (int i = 1; i <= testCases; i++) { int numGooglers = scanner.nextInt(); int numSurprising = scanner.nextInt(); int bestResultThreshold = scanner.nextInt(); int[] googlers = new int[numGooglers]; for (int j = 0; j < numGooglers; j++) { googlers[j] = scanner.nextInt(); } int passingGooglers = dancingWithTheGooglers(numGooglers, numSurprising, bestResultThreshold, googlers); System.out.println(String.format("Case #%d: %d", i, passingGooglers)); } } catch (FileNotFoundException e) { e.printStackTrace(); } } private static int dancingWithTheGooglers(int numGooglers, int numSurprising, int bestResultThreshold, int[] googlers) { int passingGooglers = 0; for (int i = 0; i < numGooglers; i++) { if (googlers[i] / 3.0 > bestResultThreshold - 1) { // in the case of say, [30,29,28,27,26,25], they can all meet // a threshold of 9 without being 'surprising' passingGooglers++; } else if (numSurprising > 0 && bestResultThreshold > 1 && googlers[i] >= ((bestResultThreshold - 1) * 3) - 1) { // boundary cases are when the threshold is 1 or less - in that // case, any non zero score would work here. passingGooglers++; numSurprising--; } } return passingGooglers; } }
0
680
A12852
A12030
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.prototype; import java.io.File; import java.io.IOException; import java.util.Arrays; import jp.funnything.competition.util.CompetitionIO; import jp.funnything.competition.util.Packer; import org.apache.commons.io.FileUtils; public class Runner { public static void main( final String[] args ) throws Exception { new Runner().run(); } void pack() { try { final File dist = new File( "dist" ); if ( dist.exists() ) { FileUtils.deleteQuietly( dist ); } final File workspace = new File( dist , "workspace" ); FileUtils.copyDirectory( new File( "src/main/java" ) , workspace ); FileUtils.copyDirectory( new File( "../../../../CompetitionUtil/Lib/src/main/java" ) , workspace ); Packer.pack( workspace , new File( dist , "sources.zip" ) ); } catch ( final IOException e ) { throw new RuntimeException( e ); } } void run() throws Exception { final CompetitionIO io = new CompetitionIO(); final int t = io.readInt(); for ( int index = 0 ; index < t ; index++ ) { final int[] values = io.readInts(); final int n = values[ 0 ]; final int s = values[ 1 ]; final int p = values[ 2 ]; final int[] ts = Arrays.copyOfRange( values , 3 , values.length ); if ( n != ts.length ) { throw new RuntimeException( "assert" ); } io.write( index + 1 , solve( s , p , ts ) ); } io.close(); pack(); } int solve( final int s , final int p , final int[] ts ) { int count = 0; int consumed = 0; for ( final int sum : ts ) { // if not surprising int max = sum % 3 == 0 ? sum / 3 : sum / 3 + 1; if ( max >= p ) { count++; continue; } if ( consumed < s && sum > 1 ) { // if surprising max = sum % 3 == 2 ? sum / 3 + 2 : sum / 3 + 1; if ( max >= p ) { consumed++; count++; } } } return count; } }
0
681
A12852
A10922
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qualification; import java.io.IOException; import java.util.HashMap; import java.util.Map; import codejam.Task; public class B extends Task { private int t; private String[][] testCases; private String[] resultset; public B(String[] args) { super(args); } public static void main(String[] args) throws IOException { Task taskB = new B(args); taskB.execute(); } protected void catchInputData() throws IOException { t = Integer.parseInt(readLine()); testCases = new String[t][]; // iterates over cases for (int c = 0; c < t; c++) { testCases[c] = readLine().split(" "); } } protected void processInputData() { resultset = new String[t]; // iterates over cases for (int c = 0; c < t; c++) { String[] testCase = testCases[c]; int n = Integer.valueOf(testCase[0]); int s = Integer.valueOf(testCase[1]); int p = Integer.valueOf(testCase[2]); int y = 0; for (int i = 3; i < 3 + n; i++) { int t = Integer.valueOf(testCase[i]); if (Math.ceil((float) t / 3) >= p) { y++; } else if (s > 0 && t > 1 && (Math.round((float) t / 3) + 1) >= p) { y++; s--; } } resultset[c] = ""+y; } } protected void generateOutputFile() throws IOException { // iterates over cases for (int c = 0; c < t; c++) { writeLine("Case #" + (c + 1) + ": " + resultset[c]); } } }
0
682
A12852
A12251
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 year2012.qualification.b; import java.io.File; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.Scanner; public class DancingWithTheGooglers { public static void main(String[] args) throws Exception{ //GCJ共通 String filename = "src/year2012/qualification/b/B-small-attempt5"; PrintWriter out = new PrintWriter(new File(filename + ".out")); Scanner scan = new Scanner(new File(filename + ".in")); final int T = scan.nextInt(); for(int i=0;i<T;i++){ int N = scan.nextInt(); int S = scan.nextInt(); int p = scan.nextInt(); int[] t = new int[N]; int ans = 0; for(int j=0;j<N;j++){ t[j] = scan.nextInt(); } //surprisingの候補 List<Integer> probableSurprising = new ArrayList<Integer>(); //30と29と28は例外 for(int j=0;j<N;j++){ if(t[j] == 30 || t[j] == 29 || t[j] == 28){ ans++; }else if(t[j] == 0){ if(p==0) ans++; }else if(t[j] == 1){ if(p==1) ans++; }else{ if((int) Math.ceil((double)t[j] / 3.0) < p){ probableSurprising.add(t[j]); }else{ ans++; } } } //「surprisingかもしれない数」を見てゆく。 Collections.sort(probableSurprising, new Comparator<Integer>(){ public int compare(Integer t1, Integer t2) { return t2 - t1; } }); for(int j=0;j<probableSurprising.size();j++){ int best=-1; //最初のS個はsurprising if(j<S){ int mod =probableSurprising.get(j) %3; if(mod == 1){ best = (probableSurprising.get(j) + 2) / 3; }else if(mod == 2){ best = (probableSurprising.get(j) + 4) / 3; }else if(mod == 0){ best = (probableSurprising.get(j) + 3) / 3; } }else{ //surprisingではない数。3で割って切り上げればbestの点が出る best =(int) Math.ceil((double)probableSurprising.get(j) / 3.0); } if(best >= p){ ans++; } } System.out.println("Case #"+(i+1)+": "+ ans); out.printf("Case #%d: %s\n", i+1, ans); } out.flush(); } }
0
683
A12852
A10629
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package br.com.app; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.util.Scanner; public class DancingWithTheGooglers { private static Scanner scan = new Scanner(System.in); private static String[] entrada; private static int[] possiveisValoresExtra; private static int pontuacao, totEntradas, totSituacoes, totCompetidores, valorMinimo, totPossiveisValoresExtra, totValores, resto, resultado, totSituacoesMontadas, totCasos; private static StringBuilder temp = new StringBuilder(); private static StringBuilder saida = new StringBuilder(); private static File arquivoEntrada = new File("/home/emanuel/input.txt"); private static File arquivoSaida = new File("/home/emanuel/output.txt"); private static BufferedReader leitura; private static FileOutputStream fos; private static String linha; public static void main(String[] args) { try { leitura = new BufferedReader(new FileReader(arquivoEntrada)); linha = leitura.readLine(); totEntradas = Integer.parseInt(linha); totCasos = 1; for (int i = 0; i < totEntradas; i++) { linha = leitura.readLine(); entrada = linha.split(" "); totCompetidores = Integer.parseInt(entrada[0]); totSituacoes = Integer.parseInt(entrada[1]); valorMinimo = Integer.parseInt(entrada[2]); totPossiveisValoresExtra = 0; totValores = 0; possiveisValoresExtra = new int[totCompetidores]; for (int j = 3; j < entrada.length; j++) { pontuacao = Integer.parseInt(entrada[j]); if (pontuacao == 0) { if (valorMinimo == 0) { totValores++; } continue; } resto = pontuacao % 3; resultado = (pontuacao / 3); switch (resto) { case 2: if ((resultado + 1) >= valorMinimo) { totValores++; break; } possiveisValoresExtra[totPossiveisValoresExtra++] = pontuacao; break; case 1: if ((resultado + 1) >= valorMinimo) { totValores++; } break; default: if (resultado >= valorMinimo) { totValores++; } else { possiveisValoresExtra[totPossiveisValoresExtra++] = pontuacao; } break; } } totSituacoesMontadas = 0; for (int j = 0; j < totPossiveisValoresExtra && totSituacoesMontadas < totSituacoes; j++) { pontuacao = possiveisValoresExtra[j]; resto = pontuacao % 3; resultado = (pontuacao / 3); if (resto == 2) { if ((resultado + 2) >= valorMinimo) { totSituacoesMontadas++; totValores++; } } else { if ((resultado + 1) >= valorMinimo) { totSituacoesMontadas++; totValores++; } } } saida.append("Case #").append(totCasos++).append(": ").append(totValores).append("\n"); } fos = new FileOutputStream(arquivoSaida); fos.write(saida.toString().getBytes()); fos.close(); } catch (Exception e) { System.out.println(e.getMessage()); } } }
0
684
A12852
A11855
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Dancers { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int times = sc.nextInt(); for (int c = 1; c <= times; c++) { int players = sc.nextInt(); int surprises = sc.nextInt(); int best = sc.nextInt(); int count = 0; int[] scores = new int[] { 0, 0, 0 }; for (int i = 0; i < players; i++) { int score = sc.nextInt(); scores[0] = scores[1] = scores[2] = score / 3; if (score / 3 >= best) { count++; } else { int difference = score - scores[0]*3; switch (difference) { case 0: { if (surprises > 0) { if (scores[0] > 0 && scores[0] + 1 >= best) { count++; surprises--; } } break; } case 1: { if (scores[0] + 1 >= best) { count++; } else if (surprises > 0) { if (scores[0] + 1 >= best) { count++; surprises--; } } break; } case 2: { if (scores[0] + 1 >= best) { count++; } else if (surprises > 0) { if (scores[0] + 2 >= best) { count++; surprises--; } } break; } default: break; } } } System.out.println("Case #"+c+": "+count); } } }
0
685
A12852
A12662
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileNotFoundException; import java.io.FileReader; import java.util.Iterator; import java.util.Scanner; public class DancingWithGooglers { public static class Scores { public final int S; public final int p; public final int[] t; public Scores(int S, int p, int[] t) { this.S = S; this.p = p; this.t = t; } } public static Iterator<Scores> iterator(Readable input) { final Scanner scanner = new Scanner(input); return new Iterator<Scores>() { private int cases = scanner.nextInt(); @Override public boolean hasNext() { return cases > 0; } @Override public Scores next() { int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int[] t = new int[N]; for (int i = 0; i < N; i++) { t[i] = scanner.nextInt(); } cases--; return new Scores(S, p, t); } @Override public void remove() { throw new AbstractMethodError(); } }; } public static int maxTuples(Scores scores) { int tuples = 0; int s = scores.S; for (int i : scores.t) { int[] tuple = tuplesWithMax(i, scores.p); if (tuple.length == 3) { if (tuple[0] - tuple[2] == 2 && s > 0) { tuples++; s--; } else if (tuple[0] - tuple[2] <= 1) { tuples++; } } } return tuples; } public static int[][] tuples(int total) { if (total == 0) { return new int[][]{{0, 0, 0}}; } if (total == 30) { return new int[][]{{10, 10, 10}}; } int max = total / 3; if (total % 3 == 0) { return new int[][]{{max, max, max}, {max + 1, max, max - 1}}; } if (total % 3 == 1) { return new int[][]{{max + 1, max, max}, {max + 1, max + 1, max - 1}}; } if (max < 9) { return new int[][]{{max + 1, max + 1, max}, {max + 2, max, max}}; } return new int[][]{{max + 1, max + 1, max}}; } public static int[] tuplesWithMax(int t, int max) { for (int[] tuple : tuples(t)) { if (tuple[0] >= max) return tuple; } return new int[]{}; } public static void main(String[] args) throws FileNotFoundException { FileReader fileReader = new FileReader(args[0]); int caseId = 1; Iterator<Scores> iterator = iterator(fileReader); while (iterator.hasNext()) { int result = maxTuples(iterator.next()); System.out.format("Case #%s: %s\n", caseId, result); caseId++; } } }
0
686
A12852
A13222
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.first; public class BDancingWiththeGooglers { ReadWriteFileForCodeJam flatFile; public BDancingWiththeGooglers() { flatFile = new ReadWriteFileForCodeJam(); initializeFlatFileParameters(); performSolution(); finalizeSolutionFileToSend(); } private void performSolution(){ String[] items; int noDancers, noOfSurprises, bestScore; int maxGooglers; int maxAchieved; boolean surprise; for(int i=1; i<=Integer.parseInt(flatFile.GetSingleLineFromFile(1)); i++){ maxGooglers = 0; surprise = true; items = flatFile.GetSingleLineFromFile(i + 1).split(" "); noDancers = Integer.parseInt(items[0]); noOfSurprises = Integer.parseInt(items[1]); bestScore = Integer.parseInt(items[2]); flatFile.setFileContentToWrite("Case #" + i + ":", true, true); for(int j=0; j<noDancers; j++){ if ((noOfSurprises <= 0) && surprise) surprise = false; maxAchieved = isBestScorePossible(Integer.parseInt(items[j+3]), bestScore); switch (maxAchieved){ case 0: break; case 1: maxGooglers++; break; case 2: if (surprise){ maxGooglers++; noOfSurprises--; } break; } } flatFile.setFileContentToWrite(String.valueOf(maxGooglers), true, false); } } private int isBestScorePossible(int total, int least){ /* return 0 if not possible * 1 if possible without surprise * 2 if possible with surprise */ if (total == 0){ if (least == 0) return 1; else return 0; } if (total == 1){ if ((least <= 1)) return 1; else return 0; } if (least * 3 - 2 <= total) return 1; if (least * 3 - 4 <= total) return 2; return 0; } private void initializeFlatFileParameters() { flatFile.setFileNameForRead("C:\\Users\\i067221\\Downloads\\B-small-attempt0.in"); flatFile.setFileNameForWrite("C:\\Users\\i067221\\Downloads\\Upload\\B-small-attempt0.txt"); flatFile.setFileSeperatorForWrite(" "); System.out.println("File read, (" + flatFile.ReadFile(false) + ") returned."); } private void finalizeSolutionFileToSend() { System.out.println("Successful write to file performed: " + flatFile.WriteFile(false)); } }
0
687
A12852
A12040
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.File; import java.math.BigDecimal; import java.math.BigInteger; import org.apache.commons.io.FileUtils; public class CompetitionIO { private final QuestionReader _reader; private final AnswerWriter _writer; /** * Default constructor. Use latest "*.in" as input */ public CompetitionIO() { this( null , null , null ); } public CompetitionIO( final File input , final File output ) { this( input , output , null ); } public CompetitionIO( File input , File output , final String format ) { if ( input == null ) { for ( final File file : FileUtils.listFiles( new File( "." ) , new String[] { "in" } , false ) ) { if ( input == null || file.lastModified() > input.lastModified() ) { input = file; } } if ( input == null ) { throw new RuntimeException( "No *.in found" ); } } if ( output == null ) { final String inPath = input.getPath(); if ( !inPath.endsWith( ".in" ) ) { throw new IllegalArgumentException(); } output = new File( inPath.replaceFirst( ".in$" , ".out" ) ); } _reader = new QuestionReader( input ); _writer = new AnswerWriter( output , format ); } public CompetitionIO( final String format ) { this( null , null , format ); } public void close() { _reader.close(); _writer.close(); } public String read() { return _reader.read(); } public BigDecimal[] readBigDecimals() { return _reader.readBigDecimals(); } public BigDecimal[] readBigDecimals( final String separator ) { return _reader.readBigDecimals( separator ); } public BigInteger[] readBigInts() { return _reader.readBigInts(); } public BigInteger[] readBigInts( final String separator ) { return _reader.readBigInts( separator ); } /** * Read line as single integer */ public int readInt() { return _reader.readInt(); } /** * Read line as multiple integer, separated by space */ public int[] readInts() { return _reader.readInts(); } /** * Read line as multiple integer, separated by 'separator' */ public int[] readInts( final String separator ) { return _reader.readInts( separator ); } /** * Read line as single integer */ public long readLong() { return _reader.readLong(); } /** * Read line as multiple integer, separated by space */ public long[] readLongs() { return _reader.readLongs(); } /** * Read line as multiple integer, separated by 'separator' */ public long[] readLongs( final String separator ) { return _reader.readLongs( separator ); } /** * Read line as token list, separated by space */ public String[] readTokens() { return _reader.readTokens(); } /** * Read line as token list, separated by 'separator' */ public String[] readTokens( final String separator ) { return _reader.readTokens( separator ); } public void write( final int questionNumber , final Object result ) { _writer.write( questionNumber , result ); } public void write( final int questionNumber , final String result ) { _writer.write( questionNumber , result ); } public void write( final int questionNumber , final String result , final boolean tee ) { _writer.write( questionNumber , result , tee ); } }
0
688
A12852
A11936
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Saifuddin Merchant * */ package com.sam.googlecodejam.helper; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class InputReader { BufferedReader iFileBuffer; long iCurrentLineNumber; public InputReader(String pFileName) { try { iFileBuffer = new BufferedReader(new FileReader(pFileName)); } catch (FileNotFoundException e) { e.printStackTrace(); } iCurrentLineNumber = 0; } public String readNextLine() { try { return iFileBuffer.readLine(); } catch (IOException e) { e.printStackTrace(); } return null; } public void close() { try { iFileBuffer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
689
A12852
A11663
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 ProblemB { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int tt = 1; tt <= t; tt++) { int n = sc.nextInt(); int s = sc.nextInt(); int p = sc.nextInt(); int v[] = new int[n]; for (int i = 0; i < n; i++) { v[i] = sc.nextInt(); } int c = 0; int vx[][] = new int[n][3]; for (int i = 0; i < n; i++) { int x[] = new int[3]; x[0] = x[1] = x[2] = v[i] / 3; if (v[i] != x[0] + x[1] + x[2]) { x[2]++; } if (v[i] != x[0] + x[1] + x[2]) { x[1]++; } vx[i] = x; } for (int i = 0; i < n; i++) { if (vx[i][0] >= p || vx[i][1] >= p || vx[i][2] >= p) { c++; } else { if (v[i] >= 2 && v[i] <= 28 && s != 0) { if (vx[i][1] == vx[i][2]) { vx[i][1]--; vx[i][2]++; if (vx[i][0] >= p || vx[i][1] >= p || vx[i][2] >= p && (vx[i][0] >= 0 && vx[i][1] >= 0 && vx[i][2] >= 0)) { c++; s--; } } else if (vx[i][0] == vx[i][1]) { vx[i][0]--; vx[i][1]++; if (vx[i][0] >= p || vx[i][1] >= p || vx[i][2] >= p && (vx[i][0] >= 0 && vx[i][1] >= 0 && vx[i][2] >= 0)) { c++; s--; } } } } // System.out.println(p + " " + c + " " + v[i] + " " + vx[i][0] + " " + vx[i][1] + " " + vx[i][2]); } System.out.println("Case #" + tt + ": " + c); } } } //WA
0
690
A12852
A12152
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class _2012_QR_ProblemB { public static void main(String[] args){ try { BufferedReader in = new BufferedReader(new FileReader("C://B-small-attempt3.in")); BufferedWriter out = new BufferedWriter(new FileWriter("C://B-small-attempt3.out")); int numberOfTests = Integer.parseInt(in.readLine()); for (int i = 0; i < numberOfTests; i++) { StringTokenizer st = new StringTokenizer(in.readLine()); int N = Integer.parseInt(st.nextToken()); int S = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int alto = (p-1)*3 + 1; int baixo = (p != 1) ? (p-1)*3 - 1 : 1; int quant = 0; int poss = 0; for (int j = 0; j < N; j++) { int nota = Integer.parseInt(st.nextToken()); if (nota >= alto){ quant++; }else{ if (nota >= baixo){ poss++; } } } quant += (poss > S) ? S : poss; out.append("Case #" + (i+1) +": " + quant); if (i + 1 < numberOfTests){ out.newLine(); } } out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NumberFormatException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
691
A12852
A11315
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class DancingWithTheGooglers { public static void main(String[] args) { FileReader fin; try { fin = new FileReader( new File( "C:\\Users\\Subir Kumar Sao\\Desktop\\Sample\\A-small-attempt0.in")); FileWriter fr = new FileWriter( new File( "C:\\Users\\Subir Kumar Sao\\Desktop\\Sample\\A-Small-out.txt")); BufferedReader br = new BufferedReader(fin); String line = br.readLine(); int N = Integer.parseInt(line); for (int i = 0; i < N; i++) { line = br.readLine(); String[] nums = line.split(" "); int T = Integer.parseInt(nums[0]); int S = Integer.parseInt(nums[1]); int P = Integer.parseInt(nums[2]); List<Integer> numArray = new ArrayList<Integer>(); for(int j=0;j<T;j++){ numArray.add(Integer.parseInt(nums[3+j])); } Collections.sort(numArray); Collections.reverse(numArray); int count=0; for(int num :numArray){ if(num==0 && P>0) continue; if((num/3)>=P){ count++; } else if(((num%3)>=1) && (((num/3)+1) >= P)){ count++; } else if(S>0){ if((num%3==0) || (num%3==2)){ if(((num/3)+2)>=P){ S--; count++; } } } } fr.write("Case #"+(i+1)+": "+count+"\r\n"); } fr.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
692
A12852
A11631
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.*; public class Bsmall { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("./src/qualification/B-small-attempt1.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("./src/qualification/B-small-attempt1.out")); int[][] inputs = new int[100][103]; int casenumber = 0; String input = null; int total = 0; while((input=br.readLine()) != null) { if(casenumber==0) { total = Integer.parseInt(input); }else{ String[] array = input.split(" "); // N inputs[casenumber-1][0] = Integer.parseInt(array[0]); // S inputs[casenumber-1][1] = Integer.parseInt(array[1]); // p inputs[casenumber-1][2] = Integer.parseInt(array[2]); // N integers ti. for(int i=3;i<array.length;i++) { inputs[casenumber-1][i] = Integer.parseInt(array[i]); } } casenumber++; } casenumber=1; while(casenumber <= total) { //System.out.println("Case #" + casenumber + ": " + String.valueOf(surprisingTriplets(inputs[casenumber-1], bw))); bw.write("Case #" + casenumber + ": " + String.valueOf(surprisingTriplets(inputs[casenumber-1], bw))); bw.newLine(); casenumber++; } bw.close(); } public static int surprisingTriplets(int[] inputs, BufferedWriter bw) throws IOException { int n = inputs[0]; int s = inputs[1]; int p = inputs[2]; int sum=0; int count=0; int used=0; int i = 0; while(i<n) { sum=inputs[i+3]; if(sum==0 && p==0){ count++; }else if(sum!=0){ int[] triplets = new int[3]; triplets[0]=sum/3; triplets[1]=sum/3; triplets[2]=sum/3; if(triplets[0]>=p) { count++; }else if(sum%3==2) { if(triplets[0]==(p-2) && (s-used>0)) { triplets[0]+=2; used++; count++; }else{ triplets[0]++; triplets[1]++; if(triplets[0]>=p) { count++; } } }else if(sum%3==1) { triplets[0]++; if(triplets[0]>=p) { count++; } }else if(sum%3==0) { if(s-used>0 && triplets[0]==p-1) { triplets[0]++; triplets[2]--; used++; count++; } } } i++; } return count; } }
0
693
A12852
A11475
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.IOException; import java.nio.charset.Charset; import java.nio.file.Files; //DancingGooglers.java //Completes the Dancing with Googlers problem for Google Code Jam 2012 //By Jack Thakar //Coded in Java using Eclipse 3.7 public class DancingGooglers { public static void main(String[] args){ String input = readFile("B-small-attempt0.in"); String[] lines = input.split(System.lineSeparator()); String output = ""; for(int i=1;i<lines.length;i++){ String line = lines[i]; Case c = (new DancingGooglers()).new Case(line); output+="Case #"+i+": "; output+=c.getSolution(); if(i<lines.length-1) output+=System.lineSeparator(); } writeFile("B-small-attempt0.out",output); } class Case{ int dancers; int surprising; int required; int[] scores; public Case(String data){ String[] splits = data.split(" "); int[] datas = new int[splits.length]; for(int i=0;i<splits.length;i++){ datas[i] = Integer.parseInt(splits[i]); } dancers = datas[0]; surprising = datas[1]; required = datas[2]; scores = new int[dancers]; for(int i=0;i<scores.length;i++){ scores[i] = datas[i+3]; } } public int getSolution(){ int possible = 0; int surprised = surprising; for(int score:scores){ int result = getBestResult(score); if(result==2){ possible++; }else if(result==1&&surprised>0){ possible++; surprised--; } } return possible; } //0 - Not possible, 1 - Suprising, 2 - Not suprising public int getBestResult(int score){ int dividend = score/3; int remainder = score%3; if(dividend>=required) return 2; if(dividend+1>=required&&(remainder>=1)) return 2; if(dividend+2>=required&&(remainder>=2)) return 1; if(dividend+1>=required&&dividend>0) return 1; return 0; } } private static String readFile(String name){ File file = new File("input"+File.separator+name); Charset charset = Charset.forName("ASCII"); String text = ""; try (BufferedReader reader = Files.newBufferedReader(file.toPath(), charset)) { String line = null; while ((line = reader.readLine()) != null) { text+=line+System.lineSeparator(); } } catch (IOException e) { } return text; } private static void writeFile(String name, String data){ File file = new File("output"+File.separator+name); Charset charset = Charset.forName("ASCII"); try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), charset)) { writer.write(data, 0, data.length()); } catch (IOException e) { } } }
0
694
A12852
A11307
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 qualb; import java.util.Scanner; /** * * @author marcin */ public class QualB { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = Integer.parseInt(in.nextLine()); for (int ci = 1; ci <= T; ++ci) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int certains = 0; int possibles = 0; for (int i = 0; i < N; ++i) { int total = in.nextInt(); int temp = total - (3 * p); if (temp >= 0) { ++certains; } else { if ((p - 1 >= 0) && (temp >= -2)) { ++certains; } else if ((p - 2 >= 0) && (temp >= -4)) { ++possibles; } } } int optional = S > possibles ? possibles : S; int answer = certains + optional; System.out.println("Case #" + ci + ": " + answer); } } }
0
695
A12852
A10468
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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; public class Dancing { public static void main(String args[]) throws NumberFormatException, IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(in.readLine()); int t = 0; String str = ""; String regex = " "; String[] split; String[] result = new String[T+1]; int N = 0; int S = 0; int p = 0; for(int x = 1; x <= T; x++){ str = in.readLine(); split = str.split(regex); N = Integer.parseInt(split[0]); S = Integer.parseInt(split[1]); p = Integer.parseInt(split[2]); for(int y = 3; y < (3 + N); y++ ) { if(bestScore(N, S, p, Integer.parseInt(split[y])) == 1) { t++; } if(bestScore(N, S, p, Integer.parseInt(split[y])) == 2) { S--; t++; } } result[x] = "Case #" + x + ": " + t; t=0; } for(int u = 1; u <= T; u++){ System.out.println(result[u]); } } public static int bestScore (int N, int S, int p, int t){ int work = 0; int temp = t; int score; int special = 2; if(S != 0){ for(score = 10; score > 0; score--){ if(t - score >= (score - special)*(2) && (t-score > 0)) { temp = score; score = -1; } } if(temp >= p) { work = 2; } } temp = t; special = 1; for(score = 10; score >= 0; score--){ if(t - score >= (score - special)*(2) && (t-score > 0)) { temp = score; score = -1; } } if(temp >= p) { work = 1; } return work; } }
0
696
A12852
A12733
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); for(int t=1; t<=T; t++){ int N=sc.nextInt(); int S=sc.nextInt(); int P=sc.nextInt(); int P1 = P-1<0 ? 0 : P-1; int P2 = P-2<0 ? 0 : P-2; int[] sum = new int[N]; for(int i=0; i<N; i++) sum[i] = sc.nextInt(); int out = 0; for(int i=0; i<N; i++) if(sum[i] >= 2*P1+P) { out++; sum[i] = -1; } for(int i=0; i<N && S>0; i++) if(sum[i] >= 2*P2+P){ S--; sum[i] = -1; out++; } System.out.println("Case #"+t+": "+out); } } }
0
697
A12852
A12596
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.*; public class DancingWithGooglers { public static void main(String[] args) throws IOException { BufferedReader inp = new BufferedReader(new InputStreamReader(System.in)); int noOfTestCases = Integer.parseInt(inp.readLine()); StringTokenizer str; int noOfGooglers; int noOfSurprises; int bandWidth; int currScore; ArrayList<Integer> results = new ArrayList<Integer>(); for(int i=0;i<noOfTestCases;i++) { int num = 0; str = new StringTokenizer(inp.readLine()); noOfGooglers = Integer.parseInt(str.nextToken()); noOfSurprises = Integer.parseInt(str.nextToken()); bandWidth = Integer.parseInt(str.nextToken()); if(bandWidth == 0) { results.add(noOfGooglers); continue; } for(int j=0;j<noOfGooglers;j++) { currScore = Integer.parseInt(str.nextToken()); if(currScore > (bandWidth - 1)*3) { num++; continue; } if(bandWidth == 1) continue; if(noOfSurprises > 0 && currScore > ((bandWidth - 2)*3 + 1)) { num++; noOfSurprises--; } } results.add(num); } ListIterator<Integer> itr = results.listIterator(); int i=1; while(itr.hasNext()) { System.out.println("Case #" + i + ": " + itr.next()); i++; } } }
0
698
A12852
A13073
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.vp.common; public class CommonUtility { public static int[] convertStringArraytoIntArray(String[] sarray) { if (sarray != null) { int intarray[] = new int[sarray.length]; for (int i = 0; i < sarray.length; i++) { intarray[i] = Integer.parseInt(sarray[i]); } return intarray; } return null; } public static float[] convertStringArraytoFloatArray(String[] sarray) { if (sarray != null) { float floatArray[] = new float[sarray.length]; for (int i = 0; i < sarray.length; i++) { floatArray[i] = Float.parseFloat(sarray[i]); } return floatArray; } return null; } public static double[] convertStringArraytoDoubleArray(String[] sarray) { if (sarray != null) { double darray[] = new double[sarray.length]; for (int i = 0; i < sarray.length; i++) { darray[i] = Double.parseDouble(sarray[i]); } return darray; } return null; } public static long[] convertStringArraytoLongArray(String[] sarray) { if (sarray != null) { long longarray[] = new long[sarray.length]; for (int i = 0; i < sarray.length; i++) { longarray[i] = Long.parseLong(sarray[i]); } return longarray; } return null; } public static void print(int a[]) { System.out.print("[ "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.print(" ]"); System.out.println(""); } public static void printWithoutExtrLine(int a[]) { System.out.print("[ "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.print(" ]"); } public static void print(float a[]) { System.out.print("[ "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.print(" ]"); System.out.println(""); } public static void print(double a[]) { System.out.print("[ "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.print(" ]"); System.out.println(""); } public static void print(long a[]) { System.out.print("[ "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.print(" ]"); System.out.println(""); } public static void print(String a[]) { System.out.print("[ "); for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.print(" ]"); System.out.println(""); } }
0
699