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
A12399
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 googlers; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; /** * * @author Floran */ public class Googlers { int nbCase; static String inName; static String outName; public final char h=(char) 104; public static void solve() throws IOException{ PrintWriter out=new PrintWriter(new BufferedWriter(new FileWriter(outName))); //Scanner in=new Scanner("A-small-practice.txt"); BufferedReader in=new BufferedReader(new FileReader(inName)); String ligne=in.readLine(); // nb de cas System.out.println(ligne); int nbCase=Integer.parseInt(ligne); //compte int count=0; for(int i=1;i<=nbCase;i++){ int ns=0;//nb suprise count=0; String[] parametre=in.readLine().split(" "); System.out.println("lenght"+parametre.length); int nb=Integer.parseInt(parametre[0]);//nb de participant System.out.println("nb"+nb); int suprise=Integer.parseInt(parametre[1]);//nb de triplet surprise System.out.println("sup"+suprise); int min=Integer.parseInt(parametre[2]);//un quote du triplet doit être >=min for(int m=3;m<nb+3;m++){ //int[][] tab=decomposition(Integer.parseInt(parametre[i])); int[] tab=decomp(Integer.parseInt(parametre[m])); if(tab.length==1){ //if(tab[0][2]>=min) if(tab[0]>=min) count++; } else{ //if(tab[0][2]>=min) if(tab[0]>=min) count++; //else if(tab[0][2]>=min &&ns<=suprise){ else if(tab[1]>=min && ns<suprise){ ns++; count++; } } } out.println("Case #"+i+": "+count); } out.flush(); out.close(); in.close(); } /* public static int[][] decomposition(int quote){ int mod=quote%3; int div=quote/3; int[][] tab; if(mod==1){ tab=new int[1][3]; tab[0][0]=div; tab[0][1]=div; tab[0][2]=div+1; return tab; } if(mod==2){ tab=new int[2][3]; tab[0][0]=div; tab[0][1]=div+1; tab[0][2]=div+1; tab[1][0]=div; tab[1][1]=div; tab[1][2]=div+2; return tab; } else{ tab=new int[2][3]; tab[0][0]=div; tab[0][1]=div; tab[0][2]=div; tab[1][0]=div; tab[1][1]=div-1; tab[1][2]=div+1; return tab; } }*/ public static int[] decomp(int quote){ int mod=quote%3; int div=quote/3; int[] tab; if(mod==1){ tab=new int[1]; tab[0]=div+mod; return tab; } if(mod==2){ tab=new int[2]; tab[0]=div+(mod/2); tab[1]=div+mod; return tab; } else{ tab=new int[2]; tab[0]=div; if(quote==0) tab[1]=div; else tab[1]=div+1; return tab; } } /** * @param args the command line arguments */ public static void main(String[] args) { //inName="A-small-practice.txt"; //inName="test.txt"; //outName="solution7.txt"; inName="B-small-attempt4.in"; outName="solution_small4.txt"; //inName="A-large-practice.in"; //outName="Large_solution.txt"; try{ solve(); } catch(IOException e){ System.out.println(e.getMessage()); } System.out.println("fini"); } }
0
700
A12852
A11657
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package uk.co.epii.codejam.dancingwiththegooglers; import uk.co.epii.codejam.common.AbstractMain; /** * * @author jim */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { AbstractMain.main(args, new DancingWithTheGooglersProcessor()); } }
0
701
A12852
A11312
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; public class B { public static void main(String[] args) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); int T; T = Integer.parseInt(reader.readLine()); for (int i = 1; i <= T; i++) { String[] input = reader.readLine().split(" "); int result = 0; int N = Integer.parseInt(input[0]); int S = Integer.parseInt(input[1]); int p = Integer.parseInt(input[2]); for (int j = 3; j < input.length; j++) { int score = Integer.parseInt(input[j]); int temp = score/3; if(score % 3 ==0){ if(temp>=p){ ++result; } else if (temp+1>=p && S>0 && temp>=1){ ++result; --S; } } else if(score % 3 ==1){ if (temp+1>=p){ ++result; } } else { if (temp+1>=p){ ++result; } else if(temp+2>=p && S>0){ ++result; --S; } } } if (i < T) { System.out.println("Case #" + i + ": " + result); } else { System.out.print("Case #" + i + ": " + result); } } } }
0
702
A12852
A10682
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/** * */ package google.exercise.b; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Scanner; /** * @author tomtom * */ public class B { private static Scanner in; private static PrintWriter out; private static int nbCase; private static class Solver { private int currentNbMax; private int currentNbMin; private int treshold; private int nbGooglers; private List<Integer> scores; private int nbSurprise; public void solve() { for (int i = 1; i <= nbCase; i++) { out.printf("Case #%d: %s%n", i, doSolve()); in.nextLine(); } } private int doSolve() { int nbGoodScorer = 0; scores = new ArrayList<Integer>(); nbGooglers = in.nextInt(); nbSurprise = in.nextInt(); treshold = in.nextInt(); currentNbMax = treshold * 3 - 2; currentNbMin = ((treshold - 2) < 0 ? 0 : treshold - 2) * 2 + treshold; for (int i = 0; i < nbGooglers; i++) { scores.add(in.nextInt()); } Collections.sort(scores); Collections.reverse(scores); for (Integer score : scores) { if (score >= currentNbMax) { nbGoodScorer++; } else if (score < currentNbMax && score >= (currentNbMax - 2)) { if (nbSurprise > 0) { nbSurprise--; if (score >= treshold) { nbGoodScorer++; } } } } return nbGoodScorer; } } /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { in = new Scanner( new File("/Users/tomtom/Desktop/jam-2012/input-B/B.in")); out = new PrintWriter(new FileOutputStream( "/Users/tomtom/Desktop/jam-2012/input-B/B.out")); nbCase = in.nextInt(); in.nextLine(); new Solver().solve(); in.close(); out.close(); } }
0
703
A12852
A10987
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 ch.socaciu.andrei.codejam; import java.io.*; import java.util.ArrayList; import java.util.List; /** * @author Andrei Socaciu */ public class Dancing { public static void main(String[] args) throws Exception { String in = "data/Dancing-small-attempt0.in.txt"; String out = "data/Dancing-small-attempt0.out.txt"; String line = null; BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(in))); List<String> lines = new ArrayList<String>(); while ((line = reader.readLine()) != null) { lines.add(line); } reader.close(); int tests = Integer.parseInt(lines.get(0)); List<String> res = new ArrayList<String>(); int k = 1; for (int i = 1; i <= tests; i++) { line = lines.get(k++); String[] parts = line.split(" "); int n = Integer.parseInt(parts[0]); int[] scores = new int[n]; int s = Integer.parseInt(parts[1]); int p = Integer.parseInt(parts[2]); for (int j = 0; j < n; j++) { scores[j] = Integer.parseInt(parts[3+j]); } int result = solve(scores, s, p); res.add("Case #" + i + ": " + result); } BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out))); for (String re : res) { writer.write(re); writer.write("\n"); } writer.close(); } private static int solve(int[] scores, int s, int p) { int count = 0; int special = s; for (int score : scores) { if (score / 3 >= p) { //avg. larger than p, at least one score will be >= p count++; } else if (score == 3*p - 1 || score == 3*p - 2) { //these are covered by the not-special cases count++; } else if (special > 0) { //try to see if a special case matches if (score % 3 == 0) { //s-1,s,s+1 if (score / 3 + 1 >= p && score / 3 - 1 >= 0) { count++; special--; } } else if (score % 3 == 1) {//s,s,s-2 if ((score + 2) / 3 >= p) { count++; special--; } } else {//s,s,s+2 if ((score - 2) / 3 + 2 >= p) { count++; special--; } } } } return count; } }
0
704
A12852
A11345
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Round1; /* ID: kevinle7 LANG: JAVA TASK: dancing */ import java.io.*; import java.util.*; class dancing { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new FileReader("dancing.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("dancing.out"))); int t = Integer.parseInt(f.readLine()); for (int i = 0 ; i < t; i++) { StringTokenizer st = new StringTokenizer(f.readLine()); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int ans = 0; int poss = 0; int goodscore = 3*p - 2; int okayscore = 3*p - 4; if (p == 1) okayscore = 1; for (int j = 0; j < n; j++) { int score = Integer.parseInt(st.nextToken()); if (score >= goodscore) ans++; else if (score >= okayscore) poss++; } if (poss < s) ans += poss; else ans += s; out.println("Case #" + (i+1) + ": " + ans); } out.close(); System.exit(0); } }
0
705
A12852
A12748
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 slerig * */ import java.io.*; import java.util.*; public class ScoreChecker { /** * @param args * @throws FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException { File inFile = new File("B-small.in"); PrintWriter outFile = new PrintWriter("B-small.out"); Scanner in = new Scanner(inFile); int cases = in.nextInt(); for(int i = 1; i <= cases; i++) { int googlers = in.nextInt(); int surprising = in.nextInt(); int minScore = in.nextInt(); int googlersWithMin = 0; int[][] scores = new int[googlers][3]; // Determining individual scores from total scores; before // surprising scores are taken into account. for(int j = 0; j < googlers; j++) { float score = in.nextLong(); float ftemp = score / 3; int temp = (int)ftemp; if(ftemp - temp > 0.5) { scores[j][0] = temp + 1; scores[j][1] = temp + 1; scores[j][2] = temp; } else if(ftemp - temp > .25) { scores[j][0] = temp + 1; scores[j][1] = temp; scores[j][2] = temp; } else { for(int k = 0; k < 3; k++) { scores[j][k] = temp; } } } // Editing for surprising scores. for(int j = 0; j < googlers; j++) { // Very complicated way of deciding which scores are the surprising scores. if(surprising > 0 && scores[j][0] != 0 && scores[j][1] != 0 && scores[j][2] != 0) if(scores[j][0] != 10 && (scores[j][0] >= minScore-1 && scores[j][0] < minScore)) if((scores[j][0] == scores[j][1])) { scores[j][0]++; scores[j][1]--; surprising--; } } // Checking for googlers with min score. for(int j = 0; j < googlers; j++) { if(scores[j][0] >= minScore) googlersWithMin++; } outFile.println("Case #" + i + ": " + googlersWithMin); /* Debugging code outFile.println(); for(int j = 0; j < googlers; j++) { for(int k = 0; k < 3; k++) { outFile.print(scores[j][k] + " "); } outFile.println(); } */ } outFile.close(); } }
0
706
A12852
A11291
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.Scanner; public class ProblemB { public static void main(String[] args) { try (BufferedReader reader = new BufferedReader(new FileReader("B-small.in"))) { try (BufferedWriter writer = new BufferedWriter(new FileWriter("B-small.out"))) { String line = reader.readLine(); int numCases = Integer.parseInt(line); Scanner scanner; for(int caseIdx = 0; caseIdx < numCases; caseIdx++) { scanner = new Scanner(reader.readLine()); int N = scanner.nextInt(); // number of Googlers int S = scanner.nextInt(); // number of suprising triplets int p = scanner.nextInt(); // point limit - maximum number of Googlers who could have had the best result of p // System.out.println(String.format("Case #%d: N_%d S_%d p_%d", caseIdx+1, N, S, p)); int[] t = new int[N]; // total points of Googlers for(int idx = 0; idx < N; idx++) { t[idx] = scanner.nextInt(); } // not suprising : 0 1 29 30 // 2 - 0 0 2 | 3 - 0 1 2 | 4 - 0 2 2 // 5 - 1 1 3 | 6 - 1 2 3 | 7 - 1 3 3 // 8 - 2 2 4 | 9 - 2 3 4 | 10 - 2 4 4 // 11 - 3 3 5 | ... // suprising formula: s_max(x) - (x+1)/3+1 // 2 - 0 1 1 | 3 - 1 1 1 | 4 - 1 1 2 // 5 - 1 2 2 | 6 - 2 2 2 | 7 - 2 2 3 // 8 - 2 3 3 | 9 - 3 3 3 | 10 - 3 3 4 // 11 - 3 4 4 | 12 - 4 4 4 | ... // unsuprising formula: us_max(x) - (x-1)/3+1 int possibleNotSuprising = 0; int possibleSuprising = 0; for(int idx = 0; idx < N; idx++) { // int max; boolean suprising = false; int ti = t[idx]; int us_max = ti < 2 ? ti : Math.min(10, (ti - 1) / 3 + 1); if(us_max >= p) { possibleNotSuprising++; // max = us_max; } else { int s_max = ti < 2 ? ti : Math.min(10, (ti + 1) / 3 + 1); // max = s_max; suprising = true; if(s_max >= p) { if(ti < 2 || ti > 28) possibleNotSuprising++; else possibleSuprising++; } } // System.out.println(String.format("Case #%d: G_%d Total_%d Max_%d S?", caseIdx+1, idx+1, ti, max) + Boolean.toString(suprising)); } int result = possibleNotSuprising + Math.min(S, possibleSuprising); String caseOutput = String.format("Case #%d: %d", caseIdx + 1, result); System.out.println(caseOutput); writer.append(caseOutput); writer.newLine(); } } } catch(IOException ioEx) { ioEx.printStackTrace(); } } }
0
707
A12852
A12412
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * Program Name :- B.java * Author :- Happy Mittal * Created on 14 April, 2012 * * */ package googlecodejam11; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; import java.util.Arrays; public class B { /** Creates a new instance of B */ public B() { try{ // Open the input file FileInputStream finstream = new FileInputStream("E:\\B-small-attempt0.in"); // FileInputStream finstream = new FileInputStream("E:\\B-large-attempt0.in"); //FileInputStream finstream = new FileInputStream("E:\\test-input.in"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(finstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); // Create a output file FileWriter foutstream = new FileWriter("E:\\B-small-output.in"); // FileWriter foutstream = new FileWriter("E:\\B-small-output.in"); //FileWriter foutstream = new FileWriter("E:\\test-output.in"); BufferedWriter bw = new BufferedWriter(foutstream); br.readLine(); // read the first line it contains no of cases String strLine; int caseno = 1; //Read File Line By Line // strLine = br.readLine(); while ((strLine = br.readLine()) != null) { // Print the content on the console // System.out.println (strLine); strLine = strLine.trim(); int result = NoOFTriplets(strLine); //System.out.println (result); String netresult = "Case #" + caseno + ": " + result ; bw.write(netresult); bw.newLine(); caseno ++; } //Close the input stream in.close(); //Close the output stream bw.close(); }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } public static void main(String[] args) { // TODO code application logic here B b1 = new B(); } public int NoOFTriplets(String str){ String input[] = str.split(" "); int MaxGooglers = 0 ; int N = Integer.parseInt(input[0]); int S = Integer.parseInt(input[1]); int p = Integer.parseInt(input[2]); // int value[] = new int[N]; for(int i=0;i<N;i++) { int score = Integer.parseInt(input[i+3]); if(score <= 1) { if(score >= p) MaxGooglers ++; continue; } int div = score / 3 ; int rem = score % 3; //System.out.println ("Values " + div + " -- " + rem); if(rem != 0 ) div ++; if (div >= p) { MaxGooglers ++; // System.out.println ("Hello1"); } else if(S > 0 && rem != 1 && div + 1 >= p ) { // System.out.println (S + "Hello2"); MaxGooglers ++; S--; } } return MaxGooglers; } }
0
708
A12852
A11760
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; /** * */ /** * @author kishor * */ public class Dance { /** * @param args */ public static void main(String[] args) throws Exception { File f = new File("/tmp/dance.txt"); BufferedReader bReader = new BufferedReader(new InputStreamReader( new FileInputStream(f))); int lines = Integer.parseInt(bReader.readLine()); String strLine = null; int n, s, p; int score[]; String tokens[]; for (int i = 0; i < lines; i++) { strLine = bReader.readLine(); tokens = strLine.split(" "); n = Integer.parseInt(tokens[0]); s = Integer.parseInt(tokens[1]); p = Integer.parseInt(tokens[2]); score = new int[n]; for (int j = 3; j < n + 3; j++) { score[j - 3] = Integer.parseInt(tokens[j]); } System.out.println("Case #" + (i + 1) + ": " + getMaxDancers(s, p, score)); } } protected static int getMaxDancers(int s, int p, int scores[]) { int retValue = 0; int rem; int a, b; int d1, d2, d3; for (int score : scores) { if (p * 3 <= score) { retValue++; continue; } if (score < p) continue; rem = score - p; a = (int) rem / 2; b = score - p - a; if (b < 0) continue; d1 = a > b ? a - b : b - a; d2 = a > p ? a - p : p - a; d3 = b > p ? b - p : p - b; if(d1 >= 3 || d2 >= 3 || d3 >= 3) continue; if(d1 == 2 || d2 == 2 || d3 == 2) { if(s > 0) { s--; retValue++; continue; } else { continue; } } retValue ++; } return retValue; } }
0
709
A12852
A11326
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.r0; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; /** * @author julian */ public class B { public static final void main(String[] args) throws IOException { (new B()).run(); } private int getBestRes(int v) { return ((v % 3 == 0) ? 0 : 1) + ((int) v / 3); } private int getBestSurRes(int v) { return ((v % 3 == 2) ? 2 : Math.min(v, 1)) + ((int) (v / 3)); } public void run() throws IOException { BufferedReader in = new BufferedReader(new FileReader("B-small.in")); BufferedWriter out = new BufferedWriter(new FileWriter("B.out")); int t = Integer.parseInt(in.readLine()); for (int i = 0; i < t; i++) { StringTokenizer stok = new StringTokenizer(in.readLine()); int n = Integer.parseInt(stok.nextToken()); int s = Integer.parseInt(stok.nextToken()); int p = Integer.parseInt(stok.nextToken()); int[] total = new int[n]; for (int k = 0; k < n; k++) { total[k] = Integer.parseInt(stok.nextToken()); } out.write("Case #" + (i + 1) + ": " + solve(n, s, p, total) + "\n"); } in.close(); out.flush(); out.close(); } public int solve(int n, int s, int p, int[] t) { int good = 0; int soso = 0; for (int i = 0; i < n; i++) { if (getBestRes(t[i]) >= p) { good++; } else if (getBestSurRes(t[i]) >= p) { soso++; } } return good + Math.min(s, soso); } }
0
710
A12852
A12337
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.StringTokenizer; public class B { void main2(String[] args) throws Exception { BufferedReader br = new BufferedReader(new FileReader(args[0])); String line = br.readLine(); int count = Integer.parseInt(line); for (int i = 0; i < count; i++) { line = br.readLine(); // 3 1 5 15 13 11 StringTokenizer st = new StringTokenizer(line, " ", false); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int[] t = new int[n]; for (int j = 0; j < n; j++) { t[j] = Integer.parseInt(st.nextToken()); } System.out.println("Case #" + (i + 1) + ": " + max(n, s, p, t)); } br.close(); } private int max(int n, int s, int p, int[] t) { int max = 0; for (int i = 0; i < n; i++) { int r = t[i] % 3; int k = t[i] / 3; int b = 0; int bs = 0; switch (r) { case 0: b = k; bs = t[i] == 0 ? 0 : k + 1; break; case 1: b = k + 1; bs = t[i] == 1 ? -1 : k + 1; break; case 2: b = k + 1; bs = k + 2; } if (b >= p) { max++; } else if (bs >= p && s > 0) { max++; s--; } } return max; } public static void main(String[] args) throws Exception { new B().main2(args); } }
0
711
A12852
A13191
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.ArrayList; public class DancingWithTheGooglers { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { BufferedReader br = new BufferedReader(new FileReader("/Users/William/Desktop/B-small-attempt0.in")); String strLine; strLine = br.readLine(); int numOfLine = Integer.parseInt(strLine); // ArrayList<String> inputs = new ArrayList<String>(); for (int i=0;i<numOfLine;i++) { strLine = br.readLine(); String splitedStr[] = strLine.split(" "); int numOfDancer = Integer.parseInt(splitedStr[0]); int suprise = Integer.parseInt(splitedStr[1]); int gap = Integer.parseInt(splitedStr[2]); int numSuccess = 0; for (int j=0;j<numOfDancer;j++) { int score = Integer.parseInt(splitedStr[j+3]); int average = score / 3; if (average >= gap) { numSuccess++; } else if (average == gap-1){ switch (score%3) { case 0: if ((suprise>0) && (score>0)){ numSuccess++; suprise--; } break; case 1: if (score>1) { numSuccess++; } break; case 2: if ((score==2) && (suprise>0)){ numSuccess++; suprise--; } else { numSuccess++; } break; } } else if (average == gap-2) { switch (score%3) { case 0: case 1: break; case 2: if (suprise>0) { numSuccess++; suprise--; } break; } } } int caseNum = i + 1; System.out.println("Case #" + caseNum + ": " + numSuccess); } } catch (Exception e) { System.err.println("Error: " + e.getMessage()); } } }
0
712
A12852
A10410
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 codeJamB; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.PrintStream; public class PgmTemplate { /** * @param args */ public static String delims = "[ ]+"; public static PrintStream ps; public static void main(String[] args) { for (String s : args) { System.out.println(s); } try { // Open the file that is the first command line parameter FileInputStream fstream = new FileInputStream(args[0]+".txt"); ps = new PrintStream(args[0]+".out"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By Line strLine = br.readLine(); //System.out.println(strLine); int numCases = Integer.parseInt(strLine); // Read File Line By Line for (int i = 0; i < numCases; i++) { strLine = br.readLine(); //System.out.println(i + " " + strLine); doCode(i, strLine); } // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } public static void doCode(int Case, String strLine) { String[] tokens = strLine.split(delims); int N = Integer.parseInt(tokens[0]); int S = Integer.parseInt(tokens[1]); int P = Integer.parseInt(tokens[2]); int[] T = new int[N]; for (int i=0; i< N; i++) { T[i] = Integer.parseInt(tokens[3+i]); } int noSurprise = 0; int withSurprise = 0; for (int i=0; i< N; i++) { if (doWithNoSurprise(P, T[i])) noSurprise += 1; else if (doWithSurprise(P, T[i])) withSurprise += 1; } int TotalCount = noSurprise + Math.min(withSurprise, S); System.out.format("Case #%d: %d\n", Case + 1, TotalCount); ps.format("Case #%d: %d\n", Case + 1, TotalCount); /*System.out.format(" N: %d\n", N); System.out.format(" S: %d\n", S); System.out.format(" P: %d\n", P); for (int i=0; i< N; i++) { System.out.format(" T[%d]: %d\n", i, T[i]); }*/ } public static boolean doWithNoSurprise(int P, int T) { int score1 = T / 3; int score2 = (T - score1) / 2; int score3 = T - (score1 + score2); //System.out.format ("P: %d T: %d S1: %d S2: %d S3: %d\n", P, T, score1, score2, score3); if (score3 >= P) return true; return false; } public static boolean doWithSurprise(int P, int T) { if ((T < 2) || (T>28)) return false; int score1 = T / 3; int score2 = (T - score1) / 2; int score3 = T - (score1 + score2); if ((P - score3) > 1) return false; if ((score3 +1) - (score2 -1) > 2) return false; if ((score3 +1) - (score1) > 2) return false; //System.out.format ("P: %d T: %d S1: %d S2: %d S3: %d\n", P, T, score1, score2, score3); return true; } }
0
713
A12852
A13068
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileWriter; import java.util.HashSet; import java.util.Iterator; import java.util.Scanner; public class GCJ3 { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] hold = new int[n]; for (int i = 0; i < n; i++) { hold[i] = 0; int a = sc.nextInt(); int b = sc.nextInt(); int k = (int) Math.log10(a); HashSet<Integer> checked = new HashSet<Integer>(); for (int j = a; j <= b; j++) { if(checked.contains(j)) continue; HashSet<Integer> set = new HashSet<Integer>(); set.add(j); int curr = j; for (int l = 0; l <= k; l++) { int firstDig = curr / (int) Math.pow(10, k); int mod = curr % (int) Math.pow(10, k); curr = mod * 10 + firstDig; if ((int) Math.log10(curr) == k) { if (a<=curr && curr <=b) { set.add(curr); } } } if (set.size() > 1){ Iterator<Integer> p = set.iterator(); for(int m = 0;m<set.size();m++){ int P = p.next(); checked.add(P); } hold[i] += set.size() * (set.size() - 1) / 2; } } } try { // Create file FileWriter fstream = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream); for (int i = 0; i < n; i++) { out.write("Case #" + (1 + i) + ": " + hold[i]); if (i < n - 1) out.write("\n"); } out.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
714
A12852
A10194
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Main { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader(args[0])); br.readLine(); int c = 1; for(String s = br.readLine(); s != null ;s = br.readLine()){ int[] vals = strToInt(s.split(" ")); int special = 0; int possible = 0; float score = vals[2]; for(int i = 3; i < vals.length; i++){ if(isSpecial(score, vals[i])){ special++; }else if(canBeSpecial(score, vals[i])){ possible ++; } } System.out.println("Case #" + c + ": " + (special + Math.min(possible, vals[1]))); c++; } } private static boolean isPossible(float s, float num){ return((num) >= s); } private static boolean isSpecial(float s, float num){ return(isPossible(s, num) && (num/3+1) > s); } private static boolean canBeSpecial(float s, float num){ return(isPossible(s, num) && (num/3+2) > s + 0.5); } private static int[] strToInt(String[] s){ int[] ret = new int[s.length]; for(int i = 0; i < s.length; i++){ ret[i] = Integer.parseInt(s[i]); } return ret; } }
0
715
A12852
A11626
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam.surprisingGooglers; import java.util.Arrays; public class ProblemCase { private Integer[] scores; private int p; private int surpriseCount; public Integer[] getScores() { return scores; } public int getP() { return p; } public int getSurpriseCount() { return surpriseCount; } public ProblemCase(Integer[] scores, int p, int surpriseCount) { super(); this.scores = scores; this.p = p; this.surpriseCount = surpriseCount; } @Override public String toString() { return "ProblemCase [scores=" + Arrays.toString(scores) + ", p=" + p + ", surpriseCount=" + surpriseCount + "]"; } }
0
716
A12852
A12159
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.*; /** * * @author Jhon */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner cin = new Scanner(System.in); int a = cin.nextInt(); int dancers, surp, p, sum; float aa; List<Integer> dancerL = new ArrayList<>(); for (int i = 0; i < a; i++) { sum = 0; dancerL.clear(); dancers = Integer.parseInt(cin.next()); surp = Integer.parseInt(cin.next()); p = Integer.parseInt(cin.next()); for (int j = 0; j < dancers; j++) { dancerL.add(Integer.parseInt(cin.next())); } for (Integer ii : dancerL) { aa = (float) ii / 3; if (p == 0) { sum++; } else if((int) (ii / 3)!= 0){ if (aa == (int) (ii / 3)) { if (p <= (int) (ii / 3)) { sum++; } else { if (p == ((int) (ii / 3) + 1)) { if (surp > 0) { surp--; sum++; } } } } else if (aa >= ((int) ii / 3) + 0.5) { if (p <= (int) (ii / 3)) { sum++; } else { if (p == ((int) (ii / 3) + 1)) { sum++; } else if (p == ((int) (ii / 3) + 2)) { if (surp > 0) { surp--; sum++; } } } } else { if (p <= (int) (ii / 3)) { sum++; } else { if (p == ((int) (ii / 3) + 1)) { sum++; } } } } } System.out.println("Case #" + (i + 1) + ": " + sum); } } }
0
717
A12852
A11890
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 DWG { public static int[] SuspA = null; public static int[] nonSuspA = null; /** * @param args */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); int T = scnr.nextInt(); for (int t = 1; t <= T; t++) { int N = scnr.nextInt(); int S = scnr.nextInt(); int p = scnr.nextInt(); SuspA = new int[N]; nonSuspA = new int[N]; int ans = 0; int suspCount = 0; for (int n = 0; n < N; n++) { int x = scnr.nextInt(); calcCombs(x, p, n); //System.out.printf ( "a (%d) b (%d) \n" , SuspA[n], nonSuspA[n]); if (nonSuspA[n] > 0) { ans++; } else { if (SuspA[n] > 0 && suspCount < S) { ans++; suspCount++; } } } System.out.println("Case #" + t + ": " + ans); // System.out.printf("Case #%d: %d\n", t, ans); } } private static void calcCombs(int n, int p, int index) { int sum = n; int minP = p; int susp = 0; int nonSusp = 0; for (int i = 0; i <= 10; i++) { for (int j = 0; j <= 10; j++) { for (int k = 0; k <= 10; k++) { if (i + j + k == sum) { if (i >= minP || j >= minP || k >= minP) { if (Math.abs(i - j) > 2 || Math.abs(j - k) > 2 || Math.abs(i - k) > 2 ) { continue; } if (Math.abs(i - j) == 2 || Math.abs(j - k) == 2 || Math.abs(i - k) == 2 ) { if (i == j && j == k) { susp = susp + 3; } else { susp++; } //System.out.printf(" susp (%d)(%d)(%d) \n ", i , j, k); } else { if (i == j && j == k) { nonSusp = nonSusp + 3; } else { nonSusp++; } nonSusp++; //System.out.printf(" nonsusp (%d)(%d)(%d) \n ", i , j, k); } } } } } } //System.out.printf("susp: %d nonsusp: %d", susp/3, nonSusp/3); SuspA[index] = susp / 3; nonSuspA[index] = nonSusp / 3; } }
0
718
A12852
A10920
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 DancingGoogler { public static void main (String [] args) { Scanner sc = new Scanner (System.in); int x = sc.nextInt(); for (int i = 0; i < x; i++) { int num = sc.nextInt(); int lim = sc.nextInt(); int goal = sc.nextInt(); int [] list = new int [num]; for (int j = 0; j < num; j++) list[j] = sc.nextInt(); Arrays.sort(list); int count = 0; for (int j = num-1; j >= 0; j--) { if (list[j] >= goal*3-2) count++; else if (lim > 0 && list[j] >= goal && list[j] >= goal*3-4) { count++; lim--; } } System.out.println("Case #" + (i+1) + ": " + count); } } }
0
719
A12852
A11846
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.List; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Amya */ public class Dancing { public static void main(String args[]) throws FileNotFoundException{ List<String> lines = FileUtil.readFileByLine("input1"); int records = Integer.parseInt(lines.get(0)); int numOfGooglers = 0; int numOfSurprises = 0; int bestScore = 0; String[] nums = null; int eligiblesWithSurprise = 0; int eligiblesWithoutSurprise = 0; int onBorder = 0; int finalEligibles = 0; for(int i = 1; i<=records; i++){ nums = lines.get(i).split(" "); numOfGooglers = Integer.parseInt(nums[0]); numOfSurprises = Integer.parseInt(nums[1]); bestScore = Integer.parseInt(nums[2]); for(int j=3 ; j<nums.length; j++){ if(Integer.parseInt(nums[j])>=bestScore){ if(Integer.parseInt(nums[j])>=(bestScore*3 - 4)){ eligiblesWithSurprise ++; } if(Integer.parseInt(nums[j])>=(bestScore*3 - 2)){ eligiblesWithoutSurprise ++; } } } finalEligibles = eligiblesWithoutSurprise; onBorder = eligiblesWithSurprise - eligiblesWithoutSurprise; if(onBorder > numOfSurprises){ finalEligibles += numOfSurprises; }else{ finalEligibles += onBorder; } if(i == records) FileUtil.writeOutput("Case #"+i+": "+finalEligibles, true); else FileUtil.writeOutput("Case #"+i+": "+finalEligibles, false); eligiblesWithSurprise = 0; eligiblesWithoutSurprise = 0; } } }
0
720
A12852
A11867
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.math.*; import java.util.*; class Main{ static BufferedReader br; static PrintWriter pw; static File in; static File out; static String name="B-small-attempt0"; public static void main(String[] args){ try{ in=new File(name+".in"); out=new File(name+".out"); br=new BufferedReader(new FileReader(in)); pw=new PrintWriter(new BufferedWriter(new FileWriter(out))); int nbCase = Integer.parseInt(br.readLine()); for (int n=1;n<=nbCase;n++){ String line=br.readLine(); int googlers=Integer.parseInt(line.substring(0,line.indexOf(" "))); line=line.substring(line.indexOf(" ")+1); int surprise=Integer.parseInt(line.substring(0,line.indexOf(" "))); line=line.substring(line.indexOf(" ")+1); int min=Integer.parseInt(line.substring(0,line.indexOf(" "))); line=line.substring(line.indexOf(" ")+1); int scoreSurprise=min+Math.max(0,min-2)*2; int score=min+Math.max(0,min-1)*2; int count=0; for (int i=0;i<googlers;i++){ int point; if (i==googlers-1) point=Integer.parseInt(line); else{ point=Integer.parseInt(line.substring(0,line.indexOf(" "))); line=line.substring(line.indexOf(" ")+1); } if (point>=score) count++; else{ if (surprise!=0){ if (point>=scoreSurprise){ surprise--; count++; } } } } pw.println("Case #"+n+": "+count); } pw.flush(); pw.close(); br.close(); }catch(Exception e){ e.printStackTrace(); } } }
0
721
A12852
A11027
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package fixjava; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Map.Entry; import java.util.Set; /** * Simple multimap class. <code> MultiMap<String, String> map = MultiMapKeyToSet.make(); map.put("a", "x"); map.put("a", "x"); map.put("a", "y"); map.put("b", "z"); System.out.println(Join.joinRecursive(map.entrySet(), ", ", "[", "]")); </code> * * @author luke */ public class MultiMapKeyToSet<S, T> { HashMap<S, HashSet<T>> map = new HashMap<S, HashSet<T>>(); public static <K, V> MultiMapKeyToSet<K, V> make() { return new MultiMapKeyToSet<K, V>(); } /** Return true if this multimap did not already contain the specified value at the specified key. */ public boolean put(S key, T value) { HashSet<T> set = map.get(key); if (set == null) { set = new HashSet<T>(); map.put(key, set); } return set.add(value); } public void putAll(S key, Iterable<T> values) { boolean putSomething = false; for (T val : values) { put(key, val); putSomething = true; } if (!putSomething && !map.containsKey(key)) // If putting an empty collection, need to create an empty set at the key map.put(key, new HashSet<T>()); } public void putAll(S key, T[] values) { if (values.length == 0 && !map.containsKey(key)) // If putting an empty collection, need to create an empty set at the key map.put(key, new HashSet<T>()); else for (T val : values) put(key, val); } public HashSet<T> get(S key) { return map.get(key); } /** * Get the single value mapped to by the key, or null if no value mapped to for this key. * * @throws IllegalRuntimeException * if there is more than one value mapped to by this key. */ public T getSingleVal(S key) { HashSet<T> set = map.get(key); return CollectionUtils.getSingleVal(set); } public boolean containsKey(S key) { return map.containsKey(key); } public int sizeKeys() { return map.size(); } public Set<Entry<S, HashSet<T>>> entrySet() { return map.entrySet(); } /** * Return the union of all values in all mapped sets (i.e. the union of all values mapped to by some key in this MultiMap). * NOTE: creates a new HashSet with the current union on every invocation, so if you modify the contents of the returned * HashSet, it won't affect the map. */ public HashSet<T> valuesUnion() { return CollectionUtils.union(map.values()); } public HashMap<S, HashSet<T>> getRawMap() { return map; } public Set<S> keySet() { return map.keySet(); } /** Invert the mapping */ public MultiMapKeyToSet<T, S> invert() { MultiMapKeyToSet<T, S> inv = new MultiMapKeyToSet<T, S>(); for (Entry<S, HashSet<T>> ent : map.entrySet()) { S key = ent.getKey(); for (T val : ent.getValue()) inv.put(val, key); } return inv; } public ArrayList<Pair<S, HashSet<T>>> toList() { ArrayList<Pair<S, HashSet<T>>> result = new ArrayList<Pair<S,HashSet<T>>>(); for (Entry<S, HashSet<T>> ent : map.entrySet()) result.add(Pair.make(ent.getKey(), ent.getValue())); return result; } /** Write out to a TSV file */ public void writeOutToFile(String tsvFile) throws IOException { PrintWriter writer = new PrintWriter(tsvFile); for (Entry<S, HashSet<T>> ent : map.entrySet()) { S key = ent.getKey(); StringBuilder buf = new StringBuilder(); buf.append(key); for (T val : ent.getValue()) buf.append("\t" + val); writer.println(buf.toString()); } writer.close(); } /** Read in a String->String map from a TSV file */ public static MultiMapKeyToSet<String, String> readFromFile(String tsvFile) throws IOException { MultiMapKeyToSet<String, String> map = new MultiMapKeyToSet<String, String>(); for (String line : new FileLineIterator(tsvFile)) { String[] parts = Split.split(line, "\t"); String key = parts[0]; for (int i = 1; i < parts.length; i++) map.put(key, parts[i]); } return map; } }
0
722
A12852
A10169
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 triplet { public int one ; public int two ; public int three ; public boolean surprise= false; public boolean flag = false; }
0
723
A12852
A11595
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Date; import java.util.StringTokenizer; public class Cj2012_qr_b_java { // <Common Declarations> // private static final String IN_FILE = "test.in"; private static final String IN_FILE = "test_small.in"; // private static final String IN_FILE = "test_large.in"; private static final String OUT_FILE = IN_FILE + ".out"; private static final DateFormat DATE_FORMAT = new SimpleDateFormat("HH:mm.ss"); private static long lBeginTimeMillis; private static BufferedReader bufferedReader; private static PrintWriter printWriter; private static int nNbCases, nIndexCase; // </Common Declarations> // <Specific Declarations> private static int N, S, p, t[] = new int[100], nP; // </Specific Declarations> private static void begin() throws Exception { // <Common Commands> lBeginTimeMillis = System.currentTimeMillis(); System.out.println(Cj2012_qr_b_java.class.toString()); System.out.println("Begin: " + DATE_FORMAT.format(new Date(lBeginTimeMillis)) + "."); bufferedReader = new BufferedReader(new FileReader(IN_FILE)); printWriter = new PrintWriter(new BufferedWriter(new FileWriter(OUT_FILE))); // </Common Commands> // <Specific Commands> nNbCases = Integer.parseInt(bufferedReader.readLine()); // </Specific Commands> } private static void end() throws Exception { // <Specific Commands> // ... // </Specific Commands> // <Common Commands> bufferedReader.close(); printWriter.close(); long lEndTimeMillis = System.currentTimeMillis(); System.out.println("End: " + DATE_FORMAT.format(new Date(lEndTimeMillis)) + "."); System.out.println((lEndTimeMillis - lBeginTimeMillis) + "."); // </Common Commands> } private static void readCase() throws Exception { // <Specific Commands> StringTokenizer strTokenizer = new StringTokenizer( bufferedReader.readLine(), " "); N = Integer.parseInt(strTokenizer.nextToken()); S = Integer.parseInt(strTokenizer.nextToken()); p = Integer.parseInt(strTokenizer.nextToken()); for (int i = 0; i < N; i++) t[i] = Integer.parseInt(strTokenizer.nextToken()); // </Specific Commands> } private static void processCase() { // <Specific Commands> Arrays.sort(t, 0, N); nP = 0; for (int i = N - 1; i >= 0; i--) { int n = t[i] / 3; if (n >= p) nP++; else { int n1 = t[i] % 3; switch (n1) { case 0: if (t[i] > 0 && n + 1 >= p && n + 1 <= 10 && S > 0) { nP++; S--; } break; case 1: if (n + 1 >= p && n + 1 <= 10) { nP++; } else if (n + 1 >= p && n + 1 <= 10 && S > 0) { nP++; S--; } break; case 2: if (n + 1 >= p && n + 1 <= 10) { nP++; } else if (n + 2 >= p && n + 2 <= 10 && S > 0) { nP++; S--; } break; } } } // </Specific Commands> } private static void writeCase(int nIndexCase) throws Exception { // <Common Commands> printWriter.print("Case #"); printWriter.print(nIndexCase + 1); printWriter.print(":"); // </Common Commands> // <Specific Commands> printWriter.print(" "); printWriter.print(nP); printWriter.println(); // </Specific Commands> } public static void main(String[] args) throws Exception { // <Common Commands> begin(); for (nIndexCase = 0; nIndexCase < nNbCases; nIndexCase++) { readCase(); processCase(); writeCase(nIndexCase); } end(); // </Common Commands> } }
0
724
A12852
A10148
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.nitrous.codejam; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class DancingWithGooglers { public static void readFile(String inputFile) throws IOException { File in = new File(inputFile); File dir = in.getParentFile(); File outFile = new File(dir, in.getName()+".out"); System.out.println("Output file is "+outFile.getAbsolutePath()); PrintWriter out = new PrintWriter(outFile); BufferedReader reader = new BufferedReader(new FileReader(in)); String line = null; int testCaseCount = Integer.parseInt(reader.readLine().trim()); System.out.println("Read count="+testCaseCount); for (int testCase = 0 ; testCase < testCaseCount; testCase++) { line = reader.readLine(); // // debug - ignore commented lines in input file // if (line.startsWith("#")) { // continue; // } System.out.println("\nCase #"+(testCase+1)+": "+line); String[] numStrArr = line.split(" "); int[] numArr = new int[numStrArr.length]; for (int i = 0 ; i < numStrArr.length; i++) { numArr[i] = Integer.parseInt(numStrArr[i]); } int numGooglers = numArr[0]; int surprises = numArr[1]; int minHighScore = numArr[2]; System.out.println("Googlers="+numGooglers); System.out.println("Suprises="+surprises); System.out.println("minHighScore="+minHighScore); int[] totalScore = new int[numGooglers]; Googler[] googlers = new Googler[numGooglers]; for (int googler = 0; googler < numGooglers; googler++) { totalScore[googler] = numArr[3 + googler]; System.out.println("Googler ["+(googler+1)+"] got score "+totalScore[googler]); googlers[googler] = getPossibleScores(totalScore[googler], minHighScore); } int result = calculate(googlers, surprises, minHighScore); out.println("Case #"+(testCase+1)+": "+result); System.out.println("Case #"+(testCase+1)+": "+result); } out.flush(); out.close(); } private static int calculate(Googler[] allGooglers, int expectedSurprises, int expectedMinResult) { // the active triplets being considered for the current iteration Triplet[] activeTriplet = new Triplet[allGooglers.length]; Triplet[] resultTriplet = new Triplet[allGooglers.length]; // pointer to current triplet being considered for each googler int[] activeTripletIdx = new int[allGooglers.length]; for (int i = 0 ; i < activeTripletIdx.length; i++) { activeTripletIdx[i] = 0; } int permutations = 0; for (Googler googler : allGooglers) { if (permutations == 0) { permutations = googler.possibleScores.length; } else { permutations = permutations * googler.possibleScores.length; } } System.out.println("Processing "+permutations+" permutations"); // the result int maxWinningGooglers = -1; for (int permutation = 0 ; permutation < permutations; permutation++) { // update pointers based on current permutation int tempPermutation = permutation; for (int googlerIdx = allGooglers.length - 1; googlerIdx >=0; googlerIdx--) { int idx = tempPermutation % allGooglers[googlerIdx].possibleScores.length; activeTripletIdx[googlerIdx] = idx; tempPermutation = tempPermutation / allGooglers[googlerIdx].possibleScores.length; // grab active triplet from each googler int pointer = activeTripletIdx[googlerIdx]; activeTriplet[googlerIdx] = allGooglers[googlerIdx].possibleScores[pointer]; } // check current set of triplets to see whether it yields the highest result int winningGooglers = 0; int numSurprises = 0; for (Triplet triplet : activeTriplet) { if (triplet.isSurprise) { numSurprises++; } if (numSurprises > expectedSurprises) { // exceeds expected number of surprises. not a match break; } if (triplet.bestResult >= expectedMinResult) { winningGooglers++; } } if (numSurprises == expectedSurprises) { // found the expected number of surprises. maxWinningGooglers = Math.max(maxWinningGooglers, winningGooglers); // debug for (int i = 0 ; i < resultTriplet.length; i++) { resultTriplet[i] = activeTriplet[i]; } } } // debug StringBuffer debug = new StringBuffer("Max winning scores: "); for (int i = 0 ; i < resultTriplet.length; i++) { debug.append(resultTriplet[i]+","); } System.out.println(debug.toString()); return maxWinningGooglers; } private static Googler getPossibleScores(int score, int minHighScore) { ArrayList<Triplet> possibleScores = new ArrayList<Triplet>(); for(int judge0Score = 0; judge0Score <= 10; judge0Score++) { for(int judge1Score = 0; judge1Score <= 10; judge1Score++) { for(int judge2Score = 0; judge2Score <= 10; judge2Score++) { // skip impossible scores where 2 or more scores are more than 2 apart if (Triplet.isImpossible(judge0Score, judge1Score, judge2Score)) { continue; } // only add score combinations that result in the correct total score int totalScore = judge0Score + judge1Score + judge2Score; if (totalScore != score) { // skip non matching total scores continue; } // valid score combination add to googler Triplet t = new Triplet(judge0Score, judge1Score, judge2Score); possibleScores.add(t); System.out.println("possible scores= ("+judge0Score+","+judge1Score+","+judge2Score+") "+(t.isSurprise ? " (*)" :"")); } } } System.out.println("Possible score count "+possibleScores.size()); Googler googler = new Googler(possibleScores.toArray(new Triplet[possibleScores.size()])); return googler; } private static class Googler { Triplet[] possibleScores; public Googler(Triplet[] possibleScores) { this.possibleScores = possibleScores; } } private static class Triplet { boolean isSurprise; int bestResult; private int scoreA, scoreB, scoreC; public Triplet(int scoreA, int scoreB, int scoreC) { this.scoreA = scoreA; this.scoreB = scoreB; this.scoreC = scoreC; this.isSurprise = isSurprise(scoreA, scoreB, scoreC); this.bestResult = Math.max(scoreA, Math.max(scoreB, scoreC)); } @Override public String toString() { return "sum="+(scoreA+scoreB+scoreC)+" (" + scoreA + ", " + scoreB+", "+ scoreC + ")" +(isSurprise ? " *" : ""); } /** * Triplet is surprising if 2 or more scores are 2 apart * @param scoreA * @param scoreB * @param scoreC * @return */ public static boolean isSurprise(int scoreA, int scoreB, int scoreC) { if (Math.max(scoreA, scoreB) - Math.min(scoreA, scoreB) >= 2) { return true; } if (Math.max(scoreB, scoreC) - Math.min(scoreB, scoreC) >= 2) { return true; } if (Math.max(scoreA, scoreC) - Math.min(scoreA, scoreC) >= 2) { return true; } return false; } /** * No triplet contains scores > 2 apart * @param scoreA * @param scoreB * @param scoreC * @return */ public static boolean isImpossible(int scoreA, int scoreB, int scoreC) { if (Math.max(scoreA, scoreB) - Math.min(scoreA, scoreB) > 2) { return true; } if (Math.max(scoreB, scoreC) - Math.min(scoreB, scoreC) > 2) { return true; } if (Math.max(scoreA, scoreC) - Math.min(scoreA, scoreC) > 2) { return true; } return false; } } public static void main (String[] args) throws IOException { // readFile("D:/workspace/CodeJam/data/in.txt"); readFile("D:/workspace/CodeJam/data/B-small-attempt0.in"); } }
0
725
A12852
A10931
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author nzeyi */ public class B { public static void main(String[] arg) throws Exception { String in = "/home/nzeyi/Downloads/B-small-attempt0.in"; String out = "/home/nzeyi/Desktop/out"; long a = System.currentTimeMillis(); BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(in))); PrintWriter w = new PrintWriter(new FileOutputStream(out)); int c = 0; int t = Integer.parseInt(r.readLine()); String s; while ((s = r.readLine()) != null) { if (!"".equals(s)) { c++; w.print("Case #" + c + ": " + max(s)); if (c < t) { w.println(); } } } r.close(); w.flush(); w.close(); long b = System.currentTimeMillis(); System.out.println("Done(MS): " + (b - a)); } public static int max(String line) { String[] t = line.trim().split("\\s"); int n = Integer.parseInt(t[0]); int s = Integer.parseInt(t[1]); int p = Integer.parseInt(t[2]); int ret = 0; int sp = 0; for (int i = 3; i < t.length; i++) { int x = Integer.parseInt(t[i]); if (br(x, 1) >= p) { ret++; } else if (sp < s) { if (br(x, 2) >= p) { ret++; sp++; } } } return ret; } private static int br(int s, int d) { return (s == 0) ? 0 : (s / 3) + ((d + (s % 3)) / 2); } }
0
726
A12852
A12730
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package gcj2012.qr; import java.io.*; import java.util.StringTokenizer; /** * * @author Scott DellaTorre */ public class B { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("src/gcj2012/qr/in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/gcj2012/qr/B.out"))); int T = Integer.parseInt(in.readLine()); for (int i = 0; i < T; i++) { StringTokenizer st = new StringTokenizer(in.readLine()); int N = Integer.parseInt(st.nextToken()); // Number of Googlers int S = Integer.parseInt(st.nextToken()); // Number of suprising cases int p = Integer.parseInt(st.nextToken()); int[] t = new int[N]; // Total points of the Googlers for (int j = 0; j < N; j++) { t[j] = Integer.parseInt(st.nextToken()); } // What is the maximum number of Googlers that could have had a best // result of at least p? int lowSurprising = p < 2 ? p : p * 3 - 4; int lowNormal = p < 1 ? p : p * 3 - 2; int count = 0; for (int j = 0; j < N; j++) { if (t[j] >= lowNormal) { count++; } else if (S > 0 && t[j] >= lowSurprising) { S--; count++; } } out.println("Case #" + (i + 1) + ": " + count); } out.close(); } }
0
727
A12852
A10703
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.edwarddrapkin; import java.io.File; import java.io.IOException; import java.util.Scanner; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; public class Dancing { AtomicInteger possibleNoCheat = new AtomicInteger(0); AtomicInteger possibleWithCheatOnly = new AtomicInteger(0); AtomicInteger jobsWorking = new AtomicInteger(0); ExecutorService service = Executors.newFixedThreadPool(4); private void reset() { possibleNoCheat = new AtomicInteger(0); possibleWithCheatOnly = new AtomicInteger(0); } private boolean testArray(int[] arr, int input, int maxDist, int minimumPositive) { if(arr[0] + arr[1] + arr[2] != input) { return false; } int diff1 = Math.abs(arr[0] - arr[1]); int diff2 = Math.abs(arr[0] - arr[2]); int diff3 = Math.abs(arr[1] - arr[2]); if( (diff1 > maxDist || diff2 > maxDist || diff3 > maxDist) || (arr[0] < minimumPositive && arr[1] < minimumPositive && arr[2] < minimumPositive)) { return false; } else { return true; } } private void calculatePossibleScores(final int total, final int maxcheat, final int minimumPositive) { Runnable r = new Runnable() { public void run() { int[] working = new int[3]; boolean withCheat = false; for(int i = 0; i <= 10; i++) { working[0] = i; for(int j = 0; j <= 10; j++) { working[1] = j; for(int k = 0; k <= 10; k++) { working[2] = k; if(working[0] + working[1] + working[2] != total) { continue; } if(testArray(working, total, 1, minimumPositive)) { //System.out.println(Arrays.toString(working) + " " + maxcheat + " " + total + " " + minimumPositive); possibleNoCheat.incrementAndGet(); jobsWorking.decrementAndGet(); return; } else if (!withCheat) { if(testArray(working, total, 2, minimumPositive)) { withCheat = true; } } } } } if(withCheat) { possibleWithCheatOnly.incrementAndGet(); } jobsWorking.decrementAndGet(); } }; service.execute(r); } public void doEverything(String file) throws Exception { String[] lines = readFile(file); int casen = 1; for(String line : lines) { reset(); //System.out.println("\n\n\n"); String[] sints = line.split("\\s+"); int[] ints = new int[sints.length]; for(int i = 0; i < sints.length; i++) { ints[i] = Integer.parseInt(sints[i]); } int numGooglers = ints[0]; int start = 3; int maxcheat = ints[1]; int minPositive = ints[2]; // System.out.println(numGooglers + " " + maxcheat + " " + minPositive); for(int i = start; i < ints.length; i++) { // System.out.println("Testing: " + ints[i]); jobsWorking.incrementAndGet(); calculatePossibleScores(ints[i], maxcheat, minPositive); // System.out.println(); } while(jobsWorking.get() > 0) { Thread.sleep(100); } System.out.println("Case #" + casen + ": " + (possibleNoCheat.get() + (possibleWithCheatOnly.get() > maxcheat ? maxcheat : possibleWithCheatOnly.get()))); casen++; } service.shutdown(); } public static void main(String[] args) throws Throwable { new Dancing().doEverything("C:/Users/Eddie/Desktop/google_input.txt"); } private static String[] readFile(String file) throws IOException { Scanner scanner = new Scanner(new File(file)); String numLines = scanner.nextLine(); int nl = Integer.parseInt(numLines); String[] lines = new String[nl]; int i = 0; while(scanner.hasNextLine() && i < nl) { lines[i] = scanner.nextLine(); ++i; } return lines; } }
0
728
A12852
A12676
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 sc = new Scanner(System.in); int n = sc.nextInt(); int test = 1, i, j; int[] arr = new int[100]; int[] arr1 = new int[100]; while (test <= n ) { int N_G = sc.nextInt(); int N_S = sc.nextInt(); int query = sc.nextInt(); int count = 0; int surprize_count = 0; for(i = 0 ; i < N_G ; i++) arr[i] = sc.nextInt(); int total = 0; int temp = query-1; int temp1 = query-2; for(i = 0 ; i < N_G ; i++){ if(arr[i]/3 >= query || (arr[i]/3 == query-1 && arr[i]%3 > 0)) total++; else if(N_S > 0 && ((arr[i]/3 == temp1 && arr[i]%3 == 2) || (arr[i]/3 == temp && temp != 0))){ N_S--; total++; } } arr1[test-1] = total; test++; } for(i = 1 ; i <= n ; i++) System.out.println("Case #" +i+": "+arr1[i-1]); } }
0
729
A12852
A12854
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 javaapplication3; import java.io.*; import java.math.*; import java.util.*; public class Dance { public static final String INPUT = "dance"; @SuppressWarnings("unchecked") private static void solve() throws IOException { int T = 0; T = nextInt(); int googlers = 0; int suprise = 0; int prog = 0; int wynik = 0; int triplet = 0; int licznik = 0; System.out.println("START"); try { for (int t = 0; t < T; t++) { wynik = 0; googlers = nextInt(); suprise = nextInt(); prog = nextInt(); System.out.println("googlers = " + googlers); System.out.println("suprise = " + suprise); System.out.println("prog = " + prog); if (prog > 0) { System.out.println("prog >0"); for (int i = 0; i < googlers; i++) { triplet = nextInt(); System.out.println("TRIPLET = " + triplet); if (triplet > 2) { if (triplet % 3 == 0) { if (triplet / 3 >= prog) { System.out.println("triplet / 3 >= prog"); wynik++; } else if (((triplet / 3) + 1 == prog) && (suprise > 0)) { System.out.println("((triplet / 3) + 1 == prog) && (suprise > 0)"); wynik++; suprise--; } } else if (triplet % 3 == 1) { if ((triplet + 2) / 3 >= prog) { System.out.println("((triplet + 2) / 3 >= prog"); wynik++; } } else { if ((triplet + 1) / 3 >= prog) { System.out.println("(triplet + 1) / 3 >= prog"); wynik++; } else { if ((suprise > 0) && (triplet < 27)) { System.out.println("(suprise > 0) && (triplet < 27)"); if ((triplet + 4) / 3 >= prog) { System.out.println("((triplet + 4) / 3 >= prog)"); wynik++; suprise--; } } } } } else if (((triplet == 2) || (triplet == 1)) && (prog == 1)) { wynik++; } else if ((triplet == 2) && (prog == 2) && (suprise > 0)) { wynik++; } } } else if (prog == 0) { for (int i = 0; i < googlers; i++) { triplet = nextInt(); System.out.println("(prog == 0)"); wynik = googlers; } } // if (suprise < 0) { // wynik = wynik + suprise; // } licznik = t + 1; System.out.println("Case #" + licznik + " " + wynik); out.println("Case #" + licznik + ": " + wynik); } System.out.println("STOP"); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static String zmienLitere(String znak) { String nowyZnak = ""; HashMap hashMap = new HashMap(); hashMap.put("a", "y"); hashMap.put("b", "h"); hashMap.put("c", "e"); hashMap.put("d", "s"); hashMap.put("e", "o"); hashMap.put("f", "c"); hashMap.put("g", "v"); hashMap.put("h", "x"); hashMap.put("i", "d"); hashMap.put("j", "u"); hashMap.put("k", "i"); hashMap.put("l", "g"); hashMap.put("m", "l"); hashMap.put("n", "b"); hashMap.put("o", "k"); hashMap.put("p", "r"); hashMap.put("q", "z"); hashMap.put("r", "t"); hashMap.put("s", "n"); hashMap.put("t", "w"); hashMap.put("u", "j"); hashMap.put("v", "p"); hashMap.put("w", "f"); hashMap.put("x", "m"); hashMap.put("y", "a"); hashMap.put("z", "q"); nowyZnak = (String) hashMap.get(znak); // if ("a".equals(znak)) { // nowyZnak = "y"; // } else { // nowyZnak = znak; // } return nowyZnak; } private static long dajSume(ArrayList<String> cuksy) { long lewa = 0; long prawa = 0; long lewaSum = 0; long prawaSum = 0; long max = 0; for (int i = 1; i < cuksy.size() - 1; i++) { lewaSum = 0; prawaSum = 0; for (int j = 0; j < i; j++) { lewa = lewa ^ Long.parseLong(cuksy.get(j)); lewaSum = lewaSum + Long.parseLong(cuksy.get(j)); } for (int k = i; k < cuksy.size(); k++) { prawa = prawa ^ Long.parseLong(cuksy.get(k)); prawaSum = prawaSum + Long.parseLong(cuksy.get(k)); } if (prawa == lewa) { // System.out // .println(i + " lewa " + lewaSum + " prwa " + prawaSum); if ((prawaSum > max) && (prawaSum > lewaSum)) { // System.out.println(i); max = prawaSum; } else if ((lewaSum > max) && (prawaSum < lewaSum)) { // System.out.println(i); max = lewaSum; } } } //System.out.println(" max " + max); return max; } // ----------------------------------------------- private static BufferedReader br; private static StringTokenizer _st; private static PrintWriter out; private static String next() throws IOException { while (_st == null || !_st.hasMoreTokens()) { String s = br.readLine(); if (s == null) { return s; } _st = new StringTokenizer(s); } return _st.nextToken(); } private static int nextInt() throws IOException { return Integer.parseInt(next()); } private static long nextLong() throws IOException { return Long.parseLong(next()); } private static double nextDouble() throws IOException { return Double.parseDouble(next()); } private static String nextLine() throws IOException { _st = null; return br.readLine(); } public static void run() { long startTime = System.nanoTime(); try { br = new BufferedReader(new FileReader( "c:/software/Projects/" + INPUT + ".in")); out = new PrintWriter("c:/software/Projects/" + INPUT + ".output"); try { solve(); } finally { out.close(); } } catch (IOException e) { System.err.println(e.getClass().getName() + ": " + e.getMessage()); e.printStackTrace(); } long finishTime = System.nanoTime(); System.err.printf("%.3f\n", (finishTime - startTime) / 1e9); } public static void main(String[] args) { run(); } }
0
730
A12852
A10936
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 ProblemB { public static int[] generateTriplet(int totalScore) { int third = totalScore/3; int[] triplet = new int[3]; int total = 0; int i = 0; triplet[0] = third; triplet[1] = third; triplet[2] = third; total = third*3; while(total < totalScore) { triplet[i] += 1; total += 1; i = (i+1)%3; } //System.out.println( triplet[0] + "," + triplet[1] + "," + triplet[2]); return triplet; } }
0
731
A12852
A12352
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.Stack; import java.util.StringTokenizer; import junit.framework.Assert; /** * Problem B - Dancing With The Googlers * * @author nhancvu@gmail.com */ public class ProblemB { private static final boolean DEBUG = false; private static final int MAX_TEST_CASES = 100; private static final int MAX_RESULT = 10; private static final int MAX_TOTAL_POINT = 30; public static void main(String[] args) { if (DEBUG) { int result1 = processTestCase("3 1 5 15 13 11"); int result2 = processTestCase("3 0 8 23 22 21"); int result3 = processTestCase("2 1 1 8 0"); int result4 = processTestCase("6 2 8 29 20 8 18 18 21"); int result5 = processTestCase("1 0 4 8"); Assert.assertEquals(3, result1); Assert.assertEquals(2, result2); Assert.assertEquals(1, result3); Assert.assertEquals(3, result4); Assert.assertEquals(0, result5); } int numberOfTestCases; int results[]; try { BufferedReader bufferRead = new BufferedReader(new InputStreamReader(System.in)); String input = bufferRead.readLine(); if (null != input) { numberOfTestCases = Math.min(Integer.valueOf(input), MAX_TEST_CASES); results = new int[numberOfTestCases]; for (int i = 0; i < numberOfTestCases; i++) { input = bufferRead.readLine(); if (null != input) { results[i] = processTestCase(input); } } for (int i = 0; i < numberOfTestCases; i++) { System.out.println("Case #" + (i + 1) + ": " + results[i]); } } } catch (IOException e) { e.printStackTrace(); } } public static int processTestCase(String testCase) { int maxNumGooglers = 0; StringTokenizer tokenizer = new StringTokenizer(testCase, " "); int numOfGooglers = (tokenizer.hasMoreTokens() ? Integer.valueOf(tokenizer.nextToken()) : 0); int numOfSurprisingTripletsOfScores = (tokenizer.hasMoreTokens() ? Integer.valueOf(tokenizer.nextToken()) : 0); int bestResult = (tokenizer.hasMoreTokens() ? Integer.valueOf(tokenizer.nextToken()) : 0); if (numOfSurprisingTripletsOfScores > numOfGooglers) return maxNumGooglers; if (0 > bestResult || bestResult > MAX_RESULT) return maxNumGooglers; List<Googler> googlers = new ArrayList<Googler> (); int totalPointPerGooglers[] = new int[numOfGooglers]; for (int i = 0; i < numOfGooglers; i++) { totalPointPerGooglers[i] = (tokenizer.hasMoreTokens() ? Integer.valueOf(tokenizer.nextToken()) : 0); if (0 > totalPointPerGooglers[i] || totalPointPerGooglers[i] > MAX_TOTAL_POINT) return maxNumGooglers; googlers.add(new Googler(i, getAllPossibleScores(totalPointPerGooglers[i]))); } maxNumGooglers = getMaxNumGooglersWithAtLeastBestScore(googlers, numOfSurprisingTripletsOfScores, bestResult); return maxNumGooglers; } public static int getMaxNumGooglersWithAtLeastBestScore(List<Googler> googlers, int numOfSurprisingTripletsOfScores, int bestResult) { int bestMaxNumGooglers = 0; int googlerIndex = 0; List<PossibleTripletScores> possibleTripletScoresList = new ArrayList<PossibleTripletScores>(); PossibleTripletScores runningTallyPossibleScores; PossibleTripletScores possibleScores; Stack<Googler> state = new Stack<Googler>(); state.push(googlers.get(googlerIndex++)); Googler currentGoogler; do { if (googlerIndex < googlers.size()) { state.push(googlers.get(googlerIndex++)); } else { currentGoogler = (Googler) state.pop(); googlerIndex--; runningTallyPossibleScores = new PossibleTripletScores(); for (Googler googler : state) { runningTallyPossibleScores.addTripletScores(googler.getCurrentTripletScores()); } currentGoogler.firstTripletScores(); do { possibleScores = new PossibleTripletScores(runningTallyPossibleScores); possibleScores.addTripletScores(currentGoogler.getCurrentTripletScores()); possibleTripletScoresList.add(possibleScores); currentGoogler.nextTripletScores(); } while (currentGoogler.hasMoreTripletScores()); if (!state.isEmpty()) { do { currentGoogler = (Googler) state.peek(); if (currentGoogler.hasMoreTripletScores()) { currentGoogler.nextTripletScores(); break; } else { currentGoogler = (Googler) state.pop(); currentGoogler.firstTripletScores(); googlerIndex--; } } while (!state.isEmpty()); } } } while (!state.isEmpty()); for (PossibleTripletScores possibleTripletScores : possibleTripletScoresList) { if (possibleTripletScores.getSuprisingTripletScoreCount() == numOfSurprisingTripletsOfScores) { bestMaxNumGooglers = Math.max(bestMaxNumGooglers, possibleTripletScores.getHasAtLeastBestScoreCount(bestResult)); } } return bestMaxNumGooglers; } public static List<TripletScores> getAllPossibleScores(int googlerTotalPoint) { List<TripletScores> list = new ArrayList<TripletScores>(); for (int firstJudgeScore = MAX_RESULT; firstJudgeScore >= 0; firstJudgeScore--) { if (firstJudgeScore > googlerTotalPoint) continue; for (int secondJudgeScore = Math.min(MAX_RESULT, googlerTotalPoint - firstJudgeScore); secondJudgeScore >= 0; secondJudgeScore--) { if (Math.abs(firstJudgeScore - secondJudgeScore) > 2) continue; int thirdJudgeScore = googlerTotalPoint - (secondJudgeScore + firstJudgeScore); if (Math.abs(thirdJudgeScore - secondJudgeScore) > 2) continue; if (Math.abs(thirdJudgeScore - firstJudgeScore) > 2) continue; list.add(new TripletScores(firstJudgeScore, secondJudgeScore, thirdJudgeScore)); } } return list; } public static class PossibleTripletScores { private List<TripletScores> scores; public PossibleTripletScores() { this.scores = new ArrayList<TripletScores>(); } public PossibleTripletScores(PossibleTripletScores another) { this.scores = new ArrayList<TripletScores>(another.getScores()); } public List<TripletScores> getScores() { return this.scores; } public void addTripletScores(TripletScores score) { this.scores.add(score); } public int getHasAtLeastBestScoreCount(int bestScore) { int count = 0; for (TripletScores score : scores) { if (score.hasAtLeastBestScore(bestScore)) { count++; } } return count; } public int getSuprisingTripletScoreCount() { int count = 0; for (TripletScores score : scores) { if (score.isSurprising()) { count++; } } return count; } public String toString() { StringBuilder s = new StringBuilder(); s.append("Possible TripletScores: "); for (TripletScores score : scores) { s.append(score); s.append(" "); } return s.toString(); } } public static class Googler { private int googlerIndex; private List<TripletScores> possibleTripletScores; private int tripletScoresIndex; public Googler(int googlerIndex, List<TripletScores> possibleTripletScores) { this.googlerIndex = googlerIndex; this.possibleTripletScores = possibleTripletScores; this.tripletScoresIndex = 0; } public final int getGooglerIndex() { return googlerIndex; } public void firstTripletScores() { tripletScoresIndex = 0; } public void nextTripletScores() { tripletScoresIndex++; } public TripletScores getCurrentTripletScores() { return possibleTripletScores.get(tripletScoresIndex); } public boolean hasMoreTripletScores() { return (this.tripletScoresIndex < possibleTripletScores.size() - 1); } public String toString() { StringBuilder s = new StringBuilder(); s.append("Googler ["); s.append(this.googlerIndex); s.append("] "); s.append(this.tripletScoresIndex); s.append(" "); for (TripletScores score : this.possibleTripletScores) { s.append(score); s.append(" "); } return s.toString(); } } public static class TripletScores { private int s1; private int s2; private int s3; public TripletScores(int s1, int s2, int s3) { this.s1 = s1; this.s2 = s2; this.s3 = s3; } public boolean isSurprising() { return (Math.abs(this.s1 - this.s2) >= 2) || (Math.abs(this.s1 - this.s3) >= 2) || (Math.abs(this.s2 - this.s3) >= 2); } public boolean hasAtLeastBestScore(int bestScore) { return (this.s1 >= bestScore || this.s2 >= bestScore || this.s3 >= bestScore); } public String toString() { StringBuilder s = new StringBuilder(); s.append("("); s.append(this.s1); s.append(", "); s.append(this.s2); s.append(", "); s.append(this.s3); s.append(")"); return s.toString(); } } }
0
732
A12852
A12460
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 pandit.codejam; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Writer; import java.util.Scanner; /** * @author Manu Ram Pandit * */ public class DancingWithGooglersUpload { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { FileInputStream fStream = new FileInputStream( "input.txt"); Scanner scanner = new Scanner(new BufferedInputStream(fStream)); Writer out = new OutputStreamWriter(new FileOutputStream("output.txt")); int T = scanner.nextInt(); int N,S,P,ti; int counter = 0; for (int count = 1; count <= T; count++) { N=scanner.nextInt(); S = scanner.nextInt(); counter = 0; P = scanner.nextInt(); for(int i=1;i<=N;i++){ ti=scanner.nextInt(); if(ti>=(3*P-2)){ counter++; continue; } else if(S>0){ if(P>=2 && ((ti==(3*P-3)) ||(ti==(3*P-4)))) { S--; counter++; continue; } } } // System.out.println("Case #" + count + ": " + counter); out.write("Case #" + count + ": " + counter + "\n"); } fStream.close(); out.close(); } }
0
733
A12852
A10544
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 practicejam; import java.io.*; /** * * @author GreenTie */ public class PracticeJam { // public int[] compute(int[][] input){ // int[] result=new int[input.length]; // for(int i=0;i<input.length;i++) // result[i]=compute(input[0],input[1]); // return result; // } public static int compute(int n, int k) { if ((k & 0x01) == 0) { return 0; } else { int x = (1 << n); return (k + 1) % x == 0 ? 1 : 0; } } public static final String[] Result = {"OFF", "ON"}; public static final char[] DicB = {'Y', 'H', 'E', 'S', 'O', 'C', 'V', 'X', 'D', 'U', 'I', 'G', 'L', 'B', 'K', 'R', 'Z', 'T', 'N', 'W', 'J', 'P', 'F', 'M', 'A', 'Q'}; public static final char[] DicA = {'y', 'h', 'e', 's', 'o', 'c', 'v', 'x', 'd', 'u', 'i', 'g', 'l', 'b', 'k', 'r', 'z', 't', 'n', 'w', 'j', 'p', 'f', 'm', 'a', 'q'}; public static final int[] Normal = {0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10}; public static final int[] Surprising = {0, 0, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 0, 0 }; public static String problemA(String G) { StringBuilder sb = new StringBuilder(G.length()); for (int i = 0; i < G.length(); i++) { char x = G.charAt(i); if (x >= 'A' && x <= 'Z') { sb.append(DicB[x - 'A']); } else if (x >= 'a' && x <= 'z') { sb.append(DicA[x - 'a']); } else { sb.append(x); } } return sb.toString(); } public static int problemB(String G){ int result=0; String[] temp=G.split(" "); int N=Integer.parseInt(temp[0]); int S=Integer.parseInt(temp[1]); int p=Integer.parseInt(temp[2]); int[] scr=new int[N]; int count=N; int suprise=S; for(int i=0;i<N;i++){ scr[i]=Integer.parseInt(temp[i+3]); if(scr[i]>=29){result++;count--;} else if(scr[i]==1){count--;if(p<=1)result++;} else if(scr[i]==0){count--;if(p==0)result++;} else if(Normal[scr[i]]>=p){ result++;count--; } else{ if(Surprising[scr[i]]>=p&&suprise>0){ result++; count--; suprise--; } } } return result; } /** * @param args the command line arguments */ public static void mainA(String[] args) { String[] x = {"ejp mysljylc kd kxveddknmc re jsicpdrysi", "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd", "de kr kd eoya kw aej tysr re ujdr lkgc jv"}; for (String G : x) { System.out.println(problemA(G)); } } public static void main(String[] args) throws FileNotFoundException, IOException { BufferedReader br = new BufferedReader(new FileReader(new File("B-small-attempt0.in"))); int x = Integer.parseInt(br.readLine()); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= x; i++) { //String[] temp=br.readLine().trim().split(" "); sb.append("Case #").append(i).append(": ").append(problemB(br.readLine())); sb.append('\n'); //sb.append("Case #").append(i).append(": ").append(Result[compute(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]))]).append('\n'); //System.out.printf("Case #%d: %s\n",i,Result[compute(Integer.parseInt(temp[0]),Integer.parseInt(temp[1]))]); } System.setOut(new PrintStream(new File("B-small-attempt0.out"))); System.out.print(sb.toString()); br.close(); } }
0
734
A12852
A11931
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.Scanner; import java.util.regex.Pattern; public class ProblemB { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { Scanner input = new Scanner(new FileReader("B-small-attempt1.in")); PrintWriter output = new PrintWriter(new FileWriter("output2.txt")); int numberCases = input.nextInt(); String data = input.nextLine(); for (int i = 0; i < numberCases; i++) { output.print("Case #" + (i + 1) + ": "); data = input.nextLine(); String[] intS = Pattern.compile(" ").split(data); int[] numbers = new int[intS.length]; for (int j = 0; j < intS.length; j++) { numbers[j] = Integer.parseInt(intS[j]); } int numberGooglers = numbers[0]; int surprising = numbers[1]; int p = numbers[2]; int count = 0; //System.out.print("N "); for (int j = 0; j < numberGooglers; j++) { if (((numbers[j + 3] / 3.0)) > (p - 1)) { //System.out.print(numbers[j + 3] + " "); count++; } } //System.out.print("S "); if (surprising > 0) { for (int j = 0; j < numberGooglers && surprising != 0; j++) { if ((numbers[j + 3] / 3.0) <= (p - 1) && (numbers[j + 3] / 3.0) >= (p - 2)) { if (Math.floor(((numbers[j + 3] - p) / 2.0)) >= (p - 2) && (numbers[j + 3] - p) >= 0) { //System.out.print(numbers[j + 3] + " "); count++; surprising--; } } } } //System.out.println("Counter " + count); output.print(count); output.print("\n"); } output.flush(); output.close(); input.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } }
0
735
A12852
A11726
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 round02; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Scanner; /** * Problem B. Dancing With the Googlers * * 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. ample 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 * @author chmin * */ public class DancingWithGooglers { static class ScoreHolder { int s1, s2, s3; int remainder ; boolean passed = false; ScoreHolder (int total){ s1 = s2 = s3 = total /3 ; remainder = total % 3; } private String asString(int v1, int v2, int v3){ return "" + v1 + " " + v2 + " " + v3; } public String [] toScores(int p, boolean allowSuprising ) { ArrayList<String> list = new ArrayList<>(); int v1 = s1; int v2 = s2; int v3 = s3; if ( remainder == 0){ if ( v1 >= p ) list.add(asString(v1, v2, v3)); if ( v1 + 1 >= p && v3 > 0 && allowSuprising ) list.add(asString(v1+1, v2, v3-1)); } if ( remainder == 1 ){ if ( (v1+1) >= p ) list.add ( asString(v1+1, v2, v3)); } else if ( remainder == 2 ){ if ( v3+1 >= p ) { list.add(asString(v1, v2+1, v3+1)); } if ( v3+2 >= p && allowSuprising ) list.add( asString(v1, v2, v3+2)); } String [] result = new String [list.size()]; list.toArray(result); return result; } } static List<ScoreHolder []> readFile ( InputStream in) throws IOException{ ArrayList<ScoreHolder []> list = new ArrayList<>(); StringBuilder sb = new StringBuilder(); Scanner scanner = new Scanner(in); int T = scanner.nextInt(); for ( int i = 0 ;i < T ; i++){ int N = scanner.nextInt(); // the number of googlers int S = scanner.nextInt(); // the number of surprising triplets of scores int P = scanner.nextInt(); // min score // System.out.print ("N(" + N + // "), S(" + S + // "), p(" + P + // ") "); ScoreHolder [] sh = new ScoreHolder[N]; for( int k = 0 ; k < N ; k++){ sh[k] = new ScoreHolder(scanner.nextInt()); } int cnt = 0; for ( int k = 0 ; k < sh.length ; k++){ if ( sh[k].toScores(P, false).length > 0 ){ cnt ++ ; sh[k].passed = true; } } if ( S > 0 ){ int cntS = S; String [] vals = null; for( int k = 0 ; k < sh.length ; k ++ ){ if ( sh[k].passed ) continue; vals = sh[k].toScores(P, true); if ( vals.length > 0 ){ cnt ++ ; cntS -- ; } if ( cntS == 0)break; } } // System.out.println("CASE #" + (i+1) + ": " + cnt ); sb.append("Case #" + (i+1) + ": " + cnt + System.getProperty("line.separator")); list.add(sh); } BufferedWriter bw = new BufferedWriter(new FileWriter("R2-small.out")); bw.write(sb.toString()); bw.close(); return list; } private static void dump(String[] vals) { for (int j = 0; j < vals.length; j++) { System.out.print(" => " + vals[j]); } } /** * @param args */ public static void main(String[] args) { try { List<ScoreHolder []> lines = readFile( DancingWithGooglers.class.getResourceAsStream("R2-small.in") ); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
736
A12852
A12914
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.menzus.gcj._2012.qualification.b; import com.menzus.gcj.common.OutputProducer; public class BOutputProducer implements OutputProducer<BInput, BOutputEntry> { @Override public BOutputEntry produceOutput(BInput input) { int avaragesAboveLimit = 0; int avaragesBelowLimitIfTheyWereSuprising = 0; for (int i = 0; i < input.getGooglerScores().length; i++) { if (maximumNotSurprisingScoreOfTotalScore(input.getGooglerScores()[i]) >= input.getLimit()) { avaragesAboveLimit++; } else if (maximumSurprisingScoreOfTotalScore(input.getGooglerScores()[i]) >= input.getLimit()) { avaragesBelowLimitIfTheyWereSuprising++; } } BOutputEntry outputEntry = new BOutputEntry(); outputEntry.setMaximumGooglersNumber(avaragesAboveLimit + Math.min(avaragesBelowLimitIfTheyWereSuprising, input.getSurprisingTripletsNumber())); return outputEntry; } private int maximumNotSurprisingScoreOfTotalScore(int totalScore) { if (totalScore % 3 == 0) { return totalScore / 3; } else { return totalScore / 3 + 1; } } private int maximumSurprisingScoreOfTotalScore(int totalScore) { int maximumNotSurprisingScoreOfTotalScore = maximumNotSurprisingScoreOfTotalScore(totalScore); if (maximumNotSurprisingScoreOfTotalScore == 0) { return maximumNotSurprisingScoreOfTotalScore; } else { return maximumNotSurprisingScoreOfTotalScore + 1; } } }
0
737
A12852
A10576
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class Round { private static Logger log = LoggerFactory.getLogger(Round.class); private final List<Integer> totals; private final Memory memory; public Round(List<Integer> totals, Memory memory) { this.totals = totals; this.memory = memory; } public int run(int s, int p) { int count = 0; for (Integer total : totals) { List<Triplet> triplets = memory.data.get(total); if (triplets.isEmpty()) { throw new IllegalStateException(); } log.debug("for total: {} triplets are: {}", total, triplets); boolean has = false; boolean hasNotSurprising = false; for (Triplet triplet : triplets) { if (triplet.hasAtLeast(p)) { has = true; if (!triplet.surprising) { hasNotSurprising = true; } } } log.debug("--> has: {} hasNotSurprising: {}", has, hasNotSurprising); if (has) { if (hasNotSurprising) { ++count; } else { if (s > 0) { --s; ++count; } } } } return count; } }
0
738
A12852
A11770
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qualification.googlersdance; import java.util.List; import util.BaseResolver; import util.Util; /** * * @author bohmd */ public class GooglersDance extends BaseResolver { int cases; public static void main(String[] args) throws Exception { if (args.length == 0 || args[0].equals("")) { throw new Exception("The first parameter must be the input file name without extension."); } else { new GooglersDance(args[0]).resolve(); } } public GooglersDance(String file) { super(file); } @Override protected void executeLine(String line) throws Exception { if (getLineNum() == 0) { cases = Util.getInt(line); } else { List<Integer> lineCase = Util.getIntList(line); write(resolveCase(lineCase.get(0), lineCase.get(1), lineCase.get(2), lineCase.subList(3, lineCase.size()))); } } protected String resolveCase(int dancersCount, int supricesCount, int p, List<Integer> points) { int count=0; for(Integer point: points) { if(point+3>3*p) { count++; } else if(point+5>3*p && supricesCount>0 && point>0) { supricesCount--; count++; } } return " "+count; } }
0
739
A12852
A10706
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 test; import javax.print.attribute.standard.DateTimeAtCompleted; import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.sql.Array; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Properties; import java.util.Scanner; public class A { public static int getDiff(int x , int y , int z , int l){ if(y>=l && z>=l) return 0; ArrayList<Integer> arr = new ArrayList<>(); arr.add(Math.abs(x-y)); arr.add(Math.abs(x-z)); arr.add(Math.abs(y-z)); return Collections.max(arr); } public static void main(String[] args) throws Exception { Scanner in = new Scanner(new File("B-small-attempt3.in")); PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("bout.txt"))); int repeats=0; int numTests; int t; int limit,ex,k; repeats = in.nextInt(); for(int j=1;j<=repeats;j++) { // System.out.print("Case #"+j+":"); out.print("Case #" + (j) + ": "); numTests = in.nextInt(); ex = in.nextInt(); limit = in.nextInt(); int res=0; for(int i=0;i<numTests;i++){ t = in.nextInt(); if(t>=limit){ if(limit != 0 && t/limit==3) res++; else{ int rMain =t-limit; int r1 = rMain/2; int r2 = t-limit-r1; int fin = getDiff(limit,r1,r2,limit); if(fin<2) res++; else if(fin==2 && ex>0){ res++; ex--; } } } } //System.out.println(" "+res); System.out.println("Case #" + (j) + ": " + res); } /* try { BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("B-small-attempt0.in"))); // int t = Integer.parseInt(in.readLine()); int repeats = Integer.parseInt(in.readLine()); PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream("bout.txt"))); for (int i = 1; i <= repeats; i++) { //String res = ""; int numTests = (in.read()); int ex = in.read(); int limit = in.read(); int res=0; // String input = in.readLine(); for(int j=0;j<numTests;j++){ int t = in.read(); if(t>limit){ if(t%limit==0) res++; else{ int rMain =t-limit; int r1 = rMain/2; int r2 = t-limit-r1; int fin = getDiff(limit,r1,r2,limit); if(fin<2) res++; else if(fin==2 && ex>0){ res++; ex--; } } } } out.println("Case #" + (i) + ": " + res); } out.close(); }catch(Exception e){ e.printStackTrace(); }*/ } }
0
740
A12852
A13021
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.google.codejam.googlers; import java.util.List; /** * Main class used for DancingWithGooglers. * @author Sushant */ public class DancingWithGooglers { /** * Main method from where application start execution. * * @param args String [] */ public static void main(final String[] args) { if (args.length != 1) { System.out.println("Problem with the command used for execution"); System.out.println("Usage: java com.google.codejam.googlers.DancingWithGooglers <Path to input file>"); System.exit(1); } final List<TestCase> testCases = InputReader.prepareTestCases(args[0]); if (testCases != null && testCases.size() != 0) { long startTime = System.currentTimeMillis(); System.out.println("Test Cases execution start time " + startTime); for (TestCase testcase : testCases) { executeTestCase(testcase); } OutputRecorder.generateTestReport(testCases, args[0] + ".out"); long endTime = System.currentTimeMillis(); System.out.print("Test cases execution end time " + endTime); System.out.println("Total Execution Time " + (endTime - startTime) + " milliseconds"); } } /** * Method to execute test cases. * * @param testcase TestCase */ private static void executeTestCase(final TestCase testcase) { int bestResultCount = 0; final int noOfGooglers = testcase.getNoOfGooglers(); int noSurpriseScores = testcase.getNoOfurprisingTriplets(); final int bestResult = testcase.getBestResult(); final int[] scores = testcase.getScores(); for (int i = 0; i < noOfGooglers; i++) { int[] triplets = new int[3]; int score = scores[i]; if(score == 0) { triplets[0] = triplets[1] = triplets[2] = 0; } else if (score % 3 == 0) { int tempScore = score / 3; triplets[0] = tempScore; if (noSurpriseScores != 0 && (Math.abs(triplets[0] - bestResult) == 1 )) { triplets[1] = tempScore + 1; triplets[2] = tempScore - 1; noSurpriseScores = noSurpriseScores - 1; } else { triplets[1] = tempScore; triplets[2] = tempScore; } } else { triplets[0] = score / 3; int remainingScore = score - triplets[0]; triplets[1] = remainingScore / 2; triplets[2] = score - (triplets[0] + triplets[1]); if(noSurpriseScores != 0) { if((triplets[1] != 10 && triplets[2] != 10) && (Math.abs(triplets[2] - bestResult)== 1)) { triplets[1] = triplets[1] + 1; triplets[2] = triplets[2] - 1; noSurpriseScores = noSurpriseScores - 1; } } } boolean isBest = isBestTriplet(triplets, bestResult); if(isBest) { bestResultCount = bestResultCount + 1; } } testcase.setOutput(new TestResult(bestResultCount)); } /** * Method to check whether given triplet is best or not. * @param triplets int [] * @param bestResult int * @return boolean */ private static boolean isBestTriplet(final int[] triplets, final int bestResult) { for(int i = 0; i < triplets.length; i++) { if(triplets[i] >= bestResult) { return true; } } return false; } }
0
741
A12852
A11637
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedInputStream; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.Writer; public class ProblemB { public static void main(String[] args) { try { File input = new File("B-small-attempt1.in"); Writer fin = null; File output = new File("b2.txt"); fin = new BufferedWriter(new FileWriter(output)); FileInputStream fis = null; BufferedInputStream bis = null; DataInputStream dis = null; String out = ""; fis = new FileInputStream(input); bis = new BufferedInputStream(fis); dis = new DataInputStream(bis); int t = Integer.parseInt(dis.readLine()); for (int i = 0; i < t; i++) { out += "Case #" + (i + 1) + ": "; String h = dis.readLine(); String[] a = h.split(" "); int result = 0; int n = Integer.parseInt(a[0]); int s = Integer.parseInt(a[1]); int p = Integer.parseInt(a[2]); for (int j = 3; j < a.length; j++) { int v1 = Integer.parseInt(a[j]); int v2 = v1 / 3; int v3 = v1 % 3; if ((v2 >= p) || (v3 >= 1 && v2 + 1 >= p)) { result++; } else if (v3 == 2 && v2 + 2 >= p && s > 0) { result++; s--; } else if (v3 == 0 && v2 > 0 && v2 + 1 >= p && s > 0) { result++; s--; } } out += result; fin.write(out); out = "\n"; } fis.close(); bis.close(); dis.close(); fin.close(); } catch (Exception ex) { } } }
0
742
A12852
A10940
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class codejamp2 { public static char[] map; public static void main(String[] args) throws IOException{ readFile(); } public static String getResult(String input){ int resultInt = 0; String[] splitResult = input.split(" "); int dancerCount = Integer.parseInt(splitResult[0]); int suprising = Integer.parseInt(splitResult[1]); int max = Integer.parseInt(splitResult[2]); for(int i = 3; i < dancerCount + 3; i++){ int current = Integer.parseInt(splitResult[i]); int ave = current/3; int remain = current - 3*ave; int currentmax = ave + remain; if(remain == 0 && (max - currentmax == 1) && current!= 0){ if(suprising > 0){ suprising--; resultInt++; } } if(currentmax >= max){ if(remain<=1){ resultInt++; } else if(remain == 2){ if(max - ave<=1){ resultInt++; } else if(suprising > 0){ suprising--; resultInt++; } } } } return ""+resultInt; } public static void readFile() throws IOException{ FileWriter fstream = new FileWriter("out.txt"); BufferedWriter out = new BufferedWriter(fstream); FileReader input = new FileReader("in.txt"); BufferedReader bufRead = new BufferedReader(input); String line = bufRead.readLine(); String current = getResult(line); int i = 1; out.write("Case #" + i + ": " + current); line = bufRead.readLine(); while (line != null){ i++; System.out.println("Case #" + i + ": " + getResult(line)); out.write('\n' + "Case #" + i + ": " + getResult(line)); line = bufRead.readLine(); } bufRead.close(); out.close(); } }
0
743
A12852
A13180
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 reverse { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc=new Scanner(System.in); int m=sc.nextInt(); int i; int j; for(i=1;i<=m;i++) { int n=sc.nextInt(); int s=sc.nextInt(); int p=sc.nextInt(); int count=0; for(j=0;j<n;j++) { int a=sc.nextInt(); if(3*p-2<=a && p<=a) { count++; } else if(3*p-4<=a && p<=a && s>0) { s--; count++; } } System.out.println("Case #"+i+": "+count); } } }
0
744
A12852
A12669
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.Arrays; import java.util.InputMismatchException; import java.util.ArrayList; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author lwc626 */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; MyInputReader in = new MyInputReader(inputStream); MyOutputWriter out = new MyOutputWriter(outputStream); B_Dancing_With_the_Googlers solver = new B_Dancing_With_the_Googlers(); solver.solve(1, in, out); out.close(); } } class B_Dancing_With_the_Googlers { public void solve(int testNumber, MyInputReader in, MyOutputWriter out) { int test = in.nextInt() ; for (int tc = 0; tc < test; tc++) { int n = in.nextInt() ; int s = in.nextInt() ; int p = in.nextInt() ; int[] A = new int[ n ]; ArrayList<Pair<Integer,Integer>> ap = new ArrayList<Pair<Integer, Integer>>(); for( int i = 0 ; i < n ; i ++ ){ A[i] = in.nextInt() ; if( A[i] % 3 == 0 ){ ap.add( Pair.makePair( A[i] / 3 , A[i] >= 3 ? A[i] / 3 + 1 : -1 )); } else if( A[i] % 3 == 1 ){ ap.add( Pair.makePair( (A[i] + 2)/ 3 , A[i] >= 4 ? (A[i]+2) / 3 : -1 ) ); }else{ ap.add( Pair.makePair( (A[i] + 1)/ 3 , A[i] >= 2 ? (A[i] + 4)/3 : -1 ) ); } } //out.printLine( ap.toString()); int [][] dp = new int[ n+1 ][ s+1 ]; for( int[] o : dp ) Arrays.fill( o , -1 ); dp[0][0] = 0 ; for( int i = 0 ; i < n ; i ++ ){ for( int j = 0 ; j <= s ; j ++ ) if( dp[i][j] != -1 ){ update( dp , i+1 , j , dp[i][j] + (ap.get(i).first >= p ? 1 : 0) ); if(j+1<=s && ap.get(i).second != -1) update( dp , i+1 , j+1 , dp[i][j] + (ap.get(i).second >= p ? 1 : 0 ) ); } } //for( int[] o : dp ) IOUtils.printIntArrays( out, o ); out.printLine( "Case #" + (tc+1) +": "+ dp[n][s] ); } } private void update(int[][] dp, int i, int j, int v) { if( dp[i][j] == -1 || dp[i][j] < v ) dp[i][j] = v ; } } class MyInputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public MyInputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int nextInt(){ return readInt() ; } public static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } class MyOutputWriter { private final PrintWriter writer; public MyOutputWriter(OutputStream outputStream) { writer = new PrintWriter(outputStream); } public MyOutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object...objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void printLine(Object...objects) { print(objects); writer.println(); } public void close() { writer.close(); } } class Pair<U, V> implements Comparable<Pair<U, V>> { public final U first; public final V second; public static<U, V> Pair<U, V> makePair(U first, V second) { return new Pair<U, V>(first, second); } private Pair(U first, V second) { this.first = first; this.second = second; } public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Pair pair = (Pair) o; return !(first != null ? !first.equals(pair.first) : pair.first != null) && !(second != null ? !second.equals(pair.second) : pair.second != null); } public int hashCode() { int result = first != null ? first.hashCode() : 0; result = 31 * result + (second != null ? second.hashCode() : 0); return result; } public String toString() { return "(" + first + "," + second + ")"; } public int compareTo(Pair<U, V> o) { int value = ((Comparable<U>)first).compareTo(o.first); if (value != 0) return value; return ((Comparable<V>)second).compareTo(o.second); } }
0
745
A12852
A12095
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 cjam; import java.io.*; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Administrator */ public class Cjam { /** * @param args the command line arguments */ public BufferedWriter output; public Scanner input; public int T; public Cjam() { try { input = new Scanner(new FileReader("B-small-attempt0.in")); output = new BufferedWriter(new FileWriter(new File("b.out"))); } catch (IOException ex) { Logger.getLogger(Cjam.class.getName()).log(Level.SEVERE, null, ex); } T = input.nextInt(); } public static void main(String[] args) { // TODO code application logic here Cjam c = new Cjam(); for(int i = 1; i <= c.T ; i++) { int N,S,p,ti[],b1,b2; int max1=0,max2=0,max3=0,max=0; N = c.input.nextInt(); S = c.input.nextInt(); p = c.input.nextInt(); ti = new int[N]; for(int j=0 ; j < N ; j++) { ti[j] = c.input.nextInt(); } if(p > 1) { b1 = 3*(p-1) - 1; b2 = 3*(p-1) ; for(int k = 0 ; k < N ; k++ ) { if( ti[k] > b2 ) { max1++; } else if( (ti[k]==b1) || (ti[k]==b2) ) { max2++; } } if( max2 > S ) { max = max1 + S; } else { max = max1 + max2; } } else if(p==1) { for(int k = 0 ; k < N ; k++ ) { if(ti[k] >= 1) { max1++; } max= max1; } } else if(p==0) { max = N; } try { c.output.append("Case #"+i+": "+max); if(i != c.T) c.output.newLine(); } catch (IOException ex) { Logger.getLogger(Cjam.class.getName()).log(Level.SEVERE, null, ex); } } try { c.output.close(); } catch (IOException ex) { Logger.getLogger(Cjam.class.getName()).log(Level.SEVERE, null, ex); } c.input.close(); } }
0
746
A12852
A12084
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.*; class B{ public static void main(String... arg){ Scanner sc = new Scanner(System.in); int cases = sc.nextInt(); for(int caseNo = 1; caseNo <= cases; caseNo++ ){ int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int[] t = new int[N]; int n = 0; for(int i = 0; i < N; i++) t[i] = sc.nextInt(); if(p == 0) System.out.println("Case #" + caseNo + ": " + N); else{ for(int i = 0; i < N; i++){ int tmp = ((int)(t[i]/3)); if(t[i] == 0) tmp = 0; else{ if(t[i] % 3 != 0) tmp = tmp + 1; } if(tmp >= p) n++; } if (S == 0) System.out.println("Case #" + caseNo + ": " + n); else{ Arrays.sort(t); for(int i = N-n-1; i >= 0 && S > 0; i--){ int tmp = ((int)(t[i]/3)); if(t[i] == 0) tmp = 0; else{ int rem = t[i] % 3; if(rem == 2 && t[i] <= 28) tmp = tmp + 2; else if(rem == 0 && t[i] <= 29) tmp = tmp + 1; else continue; } if(tmp >= p) { n++; S--; } } System.out.println("Case #" + caseNo + ": " + n); } } } } }
0
747
A12852
A11159
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 codjamdoce; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class DancingGooglers { private final File file; private int ncases; private DanceContest[] contests; private int[] result; public DancingGooglers(File file) { this.file = file; } public void init() throws Exception { int numberOfParticipantsIndex = 0; int numberOfSurprisingScoresIndex = 1; int minScoreIndex = 2; BufferedReader reader = new BufferedReader(new FileReader(file)); try { String line; int lineNumber = 0; int contestsCount = 0; while ((line = reader.readLine()) != null) { if (lineNumber == 0) { ncases = Integer.valueOf(line.trim()); contests = new DanceContest[ncases]; result = new int[ncases]; } else { StringTokenizer tokenizer = new StringTokenizer(line.trim(), " "); int index = 0; Googler[] participants = null; int surprisingScores = 0; int minScore = 0; int participantsCount = 0; while (tokenizer.hasMoreElements()) { String next = tokenizer.nextToken(); if (index == numberOfParticipantsIndex) { participants = new Googler[Integer.valueOf(next)]; } else if (index == numberOfSurprisingScoresIndex) { surprisingScores = Integer.valueOf(next); } else if (index == minScoreIndex) { minScore = Integer.valueOf(next); } else { Googler googler = new Googler(Integer.valueOf(next), minScore); participants[participantsCount] = googler; participantsCount++; } index++; } if (participants != null && surprisingScores >= 0 && minScore >= 0) { contests[contestsCount] = new DanceContest(participants, surprisingScores); contestsCount++; } } lineNumber++; } } finally { reader.close(); } } public void processContests() { int count = 0; for (DanceContest contest : contests) { result[count] = contest.getBestResultParticipants(); count++; } } public void printResult() throws IOException { int count = 0; File outfile = new File("out"); if (outfile.exists()) outfile.delete(); outfile.createNewFile(); FileOutputStream out = new FileOutputStream(outfile); try { for (int r : result) { if (count == ncases - 1) { out.write(MessageFormat.format("Case #{0}: {1}", (count + 1), r).getBytes()); } else { out.write(MessageFormat.format("Case #{0}: {1}\n", (count + 1), r).getBytes()); } count++; } } finally { out.close(); } } private static class DanceContest { private final Googler[] participants; private final int surprisingScores; public DanceContest(Googler[] participants, int surprisingScores) { this.participants = participants; this.surprisingScores = surprisingScores; } private int getBestResultParticipants() { int surprisingScoresLeft = surprisingScores; int result = 0; for (Googler participant : participants) { participant.getBestScoreTable(surprisingScoresLeft > 0); boolean haveSurprisingScore = participant.haveSurprisingScore(); if (participant.hasBestResult(participant.getTableScore())) { if (!haveSurprisingScore) { result++; } else if (haveSurprisingScore && surprisingScoresLeft > 0) { result++; } } if (haveSurprisingScore) { surprisingScoresLeft--; } } return result; } } private static class Googler { enum ScoreType { LESSER, GREATER, EQUAL } private final int score; private final int MAX_SCORE = 30; private List<Integer> tableScore; private final int minScore; public Googler(int score, int minScore) { this.score = score; this.minScore = minScore; } public void getBestScoreTable(boolean canBeSurprising) { tableScore = new ArrayList<Integer>(); if (this.score == 0) { tableScore.add(0); tableScore.add(0); tableScore.add(0); return; } this.tableScore = calculateTable((getScore() * 10) / MAX_SCORE); if (!isValidTable(this.tableScore) || !hasBestResult(this.tableScore)) { int retry = 4; while (retry > 0) { if (retryTable(canBeSurprising, retry) && isValidTable(this.tableScore)) { break; } retry--; } } if (!isValidTable(this.tableScore)) { Integer[] array = this.tableScore.toArray(new Integer [tableScore.size()]); this.tableScore = new ArrayList<Integer>(); this.tableScore.add(array[0]); this.tableScore.add(array[1] - 1); this.tableScore.add(array[2] + 1); } if (!isValidTable(this.tableScore)) { System.out.println(); } return; } public boolean retryTable(boolean canBeSurprising, int retry) { int average = (getScore() * 10) / MAX_SCORE; if (retry == 6 && average > 2 && canBeSurprising) { List<Integer> table = calculateTable(average - 2); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } table = calculateTable(average - 2); Integer second = table.remove(1); Integer third = table.remove(1); second -=1; third +=1; table.add(second); table.add(third); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 6 && average > 1) { List<Integer> table = calculateTable(average - 1); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 5 && average > 2 && canBeSurprising) { List<Integer> table = calculateTable(average - 2); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 5 && average > 1) { List<Integer> table = calculateTable(average - 1); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 4 && canBeSurprising) { List<Integer> table = calculateTable(average + 2); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } table = calculateTable(average + 2); Integer second = table.remove(1); Integer third = table.remove(1); second -=1; third +=1; table.add(second); table.add(third); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 4 && average > 1) { List<Integer> table = calculateTable(average + 1); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 3 && canBeSurprising) { List<Integer> table = calculateTable(average + 2); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } table = calculateTable(average + 2); Integer second = table.remove(1); Integer third = table.remove(1); second -=1; third -=1; table.add(second); table.add(third); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } if (retry == 3 && average > 1) { List<Integer> table = calculateTable(average + 1); if (hasBestResult(table) && isValidTable(table)) { this.tableScore = table; return true; } } return false; } public List<Integer> calculateTable(int average) { List<Integer> table = new ArrayList<Integer>(); if (average * 3 == getScore()) { table.add(average); table.add(average); table.add(average); } else { ScoreType scoreType = firstScoreType(average); if (scoreType != null) { if (scoreType != null && scoreType == ScoreType.LESSER) { processLesser(average, table); } else if (scoreType == ScoreType.GREATER) { processGreater(average, table); } else { processEqual(average, table); } } else { scoreType = secondScoreType(average); if (scoreType != null) { if (scoreType == ScoreType.LESSER) { processLesser(average, table); } else if (scoreType == ScoreType.GREATER) { processGreater(average, table); } else { processEqual(average, table); } } } } return table; } private void processEqual(int average, List<Integer> table) { table.add(average); table.add(average + 1); table.add((getScore() - ((average + average)))); } private boolean hasBestResult(List<Integer> tableScore) { for (int score : tableScore) { if (score >= this.minScore) { return true; } } return false; } public void processGreater(int average, List<Integer> table) { table.add(average); table.add(average + 1); table.add((getScore() - ((average + 1) + average))); } public void processLesser(int average, List<Integer> table) { table.add(average); table.add(average - 1); table.add((getScore() - ((average - 1) + average))); } public ScoreType secondScoreType(int average) { int number = getScore() - ((average - 1) + average); boolean result = number - average <= 2; boolean lesser = result; number = getScore() - ((average + 1) + average); result = number - average <= 2; boolean greater = result; if (lesser) { return ScoreType.LESSER; } else if (greater) { return ScoreType.GREATER; } else { number = getScore() - ((average) + average); result = number - average <= 2; if (result) { return ScoreType.EQUAL; } return null; } } public ScoreType firstScoreType(int average) { int number = getScore() - ((average - 1) + average); number = number - average; boolean lesser = number == 1 || number == 0; number = getScore() - ((average + 1) + average); number = number - average; boolean greater = number == 1 || number == 0; if (lesser) { return ScoreType.LESSER; } else if (greater) { return ScoreType.GREATER; } else { number = getScore() - ((average) + average); boolean result = (number - average) == 0 || (number - average) == 1; if (result) { return ScoreType.EQUAL; } return null; } } public int getScore() { return this.score; } public List<Integer> getTableScore() { return this.tableScore; } public boolean haveSurprisingScore() { boolean result = false; outer: for (int s : tableScore) { for (int cs : tableScore) { if ((cs - s) == 2) { result = true; break outer; } if ((cs - s) > 2) { System.out.println(); } } } return result; } private boolean isValidTable(List<Integer> table) { boolean valid = true; int calculatedScore = 0; for (int s : table) { calculatedScore += s; } if (calculatedScore != score) { return false; } outer: for (int s : table) { for (int cs : table) { if ((cs - s) > 2) { valid = false; break outer; } } } return valid; } } public static void main(String[] args) throws Exception { if (args.length < 1) { System.out.println("Provide absolute path of input file"); } File file = new File(args[0]); if (file.isFile()) { DancingGooglers dancingGooglers = new DancingGooglers(file); dancingGooglers.init(); dancingGooglers.processContests(); dancingGooglers.printResult(); } } }
0
748
A12852
A12355
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileInputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; public class B { public static void main(String args[]) { try { String fileName = "C:\\Users\\Lenovo Z370\\Desktop\\gcj\\comp-2012\\B-small-attempt0.in"; BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); int t = Integer.parseInt(br.readLine()); for(int i=0; i<t; i++) { String[] vals = br.readLine().split("\\s+"); int n = Integer.parseInt(vals[0]); int s = Integer.parseInt(vals[1]); int p = Integer.parseInt(vals[2]); int[] scores = new int[n]; int tn=n+3; for(int j=3; j<tn; j++) { scores[j-3] = Integer.parseInt(vals[j]); } System.out.println("Case #" + (i+1) + ": " + (solve(n, s, p, scores))); } } catch(Exception e) { e.printStackTrace(); } } private static int solve(int n, int s, int p, int[] scores) { List<Triplet[]> list = new ArrayList<Triplet[]>(n); int sn = 0, fn = 0; for(int i=0; i<n; i++) { Triplet[] t = Triplet.getTriplets(scores[i], p); if(t != null) { list.add(t); if(t[1] != null) { sn++; } fn++; // System.out.print(scores[i] + "=[" + t[0] + " & " + t[1] + "]; "); } } // System.out.println(); long[] ca = new long[fn]; Arrays.fill(ca, 0); long c = computeCombination(sn, s); long mc = computeCombination(sn-1, s-1); int max = 0; // System.out.println("Combi: " + c); for(long i=0; i<c; i++) { int st = s; int lmax = 0; for(int j=0; j<fn; j++) { Triplet[] t = list.get(j); if(st > 0 && t[1] != null && ca[j] < mc) { ca[j]++; if(t[1] != null) { if(t[1].max >= p) lmax++; st--; // System.out.print(t[1] + " "); } else { if(t[0] != null && t[0].max >= p) lmax++; // System.out.print(t[0] + " "); } } else { if(t[0] != null && t[0].max >= p) lmax++; // System.out.print(t[0] + " "); } } if(lmax > max) { max = lmax; } // System.out.println(); } return max; } private static long computeCombination(int n, int r) { long nf = 1; for(int i=n; i>r; i--) { nf *= i; } int nmr = n-r; long nrf = 1; for(int i=nmr; i>1; i--) { nrf *= i; } return nf/nrf; } private static class Triplet { int total; int max; boolean isSurprise; int s1,s2,s3; public Triplet(int s1, int s2, int s3, boolean isSurprise) { this.total = s1+s2+s3; this.max = Math.max(s1, Math.max(s2, s3)); this.isSurprise = isSurprise; this.s1 = s1; this.s2 = s2; this.s3 = s3; } public static Triplet[] getTriplets(int s, int p) { int is = s/3; int rs = s%3; int s1 = is; int s2 = is; int s3 = is; Triplet res0 = null, res1 = null; int sm3 = s%3; if(sm3 == 2) { res0 = new Triplet(s1, s2+1, s3+1, false); if(s3+2 < 11) { res1 = new Triplet(s1, s2, s3+2, true); } } else if(sm3 == 1) { res0 = new Triplet(s1, s2, s3+1, false); if(s1-1 >0 && s2+1 < 11 && s3+1 <11) { res1 = new Triplet(s1-1, s2+1, s3+1, true); } } else { res0 = new Triplet(s1, s2, s3, false); if(s1-1 >0 && s3+1 <11) { res1 = new Triplet(s1-1, s2, s3+1, true); } } if((res0 == null || res0.max < p) && (res1 == null || res1.max <p)) { return null; } Triplet[] res = new Triplet[2]; if(res0 != null && res0.max >= p) res[0] = res0; if(res1 != null && res1.max >= p) res[1] = res1; return res; } public String toString() { return "(" + s1 + ", " + s2 + ", " + s3 + ")"; } } }
0
749
A12852
A13197
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Scanner; public class B { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub Scanner scan = new Scanner(new File("B-small-attempt0.in")); BufferedWriter out = new BufferedWriter(new FileWriter("B.out")); int t = scan.nextInt(); for (int i = 1; i <= t; i++) { int N = scan.nextInt(); int S = scan.nextInt(); int p = scan.nextInt(); int surpMin = p*3 - 4; int normMin = p*3 - 2; int ans = 0; for(int j = 0; j < N; j++){ int sum = scan.nextInt(); if(p==0){ ans++; } else if(sum >= normMin){ ans++; } else if((sum >= surpMin) && (p != 1 || sum > 0) && S > 0){ ans++; S--; } } out.write("Case #" + i + ": "+ ans + "\n"); } out.close(); } }
0
750
A12852
A12398
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 javax.swing.*; import javax.swing.JOptionPane.*; import java.awt.*; import java.awt.event.*; import java.io.*; import javax.swing.text.*; import java.io.File; import javax.swing.filechooser.FileFilter; import javax.swing.text.html.*; import java.util.Scanner; import java.util.StringTokenizer; class Dancings { public static void main(String args[]) { int jumlahN[]=new int[101]; int hasil[]=new int[101]; int i=0; int j=0; int k=0; int l=0; int il=0; int cok3=0; try{ // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("b.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line j=0; while ((strLine = br.readLine()) != null) { // Print the content on the console if(j==0) { i=Integer.parseInt(strLine); if(i>100) { i=100; } else if(i<1) { i=1; } System.out.println (i); } else { int jum=0; int panjangtext=strLine.length(); int posisi=0; //String isi=strLine.trim(); char arr[]=strLine.toCharArray(); Character n2=arr[0]; String s1=n2.toString(); int n= Integer.parseInt(s1); String tmp=""; for(l=2; l<panjangtext; l++) { if(arr[l]==' ') { break; } else { tmp=tmp+arr[l]; } } int s=Integer.parseInt(tmp); String tmp2=""; for(k=l+1; k<panjangtext; k++) { if(arr[k]==' ') { break; } else { tmp2=tmp2+arr[k]; } } int p=Integer.parseInt(tmp2); System.out.println("nilai n"+n); System.out.println(strLine); System.out.println("nilai s:"+s); System.out.println("nilai p:"+p); int m=1; tmp=""; while(m<=n) { for(k=k+1; k<panjangtext; k++) { if(arr[k]==' ') { break; } else { tmp=tmp+arr[k]; } } tmp=tmp.trim(); int tmp4=Integer.parseInt(tmp); jumlahN[m]=tmp4; tmp=" "; m++; } m=1; int p2=p*2; while(m<=n) { System.out.println("nilai m :"+m+" :"+jumlahN[m]); int cok2=jumlahN[m]; int jos=cok2-p2; int param=p-2; if(jos>=param) { System.out.println("Masuk 1"); jum++; } else if(cok2>0 && s>0) { cok3=cok2-p; int p3=cok3/2; if(p3>=param) { jum++; s--; } System.out.println("Masuk 2"); } m++; } hasil[j]=jum; } //Close the input stream j++; } in.close(); } catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } try { File makefile= new File("resultdancing.txt"); FileWriter fwrite= new FileWriter(makefile); PrintWriter pw=new PrintWriter(fwrite); for(il=1; il<=i; il++) { pw.println("Case #"+(il)+": "+hasil[il]+"\n"); System.out.println("case #"+(il)+": "+hasil[il]+"\n"); } fwrite.flush(); fwrite.close(); } catch(IOException e) { e.printStackTrace(); } } }
0
751
A12852
A10870
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; public class SurprisingTripletScorer { private int numGooglers; private int numSurprisingScores; private final int minScore; private int numPossibleSurprising; public SurprisingTripletScorer(int n, int s, int p) { this.numGooglers = n; this.numSurprisingScores = s; this.minScore = p; numPossibleSurprising = 0; } /** * @param args */ public static void main(String[] args) { String[] input = null; try { input = readInput(args); } catch (IOException e) { } int cases = Integer.parseInt(input[0]); for (int i = 1; i <= cases; i++) { String[] line = input[i].split(" "); int N = Integer.parseInt(line[0]); int S = Integer.parseInt(line[1]); int p = Integer.parseInt(line[2]); SurprisingTripletScorer sts = new SurprisingTripletScorer(N, S, p); int[] scores = new int[N]; for (int j = 0; j < N; j++) { scores[j] = Integer.parseInt(line[j+3]); } int max = sts.maxGooglersWithHighScores(scores); System.out.println("Case #"+i+": "+max); } } private int maxGooglersWithHighScores(int[] totalScores) { int runningTotal = 0; List<Integer> list = new ArrayList<Integer>(); for (int ts : totalScores) { list.add(ts); } Collections.sort(list); for (Integer i : list) { // Find possible score outcome, check if it contains any number >=minScore if (containsHighScore(i)) { runningTotal++; } } return runningTotal; } private boolean containsHighScore(int totalScore) { int mod = totalScore % 3; if (totalScore == 0) { if (minScore > 0) return false; else if (minScore == 0) return true; } if (mod == 0) { if ((((double)totalScore)/3) >= minScore) { return true; } else if ((((double)totalScore)/3+1) >= minScore && numSurprisingScores > 0) { numSurprisingScores--; return true; } } else if (mod == 1) { if (Math.ceil(((double)totalScore)/3) >= minScore) { numPossibleSurprising++; return true; } } else { if (Math.floor(((double)totalScore)/3) >= minScore || Math.ceil(((double)totalScore)/3) >= minScore) { numPossibleSurprising++; return true; } else if ((Math.ceil(((double)totalScore)/3)+1) >= minScore && numSurprisingScores > 0) { numSurprisingScores--; return true; } } numPossibleSurprising++; return false; } public static String[] readInput(String[] args) throws IOException { String[] str = new String[101]; int numStrings = 0; // Buffer the input data BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); // Read the data and store in a string array while (in.ready()) { str[numStrings] = in.readLine(); numStrings++; } in.close(); return str; } }
0
752
A12852
A10137
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package template; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; public abstract class Template { static BufferedReader in; static PrintWriter out; public static void init(String problemName) throws Exception { in = new BufferedReader(new FileReader(problemName + ".in")); out = new PrintWriter(new FileWriter(problemName + ".out"), true); } public static String readString() { try { return in.readLine().trim(); } catch (Exception e) { throw new RuntimeException(); } } public static String[] readStringArray() { return readString().split("\\s"); } public static int readInt() { return Integer.parseInt(readString()); } public static double readDouble() { return Double.parseDouble(readString()); } public static int[] readIntArray() { String[] s = readStringArray(); int[] r = new int[s.length]; for (int i = 0; i < r.length; i++) { r[i] = Integer.parseInt(s[i]); } return r; } public static long[] readLongArray() { String[] s = readStringArray(); long[] r = new long[s.length]; for (int i = 0; i < r.length; i++) { r[i] = Long.parseLong(s[i]); } return r; } public static String[][] readStringArray(int lines) { String[][] r = new String[lines][]; for (int i = 0; i < lines; i++) { r[i] = readStringArray(); } return r; } public static int[][] readIntArray(int lines) { int[][] r = new int[lines][]; for (int i = 0; i < lines; i++) { r[i] = readIntArray(); } return r; } public static double[][] readDoubleArray(int lines) { double[][] r = new double[lines][]; for (int i = 0; i < lines; i++) { r[i] = readDoubleArray(); } return r; } public static double[] readDoubleArray() { String[] s = readStringArray(); double[] r = new double[s.length]; for (int i = 0; i < r.length; i++) { r[i] = Double.parseDouble(s[i]); } return r; } public static void write(String s) { out.println(s); System.out.println(s); } public static void write(String[] s) { String r = ""; for (String t : s) r += t + " "; write(r.trim()); } public static void write(int[] i) { String s = ""; for (int t : i) s += t + " "; write(s.trim()); } public static void write(int[][] i) { for (int[] t : i) write(t); } public static void write(String[][] i) { for (String[] t : i) write(t); } public static void write(double[][] i) { for (double[] t : i) write(t); } public static void write(double[] i) { String s = ""; for (double t : i) s += t + " "; write(s.trim()); } }
0
753
A12852
A10921
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public abstract class Task { private String inputFileName; private BufferedReader in; private PrintWriter out; public Task(String[] args) { inputFileName = args[0]; } public void execute() throws IOException { File f = new File(inputFileName); in = new BufferedReader(new FileReader(f)); catchInputData(); in.close(); processInputData(); f = new File(inputFileName.substring(0, inputFileName.length() - 2) + "out"); f.createNewFile(); out = new PrintWriter(new BufferedWriter(new FileWriter(f))); generateOutputFile(); out.flush(); out.close(); } protected abstract void generateOutputFile() throws IOException; protected abstract void processInputData(); protected abstract void catchInputData() throws IOException; protected String readLine() throws IOException { return in.readLine(); } protected void writeLine(String line) throws IOException { out.println(line); } }
0
754
A12852
A10178
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.StringTokenizer; import java.lang.Math; public class qualifycodejamB{ public static int surprisePVal(int score){ if(score < 4){ if(score == 0){ return 0; }else if(score == 1){ return 1; }else{ return 2; } } double dscore = (double) score; if((dscore % 3) == 1){ return (int)Math.ceil(dscore/3); } else{ return ((int)Math.ceil(dscore/3) + 1); } } public static int bestVal(int score){ if(score < 4){ if(score == 0){ return 0; }else{ return 1; } } double dscore = (double)score; return (int)Math.ceil(dscore/3); } public static int process_score(int cscore, int ttl_surp, int surp, int pval){ int returnval = 0; int currentp = bestVal(cscore); if(currentp >= pval){ return 1; } int bestp = surprisePVal(cscore); if (bestp >= pval && ttl_surp > surp){ return 3; } return returnval; } public static void main(String[] args){ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String x = null; String linein = null; int totalcases = 0; int ttl_scores = 0; int ttl_surprises = 0; int surprise_count = 0; int pval = 0; int pcount = 0; int currentscore = 0; int scorecount = 0; int counter = 1; int process_return = 0; try{ x = br.readLine(); totalcases = Integer.parseInt(x); while( (linein = br.readLine()) != null){ surprise_count = 0; pcount = 0; scorecount = 0; StringTokenizer st = new StringTokenizer(linein); ttl_scores = Integer.parseInt(st.nextToken()); ttl_surprises = Integer.parseInt(st.nextToken()); pval = Integer.parseInt(st.nextToken()); while(scorecount < ttl_scores){ currentscore = Integer.parseInt(st.nextToken()); process_return = process_score(currentscore,ttl_surprises,surprise_count,pval); if ((process_return & 1) == 1){ pcount++; } if (process_return == 3){ surprise_count++; } scorecount++; } System.out.print("Case #" + (counter) + ": "+ pcount); //System.out.println(" debug: return val: "+process_return+"; used surprises: " + surprise_count + "/"+ttl_surprises); System.out.println(); counter++; } } catch (IOException e) { e.printStackTrace(); } } }
0
755
A12852
A11522
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.is; /** * Created with IntelliJ IDEA. * User: ofer * Date: 4/13/12 * Time: 8:47 PM * To change this template use File | Settings | File Templates. */ public interface Test { /** Runs the test on the given input */ public void run(String input); /** Returns the output of the test */ public String getOutput(int testNum); }
0
756
A12852
A10508
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.PrintWriter; import java.io.FileWriter; import java.util.*; public class B { public B( String fn) { try{ BufferedReader r = new BufferedReader( new FileReader( fn + ".in")); PrintWriter w = new PrintWriter( new FileWriter( fn + ".out")); int t = Integer.valueOf( r.readLine()); for( int i = 0; i < t; i++){ String[] line = r.readLine().trim().split( " "); int y = 0; int n = Integer.valueOf( line[0]); int s = Integer.valueOf( line[1]); int p = Integer.valueOf( line[2]); for( int j = 3; j < line.length; j++){ int a = Integer.valueOf( line[j]); if( p == 1){ if( a >= 1) y++; }else if( a >= p+2*(p-1)){ y++; }else if( s > 0 && a >= p+2*(p-2)){ s--; y++; } } w.println( "Case #" + (i+1) + ": " + y); System.out.println( "Case #" + (i+1) + ": " + y); } w.close(); r.close(); }catch( Exception e){} } public static void main( String[] args) throws Exception { new B( args[0]); } }
0
757
A12852
A11015
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package fixjava; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; /** * Pair: typed 2-tuple */ public class Pair<L, R> { private final L left; private final R right; public R getRight() { return right; } public L getLeft() { return left; } public Pair(final L left, final R right) { this.left = left; this.right = right; } /** Convenience method so type params of pair don't have to be specified: just do Pair.make(l, r) */ public static <L, R> Pair<L, R> make(L left, R right) { return new Pair<L, R>(left, right); } // --------------------------------------------------------------------------------------------------- private static final boolean objEquals(Object p1, Object p2) { if (p1 == null) return p2 == null; return p1.equals(p2); } @Override public final boolean equals(Object o) { if (!(o instanceof Pair<?, ?>)) { return false; } else { final Pair<?, ?> other = (Pair<?, ?>) o; return objEquals(getLeft(), other.getLeft()) && objEquals(getRight(), other.getRight()); } } @Override public int hashCode() { int hl = getLeft() == null ? 0 : getLeft().hashCode(); int hr = getRight() == null ? 0 : getRight().hashCode(); return (hl + (127 * hr)) ^ (hr << 1); } // --------------------------------------------------------------------------------------------------- @Override public String toString() { return "(" + getLeft() + ", " + getRight() + ")"; } // --------------------------------------------------------------------------------------------------- public static <K, V> ArrayList<K> getAllLefts(Iterable<Pair<K, V>> list) { ArrayList<K> result = new ArrayList<K>(); for (Pair<K, V> pair : list) result.add(pair.getLeft()); return result; } public static <K, V> ArrayList<V> getAllRights(Iterable<Pair<K, V>> list) { ArrayList<V> result = new ArrayList<V>(); for (Pair<K, V> pair : list) result.add(pair.getRight()); return result; } // --------------------------------------------------------------------------------------------------- public static <A extends Comparable<A>, B> Comparator<Pair<A, B>> comparatorOnLeft(Collection<Pair<A, B>> tupleCollection) { return new Comparator<Pair<A, B>>() { @Override public int compare(Pair<A, B> o1, Pair<A, B> o2) { return o1.getLeft().compareTo(o2.getLeft()); } }; } public static <A extends Comparable<A>, B> Comparator<Pair<A, B>> comparatorOnLeftRev(Collection<Pair<A, B>> tupleCollection) { return new Comparator<Pair<A, B>>() { @Override public int compare(Pair<A, B> o1, Pair<A, B> o2) { return -o1.getLeft().compareTo(o2.getLeft()); } }; } public static <A, B extends Comparable<B>> Comparator<Pair<A, B>> comparatorOnRight(Collection<Pair<A, B>> tupleCollection) { return new Comparator<Pair<A, B>>() { @Override public int compare(Pair<A, B> o1, Pair<A, B> o2) { return o1.getRight().compareTo(o2.getRight()); } }; } public static <A, B extends Comparable<B>> Comparator<Pair<A, B>> comparatorOnRightRev(Collection<Pair<A, B>> tupleCollection) { return new Comparator<Pair<A, B>>() { @Override public int compare(Pair<A, B> o1, Pair<A, B> o2) { return -o1.getRight().compareTo(o2.getRight()); } }; } static <A extends Comparable<A>, B> Comparator<Pair<A, B>> comparatorOnLeft(Collection<Pair<A, B>> tupleCollection, final boolean ascending) { return new Comparator<Pair<A, B>>() { final int weight = ascending ? 1 : -1; @Override public int compare(Pair<A, B> o1, Pair<A, B> o2) { return o1.getLeft().compareTo(o2.getLeft()) * weight; } }; } static <A, B extends Comparable<B>> Comparator<Pair<A, B>> comparatorOnRight(Collection<Pair<A, B>> tupleCollection, final boolean ascending) { return new Comparator<Pair<A, B>>() { final int weight = ascending ? 1 : -1; @Override public int compare(Pair<A, B> o1, Pair<A, B> o2) { return o1.getRight().compareTo(o2.getRight()) * weight; } }; } // --------------------------------------------------------------------------------------------------- /** Sort a List<Pair<K, V>> in-place into order of increasing or decreasing K */ public static <K extends Comparable<K>, V> void sortPairsByLeft(List<Pair<K, V>> list, boolean ascending) { Collections.sort(list, comparatorOnLeft(list, ascending)); } /** Sort a List<Pair<K, V>> in-place into order of increasing K */ public static <K extends Comparable<K>, V> void sortPairsByLeft(List<Pair<K, V>> list) { Collections.sort(list, comparatorOnLeft(list, true)); } /** Sort a List<Pair<K, V>> in-place into order of increasing or decreasing V */ public static <K, V extends Comparable<V>> void sortPairsByRight(List<Pair<K, V>> list, boolean ascending) { Collections.sort(list, comparatorOnRight(list, ascending)); } /** Sort a List<Pair<K, V>> in-place into order of increasing V */ public static <K, V extends Comparable<V>> void sortPairsByRight(List<Pair<K, V>> list) { Collections.sort(list, comparatorOnRight(list)); } /** Convert a <K, V> map into a list of Pair<K, V>, final order unspecified */ public static <K, V> ArrayList<Pair<K, V>> mapToList(HashMap<K, V> map) { ArrayList<Pair<K, V>> list = new ArrayList<Pair<K, V>>(); for (Entry<K, V> ent : map.entrySet()) list.add(new Pair<K, V>(ent.getKey(), ent.getValue())); return list; } }
0
758
A12852
A12694
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.util.HashMap; import java.util.StringTokenizer; import java.util.Vector; public class Algorithm2 { static final String input_path = "F://workspace//GoogleContest2012//src//input.txt"; static final String output_path = "F://workspace//GoogleContest2012//src//output.txt"; static int total_case; static int findMax(String line){ StringTokenizer token = new StringTokenizer(line); int num = Integer.parseInt((String)token.nextElement()); int surprising = Integer.parseInt((String)token.nextElement()); int mscore = Integer.parseInt((String)token.nextElement()); int goodline = 3*mscore - 2; int middline = 3*mscore - 4; goodline = goodline>0?goodline:0; middline = middline>0?middline:1; int[] scores = new int[num]; int good = 0, middle = 0; for(int i = 0; i< num;i++){ scores[i] = Integer.parseInt((String)token.nextElement()); if(scores[i]>=goodline){ good++; }else if(scores[i]>=middline){ middle++; } } return good + (middle>=surprising?surprising:middle); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub int i = 0; Vector<String> outputs = new Vector<String>(); try{ File file = new File(input_path); BufferedReader reader =new BufferedReader(new FileReader(file)); String line = reader.readLine(); //skip number total_case = Integer.parseInt(line); while(i<total_case) { line = reader.readLine(); Integer max = findMax(line); String decoded = "Case #"+(i+1)+": "+max; System.out.println(decoded); outputs.add(decoded); i++; } File file_o = new File(output_path); BufferedWriter writer =new BufferedWriter(new FileWriter(file_o)); for(i=0;i<outputs.size();i++) { writer.write(outputs.get(i)+"\r\n"); } writer.flush(); reader.close(); writer.close(); }catch(Exception e){ System.out.println(e.toString()); } } }
0
759
A12852
A10930
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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; /** * */ /** * @author antonio081014 * @time: Apr 13, 2012, 5:01:31 PM */ public class Main { /** * @param args */ public static void main(String[] args) throws Exception { Main main = new Main(); main.run(); System.exit(0); } public void run() throws Exception { BufferedReader br = new BufferedReader(new FileReader("input.in")); BufferedWriter out = new BufferedWriter(new FileWriter("output.out")); int T = Integer.parseInt(br.readLine()); for (int t = 1; t <= T; t++) { out.write("Case #" + Integer.toString(t) + ": "); String[] str = br.readLine().split("\\s"); int surprising = 0; int partial = 0; int sum = 0; int N = Integer.parseInt(str[0]); int S = Integer.parseInt(str[1]); int p = Integer.parseInt(str[2]); for (int i = 0; i < N; i++) { int a = Integer.parseInt(str[i + 3]); if ((a == 3 * p - 4 || a == 3 * p - 3) && p >= 2) { surprising++; sum++; } else if (a >= 3 * p - 2) { sum++; partial++; } } // System.out.println(); // System.out.println(sum); // System.out.println(surprising); // System.out.println(partial); if (surprising >= S) { out.write(Integer.toString(sum + S - surprising)); // System.out.println(sum + S - surprising); } else { // if (surprising + partial >= S) { out.write(Integer.toString(sum)); // System.out.println(sum); // } // else { // // System.out.println(0); // out.write("0"); // } } out.write("\n"); } out.close(); } }
0
760
A12852
A11189
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 DancingWithGooglers { private static final Scanner sc = new Scanner(System.in); /** * @param args */ public static void main(String[] args) { int T = sc.nextInt(); //number of button presses for (int i = 0; i < T; i++){ int N = sc.nextInt(); //number of contestants int S = sc.nextInt(); //number of suprises int p = sc.nextInt(); //possible maximum score int result = 0; for (int j = 0; j < N; j++){ int t = sc.nextInt(); if (t >= (3 * p - 2)) result++; else if (p == 1); else if ((t >= (3 * p - 4)) && (S != 0)){ result++; S--; } } System.out.println("Case #" + (i + 1) + ": " + result); } } }
0
761
A12852
A12387
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 CodeJamB { public static void main (String[] args) throws IOException { int i, j, k; long startTime = System.currentTimeMillis(); File inFile = new File("B-small-attempt0.in"); // File to read from File outFile = new File("B-small-practice.out"); BufferedReader reader = new BufferedReader(new FileReader(inFile)); BufferedWriter writer = new BufferedWriter(new FileWriter(outFile)); String line = null; line = reader.readLine(); int cases = Integer.parseInt(line); int counter = 1; while ((line=reader.readLine()) != null) { int googlers = 0; int N, S, p; int sur = 0; String[] node = line.split(" "); N = Integer.parseInt(node[0]); S = Integer.parseInt(node[1]); p = Integer.parseInt(node[2]); if(p <= 1) { for(i = 3; i < node.length; i++) { if(Integer.parseInt(node[i]) >= p) googlers++; } } else { for(i = 3; i < node.length; i++) { if(Integer.parseInt(node[i]) >= (3*p-2)) { googlers++; } else if (Integer.parseInt(node[i]) >= (3*p-4)) { sur++; } } } googlers += Math.min(S, sur); writer.write("Case #"+counter+": "+googlers); writer.newLine(); counter++; } writer.close(); long endTime = System.currentTimeMillis(); long totalTime = endTime - startTime; System.out.println("Total Time: " + totalTime); } }
0
762
A12852
A11509
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 adream; import java.util.Scanner; /** * * @author sarah */ public class GoogleDancers { public int max(int[] googs , int p , int s){ int surp = 0; int max = 0; if(p == 0) return googs.length; for(int i = 0 ; i < googs.length ; i++){ int g1=0,g = googs[i]; if(g == 0)continue; if(g%3 == 0){ if(surp < s && g/3 < p && g/3 +1 >= p){ g1 = g/3 +1; surp++; }else g1 = g/3 ; }else{ if((g+1) % 3 == 0){ if(surp < s &&(g+1)/3 <p && (g+1)/3 + 1 >= p){ g1 = (g+1)/3 + 1; surp++; }else g1 = (g+1)/3; }else{ // if(surp < s &&(g-1)/3 + 1 < p && (g-1)/3 + 1 >= p){ // g1 = (g+1)/3 + 1; // surp++; // }else g1 = (g-1)/3 +1; } } if(g1 >= p) max++; } return max; } public static void main(String args[]){ GoogleDancers gd = new GoogleDancers(); Scanner sc = new Scanner(System.in); int tc = sc.nextInt(); int i = 0 ; while(i++ < tc){ int n = sc.nextInt(); // dancers int s = sc.nextInt(); //surprising int p = sc.nextInt(); //max int[] dancers = new int[n]; for(int j = 0 ; j < n ; j++) dancers[j] = sc.nextInt(); int res = gd.max(dancers,p,s); System.out.println("Case #"+i +": "+res); } } }
0
763
A12852
A11752
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.Collections; import java.util.Scanner; import javax.swing.JFileChooser; public class DancingWithTheGooglers { public static void main(String[] args) { JFileChooser chooser = new JFileChooser(); int state = chooser.showOpenDialog(null); if(state == 0) { File file = chooser.getSelectedFile(); try { FileInputStream fInputStream = new FileInputStream(file); DataInputStream dInputStream = new DataInputStream(fInputStream); BufferedReader br = new BufferedReader(new InputStreamReader(dInputStream)); PrintWriter out = new PrintWriter(new FileWriter("output")); String str = br.readLine(); int count = 1; while((str = br.readLine()) != null) { out.print("Case #" + count + ": "); Scanner scan = new Scanner(str); int numOfGooglers = scan.nextInt(); int numOfSurprising = scan.nextInt(); int atLeast = scan.nextInt(); int answer = 0; Integer[] totalPoints = new Integer[numOfGooglers]; for(int i=0; i<numOfGooglers; i++) { totalPoints[i] = scan.nextInt(); } Arrays.sort(totalPoints, Collections.reverseOrder()); for(int i=0; i<numOfGooglers; i++) { int base = totalPoints[i] / 3; int extra = totalPoints[i] % 3; if(base >= atLeast) { answer++; continue; } else { if(extra > 0) { if(base+1 >= atLeast) { answer++; continue; } } } if(numOfSurprising > 0) { if(base == 0) { continue; } if(extra == 2) { if(base+2 >= atLeast) { answer++; numOfSurprising--; continue; } } else if(extra == 1) { } else if(extra == 0) { if(base+1 >= atLeast) { answer++; numOfSurprising--; continue; } } } } count++; out.println(answer); } out.close(); dInputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } }
0
764
A12852
A10452
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class ProblemUtils { public static String[] readInput(String path) throws Exception { FileInputStream in = new FileInputStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); int nlines = Integer.parseInt(reader.readLine()); String[] lines = new String[nlines]; for (int i = 0; i < nlines; i++) { lines[i] = reader.readLine(); } return lines; } public static void writeOutput(String path, String[] lines) throws Exception { FileOutputStream out = new FileOutputStream(path); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out)); for (int i = 0; i < lines.length; i++) { writer.write("Case #" + (i + 1) + ": " + lines[i]); if (i + 1 < lines.length) { writer.write("\n"); } } writer.flush(); out.close(); } }
0
765
A12852
A11387
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 javaapplication4; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Scanner; import javax.print.DocFlavor.STRING; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.util.AbstractList; import java.util.Iterator; import java.util.List; /** * * @author Mansk */ public class JavaApplication4 { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException, IOException { // TODO code application logic here FileInputStream fstream = new FileInputStream("In.txt"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); FileOutputStream fos = new FileOutputStream("out.txt"); BufferedOutputStream bos =new BufferedOutputStream(fos); String line; int num=0; int T=0; int S=0; int P=0; line= br.readLine(); num= Integer.parseInt(line) ; Scanner s= new Scanner(br); for (int i = 0; i <num ; i++) { String line2 = new String(); int max=0; line= s.next(); T= Integer.parseInt(line) ; line= s.next(); S= Integer.parseInt(line) ; line= s.next(); P= Integer.parseInt(line) ; int[] myarr ; myarr= new int[101] ; for (int j = 0; j < T; j++) { line= s.next(); myarr[j] = Integer.parseInt(line) ; } for (int j = 0; j < T; j++) { int sum=myarr[j]; if(sum>=(3*P)) { max ++; } else { int temp =sum/3; int temp2=(sum -temp)/2; int temp1=sum-(temp2+temp); int temp3=temp; if((temp1>=P)|(temp1>=P)|(temp1>=P)) { max ++; } else { temp1=P; temp2= sum - (P + (sum-P)/2); temp3= (sum-P)/2; if((((temp1-temp2)==1)&((temp2-temp3)==1))&(S!=0)) { S--; max++; } else if(((temp2==temp3)&((temp1-temp2)==2)&(S!=0))) { S--; max++; } else if((temp2==temp3)&((temp1-temp2)==1)) { max++; } } } } line2="Case #"+(i+1)+": "+max+"\n"; bos.write(line2.getBytes()); bos.flush(); } } }
0
766
A12852
A11844
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package main; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; public class DancingWithTheGooglers { public static void main(String... args) throws NumberFormatException, IOException { BufferedReader buffer = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]))); int qtd = Integer.parseInt(buffer.readLine()); List<String> saida = new ArrayList<String>(); for (int i = 1; i <= qtd; i++) { saida.add("Case #" + i + ": " + qtdMelhoresResultados(buffer.readLine())); } buffer.close(); escrevaNoArquivoASaida("output.txt", saida); } private static void escrevaNoArquivoASaida(String nomeArquivo, List<String> saida) throws IOException { BufferedWriter br = new BufferedWriter(new FileWriter(new File(nomeArquivo))); for (String string : saida) { br.write(string + "\n"); } br.close(); } public static int qtdMelhoresResultados(String entrada) { String[] argumentos = entrada.split(" "); int qtdGooglers = Integer.valueOf(argumentos[0]); int notasSurpresas = Integer.valueOf(argumentos[1]); int notaCorte = Integer.valueOf(argumentos[2]); int qtdMelhoresResultados = 0; int surpresasUtilizados = 0; for (int i = 0; i < qtdGooglers; i++) { int notaGoogler = Integer.valueOf(argumentos[3+i]); int mediaNota = notaGoogler / 3; int nota1 = mediaNota; int nota2 = mediaNota; int nota3 = mediaNota; if (nota1 + nota2 + nota3 != notaGoogler) { nota3++; } if (nota1 + nota2 + nota3 != notaGoogler) { nota2++; } if (nota1 + nota2 + nota3 != notaGoogler) { throw new RuntimeException("Something went terribly wrong: " + entrada ); } if (nota1 >= notaCorte || nota2 >= notaCorte || nota3 >= notaCorte) { qtdMelhoresResultados++; continue; } if (surpresasUtilizados == notasSurpresas) { continue; } if (nota2 > 0 && (nota3+1) - (nota2 - 1) <= 2) { nota2--; nota3++; if (nota1 >= notaCorte || nota2 >= notaCorte || nota3 >= notaCorte) { qtdMelhoresResultados++; surpresasUtilizados++; } } } return qtdMelhoresResultados; } }
0
767
A12852
A11493
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.jam.eaque.qualif.b; import java.io.IOException; import com.google.jam.eaque.stub.InputFileManager; import com.google.jam.eaque.stub.Stub; import com.google.jam.eaque.stub.Util; public class Small extends Stub { @Override public String runTestCase(InputFileManager ifm) throws NumberFormatException, IOException { long[] numbers = Util.stringsToLongs(ifm.readAndSplit()); long[] quotients = new long[(int) numbers[0]]; long[] remainders = new long[(int) numbers[0]]; long s = numbers[1]; long p = numbers[2]; long res = 0; for (int i = 0; i < remainders.length; i++) { quotients[i] = numbers[i+3] / 3; remainders[i] = numbers[i+3] % 3; if (quotients[i] >= p) { res++; } else if (quotients[i] == (p - 1)) { if (remainders[i] != 0) { res++; } else if (quotients[i] != 0 && s > 0) { res++; s--; } } else if (quotients[i] == (p - 2) && s > 0) { if (remainders[i] == 2) { res++; s--; } } } return " " + res; } }
0
768
A12852
A13072
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.FileReader; import java.io.PrintStream; import java.util.Scanner; public class InputOutputProcessor { private int numberOfCases; private boolean doesInputHaveDataSetLines; private int indexOfDataSetLine; private int numberOfDataSetLines; private final static String DELIMITER = " "; private Scanner scanInput; public void initializeInput(String strInputFileName) { readInput(strInputFileName); numberOfCases = Integer.parseInt(scanInput.nextLine()); } /* * read input */ private void readInput(String strInputFileName) { try { scanInput = new Scanner(new BufferedReader(new FileReader( strInputFileName))); } catch (Exception exp) { // exp.printStackTrace(); System.out.println(" Please provide File Name with proper location "); } } public String[] getDataSet() throws Exception { String[] dataSet; String strDataSetLine = ""; strDataSetLine = scanInput.nextLine(); // System.out.println("strDataSetLine: " + strDataSetLine); if (doesInputHaveDataSetLines) { String[] DataSetLineArray = strDataSetLine.split(DELIMITER); numberOfDataSetLines = Integer .parseInt(DataSetLineArray[indexOfDataSetLine]); } dataSet = new String[numberOfDataSetLines]; dataSet[0] = strDataSetLine; for (int i = 1; i < numberOfDataSetLines; i++) { dataSet[i] = scanInput.nextLine(); } return dataSet; } /** * * @return Returns the numberOfDataSetLines. */ public int getNumberOfDataSetLines() { return numberOfDataSetLines; } /** * @param numberOfDataSetLines * The numberOfDataSetLines to set. */ public void setNumberOfDataSetLines(int numberOfDataSetLines) { this.numberOfDataSetLines = numberOfDataSetLines; } /** * * @return Returns the numberOfCases. */ public int getNumberOfCases() { return numberOfCases; } /** * * @return Returns the doesInputHaveDataSetLines. */ public boolean isDoesInputHaveDataSetLines() { return doesInputHaveDataSetLines; } /** * @param doesInputHaveDataSetLines * The doesInputHaveDataSetLines to set. */ public void setDoesInputHaveDataSetLines(boolean doesInputHaveDataSetLines) { this.doesInputHaveDataSetLines = doesInputHaveDataSetLines; } /** * * @return Returns the indexOfDataSetLine. */ public int getIndexOfDataSetLine() { return indexOfDataSetLine; } /** * @param indexOfDataSetLine * The indexOfDataSetLine to set. */ public void setIndexOfDataSetLine(int indexOfDataSetLine) { this.indexOfDataSetLine = indexOfDataSetLine; } public void closeScanner() { scanInput.close(); } public void writeOutput(String outputFileName, String[] resultArray) { // To be moved out PrintStream out = null; try { out = new PrintStream(new FileOutputStream(outputFileName)); for (int i = 0; i < resultArray.length; i++) { out.print(resultArray[i]); out.print("\n"); } out.close(); } catch (Exception e) { e.printStackTrace(); System.exit(0); } } }
0
769
A12852
A11350
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.Integer.*; import static java.lang.Math.*; public class CodeJamB { static boolean is(int a){ return a>=0&&a<=10; } static int normal(int n){ int max=0; if(n%3==0)max=n/3; if((n+1)%3==0&&is((n+1)/3)&&is((n+1)/3-1))max=max(max,(n+1)/3); if((n-1)%3==0&&is((n-1)/3)&&is((n-1)/3+1))max=max(max,(n-1)/3+1); return max; } static int aNormal(int n){ int max=0; if((n-3)%3==0&&is((n-3)/3)&&is((n-3)/3+1)&&is((n-3)/3+2))max=(n-3)/3+2; if((n+2)%3==0&&is((n+2)/3)&&is((n+2)/3-2))max=max(max,(n+2)/3); if((n-2)%3==0&&is((n-2)/3)&&is((n-2)/3+2))max=max(max,(n-2)/3+2); return max; } static long f(int i,int s){ if(s<0)return MIN_VALUE; if(i==arr.length)return 0; if(mem[i][s]>-1)return mem[i][s]; return mem[i][s]=max(f(i+1,s-1)+(aNormal(arr[i])>=p?1:0),f(i+1,s)+(normal(arr[i])>=p?1:0)); } static int arr[],p; static long[][] mem; public static void main(String args[]) throws Throwable { System.setOut(new PrintStream("B-Small.out")); BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); //BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); for (int t=0,T=parseInt(in.readLine().trim());t++<T;) { StringTokenizer st=new StringTokenizer(in.readLine()); int N=parseInt(st.nextToken()),S=parseInt(st.nextToken()); p=parseInt(st.nextToken()); arr=new int[N];mem=new long[N][S+1]; for(long[] m:mem)Arrays.fill(m,-1); for(int i=0;i<N;i++)arr[i]=parseInt(st.nextToken()); sb.append("Case #"+t+": "+f(0,S)+"\n"); } System.out.print(new String(sb)); } }
0
770
A12852
A10339
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.File; import java.math.BigInteger; import java.util.ArrayList; import java.util.Scanner; import java.util.TreeMap; /** * * @author Ben */ public class Main { public static Scanner freader; public static int caseCount, _height, _width; /** * @param args the command line arguments */ public static void main(String[] args) { //solveFreeCell(); //solveKiller(); sovleDWG(); //solveRC(); //solveSIT(); } public static void solveSIT() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/A-small-attempt0.in")); caseCount = freader.nextInt(); freader.nextLine(); char GtoE [] = {'y', //a 'h', //b 'e', //c 's', //d 'o', //e 'c', //f 'v', //g 'x', //h 'd', //i 'u', //j 'i', //k 'g', //l 'l', //m 'b', //n 'k', //o 'r', //p 'z', //q 't', //r 'n', //s 'w', //t 'j', //u 'p', //v 'f', //w 'm', //x 'a', //y 'q'}; //z ArrayList<String> L = new ArrayList(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { L.add(freader.nextLine()); } for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { System.out.print("Case #" + (caseIdx + 1) + ": "); char chr [] = L.get(caseIdx).toCharArray(); for(int i = 0; i < chr.length; i++) { if(chr[i] == ' ') continue; chr[i] = GtoE[chr[i] - 'a']; } System.out.println(chr); } } catch(Exception e) { e.printStackTrace(); } } public static void solveRC() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/C-small-attempt0.in")); caseCount = freader.nextInt(); freader.nextLine(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { System.out.print("Case #" + (caseIdx+1) + ": "); int A = freader.nextInt(); int B = freader.nextInt(); int result = RC(A,B); System.out.println(result); freader.nextLine(); } } catch(Exception e) { e.printStackTrace(); } } public static int RC(int A, int B) { int count = 0; ArrayList<Integer> iL; ArrayList<Integer> jL; for(int i = A; i <= B-1; i++) { for(int j = i + 1; j <= B; j++) { iL = convertNumToArray(i); jL = convertNumToArray(j); if(iL.size() != jL.size()) continue; if(recycled(iL, jL)) { count++; } } } return count; } public static boolean recycled(ArrayList<Integer> iL, ArrayList<Integer> jL) { boolean equal; int size = iL.size(); for(int i = 0; i < size; i++) { equal = true; //compare iL and jL for(int j = 0; j < size; j++) { if(iL.get(j).intValue() != jL.get(j).intValue()) { equal = false; break; } } if(equal) return true; //shift iL Integer temp = iL.get(size-1); for(int j = size-1; j > 0; j--) { iL.set(j, iL.get(j-1)); } iL.set(0, temp); } return false; } public static ArrayList<Integer> convertNumToArray(int x) { ArrayList<Integer> L = new ArrayList(); while(x > 0) { int r = x % 10; L.add(0, new Integer(r)); x = x / 10; } return L; } public static void sovleDWG() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/B-small-attempt2.in")); caseCount = freader.nextInt(); freader.nextLine(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { System.out.print("Case #" + (caseIdx+1) + ": "); int n = freader.nextInt(); int s = freader.nextInt(); int p = freader.nextInt(); int T [] = new int [n]; for(int i = 0; i < n; i++){ T[i] = freader.nextInt(); } int count = DWG(T, n, s, p); System.out.println(count); freader.nextLine(); } } catch(Exception e) { e.printStackTrace(); } } public static int DWG(int [] T, int n, int s, int p) { int minSup = p + 2 * max(p-2,0); int minNonSup = p + 2 * max(p-1,0); int count = 0; int maybe = 0; for(int i = 0; i < n; i++) { int curr = T[i]; if(curr >= minNonSup) { count++; } else if(curr < minNonSup && curr >= minSup) { maybe++; } } count = count + min(maybe, s); return count; } public static int min(int x, int y) { if (x < y){ return x; } return y; } public static int max(int x, int y) { if (x > y){ return x; } return y; } public static void solveKiller() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/B-large-practice.in")); caseCount = freader.nextInt(); freader.nextLine(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { System.out.print("Case #" + (caseIdx+1) + ": "); int n = freader.nextInt(); int m = freader.nextInt(); ArrayList<String> L = new ArrayList(n); for(int i = 0; i < n; i++){ L.add(freader.next()); } String kword = null; int score, worst; for(int j = 0; j < m; j++) { String todo = freader.next(); worst = 1; for(int i = 0; i < n; i++) { score = killer(L.get(i), todo, (ArrayList<String>)L.clone()); if(score < worst) { worst = score; kword = L.get(i); } } if(j == m-1) System.out.print(kword); else System.out.print(kword + " "); freader.nextLine(); } System.out.println(); } } catch(Exception e) { e.printStackTrace(); } } public static int killer(String word, String todo, ArrayList<String> dict) { int score = 0; int index [] = new int [26]; updateTodo(todo, dict, index); char guess [] = new char [word.length()]; for(int i = 0; i < word.length(); i++) { guess[i] = '*'; } dict = updateDict(dict, guess); int j = 0; while(j < 26) { while(index[j] == 0) { ++j; if(j >= 26) return score; } if(!updateGuess(guess, word, todo.charAt(j))){ score--; dict = filter(dict, todo.charAt(j)); } dict = updateDict(dict, guess); updateTodo(todo, dict, index); ++j; } return score; } public static ArrayList<String> filter(ArrayList<String> dict, char c) { ArrayList<String> result = new ArrayList(); for(String str : dict) { if(str.indexOf(c) < 0) { result.add(str); } } return result; } public static ArrayList<String> updateDict(ArrayList<String> dict, char [] guess) { ArrayList<String> result = new ArrayList(); for(String str : dict){ if(matches(str,guess)){ result.add(str); } } return result; } public static boolean matches(String str, char [] guess) { if(str.length() != guess.length) return false; for(int i = 0; i < guess.length; i++) { if(guess[i] == '*') { continue; } else if(guess[i] != str.charAt(i)) { return false; } } return true; } public static void updateTodo(String todo, ArrayList<String> dict, int [] index) { for(int i = 0; i < index.length; i++) index[i] = 0; for(String str : dict) { for(int i = 0; i < str.length(); i++) { index[todo.indexOf(str.charAt(i))] = 1; } } } public static boolean updateGuess(char [] guess, String word, char c) { boolean found = false; for(int i = 0; i < word.length(); i++){ if(word.charAt(i) == c){ guess[i] = c; found = true; } } return found; } public static void solveFreeCell() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/1a2011/A-large-practice.in")); caseCount = freader.nextInt(); freader.nextLine(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { System.out.print("Case #" + (caseIdx+1) + ": "); BigInteger n = new BigInteger(freader.next()); long pd = freader.nextInt(); long pg = freader.nextInt(); if(pd > 0 && pg == 0) { System.out.println("Broken"); continue; } if(pd == 0 && pg == 100) { System.out.println("Broken"); continue; } if(pd == 0 && pg != 100) { System.out.println("Possible"); continue; } if(pd < 100 && pg == 100) { System.out.println("Broken"); continue; } if(n.compareTo(new BigInteger("100")) >= 0){ System.out.println("Possible"); continue; } double den; long div; div = gcd(pd, 100); den = (double)100/div; if(den > n.intValue()) { System.out.println("Broken"); continue; } System.out.println("Possible"); freader.nextLine(); } } catch(Exception e) { e.printStackTrace(); } } public static long gcd(long x, long y) { while(x != y) { //System.out.println(x + " " + y); if(x > y) { x = x - y; } else{ y = y - x; } } return x; } public static void solveMagika() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/codejam/B-large-practice.in")); caseCount = freader.nextInt(); freader.nextLine(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { TreeMap<String, String> oppMap = new TreeMap(); TreeMap<String, String> comMap = new TreeMap(); ArrayList<String> list = new ArrayList(); int c = freader.nextInt(); for(int i = 0; i < c; i++) { String str = freader.next(); String rev = new StringBuffer(str.substring(0,2)).reverse().toString(); comMap.put(str.substring(0, 2), str.substring(2)); comMap.put(rev.substring(0, 2), str.substring(2)); } int d = freader.nextInt(); for(int i = 0; i < d; i++) { String str = freader.next(); String rev = new StringBuffer(str).reverse().toString(); oppMap.put(str, str); oppMap.put(rev, rev); } int n = freader.nextInt(); String todo = freader.next(); //System.out.println(todo); Magika(caseIdx+1, n, todo, comMap, oppMap, list); freader.nextLine(); } } catch(Exception e) { e.printStackTrace(); } } public static void Magika(int caseIdx, int n, String todo, TreeMap<String, String> comMap, TreeMap<String, String> oppMap, ArrayList<String> list) { list.add(todo.substring(0,1)); for(int i = 1; i < n; i++) { list.add(todo.substring(i,i+1)); int size = list.size(); if(size >= 2){ String newElement = comMap.get( list.get(size-2).concat(list.get(size-1)) ); if(newElement != null) { list.remove(list.size()-1); list.remove(list.size()-1); list.add(newElement); } } check(oppMap, list); } System.out.print("Case #" + caseIdx + ": ["); if(list.isEmpty()) { System.out.println("]"); } else { for(int i = 0; i < list.size()-1; i++) { System.out.print(list.get(i) + ", "); } System.out.println(list.get(list.size()-1) + "]"); } } public static void check(TreeMap<String, String> oppMap, ArrayList<String> list) { int size = list.size(); for(int j = 0; j < size-1; j++) { for(int k = 0; k < size; k++) { if(oppMap.containsKey(list.get(j).concat(list.get(k)))) { list.clear(); return; } } } } public static void solveBotTrust() { try{ freader = new Scanner( new File("C:/Users/Ben/Documents/NetBeansProjects/CodeJam/src/codejam/A-large-practice.in")); caseCount = freader.nextInt(); freader.nextLine(); int caseIdx; for(caseIdx = 0; caseIdx < caseCount; caseIdx++) { int n = freader.nextInt(); int buttons [] = new int [n]; String robots [] = new String [n]; int i; for(i = 0; i < n; i++) { robots[i] = freader.next(); buttons[i] = freader.nextInt(); } BotTrust(caseIdx+1, robots, buttons, n); freader.nextLine(); } } catch(Exception e) { e.printStackTrace(); } } public static void BotTrust(int caseIdx, String [] robots, int [] buttons, int n) { int turn, seconds; boolean buttonPressed; Robot B, O, active, passive; turn = 0; seconds = 0; B = new Robot("B"); O = new Robot("O"); for(int i = 0; i < n; i++) if(robots[i].equals("B")){ B.nextPosition = buttons[i]; break; } for(int i = 0; i < n; i++) if(robots[i].equals("O")){ O.nextPosition = buttons[i]; break; } // System.out.println("orange pos : " + O.nextPosition); // System.out.println("blue pos : " + B.nextPosition); while(turn < n) { seconds++; buttonPressed = false; if(robots[turn].equals("O")){ active = O; passive = B; } else{ active = B; passive = O; } int moveIncr; if(active.currPosition == active.nextPosition){ moveIncr = 0; }else if(active.currPosition < active.nextPosition){ moveIncr = 1; }else{ moveIncr = -1; } if(moveIncr == 0) { buttonPressed = true; } else{ active.currPosition = active.currPosition + moveIncr; } if(passive.currPosition == passive.nextPosition){ moveIncr = 0; }else if(passive.currPosition < passive.nextPosition){ moveIncr = 1; }else{ moveIncr = -1; } passive.currPosition = passive.currPosition + moveIncr; if(buttonPressed){ turn++; for(int i = turn; i < n; i++){ if(robots[i].equals(active.name)) { active.nextPosition = buttons[i]; break; } } } } System.out.println("Case #" + caseIdx + ": " + seconds); } private static class Robot { int currPosition, nextPosition; String name; public Robot(String _name) { currPosition = 1; nextPosition = 0; name = _name; } } }
0
771
A12852
A10250
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 gcj2012; /** * * @author allegea */ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.StringTokenizer; /** * * @author Allegea */ public class DancingWiththeGooglers { public static void main(String[] args) throws IOException,FileNotFoundException{ String name = "B-small-attempt0"; BufferedReader in = new BufferedReader(new FileReader(name+".in")); // BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); FileWriter archivo = new FileWriter(name+".out"); PrintWriter out = new PrintWriter(archivo); out.flush(); String line; StringBuilder buil = new StringBuilder(); line = in.readLine(); int cases = Integer.parseInt(line); int act = 0; while (act++<cases) { StringTokenizer x = new StringTokenizer(in.readLine()); int n= Integer.parseInt(x.nextToken()); int p = Integer.parseInt(x.nextToken()); int max = Integer.parseInt(x.nextToken()); int[] s = new int[n]; for(int i=0;i<n;i++) s[i] = Integer.parseInt(x.nextToken()); int count=0; int sup = 0; for(int i=0;i<n;i++){ int avg = s[i]/3; int res = s[i]-avg*3; //System.out.println(avg+" - "+res+" - "+s[i]); if(avg==0){ if(s[i]>=max)count++; continue; } if(avg>=max) { count++; continue; } if(res==0) { if(avg+1==max)sup++; }else if (res ==1){ if(avg+1==max)count++; }else{ if(avg+1==max)count++; else if(avg+2==max)sup++; } } //System.out.println(sup+" - "+count); count+=Math.min(p, sup); System.out.println("Case #"+act+": "+count); out.println("Case #"+act+": "+count); // System.out.println(line); } in.close(); out.close(); System.exit(0); } }
0
772
A12852
A11687
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 abstract class Question extends Thread{ protected Result result; protected Counter counter; public Question(Result result, Counter counter) { super(); this.result = result; this.counter = counter; } public abstract void readInput(Scanner scanner); public void solveTestCase(){ setResult(solution()); } public abstract String solution(); public String getResult() { return result.output; } public void setResult(String output) { this.result.output = output; } public void run() { solveTestCase(); //System.out.println(result); counter.increase(); } }
0
773
A12852
A11517
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileReader; import java.io.PrintWriter; import java.util.Scanner; public class Googlers { public static void main(String[] args) throws FileNotFoundException { Scanner in = new Scanner(new FileReader(new File("B-small-attempt1.in"))); PrintWriter out = new PrintWriter(new File("B-small-attempt1.out")); int t = in.nextInt(); in.nextLine(); for(int i=0; i<t; i++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int r = 0; System.out.println("s="+s+", p="+p); for(int k=0; k<n; k++) { int c = in.nextInt(); int v1 = (int)Math.round(c / 3.0); int v2 = v1; int v3 = c - v1 - v2; System.out.print(v1+"+"+v2+"+"+ v3 + " = " + c + "\t"); if (v1>=p || v3>=p) { System.out.println(" >=p"); r++; } else { if (s>0) { if (v1+1>=p && v1-1>=0) { System.out.println(" special"); r++; s--; } else { System.out.println(" can't make special"); } } else { System.out.println(" no more spec"); } } } System.out.println("------------"); System.out.println("r=" + r); System.out.println("============"); in.nextLine(); out.println("Case #" + (i+1)+ ": " + r); } out.close(); } }
0
774
A12852
A12111
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package code12; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.util.ArrayList; import java.util.List; public class Googlers { public static void main(String[] args) { try { BufferedReader fileGoo = new BufferedReader(new FileReader("B-small-attempt5.in")); FileWriter miArchivo = new FileWriter("B-small-attempt5.out"); List<String> listaCasos = new ArrayList<String>(); String linea; while ((linea = fileGoo.readLine()) != null) { listaCasos.add(linea); } int casos = new Integer(listaCasos.get(0)); listaCasos.remove(0); int indc=1; if (casos>0 && casos<=100){ for (String cadenas: listaCasos) { String [] valores= cadenas.split(" "); int n= new Integer (valores[0]); int s= new Integer (valores[1]); int p= new Integer (valores[2]); if(s<0 || s>n) continue; if(p<0 || p>10) continue; if(n<1 || n>3) // SmallData continue; int contador = 0; int casoEsp=1; for (int i = 3; i < valores.length; i++) { Integer p1= p-1<0?0:p-1; Integer p2= p-2<0?0:p-2; Integer valor =new Integer(valores[i]); Integer caso1 = p+ p+ p; Integer caso2 = p+ p+ p1; Integer caso3 = p+ p1+ p1; Integer caso4 = p+ p1+ p2; Integer caso5 = p+ p2+ p2; Integer caso6 = p+ p+ p2; if(valor<0 || valor>30) continue; if (caso1<valor ||caso2<valor || caso1.equals(valor) || caso2.equals(valor)|| caso3.equals(valor)){ contador++; } else if ((s>0 && casoEsp<=s) && (caso4.equals(valor) || caso5.equals(valor)|| caso6.equals(valor))){ contador++; casoEsp++; } } miArchivo.write("Case #" + indc + ": " + contador+"\n"); indc++; } } miArchivo.flush(); miArchivo.close(); } catch (Exception e) { e.printStackTrace(); } } }
0
775
A12852
A10533
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.googlerese.file; import java.io.*; import java.util.Map; public class FileWrite { private static FileWrite fileWrite = new FileWrite(); private FileWrite() { } public static FileWrite getInstance() { return fileWrite; } public final void write( final String fileName, final Map<Integer, String> output ) { FileWriter fstream = null; BufferedWriter out = null; try { // Create file fstream = new FileWriter( fileName ); out = new BufferedWriter( fstream ); int size = output.size(); for ( int i = 1; i <= size; i++ ) { final String outputStr = new StringBuffer( "Case #" ).append( i ).append( ": " ).append( output.get( i ) ).toString(); out.write( outputStr ); if ( i != size ) { out.newLine(); } } } catch ( Exception e ) {//Catch exception if any System.err.println( "Error: " + e.getMessage() ); } finally { //Close the output stream try { if ( out != null ) { out.close(); } if ( fstream != null ) { fstream.close(); } } catch ( IOException e ) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
0
776
A12852
A10118
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class ProblemB { public static void main(String args[]) throws IOException{ File file = new File("I:/res/ACMCS/GCJ/B-small-attempt0.in"); File outFile = new File("I:/res/ACMCS/GCJ/problemB.out.txt"); FileWriter fw = new FileWriter(outFile); BufferedWriter bw = new BufferedWriter(fw); //FileReader fileReader = new FileReader(file); Scanner in = new Scanner(file); int cs = in.nextInt(); int c = 0; while(cs -- > 0){ ++ c; int ans = 0; int n = in.nextInt(); int map[] = new int[n]; int s = in.nextInt(); int p = in.nextInt(); for(int i = 0; i < n; ++ i) map[i] = in.nextInt(); ans = ProblemB.ans(map, s, p); bw.write("Case #"); bw.write(String.valueOf(c)); bw.write(": "); bw.write(String.valueOf(ans)); bw.newLine(); } bw.close(); } public static int suprise(int triSco){ int max = (triSco + 4) / 3 + 1; int min = triSco / 3 -1 > 0 ? triSco / 3 -1 : triSco / 3; int sco = 0; for(int i = max; i >= min; -- i){ sco = triSco - i; for(int j = (sco + 2) / 2 + 1; j >= (sco) / 2 - 1; -- j){ int k = sco - j; if(Math.abs(i - j) <= 2 && Math.abs(i - k) <= 2 && Math.abs(j - k) <= 2 && i >= 0 && j >= 0 && k >= 0) return Math.max(Math.max(i, j), k); } } return max; } public static int nonSuprise(int triSco){ int max = (triSco + 2) / 3 + 1; int min = triSco / 3 - 1; int sco = 0; for(int i = max; i >= min; -- i){ sco = triSco - i; for(int j = (sco + 1) / 2 + 1; j >= (sco) / 2 - 1; -- j){ int k = sco - j; if(Math.abs(i - j) <= 1 && Math.abs(i - k) <= 1 && Math.abs(j - k) <= 1 && i >= 0 && j >= 0 && k >= 0) return Math.max(Math.max(i, j), k); } } return max; } public static int ans(int map[], int s, int p){ int max = 0; for(int i : map){ if(nonSuprise(i) >= p) ++ max; else if(suprise(i) >= p && s > 0){ ++ max; -- s; } } return max; } }
0
777
A12852
A11685
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 CodeJamWriter implements ICounterZeroEvent{ //public static String inputFile = "C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\A-test"; //public static String inputFile = "C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\A-small-attempt0"; //public static String inputFile = "C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\B-test"; public static String inputFile = "C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\B-small-attempt0"; //public static String inputFile = "C:\\Users\\user\\Desktop\\coejam\\2012-Qualificaton\\B-large-attempt"; public int T; public Result[] results; public static void main(String[] args) { CodeJamWriter codeJamWriter = new CodeJamWriter(); codeJamWriter.readInput(); } private void readInput() { Scanner scanner = null; File input = new File(inputFile+".in"); try { scanner = new Scanner(input); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } T = scanner.nextInt(); scanner.nextLine(); results = new Result[T+1]; Counter counter = new Counter(T, this); for (int i=1;i<=T;++i) { results[i] = new Result(i); Question q = new QuestionB(results[i], counter); q.readInput(scanner); q.start(); } scanner.close(); } private void writeOutput() { FileOutputStream fos = null; PrintStream printer = null; File output = new File(inputFile+".out"); try { fos = new FileOutputStream(output); printer = new PrintStream(fos); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } for (int i=1;i<=T;++i) { printer.println(results[i]); } System.out.println("FINISHED!!!"); printer.close(); } @Override public void fireEvent() { writeOutput(); } }
0
778
A12852
A11620
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 DancingGooglers { public static void main(String[] args) { try { Scanner in = new Scanner(new File("C:/Users/Ross/Downloads/B-small-attempt1.in")); int T = in.nextInt(); String out = ""; for(int i = 0; i < T; i++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int count = 0; for(int j = 0; j < N; j++) { int t = in.nextInt(); if(t > 3*p-3) count++; else if(S > 0 && t >= 3*p-4 && t != 0) { S--; count++; } } out += "Case #" + (i+1) + ": "; out += count + "\n"; System.out.println(out); } } catch(Exception e) { e.printStackTrace(); } } }
0
779
A12852
A12160
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Solution { private StringTokenizer st; private BufferedReader in; private PrintWriter out; // final String file = "sample"; final String file = "B-small-attempt1"; public void solve() throws IOException { int tests = nextInt(); for (int test = 0; test < tests; ++test) { int n = nextInt(); int k = nextInt(); int p = nextInt(); int[] d = new int[k + 1]; Arrays.fill(d, -1000000000); d[0] = 0; for (int i = 0; i < n; ++i) { int[] d1 = new int[k + 1]; int a = nextInt(); int val0 = -1000000000, val1 = -1000000000; for (int u = 0; u <= 10 && 3 * u <= a; ++u) { for (int v = u; v <= 10 && v <= u + 2 && u + 2 * v <= a; ++v) { int w = a - u - v; if (w <= u + 2 && w >= 0 && w <= 10) { if (w - u <= 1) { val0 = Math.max(val0, w >= p ? 1 : 0); } else { val1 = Math.max(val1, w >= p ? 1 : 0); } } } } for (int j = 0; j <= k; ++j) { d1[j] = d[j] == -1000000000 ? -1000000000 : d[j] + val0; } for (int j = 0; j < k; ++j) { if (d[j] != -1000000000) { d1[j + 1] = Math.max(d1[j + 1], d[j] + val1); } } d = d1; } out.printf("Case #%d: %d%n", test + 1, d[k]); } } public void run() throws IOException { in = new BufferedReader(new FileReader(file + ".in")); out = new PrintWriter(file + ".out"); eat(""); solve(); out.close(); } void eat(String s) { st = new StringTokenizer(s); } String next() throws IOException { while (!st.hasMoreTokens()) { String line = in.readLine(); if (line == null) { return null; } eat(line); } return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); new Solution().run(); } }
0
780
A12852
A11660
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class Main { /** * @param args */ public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for(int k = 1; k<=T; k++){ int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int[] t=new int[n]; for (int i =0; i<n; i++) t[i]=in.nextInt(); Arrays.sort(t); int comp =0; for (int i = n-1; i>=0; i--){ if (t[i]<p) { continue; } if (t[i]>=3*p-2) { comp++; continue; } if (s>0 && t[i]>=3*p-4){ s--; comp++; continue; } break; } System.out.println("Case #"+k+": "+comp); } } }
0
781
A12852
A11778
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Competitiopn; import java.util.Scanner; /** * * @author vidz */ public class DancingWithTheGooglers { public void solve() { Scanner sc = new Scanner(System.in); int T = sc.nextInt(); int i = 0, j = 0; int N = 0;//number of googlers int S = 0, s = 0;//suprise int p = 0;//limit to pass int count = 0; while (i < T) { N = sc.nextInt(); s = S = sc.nextInt(); p = sc.nextInt(); j = 0; count = 0; while (j < N) { int temp = sc.nextInt(); if (temp >= (3 * p - 2) ) { count++; } else if (temp == (3 * p - 3) && s > 0 && (3 * p - 3) > 0) { count++; s--; } else if (temp == (3 * p - 4) && s > 0 && (3 * p - 4) > 0) { count++; s--; } ++j; } System.out.println("Case #" + (i + 1) + ": " + count); ++i; } } public static void main(String[] args) { new DancingWithTheGooglers().solve(); } }
0
782
A12852
A11024
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package fixjava; public class IntegerMutable { int value; public IntegerMutable(int value) { this.value = value; } public IntegerMutable() { this(0); } public int getValue() { return value; } public void setValue(int value) { this.value = value; } /** Inc and return new value (threadsafe) */ public synchronized int increment() { return ++value; } /** Dec and return new value (threadsafe) */ public synchronized int decrement() { return --value; } /** Subtract amount and return new value (threadsafe) */ public synchronized int subtract(int amount) { return value -= amount; } /** Add amount and return new value (threadsafe) */ public synchronized int add(int amount) { return value += amount; } }
0
783
A12852
A11165
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 codezam.util; import java.math.BigDecimal; public class MathUtil { public static BigDecimal pow(int a, int b) { BigDecimal result = new BigDecimal(a); BigDecimal number = new BigDecimal(a); if (b==0) { result = new BigDecimal(1); } else { for (int i=1; i<b; i++) { result = result.multiply(number); } } return result; } public static final void main (String[] args) { MathUtil mathUtil = new MathUtil(); System.out.println(mathUtil.pow(3, 3)); } }
0
784
A12852
A12836
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; /** * * @author Serban */ public class Dancing { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here Input in = new Input("B-small-attempt1.in"); } }
0
785
A12852
A11415
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.File; import java.io.FileNotFoundException; import java.io.PrintStream; import common.FileTranslatorBasis; public class B { int allOkLine; int surprisingOkLine; int allOkcount = 0; int surprisingOkcount = 0; int s; public void setS(int s){ this.s = s; } public void setP(int p){ allOkLine = p*3-2; surprisingOkLine = p*3-4; if(surprisingOkLine<=0){ surprisingOkLine = 1; } } public void setT(int t){ if(t>=allOkLine) allOkcount++; else if (t>=surprisingOkLine) surprisingOkcount++; } public int getAns(){ int surprise = surprisingOkcount > s ? s : surprisingOkcount; return surprise + allOkcount; } public static void main(String[] args) throws FileNotFoundException { System.setOut(new PrintStream(new File("output.txt"))); String fname = "B-small-attempt0.in.txt"; // String fname = "B-large-attempt0.in.txt"; FileTranslatorBasis ftb = FileTranslatorBasis.getInstance(fname); int num = ftb.getNumOfCase(); for (int i = 0; i < num; i++) { int[] input = ftb.getIntDataArray(); B b = new B(); b.setS(input[1]); b.setP(input[2]); for(int j=0;j<input[0];j++){ b.setT(input[j+3]); } System.out.println("Case #" + Integer.toString(i + 1) + ": " + String.valueOf(b.getAns())); } } }
0
786
A12852
A12550
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; import java.io.*; public class Dancing { public static void main(String[] args) { Scanner in = new Scanner(System.in); int cases = in.nextInt(); for (int i = 1; i<=cases; i++) { int n = in.nextInt(); // number of googlers int s = in.nextInt(); // number of surprising triplets int p = in.nextInt(); // ?? int[] points = new int[n]; for (int j = 0; j<n; j++) points[j] = in.nextInt(); // lowest possible unsurprising triplet: // p, p-1, p-1 // lowest possible surprising triplet: // p, p-2, p-2 int answer = 0; int possible = 0; int lowUn = lowestUnsurprising(p); int lowSu = lowestSurprising(p); for (int j = 0; j<n; j++) { if (points[j] >= lowUn) answer++; else if (points[j] >= lowSu) possible++; } answer += Math.min(possible, s); System.out.println("Case #"+i+": "+answer); } } public static int lowestUnsurprising(int p) { return p + (Math.max(p-1, 0))*2; } public static int lowestSurprising(int p) { return p + (Math.max(p-2, 0))*2; } }
0
787
A12852
A11968
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.Scanner; public class Q2 { public static void readFile() { try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("Q2-Small"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; // Read File Line By Line while ((strLine = br.readLine()) != null) { // Print the content on the console System.out.println(strLine); } // Close the input stream in.close(); } catch (Exception e) {// Catch exception if any System.err.println("Error: " + e.getMessage()); } } static int surpriseCount = 0; static int S = 0; static boolean isGreater(int totalNumbers, int p) { int single = totalNumbers/3; if(single>=p) { return true; } int remainder = totalNumbers%3; if(remainder==1) { single++; if(single>=p) { return true; } return false; } if(remainder==2) { single++; if(single>=p) { return true; } if(surpriseCount<S && single>0) { single++; if(single>=p) { surpriseCount++; return true; } } return false; } if(remainder==0) { if(surpriseCount<S && single>0) { single++; if(single>=p) { surpriseCount++; return true; } } return false; } return false; } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub // System.out.println("Hello"); try{ File file = new File("Q2_Small_Answer.out"); PrintStream output = new PrintStream(file); Scanner scanner = new Scanner(new File("Q2-Small")); int numberOfCases = scanner.nextInt(); // System.out.println(numberOfCases); int greaterCount = 0; for (int c = 0;c<numberOfCases;c++) { int N = scanner.nextInt(); // System.out.println(N); S = scanner.nextInt(); // System.out.println(S); int p = scanner.nextInt(); // System.out.println(p); greaterCount = 0; surpriseCount = 0; for (int i = 0;i<N;i++) { int totalNumbers = scanner.nextInt(); // System.out.print(totalNumbers+", "); if(isGreater(totalNumbers, p)) { // System.out.println("YES"); greaterCount ++; } else { // System.out.println("NO"); } } // System.out.println("Case #"+(c+1)+": "+greaterCount); output.println("Case #"+(c+1)+": "+greaterCount); } output.close(); System.out.println("Your file has been written"); /* // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("Q2-Small"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line // strLine = br.readLine(); int numberOfCases = in.readInt();//Integer.parseInt(strLine); System.out.println(numberOfCases); for (int i = 0;i<numberOfCases;i++) { int n = in.readInt(); System.out.println(n); } //Close the input stream in.close();*/ }catch (Exception e){//Catch exception if any System.err.println("Error: " + e.getMessage()); } } }
0
788
A12852
A12305
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.example; import java.io.IOException; import java.util.List; public class ProblemB { enum Result { INSUFFICIENT, SUFFICIENT, SUFFICIENT_WHEN_SURPRISING } public static void main(String[] a) throws IOException { List<String> lines = FileUtil.getLines("/B-small-attempt0.in"); int cases = Integer.valueOf(lines.get(0)); for(int c=0; c<cases; c++) { String[] tokens = lines.get(c+1).split(" "); int n = Integer.valueOf(tokens[0]); // N = number of Googlers int s = Integer.valueOf(tokens[1]); // S = number of surprising triplets int p = Integer.valueOf(tokens[2]); // P = __at least__ a score of P int sumSufficient = 0; int sumSufficientSurprising = 0; for(int i=0; i<n; i++) { int points = Integer.valueOf(tokens[3+i]); switch(test(points, p)) { case SUFFICIENT: sumSufficient++; break; case SUFFICIENT_WHEN_SURPRISING: sumSufficientSurprising++; break; } // uSystem.out.println("points "+ points +" ? "+ p +" => "+ result); } System.out.println("Case #"+ (c+1) +": "+ (sumSufficient + Math.min(s, sumSufficientSurprising))); // System.out.println(); // System.out.println("N="+ n +", S="+ s +", P="+ p); // System.out.println(); } } private static Result test(int n, int p) { int fac = n / 3; int rem = n % 3; if(rem == 0) { // int triplet0[] = { fac, fac, fac }; // print(n, triplet0); if(fac >= p) { return Result.SUFFICIENT; } if(fac > 0 && fac < 10) { if(fac+1 >= p) { return Result.SUFFICIENT_WHEN_SURPRISING; } // int triplet1[] = { fac+1, fac, fac-1 }; // surprising // print(n, triplet1); } } else if(rem == 1) { // int triplet0[] = { fac+1, fac, fac }; // print(n, triplet0); if(fac+1 >= p) { return Result.SUFFICIENT; } // if(fac > 0 && fac < 10) { // int triplet1[] = { fac+1, fac+1, fac-1 }; // print(n, triplet1); // } } else if(rem == 2) { // int triplet0[] = { fac+1, fac+1, fac }; // print(n, triplet0); if(fac+1 >= p) { return Result.SUFFICIENT; } if(fac < 9) { // int triplet1[] = { fac+2, fac, fac }; // surprising // print(n, triplet1); if(fac+2 >= p) { return Result.SUFFICIENT_WHEN_SURPRISING; } } } else { throw new RuntimeException("error"); } return Result.INSUFFICIENT; // System.out.println(); // System.out.println(n +" => "+ div3 +" ("+ rem +")"); } // private static void print(int n, int[] triplet) { // System.out.println("n="+ n +" ("+ (n/3) +","+ (n%3) +") => ["+ triplet[0] +","+ triplet[1] +","+ triplet[2] +"]" + (triplet[0]-triplet[2] > 1 ? " *" : "")); // } }
0
789
A12852
A10538
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.Arrays; import java.io.*; public final class problem1 { static int N; static int S; static int p; public static String getResult(int[] input){ Arrays.sort(input); int min; if(p < 2) min = p; else min = p + (p-2) + (p-2); int sur = S; int total = 0; for(int i = 0 ; i < input.length ; i++){ //System.out.print(input[i] + " " + min); //large than min surprise -> will handle this value if(input[i] >= min && input[i] <= 28){ if(input[i] % 3 == 2){ //value like 11 if(sur > 0){ int large = input[i] / 3 + 2; if(large >= p){ total++; sur--; } }else{ int large = input[i] / 3 + 1; if(large >= p){ total++; } } }else if(input[i] % 3 == 1){//value like 13 if(sur > 0){ int large = input[i] / 3 + 1; if(large >= p){ total++; sur--; } }else{ int large = input[i] / 3 + 1; if(large >= p){ total++; } } }else{ // valeu like 15 if(sur > 0){ int large = input[i] / 3 + 1; if(large >= p){ total++; sur--; } }else{ int large = input[i] / 3; if(large >= p){ total++; } } } }else if(input[i] > 28){ total++; } } //System.out.println(); return Integer.toString(total); } public static void main(String[] args){ try{ //Scanner sc = new Scanner(new File("yo.txt")); Scanner sc = new Scanner(new File("B-small-attempt0.in")); FileWriter fw = new FileWriter("small.txt"); String tmp = sc.nextLine(); int step = Integer.valueOf(tmp); int counter = 1; while(sc.hasNextLine()){ String s = sc.nextLine(); Scanner ssc = new Scanner(s); N = ssc.nextInt(); S = ssc.nextInt(); p = ssc.nextInt(); int[] arr = new int[N]; for(int i = 0 ; i < N ; i++) arr[i] = ssc.nextInt(); String xx = getResult(arr); System.out.println("Case #" + counter + ": " + xx); fw.write("Case #" + counter + ": " + xx); fw.write("\n"); counter++; if(step < counter) break; } fw.close(); }catch(Exception e){} } }
0
790
A12852
A10247
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 B; import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; public class DancingWithTheGooglers { /** * @param args */ public static void main(String[] args) throws Exception { /* Input File */ BufferedReader reader = new BufferedReader(new FileReader("G:/projects/CodeJam12/src/B/in.txt")); /* Output File */ PrintWriter writer = new PrintWriter(new FileWriter("G:/projects/CodeJam12/src/B/out.txt")); /* Getting number of test cases */ int noOfTestCases = Integer.parseInt(reader.readLine()); System.out.println("No of Test Cases : "+noOfTestCases); /* Iterating for every test case */ for ( int i=1; i <= noOfTestCases;i++){ /* Getting input test case line */ String ipline = reader.readLine(); System.out.println("\n\nTest Case "+i+" : "+ipline); /* Split the test case string */ String elements []= ipline.split(" "); int iElements [] = new int[elements.length]; /* Parsing elements to integer */ for ( int j=0; j<elements.length; j++ ){ iElements[j] = Integer.parseInt(elements[j]); } /* Assigning Values */ int noOfGooglers = iElements[0]; int noOfSuprisingTriplets = iElements[1]; int bestResultP = iElements[2]; System.out.println("No of Googlers : "+noOfGooglers); System.out.println("No of Surprising Triplets : "+noOfSuprisingTriplets); System.out.println("Best Result P : "+bestResultP); /* from 3 to < iElements.length is total scores elements of googlers */ int maxGooglersWithBestResultP = 0; for ( int j=3; j<elements.length; j++ ){ System.out.println("Total Marks of Googler "+(j-2)+" : "+iElements[j]); int avgCeilMarks = ( int ) Math.ceil( (double) iElements[j] / 3 ); System.out.println("Avg Ceil Marks of Googler "+(j-2)+" : "+avgCeilMarks); // If equal or more than best result increment counter if ( avgCeilMarks >= bestResultP ) { maxGooglersWithBestResultP++; // Check for surprising triplet }else if ( noOfSuprisingTriplets > 0 && (iElements[j] % 3 ) != 1 && (avgCeilMarks + 1) <= iElements[j] && (avgCeilMarks + 1) >= bestResultP ){ maxGooglersWithBestResultP++; noOfSuprisingTriplets --; } } System.out.println("No of Surprising Triplets Left ( In-effective Surprising Triplets ) : "+noOfSuprisingTriplets); /* print output */ System.out.println("Case #"+i+": "+maxGooglersWithBestResultP); writer.println("Case #"+i+": "+maxGooglersWithBestResultP); } /* closing streams */ System.out.println("\n\nClosing streams..."); writer.close(); reader.close(); System.out.println("Streams closed."); } }
0
791
A12852
A10017
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 googlejam2; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class Main2 { static int surprising = 0; public static String resolveTestCase(String line) { // Read input parameters String tokens [] = line.split(" "); int N = Integer.parseInt(tokens[0]); int S = Integer.parseInt(tokens[1]); int P = Integer.parseInt(tokens[2]); surprising = 0; System.out.println("N = " + N + ", S = " + S + ", P = " + P); int [] scores = new int[N]; for ( int i = 0; i < N; i++) { scores[i] = Integer.parseInt(tokens[3+i]); } // calculate result int result = 0; for ( int i = 0; i < N; i++ ) { System.out.print("Dancer " + i + " score " + scores[i]); if ( scores[i] >= Math.max(3 * P - 2, P) ) { result++; System.out.println(" ok "); } else if ( surprising < S ) { if ( scores[i] >= Math.max( 3 * P - 4, P ) ) { result++; surprising++; System.out.println(" surprising "); } } } return "" + result; } public static void main (String [] args) throws IOException { String inputFile = args[0]; File f = new File(inputFile); FileReader fr = new FileReader(f); BufferedReader br = new BufferedReader(fr); File f2 = new File(inputFile + ".out"); FileWriter fw = new FileWriter(f2); String line = br.readLine(); int count = Integer.parseInt(line); // resolve test cases int testcase = 1; for(int tests = 0; tests < count; tests++) { line = br.readLine(); System.out.println(line); String output = "Case #"+testcase+": "; output += resolveTestCase(line); System.out.println(output+"\n"); fw.write(output+"\r\n"); testcase++; } fw.close(); } }
0
792
A12852
A11374
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.lang.reflect.Array; import java.util.Arrays; import java.util.Scanner; public class B { private static final String INPUTFILE = "./B.in"; private static final String OUTPUTFILE = "./B.out"; private static FileReader in; private static FileWriter out; private static BufferedReader buffIn; private static BufferedWriter buffOut; private static Scanner s; public static String executeSingle(){ int res = 0; int N = s.nextInt(); int S = s.nextInt(); int p = s.nextInt(); int[] t= new int[N]; for(int i=0;i<N;i++){ t[i] = s.nextInt(); } Arrays.sort(t); int minimumOKScore = p+Math.max(p-1, 0)*2; int minimumPossibleScore = p+Math.max(p-2, 0)*2; //tant que le score est plus grand que le plus petit plausible possible (p+p-1+p-1) for(int i=N-1;i>=0;i--){ if(t[i]>= minimumOKScore){ res++; } else if(t[i]>= minimumPossibleScore && S > 0){ S--; res++; } } return ""+res; } public static void execute() throws IOException{ int n = s.nextInt(); s.nextLine(); for(int i=1;i<=n;i++){ buffOut.append("Case #"+i+": "+executeSingle()); buffOut.newLine(); //System.out.println("Case #"+i+": "+executeSingle()); } } public static void main(String[] args) throws IOException { in = new FileReader(INPUTFILE); out = new FileWriter(OUTPUTFILE); buffIn = new BufferedReader(in); buffOut = new BufferedWriter(out); s = new Scanner(buffIn); execute(); buffOut.flush(); buffOut.close(); buffIn.close(); out.close(); in.close(); } }
0
793
A12852
A10335
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 GoogleDancer { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(new FileReader("Dancer.in")); PrintWriter pw = new PrintWriter(new FileWriter("Dancer.out"), true); int T = sc.nextInt(); for (int c = 1; c<=T; c++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int[] points = new int[N]; for (int d = 0; d < N; d++) { points[d] = sc.nextInt(); } int num = calc(N, S, p, points); String x = String.format("Case #%d: %d", c, num); pw.println(x); } pw.close(); } public static int calc(int N, int S, int p, int[] points) { int total = 0; int min = ((p-2)<0? 0 : p-2)*2 + p; for (Integer n : points) { if (n < min) continue; int avg = n/3; if (n%3 == 0) { if (avg >= p) total++; else if ((avg+1) >= p && S>0) { total++; S--; } }else if (n%3 == 1) { if ((avg+1) >= p)total++; }else { if ((avg+1) >= p) total++; else if ((avg+2)>= p && S > 0) { total++; S--; } } } return total; } }
0
794
A12852
A11193
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.*; class CodejamB { public static char[] map; public static void main (String [] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("E:/B-small-attempt0.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("E:/outB.txt"))); int nTest = Integer.parseInt(in.readLine()); for (int testIndex = 0; testIndex < nTest; testIndex++) { out.print("Case #" + (testIndex + 1) + ": "); /***** start **********/ 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[] data = new int[n]; int remainingS = s; int result = 0; for (int i = 0; i < n; i++) { data[i] = Integer.parseInt(st.nextToken()); if (data[i] >= p + 2 * Math.max(0, p - 1)) { result++; } else if (data[i] >= p + 2 * Math.max(0, p - 2) && remainingS > 0) { remainingS--; result++; } } out.print(result); /***** end **********/ out.println(); } out.close(); } }
0
795
A12852
A11054
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 bchang; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; /** * Created with IntelliJ IDEA. * User: bchang * Date: 4/14/12 * Time: 9:08 PM * To change this template use File | Settings | File Templates. */ public class ProblemB { private static int process(String line) { StringTokenizer st = new StringTokenizer(line); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int counter = 0; for (int j = 0; j < n; j++) { int ti = Integer.parseInt(st.nextToken()); int r = ti - p; if (r >= 0) { if (r >= p * 2 - 2) { counter++; } else if (s > 0 && r >= p * 2 - 4) { counter++; s--; } } } return counter; } public static void main(String[] args) throws Exception { BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(reader.readLine()); for (int i = 0; i < t; i++) { String line = reader.readLine(); int result = process(line); System.out.println("Case #" + (i + 1) + ": " + result); } } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { } } } } }
0
796
A12852
A12409
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Googlers { public static void main(String[] args)throws IOException { Scanner sc = new Scanner(new File("input2.txt")); int loop = sc.nextInt(); int num; int s = 0; int p; int n; int count = 0; int check; ArrayList<Integer> array = new ArrayList<Integer>(); for (int i = 0 ; i < loop ; i++) { num = sc.nextInt(); s = sc.nextInt(); p = sc.nextInt(); for (int j=0 ; j<num ;j++){ array.add(sc.nextInt()); } n = p*3-2; for (Integer in : array){ if (in >= n) count++; else { if(s>0){ check = (p+(p-2)*2); if(in >= check && check >0){ count++; s--; } } } } System.out.println("Case #"+(i+1)+": "+count); count = 0; array.clear(); } } }
0
797
A12852
A10150
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintStream; import java.util.Scanner; public class DancingWiththeGooglers { enum Type{ A{ @Override public int getNoSurpiseHigh(int value) { // TODO Auto-generated method stub return (value+1)/3; } @Override public int getSurpiseHigh(int value) { // TODO Auto-generated method stub return (value+1)/3+1; } }, B{ @Override public int getNoSurpiseHigh(int value) { // TODO Auto-generated method stub return (value)/3; } @Override public int getSurpiseHigh(int value) { // TODO Auto-generated method stub return (value)/3+1; } }, C{ @Override public int getNoSurpiseHigh(int value) { // TODO Auto-generated method stub return (value-1)/3+1; } @Override public int getSurpiseHigh(int value) { // TODO Auto-generated method stub return (value-1)/3+1; } }, ZERO{ @Override public int getNoSurpiseHigh(int value) { // TODO Auto-generated method stub return 0; } @Override public int getSurpiseHigh(int value) { // TODO Auto-generated method stub return 0; } }, ONE{ @Override public int getNoSurpiseHigh(int value) { // TODO Auto-generated method stub return 1; } @Override public int getSurpiseHigh(int value) { // TODO Auto-generated method stub return 1; } }; public static Type valueOf(int value){ switch (value){ case 0: return Type.ZERO; case 1: return Type.ONE; default: switch (value%3){ case 0: return B; case 1: return C; case 2: return A; default: return null; } } } int value; public abstract int getSurpiseHigh(int value); public abstract int getNoSurpiseHigh(int value); } public static void main(String args[]) throws FileNotFoundException{ //System.setOut(new PrintStream(new File("DancingWiththeGooglers.txt"))); Scanner scanner = new Scanner(System.in); int testcasenum = Integer.valueOf(scanner.next()); scanner.nextLine(); for (int testcase = 0;testcase < testcasenum;testcase++){ int googlersnum = scanner.nextInt(); int surpisesnum = scanner.nextInt(); int atleast = scanner.nextInt(); //int totals[] = new int[googlersnum]; int maximum = 0; for (int index = 0;index < googlersnum;index++){ int total = scanner.nextInt(); Type type = Type.valueOf(total); //System.out.println(type); //System.out.println(type.getNoSurpiseHigh(total)); if (type != Type.ZERO && type != Type.ONE && type != Type.C && type.getSurpiseHigh(total) == atleast && surpisesnum > 0){ maximum++; surpisesnum--; }else if (type.getNoSurpiseHigh(total) >= atleast){ maximum++; } } System.out.print("Case #"); System.out.print(testcase+1); System.out.print(": "); System.out.println(maximum); } } }
0
798
A12852
A10267
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.StringTokenizer; public class Dancing { public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt0.in")); PrintWriter out = new PrintWriter(new FileWriter("B-small-attempt0.out")); Integer cases = Integer.valueOf(in.readLine().trim()); for (int i = 0; i < cases; i++) { StringTokenizer st = new StringTokenizer(in.readLine().trim()); int dancers = Integer.valueOf(st.nextToken().trim()); int surprising = Integer.valueOf(st.nextToken().trim()); int minScore = Integer.valueOf(st.nextToken().trim()); int[] scoreTotals = new int[dancers]; for (int j = 0; j < scoreTotals.length; j++) { scoreTotals[j] = Integer.valueOf(st.nextToken().trim()); } int maxDancers = solve(surprising, 0, minScore, scoreTotals, 0); out.println(String.format("Case #%d: %d", i+1, maxDancers)); } out.close(); in.close(); } catch (IOException e) { e.printStackTrace(); } } public static int solve(int maxSurprising, int numSurprising, int minScore, int[] scoreTotals, int totalIndex) { int maxDancers = 0; if (totalIndex < scoreTotals.length) { int totalScore = scoreTotals[totalIndex]; for (int i = (int)Math.ceil(totalScore/3); i <= (int)Math.min(totalScore,Math.ceil((totalScore+4)/3)); i++) { for (int j = Math.max(i-2,0); j <= i; j++) { int k = totalScore - i - j; if ((i - k > 2) || (i - k < 0)) continue; boolean isSurprising = Math.abs(i - j) == 2 || Math.abs(i - k) == 2 || Math.abs(j - k) == 2; if (isSurprising && maxSurprising == numSurprising) continue; int dancers = (i >= minScore ? 1 : 0) + solve(maxSurprising, numSurprising + (isSurprising ? 1 : 0), minScore, scoreTotals, totalIndex+1); maxDancers = Math.max(maxDancers, dancers); } } } return maxDancers; } }
0
799