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
A10789
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; public class C { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new FileReader("codejamb.in")); BufferedWriter brout=new BufferedWriter(new FileWriter("codejamb.out")); StringTokenizer sb=new StringTokenizer(br.readLine()); int t=Integer.parseInt(sb.nextToken()); int n; int p; int surprising; int[] values; for(int l=1;l<=t;l++) { sb=new StringTokenizer(br.readLine()); n=Integer.parseInt(sb.nextToken()); surprising=Integer.parseInt(sb.nextToken()); p=Integer.parseInt(sb.nextToken()); values=new int[n]; for(int i=0;i<n;i++) { values[i]=Integer.parseInt(sb.nextToken()); } int resultMax=getAnswer(values,p,surprising,0); brout.write("Case #"+l+": "+resultMax+"\n"); } brout.close(); return; } public static int getAnswer(int[] x,int p,int surprisingleft,int start) { if(x.length-start<surprisingleft) { return Integer.MIN_VALUE; } if(start>=x.length && surprisingleft!=0) { return Integer.MIN_VALUE; } if(start==x.length && surprisingleft==0) { return 0; } boolean flag=false; if(surprisingleft==0) { flag=true; } int ifsurprising=0; int ifnotsurprising=0; int k=x[start]%3; int num1s=0; int num2s=0; int num3s=0; int num1not=0; int num2not=0; int num3not=0; switch(k) { case 0: if(x[start]==30 || x[start]==0) { num1not=x[start]/3; num2not=x[start]/3; num3not=x[start]/3; num1s=x[start]/3; num2s=x[start]/3; num3s=x[start]/3; } else { num1s=x[start]/3-1; num2s=x[start]/3; num3s=x[start]/3+1; num1not=x[start]/3; num2not=x[start]/3; num3not=x[start]/3; } break; case 1: if(x[start]==1) { num1s=x[start]/3; num2s=x[start]/3; num3s=x[start]/3+1; num1not=x[start]/3; num2not=x[start]/3; num3not=x[start]/3+1; } else { num1s=x[start]/3-1; num2s=x[start]/3+1; num3s=x[start]/3+1; num1not=x[start]/3; num2not=x[start]/3; num3not=x[start]/3+1; } break; case 2: num1s=x[start]/3; num2s=x[start]/3; num3s=x[start]/3+2; num1not=x[start]/3; num2not=x[start]/3+1; num3not=x[start]/3+1; break; } if(num1s>=p) { ifsurprising++; } if(num2s>=p) { ifsurprising++; } if(num3s>=p) { ifsurprising++; } if(num1not>=p) { ifnotsurprising++; } if(num2not>=p) { ifnotsurprising++; } if(num3not>=p) { ifnotsurprising++; } if(flag) { if(ifnotsurprising>0) return getAnswer(x,p,surprisingleft,start+1)+1; else return getAnswer(x,p,surprisingleft,start+1); } else { int acc21=0; int acc22=0; if(ifsurprising>0) { acc21=1; } if(ifnotsurprising>0) { acc22=1; } if(getAnswer(x,p,surprisingleft-1,start+1)+acc21> getAnswer(x, p, surprisingleft, start+1)+acc22) return getAnswer(x,p,surprisingleft-1,start+1)+acc21; else return getAnswer(x, p, surprisingleft, start+1)+acc22; } } }
0
200
A12852
A10343
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.dten.cj.qual; import static java.lang.Integer.parseInt; import static java.lang.Math.max; import static java.lang.Math.min; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.apache.commons.io.FileUtils; public class B { public static final int NotSurprising = 0; public static final int Surprising = 1; public static final int Impossible = -2; private int N; private int S; private int p; private int[] scores; public int evaluate(int i, int j, int k) { int diff = max(i,max(j,k)) - min(i,min(j,k)); if (diff == 0 || diff == 1 ) return NotSurprising; if(diff == 2) return Surprising; if(diff > 2) return Impossible; return -1; } public int evaluate(int[] triple) { if (triple.length != 3) return Impossible; return evaluate(triple[0], triple[1], triple[2]); } public int processLine(String string) { String[] split = string.split(" "); if (split.length < 4) return -1; N = parseInt(split[0]); S = parseInt(split[1]); p = parseInt(split[2]); scores = new int[split.length - 3]; for (int i = 0; i < scores.length; i++) { scores[i] = parseInt(split[i + 3]); } N = parseInt(split[0]); List<int[][]> possibleCombos = new ArrayList<int[][]>(); for (int i = 0; i < scores.length; i++) { possibleCombos.add(possibleScores(scores[i])); } int non = 0; int surp = 0; int fail = 0; for (int[][] ps : possibleCombos) { if(hasNonsurprisingTripleAbove(ps)) non++; else if (hasSurprisingTripleAbove(ps)) surp++; else fail++; } return non + min(S, surp); } public boolean hasNonsurprisingTripleAbove(int[][] ps) { for (int[] triple : ps) { if (max(triple[0], max(triple[1], triple[2])) >= p && evaluate(triple) == NotSurprising) { return true; } } return false; } public boolean hasSurprisingTripleAbove(int[][] ps) { for (int[] triple : ps) { if (max(triple[0], max(triple[1], triple[2])) >= p && evaluate(triple) == Surprising) { return true; } } return false; } public int[][] possibleScores(int score) { ArrayList<int[]> list = new ArrayList<int[]>(); for (int i = 0; i <= 10; i++) for (int j = 0; j <= i; j++) for (int k = 0; k <= j; k++) if (k + j + i == score && evaluate(i, j, k) > -1) list.add(new int[] { k, j, i }); return list.toArray(new int[list.size()][]); } public String processFile(String fileName) { StringBuilder sb = new StringBuilder(); int caseCount = 1; try (BufferedReader in = new BufferedReader(new FileReader(fileName))) { String str = in.readLine(); // Skip first while ((str = in.readLine()) != null) { sb.append("Case #").append(caseCount++).append(": ") .append(processLine(str)).append("\r\n"); } } catch (IOException e) { e.printStackTrace(); } return sb.toString().trim(); } public static void main(String[] args) { B b = new B(); String fileName = "B-small-attempt0"; try { FileUtils.write(new File("outputs/qual/" + fileName + ".out"), b.processFile("inputs/qual/" + fileName + ".in")); } catch (IOException e) { e.printStackTrace(); } } }
0
201
A12852
A12219
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.IOException; import java.io.InputStreamReader; public class Dancing_with_the_Googlers { public static void main(String[] args) throws IOException { FileInputStream fis; try { fis = new FileInputStream("B-small-attempt0.in"); InputStreamReader ir = new InputStreamReader(fis); BufferedReader br = new BufferedReader(ir); String s;int i=0; br.readLine(); while (br.ready()) { i++; s = br.readLine(); System.out.print("Case #"+i+": "); tran(s); System.out.print("\r"); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } //tran(a); } static void tran(String a) { String num=""; int count=0;int N=0;int S=0;int P=0; int[] score=new int[100]; for(int i=0;i<a.length();i++) { if(Character.isDigit(a.charAt(i))&&i!=a.length()-1) { num=num+a.charAt(i); } else if(count==0) { N=Integer.parseInt(num); num=""; count++; } else if(count==1) { S=Integer.parseInt(num); num=""; count++; } else if(count==2) { P=Integer.parseInt(num); num=""; count++; } else if(i==(a.length()-1)) { num=num+a.charAt(i); score[count-3]=Integer.parseInt(num); } else { score[count-3]=Integer.parseInt(num); num=""; count++; } } //System.out.print(N+" "+S+" "+P+" "); //for(int i=0;i<N;i++){System.out.print(score[i]+" ");} int ans1=0,ans2=0,fin=0; for(int i=0;i<N;i++) { if(score[i]>=P*3-2&&score[i]>=P){ans1++;} else if(score[i]>=P*3-4&&score[i]>=P){ans2++;} } if(ans2<=S){fin=ans2+ans1;} else{fin=S+ans1;} System.out.print(fin); } }
0
202
A12852
A11772
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package qual2012; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Locale; import java.util.StringTokenizer; public class B { private static final String TASKNAME = "input"; private void solve() throws IOException { int Case = 0; for (int t = nextInt(); t > 0; t--) { int n = nextInt(); int s = nextInt(); int p = nextInt(); int res = 0; for (int i = 0; i < n; i++) { int r = nextInt(); if (r < p || (r - p) / 2 < p - 2) { continue; } if ((r - p) / 2 == p - 2 && s > 0) { s--; res++; } else if ((r - p) / 2 > p - 2) { res++; } } Case++; println("Case #" + Case + ": " + res); } } private String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } private int nextInt() throws NumberFormatException, IOException { return Integer.parseInt(nextToken()); } private double nextDouble() throws NumberFormatException, IOException { return Double.parseDouble(nextToken()); } private long nextLong() throws IOException { return Long.parseLong(nextToken()); } private void print(Object o) { writer.print(o); } private void println(Object o) { writer.println(o); } private void printf(String format, Object... o) { writer.printf(format, o); } public static void main(String[] args) { long time = System.currentTimeMillis(); Locale.setDefault(Locale.US); new B().run(); System.err.printf("%.3f\n", 1e-3 * (System.currentTimeMillis() - time)); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; private void run() { try { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out); reader = new BufferedReader(new FileReader(TASKNAME + ".in")); writer = new PrintWriter(TASKNAME + ".out"); solve(); reader.close(); writer.close(); } catch (IOException e) { e.printStackTrace(); System.exit(13); } } }
0
203
A12852
A10166
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.util.Scanner; class B{ public static void main(String[] args) { if(args.length==0){ System.out.println("Error :: Please provide input file name as first command line argument"); System.out.println("Usage :: java Main <file_name>"); System.out.println("Example :: java Main A-small-practice.in"); } else{ try{ Scanner input=new Scanner(new File("B-small-attempt0 (1).in")); //Scanner input=new Scanner(new File("input.txt")); //System.out.println("Reading Input from "+ args[0]+" file"); int no=input.nextInt(); int in[][]=new int[no][100]; for(int i=0;i<no;i++){ in[i][0]=input.nextInt(); in[i][1]=input.nextInt(); in[i][2]=input.nextInt(); for(int j=3;j<in[i][0]+3;j++){ in[i][j]=input.nextInt(); } } /*//display for(int i=0;i<no;i++){ System.out.print(in[i][0]+" "); System.out.print(in[i][1]+" "); System.out.print(in[i][2]+" "); for(int j=3;j<in[i][0]+3;j++){ System.out.print(in[i][j]+" "); } System.out.println(); }*/ int mat[][]=new int[179][4]; int count=0; for(int i=10;i>=0;i--){ for(int j=10;j>=0;j--){ for(int k=10;k>=0;k--){ if(Math.abs(i-j)<=2&&Math.abs(j-k)<=2&&Math.abs(k-i)<=2){ if(Math.abs(i-j)==2||Math.abs(j-k)==2||Math.abs(k-i)==2){ mat[count][0]=i; mat[count][1]=j; mat[count][2]=k; mat[count++][3]=-1; } else{ mat[count][0]=i; mat[count][1]=j; mat[count++][2]=k; } } } } } /*for(int i=0;i<179;i++){ System.out.print(mat[i][0]+" "); System.out.print(mat[i][1]+" "); System.out.print(mat[i][2]+" "); System.out.print(mat[i][3]+" "); System.out.println(); }*/ //Algorithm for(int i=0;i<no;i++){ int flags[][]=new int[in[i][0]][2]; for(int j=3,k=0;j<in[i][0]+3;j++,k++){ for(int a=0;a<179;a++){ if((mat[a][0]+mat[a][1]+mat[a][2]==in[i][j])&&(mat[a][0]>=in[i][2]||mat[a][1]>=in[i][2]||mat[a][2]>=in[i][2])){ if(mat[a][3]==-1){ //System.out.println(mat[a][0]+" "+mat[a][1]+" "+mat[a][2]); flags[k][1]=-1; } else{ //System.out.println(mat[a][0]+" "+mat[a][1]+" "+mat[a][2]); flags[k][0]=-1; } } } //System.out.println(flags[k][0]+" "+flags[k][1]); } int finalCount=0; int sup=in[i][1]; for(int r=0;r<in[i][0];r++){ if(flags[r][0]==-1&&flags[r][1]==-1)finalCount++; else if(flags[r][0]==-1)finalCount++; else if(flags[r][0]==0&&flags[r][1]==-1&&sup>0){ finalCount++; sup--; } } System.out.println("Case #"+(i+1)+": "+finalCount); } }catch(Exception e){ e.printStackTrace(); } } } }
0
204
A12852
A11828
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.codejam2011.dancing; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; public class Runner { public ArrayList<String> output = new ArrayList<String>(); public class DancingEvent { private ArrayList<Score> scoreList; private int surprisingCount; private int maxValue; public ArrayList<Score> getScoreList() { return scoreList; } public void setScoreList(ArrayList<Score> scoreList) { this.scoreList = scoreList; } public int getSurprisingCount() { return surprisingCount; } public void setSurprisingCount(int surprisingCount) { this.surprisingCount = surprisingCount; } public int getMaxValue() { return maxValue; } public void setMaxValue(int maxValue) { this.maxValue = maxValue; } } private class Score { private final static int JURY_COUNT = 3; private int values[] = new int[JURY_COUNT]; private int sum; private int max; private int maxSurprise; public Score(int pSum) { this.sum = pSum; } public void calcValues() { if (this.sum == 0) { max = 0; maxSurprise = 0; } else { int base = this.sum / JURY_COUNT; int rest = this.sum % JURY_COUNT; for (int i = 0; i < values.length; i++) { values[i] = base; if (rest != 0) { values[i]++; rest--; } } rest = this.sum % JURY_COUNT; if (rest == 0) { max = base; maxSurprise = base + 1; } else { max = base + 1; if (rest == 1) maxSurprise = base + 1; else maxSurprise = base + 2; } } } public boolean isBigger(int p) { if (this.max >= p) return true; else return false; } public boolean isSurpriseBigger(int p) { if (this.maxSurprise >= p) return true; else return false; } } public class InputParser { private BufferedReader br; public InputParser(String path, ArrayList<DancingEvent> dances) { try { br = new BufferedReader(new FileReader(new File(path))); String inputLine; int T = 0, N, S, P, counter = 0; int countBase = 0, counterSurprise = 0; try { while ((inputLine = br.readLine()) != null) { if (T == 0) { T = new Integer(inputLine); } else { String input[] = inputLine.split(" "); N = new Integer(input[0]); S = new Integer(input[1]); P = new Integer(input[2]); countBase = 0; counterSurprise = 0; ArrayList<Score> scores = new ArrayList<Runner.Score>(); for (int i = 3; i < input.length; i++) { Score tmpScore = new Score( new Integer(input[i])); tmpScore.calcValues(); scores.add(tmpScore); if (tmpScore.isBigger(P)) countBase++; else if (tmpScore.isSurpriseBigger(P)) counterSurprise++; } DancingEvent dance = new DancingEvent(); dance.setMaxValue(P); dance.setScoreList(scores); dance.setSurprisingCount(S); dances.add(dance); output.add("Case #"+ counter + ": " + ((Integer) Math.min( counterSurprise, S) + (Integer) countBase)); } counter++; } } catch (NumberFormatException e) { e.printStackTrace(); System.out.println("Could not parse Numbers"); } catch (IOException e) { e.printStackTrace(); System.out.println("Could not Read Lines"); } } catch (FileNotFoundException e) { e.printStackTrace(); System.out.println("Could not open file"); } } } public void writeOutput(String path){ BufferedWriter bw; try { bw = new BufferedWriter( new FileWriter(new File(path))); for(String s : output) try { bw.write(s + "\r\n"); } catch (IOException e) { e.printStackTrace(); System.out.println("Could not write in file"); } bw.close(); } catch (IOException e) { e.printStackTrace(); System.out.println("Could not open file"); } } public static void main(String args[]) { Runner r = new Runner(); ArrayList<DancingEvent> dances = new ArrayList<Runner.DancingEvent>(); r.new InputParser("src/com/google/codejam2011/dancing/input.txt", dances); r.writeOutput("src/com/google/codejam2011/dancing/output.txt"); } }
0
205
A12852
A12262
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.LinkedList; public class Triplet { public Triplet() { } public static int triplete(LinkedList<Integer> t_i, int p, int s) { int res = 0; int a,b,c; for(Integer i : t_i) { a = p; b = p-1; c = p-2; if(a+b+c < i) { c++; } if(a+b+c < i) { b++; } if(a+b+c < i) { c++; } if(a+b+c > i) { b--; } while(a+b+c < i) { if(a+b+c < i) { b++; } if(a+b+c < i) { c++; } if(a+b+c < i) { a++; } } int prue = a + b + c; if(a >= 0 && b >= 0 && c >= 0) { if(prue == i && a <= 10 && b <= 10 && c <= 10 && (a - b != 2 && a - c != 2 && b - c != 2)) { res++; } else if(prue == i &&(a - b == 2 || a - c == 2 || b - c == 2) && s > 0) { res++; s--; } } } return res; } }
0
206
A12852
A10562
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Googlers { public static void main(String[] args) throws IOException { BufferedReader read = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(read.readLine()); for (int i = 1; i <= t; i++){ String[] a = read.readLine().split(" "); int n = Integer.parseInt(a[0]); int s = Integer.parseInt(a[1]); int p = Integer.parseInt(a[2]); int result = 0; int temp = 0; for (int j = 0; j < n; j++){ temp = Integer.parseInt(a[3+j]); if (temp == 0 && p > 0); else if (temp < p); else if (temp >= 3*p) result++; else { temp = temp - p; double d = temp/2.0; double e = p; if (e - d<= 1.0) { result++; } else if (e - d <= 2.0 && s > 0) { result++; s--; } } } System.out.println("Case #"+ i + ": "+ result); } } }
0
207
A12852
A11018
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; /** * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in * Java. */ public interface Lambda2<P, Q, V> { public V apply(P param1, Q param2); }
0
208
A12852
A10320
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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; public class SolverModule { public StringBuilder process(BufferedReader in, StringBuilder builder) throws IOException { in.readLine(); String line = in.readLine(); int count = 1; while (line != null) { appendLine(line, builder,count); count++; line = in.readLine(); } return builder; } public static void appendLine(String line, StringBuilder builder, int count) { builder.append("Case #"+count+": "+line + "\r\n"); } }
0
209
A12852
A13124
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
//input file must be in.txt in this directory //output file will be out.txt import java.io.*; import java.util.*; public class B { public static Scanner in; public static PrintStream out; public static void main(String [] args) throws Throwable { in = new Scanner(new File("in.txt")); int cases = in.nextInt(); in.nextLine(); out = new PrintStream(new File("out.txt")); for (int i = 1; i <= cases; i++) { out.print("Case #" + i + ": "); printResult(); out.println(); } } public static void printResult() { int n,p,s; n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); int surprize; int good; if (p > 1) { surprize = (3*p)-4; good = (3*p) - 2; } else { surprize = p; good = p; } int tot = 0; int cur; for (int i = 0; i < n; i++) { cur = in.nextInt(); if (cur >= good) tot++; else if(cur >= surprize && s > 0) { s--; tot++; } } out.print(tot); } }
0
210
A12852
A10616
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.ArrayList; import java.util.Scanner; public class GooglerDancer { private int caseNumber; private int numberOfGooglers; private int numberOfSuprisingTriplets; private int minimumBestScoreP; private ArrayList<Integer> list; public GooglerDancer(int caseNumber,String data) { this.caseNumber=caseNumber; Scanner s=new Scanner(data); this.numberOfGooglers=s.nextInt(); this.numberOfSuprisingTriplets=s.nextInt(); this.minimumBestScoreP=s.nextInt(); list=new ArrayList<Integer>(); while(s.hasNextInt()){ list.add(s.nextInt()); } } public void process() { int count =0; if(numberOfGooglers>0){ ///// if(minimumBestScoreP>0){ for(int i=0;i<numberOfGooglers;i++){ if(list.get(i)>0) { if((Integer)(list.get(i)/minimumBestScoreP)>=3){ count++; } else{ if((Integer)(minimumBestScoreP-(list.get(i)-minimumBestScoreP)/2)==1){ count++; } else{ if((Integer)(minimumBestScoreP-(list.get(i)-minimumBestScoreP)/2)==2 && numberOfSuprisingTriplets>0){ count++; numberOfSuprisingTriplets--; } } } } } //////////// }else{ count=numberOfGooglers; } } System.out.println("Case #"+caseNumber+": "+count); } }
0
211
A12852
A12968
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package mgg.utils; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; public class CorrespondenceUtils { public static String getT9Correspondence(char c) { /** Generating code: for(int i = 0; i<=25; i++){ System.out.println("case '"+((char)(i+((int)'a')))+"':"); System.out.println("return \"\";"); } */ switch (c){ case 'a': return "2"; case 'b': return "22"; case 'c': return "222"; case 'd': return "3"; case 'e': return "33"; case 'f': return "333"; case 'g': return "4"; case 'h': return "44"; case 'i': return "444"; case 'j': return "5"; case 'k': return "55"; case 'l': return "555"; case 'm': return "6"; case 'n': return "66"; case 'o': return "666"; case 'p': return "7"; case 'q': return "77"; case 'r': return "777"; case 's': return "7777"; case 't': return "8"; case 'u': return "88"; case 'v': return "888"; case 'w': return "9"; case 'x': return "99"; case 'y': return "999"; case 'z': return "9999"; case ' ': return "0"; default: throw new RuntimeException("Not valid character: '" + c + "'"); } } public static char getGooglereseCorrespondence(char c) { /** Generating code: String strG = "ejp mysljylc kd kxveddknmc re jsicpdrysi rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd de kr kd eoya kw aej tysr re ujdr lkgc jv"; String strE = "our language is impossible to understand there are twenty six factorial possibilities so it is okay if you want to just give up"; HashSet<String> set = new HashSet<String>(); for (int i = 0; i< strE.length(); i++){ set.add("case '" + strG.charAt(i) + "':\treturn '" + strE.charAt(i) + "';"); //System.out.println("case '" + strG.charAt(i) + "':\treturn '" + strE.charAt(i) + "';"); } ArrayList<String> list = new ArrayList<String>(set); Collections.sort(list); for(String s : list){ System.out.println(s); } **/ switch (c){ case 'a': return 'y'; case 'b': return 'h'; case 'c': return 'e'; case 'd': return 's'; case 'e': return 'o'; case 'f': return 'c'; case 'g': return 'v'; case 'h': return 'x'; case 'i': return 'd'; case 'j': return 'u'; case 'k': return 'i'; case 'l': return 'g'; case 'm': return 'l'; case 'n': return 'b'; case 'o': return 'k'; case 'p': return 'r'; case 'q': return 'z'; case 'r': return 't'; case 's': return 'n'; case 't': return 'w'; case 'u': return 'j'; case 'v': return 'p'; case 'w': return 'f'; case 'x': return 'm'; case 'y': return 'a'; case 'z': return 'q'; case ' ': return ' '; default: throw new RuntimeException("Not valid character: '" + c + "'"); } } }
0
212
A12852
A10384
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; /** * * @author Dylan */ public class GooglerDance { int suprises; public GooglerDance(int sup) { suprises = sup; } public int getNumAboveP(int[] scores, int p) { int rNum = 0; for(int i = 0; i < scores.length; i++) { if(testAbove(scores[i], p)) rNum++; } return rNum; } public boolean testAbove(int total, int p) { if(p == 0) return true; if(total == 0) return false; total -= p; if(p - total/2 < 2) return true; if(p - total/2 < 3 && suprises > 0) { suprises--; return true; } return false; } public boolean aboveP(int total, int p) { int avg = total/3; if(suprises > 0){ avg += 2; if(avg > p) suprises--; } if(avg > p) return true; return false; } }
0
213
A12852
A11707
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Hashtable; public class test1 { ArrayList<String > result=new ArrayList<String>(); Hashtable<Character, Character> h=new Hashtable<Character, Character>(); int count =0; public void read_file() throws Exception { FileReader g = new FileReader("B-small-attempt0.in"); BufferedReader br = new BufferedReader(g); int No_of_Cases = Integer.parseInt(br.readLine()); String s; for(int i=0;i<No_of_Cases;i++) { s=br.readLine(); // ha2ra el lines hena solve2(s); } g.close(); write_file(); } public void solve2(String s) { String [] g=s.split(" "); int googleres=Integer.parseInt(g[0]); int sur=Integer.parseInt(g[1]); int target=Integer.parseInt(g[2]); if(target==0) { result.add(g.length-3+""); return; } int min_target=target*3-4;; int max_target=target*3-2; int counta=0; int countb=0; int temp; for(int i=3;i<g.length;i++) { temp=Integer.parseInt(g[i]); if (temp!=0 || target!=1) { if(temp>=min_target) { if(temp >=max_target) { counta++; }else { countb++; } } } } if(countb<sur) { counta+=countb; }else { counta+=sur; } result.add(counta+""); } public void Equal(String s1,String s2) { for (int i=0;i<s1.length();i++) { if(h.get(s1.charAt(i))==null) { h.put(s1.charAt(i), s2.charAt(i)); } } } public void Main1() throws Exception { tet1(); read_file(); write_file(); } public String op1(String s) { StringBuilder sb=new StringBuilder(); for(int i=0;i<s.length();i++) { sb.append(h.get(s.charAt(i))); } return sb.toString(); } public void tet1() { String [] s={"ejp mysljylc kd kxveddknmc re jsicpdrysi","rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd","de kr kd eoya kw aej tysr re ujdr lkgc jv"}; String [] s1={"our language is impossible to understand","there are twenty six factorial possibilities","so it is okay if you want to just give up"}; for (int i=0;i<3;i++) { Equal(s[i], s1[i]); } h.put('z', 'q'); h.put('q', 'z'); System.out.println(h.size()); } public void write_file() throws IOException { BufferedWriter br=new BufferedWriter(new FileWriter("test1.txt")); for(int i=0;i<result.size();i++) { br.write("Case #"+(i+1)+": "+result.get(i)); if(i!=result.size()-1) { br.newLine(); } } br.close(); } public static void main (String [] args) throws Exception { test1 t=new test1(); // t.read_file(); // t.write_file(); t.read_file(); } }
0
214
A12852
A13215
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.HashMap; public class Recycle { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new FileReader("B-small-attempt2.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("output.txt")); String line = ""; line = br.readLine(); int number = Integer.valueOf(line); for(int i = 1; i<= number; i++){ line = br.readLine(); String[] tokens = line.split(" "); int result = 0; int n = Integer.valueOf(tokens[0]); int surprising = Integer.valueOf(tokens[1]); int p = Integer.valueOf(tokens[2]); if(p == 0){ result = n; } else{ for(int a = 1;a<=n;a++){ int score = Integer.valueOf(tokens[2+a]); int d = score/3; if(score == 0) continue; if(d >=p){ result++; } else{ int m = score%3; if((m == 1||m==2) && d+1 == p) result++; else if(m == 0 && d+1 == p && surprising !=0){ result++; surprising--; } if(m == 2&& d+2 ==p &&surprising !=0){ result++; surprising--; } } } } System.out.println(result); bw.append("Case #"+i+": "+result); bw.newLine(); } br.close(); bw.close(); } }
0
215
A12852
A10753
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileReader; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.StringTokenizer; import java.util.ArrayList; public class TestJAM { public static void main (String[] args) { BufferedReader br = null; PrintStream ps = null; try { int t; int n; int s; int p; int count; int countsurprisingoblig; int countimp; ArrayList<Integer> scores; String line; StringTokenizer st; br = new BufferedReader (new FileReader ("B-small-attempt0.in")); ps = new PrintStream (new FileOutputStream ("B-small-attempt0.out")); line = br.readLine (); t = Integer.parseInt (line); for (int testCase = 0; testCase < t; testCase++) { count = 0; countsurprisingoblig = 0; countimp = 0; line = br.readLine (); st = new StringTokenizer (line); n = Integer.parseInt (st.nextToken ()); s = Integer.parseInt (st.nextToken ()); p = Integer.parseInt (st.nextToken ()); scores = new ArrayList (); for (int scoreInputIndex = 0; scoreInputIndex < n; scoreInputIndex++) { scores.add (Integer.parseInt (st.nextToken ())); } for (int score : scores) { int diff = (int) Math.abs (score - (3*p)); if ((score < (3 * p)) && ((diff == 3 || diff == 4)) && (score != 0) && (p > 0)) { countsurprisingoblig++; } else if (((score < (3 * p)) && (diff > 4)) || ((score == 0) && (p > 0))) { countimp++; } } count = scores.size () - countimp - countsurprisingoblig; if (countsurprisingoblig > s) { count += s; } else { count += countsurprisingoblig; } // System.out.println (count); // System.out.println (n + " " + s + " " + p + " " + scores.toString ()); // System.out.println ("Case #" + (testCase + 1) + ": " + s); ps.println ("Case #" + (testCase + 1) + ": " + count); } // ps.println ("test1 test1 test1"); // System.out.println ("Hola Mundo!!!"); } catch (IOException ioe) { ioe.printStackTrace (); } catch (NumberFormatException nfe) { nfe.printStackTrace (); } finally { if (ps != null) { ps.close (); } if (br != null) { try { br.close (); } catch (IOException ioe) { ioe.printStackTrace (); } } } } }
0
216
A12852
A12920
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.solver; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; public class ProblemPackageCreator implements ChallengeConstants{ private final String packageName; private String directoryName; private String challengeDef; private String readerName; private String challengeName; private String packagePath; ProblemPackageCreator(String packageName){ this.packageName = packageName; packagePath = "google.contest."+packageName; directoryName = BASE_DIR+DELIMITER+packageName; challengeDef = BASE_DIR+DELIMITER+packageName+DELIMITER+CHALLENGE_DEFINITION; readerName = packageName.substring(0,1).toUpperCase()+packageName.substring(1)+"Reader"; challengeName = packageName.substring(0,1).toUpperCase()+packageName.substring(1)+"Challenge"; } private void create() { try{ createDirectory(); createTestIn(); createChallengeDefinition2(); createReader(); createChallenge(); } catch(Exception e){ throw new RuntimeException(e); } } private void createTestIn() { writeToPath(TEST_IN, ""); } private void createChallenge() { String def ="package "+packagePath+";\n\n"+ "import google.loader.Challenge;\n"+ "import google.problems.AbstractChallenge;\n\n"+ "public class "+challengeName+" extends AbstractChallenge implements Challenge {\n\n"+ "public "+challengeName+"(int number) {\n"+ "super(number);\n"+ "setResult(\"\");\n"+ "}\n"+ "}\n"; writeJava(challengeName, def); } private void createReader() { String def = "package "+packagePath+";\n\n"+ "import google.loader.Challenge;\n"+ "import google.problems.AbstractReader;\n\n"+ "public class "+readerName+" extends AbstractReader {\n \n"+ "@Override\n"+ "protected Challenge createChallenge(int number) {\n"+ "int theLine = getActualLine();\n"+ "String[] lines = getLines();\n"+ "int value = Integer.parseInt(getLines()[theLine]);\n"+ challengeName+" chal = new "+challengeName+"(number);\n"+ "setActualLine(theLine+1);\n"+ "return chal;\n"+ "}\n"+ "\n"+ "}\n"; writeJava(readerName, def); } private void writeToPath(String fileName, String text){ write(directoryName+DELIMITER+fileName, text); } private void writeJava(String baseName, String text) { writeToPath(baseName+".java", text); } private void createChallengeDefinition() { String def = "fileName="+TEST_IN+"\n"+ "# fileName=A-small-practice.in\n"+ "# fileName=A-large-practice.in\n"+ "# fileName=B-small-practice.in\n"+ "# fileName=B-large-practice.in\n"+ "# fileName=C-small-practice.in\n"+ "# fileName=C-large-practice.in\n"+ "readerClassName="+packagePath+"."+readerName; write(challengeDef, def); } private void createChallengeDefinition2() { String def = "fileName="+TEST_IN+"\n"+ "# fileName="+packageName+"-small-practice.in\n"+ "# fileName="+packageName+"-large-practice.in\n"+ "readerClassName="+packagePath+"."+readerName; write(challengeDef, def); } private void createDirectory() throws Exception{ File file = new File(directoryName); if(! file.exists()){ file.mkdir(); }else{ throw new RuntimeException("alreadyExisting"); } } public static void main(String[] args) { String packageName =CHALLENGE_NAME; ProblemPackageCreator creator = new ProblemPackageCreator("A"); creator.create(); creator = new ProblemPackageCreator("B"); creator.create(); creator = new ProblemPackageCreator("C"); creator.create(); } public static void write(String aFileName, String text) { try{ FileWriter fstream = new FileWriter(aFileName); BufferedWriter out = new BufferedWriter(fstream); out.write(text); out.close(); }catch (Exception e){ throw new RuntimeException(e); } } }
0
217
A12852
A11525
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam.dancing; import codejam.is.TestAbstract; import java.util.StringTokenizer; /** * Created with IntelliJ IDEA. * User: ofer * Date: 4/14/12 * Time: 4:48 AM * To change this template use File | Settings | File Templates. */ public class DancingTest extends TestAbstract { @Override public void run(String s) { StringTokenizer tokenizer = new StringTokenizer(s); int numOfGooglers = Integer.parseInt(tokenizer.nextToken()); int numOfSurprises = Integer.parseInt(tokenizer.nextToken()); int bestResult = Integer.parseInt(tokenizer.nextToken()); int result = 0; for (int i = 0; i < numOfGooglers; i++) { int score = Integer.parseInt(tokenizer.nextToken()); if (score >= bestResult + 2*Math.max(bestResult-1, 0)) { result++; } else if (score >= (bestResult + 2*Math.max(bestResult-2, 0)) && numOfSurprises > 0) { result++; numOfSurprises--; } } output.append(result); } }
0
218
A12852
A10329
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.dance; public class DanceSolver { public DanceSolver() { } public String solve(String line) { String[] ss = line.split(" "); int n = Integer.parseInt(ss[0]); int s = Integer.parseInt(ss[1]); int p = Integer.parseInt(ss[2]); int yes = 0, no = 0, surpPoss = 0; for (int i = 0; i < n; i++) { int t = Integer.parseInt(ss[3 + i]); if (t >= p + 2 * Math.max(p - 1, 0)) { yes++; } else if (t >= p + 2 * Math.max(p - 2, 0)) { surpPoss++; } else { no++; } } int ans = yes + Math.min(s, surpPoss); return "" + ans; } }
0
219
A12852
A10942
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
// Google Code Jam Qualification Round 2012 // Problem B. Dancing With the Googlers import java.util.*; import java.io.*; public class DancingWithTheGooglers { static String inname = "B-small-attempt0.in"; // input file name here static String outname = "B-small-attempt0.out"; // output file name here public static void main(String[] args){ try{ Scanner in = new Scanner(new BufferedReader(new FileReader(inname))); //Scanner in = new Scanner(System.in); BufferedWriter out = new BufferedWriter(new FileWriter(outname)); int n, s, p, t[]; int T = in.nextInt(); for (int cas = 1; cas <= T; cas++){ int ans = 0; n = in.nextInt(); s = in.nextInt(); p = in.nextInt(); t = new int[n]; for (int i = 0; i < n; i++) t[i] = in.nextInt(); for (int i = 0; i < n; i++){ if (t[i]%3 == 0){ if (t[i]/3 >= p) ans++; else if (t[i]/3 == p-1 && t[i] > 1 && s > 0){ ans++; s--; } } else { if (t[i]/3+1 >= p) ans++; else if (t[i]/3+1 == p-1 && t[i] > 1 && t[i]%3 == 2 && s > 0){ ans++; s--; } } } //System.out.print("Case #" + cas + ": " + ans + "\n"); out.write("Case #" + cas + ": " + ans + "\n"); } in.close(); out.close(); } catch (IOException e) { e.printStackTrace(); } } }
0
220
A12852
A13129
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dancingwiththegooglers.codejam; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class Main { public static void main(String[] args) throws IOException{ FileWriter fw = new FileWriter("./output.txt"); //Scanner in = new Scanner(new File("/home/lotrf3/Downloads/A-small-practice.in")); Scanner in = new Scanner(new File("/home/lotrf3/Downloads/B-small-attempt0(1).in")); int cases = Integer.parseInt(in.nextLine()); for (int i=0; i<cases; i++){ Case x = new Case(in); fw.append("Case #"+(i+1) + ": " + x.solve() + "\n"); } fw.close(); } }
0
221
A12852
A11349
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.Scanner; public class DancingWithGooglers { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { Scanner in; in = new Scanner(new FileReader("B-small.in")); FileWriter output = new FileWriter("B-small.out"); int T = in.nextInt(); for(int i = 1; i <= T; i++) { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int pass = 0; for(int j = 1; j <= N; j++) { int x = in.nextInt(); if(p > x) continue; int remaining = x-p; if( (remaining/2) >= (p-1) ) { pass++; } else if ( ( (remaining/2) == (p-2) ) && (S > 0) ) { pass++; S--; } } output.write("Case #" + i + ": " + pass + "\n"); } in.close(); output.flush(); output.close(); } }
0
222
A12852
A12986
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package gcj; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; public abstract class SolverBase { public static final String TOKEN_SEPARATOR = " "; public static final String IMPOSSIBLE = "IMPOSSIBLE"; public String problemName; public boolean verbose = false; public SolverBase(String problemName) { this.problemName = problemName; } public void solve(InputStream in, PrintStream out) throws Exception { InputStreamReader isr = new InputStreamReader(in); BufferedReader reader = new BufferedReader(isr); long N = Long.parseLong(reader.readLine()); for (long i = 1; i <= N; i++) { out.print("Case #" + i + ": "); solveSingle(reader, out); } } public abstract void solveSingle(BufferedReader reader, PrintStream out) throws Exception; public long[] readSingleLineLongArray(BufferedReader reader) throws Exception { String[] longsAsStrings = readSingleLineStringArray(reader); long[] longs = new long[longsAsStrings.length]; for (int i = 0; i < longsAsStrings.length; i++) { longs[i] = Long.parseLong(longsAsStrings[i]); } return longs; } public int[] readSingleLineIntArray(BufferedReader reader) throws Exception { String[] intsAsStrings = readSingleLineStringArray(reader); int[] ints = new int[intsAsStrings.length]; for (int i = 0; i < intsAsStrings.length; i++) { ints[i] = Integer.parseInt(intsAsStrings[i]); } return ints; } public String[] readSingleLineStringArray(BufferedReader reader) throws Exception { String line = reader.readLine(); if (verbose) { System.out.println("Reading line " + line); } return line.split(TOKEN_SEPARATOR); // return StringUtils.split(line, TOKEN_SEPARATOR); } public String[][] readStringArrays(BufferedReader reader, int lines) throws Exception { String[][] arrays = new String[lines][]; for (int i = 0; i < lines; i++) { arrays[i] = readSingleLineStringArray(reader); } return arrays; } public char[][] readCharArrays(BufferedReader reader, int lines) throws Exception { char[][] arrays = new char[lines][]; for (int i = 0; i < lines; i++) { String line = reader.readLine(); arrays[i] = line.toCharArray(); } return arrays; } public long[][] readLongArrays(BufferedReader reader, int lines) throws Exception { long[][] arrays = new long[lines][]; for (int i = 0; i < lines; i++) { arrays[i] = readSingleLineLongArray(reader); } return arrays; } protected void check(boolean b) { if (!b) { throw new IllegalStateException("Check failed"); } } }
0
223
A12852
A11881
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dance; /** * * @author ALEX */ public class Scores { int first; int second; int third; int total; boolean s; public Scores(int total) { this.total=total; } public int getMaxS() { int max=0; for(int i=0;i<=10;i++) for(int j=i;(j<=i+2)&&(j<=10);j++) for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) if((i+j+k==total)&&(i+2==j||i+2==k)){ if(i>max) max=i; if(j>max) max=j; if(k>max) max=k; } return max; } public int getMaxUnS() { int max=0; for(int i=0;i<=10;i++) for(int j=i;(j<=i+2)&&(j<=10);j++) for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) if((i+j+k==total)&&(i+2!=j&&i+2!=k)){ if(i>max) max=i; if(j>max) max=j; if(k>max) max=k; } return max; } public void setFirstSurprize() { for(int i=0;i<=10;i++) for(int j=i;(j<=i+2)&&(j<=10);j++) for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) if((i+j+k==total)&&(i+2==j||i+2==k)){ first=i; second=j; third=k; s=true; return; } } public void setFirstNormal(){ for(int i=1;i<=10;i++) for(int j=i;(j<=i+2)&&(j<=10);j++) for(int k=j;(k<=j+2)&&(k<=i+2)&&(k<=10);k++) if((i+j+k==total)&&(i+2==j||i+2==k)){} else { first=i; second=j; third=k; s=false; return; } } }
0
224
A12852
A11183
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class Main { /** * @param args */ public static void main(String[] args) { //Load file ArrayList<String> in = null; try { in = readFile("input.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } String result = doit(Integer.parseInt(in.remove(0)), in); try { writeFile(result, "output.txt"); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public static ArrayList<String> readFile(String filename) throws IOException{ ArrayList<String> out = new ArrayList<String>(); // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream(filename); // 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 out.add(strLine); } //Close the input stream in.close(); return out; } public static String doit(int c, ArrayList<String> cases){ // Main logic StringBuilder out = new StringBuilder(); for(int i = 0; i < c; i++){ String s = cases.get(i); int for_sure = 0; int if_surprise = 0; ArrayList<Integer> sa = new ArrayList<Integer>(); for(String l : s.split(" ")){ sa.add(Integer.parseInt(l)); } int N = sa.get(0); int S = sa.get(1); int P = sa.get(2); for(int ii = 3; ii <= N+2; ii++){ int v = sa.get(ii); if(Math.ceil((double)v/3) >= P){ for_sure++; continue; } double d = v-2*Math.floor((double)v/3); if(d == Math.ceil((double)v/3) && d != 0){ d++; } if(d >= P){ if_surprise++; } } out.append("Case #"+(i+1)+": "+(for_sure+Math.min(S, if_surprise))); if(i != c-1){ out.append("\n"); } } return out.toString(); } public static void writeFile(String output, String file) throws IOException{ FileWriter fstream = new FileWriter(file); BufferedWriter out = new BufferedWriter(fstream); out.write(output); out.close(); } }
0
225
A12852
A11986
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class B { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 1; i <= t; ++ i) { int n = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); int[] max = new int[n]; for (int j = 0; j < n; ++ j) { max[j] = scan.nextInt(); } boolean[] surprising = new boolean[n]; for (int j = 0; j < s; ++ j) { surprising[j] = true; } int out = 0; do { out = Math.max(out, solve(max, surprising, p)); surprising = next(surprising, surprising.length); } while (surprising != null); System.out.printf("Case #%d: %d\n", i, out); } } private static boolean[] next(boolean[] old, int end) { int index = 0; for (index = end - 1; index >= 0; -- index) { if (old[index]) { break; } } if (index == -1) { return null; } if (index == end - 1) { boolean[] ret = next(old, index); if (ret == null) { return null; } ret[index] = false; for (index = index - 1; index >= 0; -- index) { if (ret[index]) { break; } } ret[index + 1] = true; return ret; } old[index] = false; old[index + 1] = true; return old; } public static int solve(int[] max, boolean[] surprising, int p) { int ret = 0; for (int i = 0; i < max.length; ++ i) { if (surprising[i]) { if (max[i] < 2) { return 0; // impossible } if (max[i] % 3 <= 1) { if (max[i] / 3 + 1 >= p) { ret ++; } } else { if (max[i] / 3 + 2 >= p) { ret ++; } } } else { if ((int)Math.ceil(max[i] / 3.0) >= p) { ret ++; } } } return ret; } }
0
226
A12852
A11725
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileInputStream; import java.io.PrintWriter; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) { try { File output = new File("output.txt"); if (output.exists()) { output.delete(); } PrintWriter pw = new PrintWriter(output); Scanner s = new Scanner(new FileInputStream("input.txt")); int T = s.nextInt(); s.nextLine(); for (int i = 0; i < T; i++) { int N = s.nextInt(); int S = s.nextInt(); int p = s.nextInt(); int[] ts = new int[N]; for (int j = 0; j < N; j++) { ts[j] = s.nextInt(); } DancingWithGooglers solve = new DancingWithGooglers(ts, S, p); pw.println(String.format("Case #%d: %d", (i+1), solve.compute())); } pw.close(); System.out.println("Done !"); } catch (Exception ex) { System.out.println("ERROR"); System.out.println(ex.getMessage()); ex.printStackTrace(); } } private int[] totals; private int surprising; private int max; public DancingWithGooglers(int[] totals, int surprising, int max) { this.totals = totals; this.surprising = surprising; this.max = max; } public int compute() { System.out.println("Trying..."); int found = 0; int surprisingLeft = surprising; for (int i = 0; i < totals.length; i++) { int t = totals[i]; System.out.println(String.format("S = %d, p = %d, t = %d", surprising, max, t)); boolean foundNormal = findNormal(t); boolean foundSurprising = findSurprising(t); if (foundNormal) found++; if (!foundNormal && foundSurprising && surprisingLeft > 0) { found++; surprisingLeft--; } System.out.println(String.format("#%d: %s / %s", (i+1), foundNormal, foundSurprising)); } System.out.println(String.format("Suprising left : %d", surprisingLeft)); System.out.println("----------------------------"); return found; } private boolean findNormal(int total) { boolean result = false; for (int s1 = 10; s1 >= 0; s1--) { if (s1 > total) continue; for (int s2 = s1; s2 >= Math.max(s1-1, 0); s2--) { if (s1 + s2 > total) continue; for (int s3 = s2; s3 >= Math.max(s1-1, 0); s3--) { if (s1 + s2 + s3 != total) continue; if (s1 >= max || s2 >= max || s3 >= max) { System.out.println(String.format("%d %d %d", s1, s2, s3)); result = true; } } } } return result; } private boolean findSurprising(int total) { boolean result = false; for (int s1 = 10; s1 >= 0; s1--) { if (s1 > total) continue; for (int s2 = s1; s2 >= Math.max(s1-2, 0); s2--) { if (s1 + s2 > total) continue; for (int s3 = s2; s3 >= Math.max(s1-2, 0); s3--) { if (s1 + s2 + s3 != total) continue; if (s1-s3 != 2) continue; if (s1 >= max || s2 >= max || s3 >= max) { System.out.println(String.format("%d %d %d (*)", s1,s2,s3)); result = true; } } } } return result; } }
0
227
A12852
A12478
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; public class DancingGooglers { public static int num (int c,int p,int [] g){ int n = 0; for (int i =0;i<g.length;i++){ if (g[i]>=p+p+p-2){ n++; } else if (g[i]>=p+p+p-4){ if (c>0){ n++; c--; } } } return n; } public static void main (String [] args) throws NumberFormatException, IOException{ BufferedReader br = new BufferedReader(new FileReader("B-small-attempt0.in")); int t = Integer.parseInt(br.readLine()); for (int i =0;i<t;i++){ StringTokenizer s1 = new StringTokenizer(br.readLine()); int [] g = new int [Integer.parseInt(s1.nextToken())]; int c = Integer.parseInt(s1.nextToken()); int p = Integer.parseInt(s1.nextToken()); for (int j =0;j<g.length;j++){ g[j] = Integer.parseInt(s1.nextToken()); } if (p>1){ System.out.printf("Case #%d: %d\n",i+1,num(c,p,g)); } else { int n = 0; for (int j =0;j<g.length;j++){ if (g[j]>=p+p+p-2){ n++; } } System.out.printf("Case #%d: %d\n",i+1,n); } } } }
0
228
A12852
A12667
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Arrays; import java.util.Locale; /** * @author Yuri Denison * @date 14.04.12 */ public class GoogleCodeJamTaskB { private static void solve() throws IOException { final int t = rInt(); for (int i = 1; i <= t; i++) { final int n = rInt(); final int s = rInt(); final int p = rInt(); int[] results = new int[n]; for (int j = 0; j < n; j++) { results[j] = rInt(); } Arrays.sort(results); if (p == 0) { out.println(String.format("Case #%d: %d", i, n)); continue; } int bestGooglers; int count1 = 0; int count2 = 0; final int limit1 = p + 2 * (p - 1); final int limit2 = (p > 1) ? p + 2 * (p - 2) : p; for (int j = 0; j < n; j++) { if (results[j] >= limit1) { count1 = results.length - j; break; } } for (int j = 0; j < n; j++) { if (results[j] >= limit2) { count2 = results.length - j; break; } } final int abs = count2 - count1; bestGooglers = count1 + ((s < abs) ? s : abs); out.println(String.format("Case #%d: %d", i, bestGooglers)); } } public static void main(String[] args) throws IOException { Locale.setDefault(Locale.US); BufferedReader br; try { final String fileName = "B-small-attempt1"; br = new BufferedReader(new FileReader(fileName + ".in")); out = new PrintWriter(new FileWriter(fileName + ".out")); } catch (Exception e) { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(new OutputStreamWriter(System.out)); } st = new StreamTokenizer(br); solve(); br.close(); out.close(); } private static StreamTokenizer st; private static PrintWriter out; static String rNext() throws IOException { st.nextToken(); return st.sval; } static int rInt() throws IOException { st.nextToken(); return (int) st.nval; } }
0
229
A12852
A11926
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package google.code.jam; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; /** * * @author Bogatinovi */ public class B { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); int br=0; for(int i=1;i<=T;i++){ int Googlers = in.nextInt(); int suprising = in.nextInt(); int p = in.nextInt(); for(int j=0;j<Googlers;j++){ int res=in.nextInt(); if(res>=p){ if(p*3<=res){++br;} else if((res-p)>=(2*p-2)){ br++; } else if(suprising>0){ res-=p; if((2*p-4)<=res){ br++; suprising--; } } } } System.out.println("Case #"+i+": "+br); br=0; } } }
0
230
A12852
A12675
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package y2012; import java.io.File; import java.io.PrintWriter; import java.util.Scanner; public class QR2 { public static void main(String[] args) throws Exception { Scanner inputFile=new Scanner(new File(args[0])); PrintWriter outputFile=new PrintWriter(new File(args[1])); int t=Integer.parseInt(inputFile.nextLine()); for(int i=0;i<t;i++){ int result = 0; String[] aCase = inputFile.nextLine().split(" "); int numGooglers = Integer.parseInt(aCase[0]); int numSurprising = Integer.parseInt(aCase[1]); int p = Integer.parseInt(aCase[2]); int[][] scoreboard = new int[numGooglers][5]; for(int j=0; j<numGooglers; j++) { scoreboard[j][0] = Integer.parseInt(aCase[3+j]); } for(int j=0; j<numGooglers;j++) { int avg = scoreboard[j][0]/3; int mod = scoreboard[j][0]%3; scoreboard[j][1] = mod; switch(mod) { case 0: scoreboard[j][2] = avg; scoreboard[j][3] = avg; scoreboard[j][4] = avg; break; case 1: scoreboard[j][2] = avg+1; scoreboard[j][3] = avg; scoreboard[j][4] = avg; break; case 2: scoreboard[j][2] = avg+1; scoreboard[j][3] = avg+1; scoreboard[j][4] = avg; break; } } for(int j=0; j<numGooglers;j++) { if(scoreboard[j][2] >= p) { result = result + 1; } else if( scoreboard[j][2] == p-1 //diff with 1 score && numSurprising > 0 //still has suprise quota && scoreboard[j][1] != 1 //suprise-able? && (scoreboard[j][0] >= 3 && scoreboard[j][0] <= 27) //suprise-able? ) { result = result + 1; numSurprising = numSurprising - 1; } } outputFile.println("Case #"+(i+1)+": " + result); System.out.println("Case #"+(i+1)+": " + result); } inputFile.close(); outputFile.close(); } }
0
231
A12852
A10396
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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_2012; /** * Time: 5:10:03 PM, Apr 13, 2012 * @author Maya is the best :-) */ import java.util.Scanner; import java.io.PrintWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; public class B { static Scanner in; static String path = "src/gcj_2012/"; static String taskname = "B-small-attempt0"; public static String solve() { int N = in.nextInt(); int S = in.nextInt(); int p = in.nextInt(); int y = 0; int t[] = new int[N]; for (int i =0; i<N; i++) t[i] = in.nextInt(); for(int i=0; i<N; i++) { if ( t[i] >= (3*p - 2) ) y++; else if ( t[i] >= (3*p - 4) && S>0 && t[i]!=0) { y++; S--; } } return "" + y; } public static void main(String[] args) { PrintWriter pW = null; try { pW = new PrintWriter(new FileOutputStream(path + taskname + ".out")); try { in = new Scanner(new FileInputStream(path + taskname + ".in")); int T = in.nextInt(); for (int caseNumber = 1; caseNumber <= T; caseNumber++) { pW.println("Case #" + caseNumber + ": " + solve()); } in.close(); pW.close(); } catch (IOException e) { System.out.println("Can not find file " + taskname + ".in"); } } catch (IOException e) { System.out.println("Open or create exception with " + taskname + ".out"); } } }
0
232
A12852
A12938
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 problems; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; /** * * @author sergeiw */ public class B { public static String FILE_SEPARATOR = System.getProperty("file.separator"); public static String FILE_INPUT_DIR = System.getProperty("user.dir") + FILE_SEPARATOR + "files" + FILE_SEPARATOR; public static String FILE_OUTPUT_DIR = System.getProperty("user.dir") + FILE_SEPARATOR + "files" + FILE_SEPARATOR; public static void main(String[] args) throws FileNotFoundException, IOException { //String filename = "B-example.in"; //String filename = "B-small-attempt0.in"; //String filename = "B-small-attempt1.in"; //String filename = "B-small-attempt2.in"; //String filename = "B-small-attempt3.in"; //String filename = "B-small-attempt4.in"; //String filename = "B-small-attempt5.in"; String filename = "B-small-attempt6.in"; //String filename = "B-large.in"; File fileOut = new File(FILE_INPUT_DIR + filename.replace(".in", ".out")); FileWriter fw = new FileWriter(fileOut); File file = new File(FILE_INPUT_DIR + filename); Scanner scanner = new Scanner(file); try { int cases = scanner.nextInt(); scanner.nextLine(); int casenum = 1; while (scanner.hasNextLine()) { int solution = 0; int N = scanner.nextInt(); int S = scanner.nextInt(); int p = scanner.nextInt(); int minScore = (p * 3) - 4; if (minScore < 0) minScore = p; for (int i = 0; i < N; i++) { int score = scanner.nextInt(); for (int q = p; q >= 0; q--) { if (score > q*3) { solution++; print(String.format("%d %d %d +", q, q, q )); break; } if (score >= ((q*3-2)) && score <= (q*3)) { if (q >= p) solution++; if (score == (q*3)-1) print(String.format("%d %d %d", q, q, q-1 )); else if (score == (q*3)-2) print(String.format("%d %d %d", q, q-1, q-1 )); else print(String.format("%d %d %d", q, q, q )); break; } if ( score == ((q*3)-4) || score == ((q*3)-3) ) { print(String.format("score: %d q: %d", score, q)); if (S-1 >= 0 && q >= p && q > 1) { S--; if (score == (q*3)-4) print(String.format("%d %d %d (*)", q, q-2, q-2 )); else print(String.format("%d %d %d (*)", q, q-1, q-2 )); solution++; break; } } } print(String.format("score: %d, min: %d, sol: %d, S: %d", score, p, solution, S)); /*if (score >= minScore) { if (score == 0 && minScore == 0) { solution++; } else { if ((score == minScore || score == (minScore + 1))) { print(String.format("s: %d min: %d", score, minScore)); S--; if (S >= 0) { solution++; } } else { solution++; } } } else { //print("LOWER"); for (int q = p - 1; q >= 2; q--) { if ( score == ((q*3)-4) || score == ((q*3)-3) ) { S--; print(String.format("LOWER: S: %d", S)); break; * } } } print(String.format("score: %d, min: %d, sol: %d, S: %d", score, minScore, solution, S)); */ } //if (S < 0) solution = 0; print(String.format("Case #%d: [%s]", casenum, solution)); fw.write(String.format("Case #%d: %s\n", casenum, solution)); casenum++; print(""); } } finally { scanner.close(); fw.close(); } } private static void print(String line) { System.out.println(line); }; private static void print(int num) { print(String.valueOf(num)); }; private static void print(int[] arr) { for(int i=0;i<arr.length;i++) System.out.print(String.valueOf(arr[i])+" "); System.out.println(); }; private static void print(String[] arr) { for(int i=0;i<arr.length;i++) System.out.print(arr[i]+" "); System.out.println(); }; }
0
233
A12852
A11436
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; public class dance { private static int T,S,p,N,current,upper,lower, count; public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(new FileWriter("B-small-attempt0.out")); T = sc.nextInt(); for(int i=1;i<=T;i++){ N = sc.nextInt(); S = sc.nextInt(); p = sc.nextInt(); count = 0; for(int j=1;j<=N;j++){ current = sc.nextInt(); if (p<2){ if(current>=p) count++; } else { upper = 3*p - 2; lower = upper -2; if(current>=upper) count++; else if((S>0)&&(current>=lower)) { count++; S--; }}} out.println("Case #"+i+": "+count); } out.close(); } }
0
234
A12852
A11529
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dancingwiththegooglers; import java.io.BufferedReader; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer; /** * * @author arjun */ public class DancingWiththeGooglers { /** * @param args the command line arguments */ public static void main(String[] args) throws FileNotFoundException { PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out); parseAndTranslate(); } private static void parseAndTranslate() { try { // Open the file that is the first // command line parameter FileInputStream fstream = new FileInputStream("B-small-attempt0.in"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine = br.readLine(); if (null != strLine) { int count = new Integer(strLine); //Read File Line By Line int lineNo = 0; while ((strLine = br.readLine()) != null) { lineNo++; doOp(strLine, lineNo); } //Close the input stream } in.close(); } catch (Exception e) {//Catch exception if any System.err.println("Error: " + e.getMessage()); } } private static void doOp(String strLine, int lineNo) { StringTokenizer st = new StringTokenizer(strLine); String temp = st.nextToken(); int noOfGooglers = new Integer(temp); temp = st.nextToken(); int surprisingTriplets = new Integer(temp); temp = st.nextToken(); int bestScore = new Integer(temp); //System.out.println("Goog: " + noOfGooglers + " surp: " + surprisingTriplets // + " bestScore: " + bestScore + " "); int nthNo = 0; Map<Integer, List<Integer>> iSet = new HashMap<Integer, List<Integer>>(); while (st.hasMoreTokens()) { nthNo++; String pts = st.nextElement().toString(); int pt = new Integer(pts); //System.out.print(" " + pt); boolean SurpUsed = compute(pt, bestScore, surprisingTriplets, iSet, nthNo); if (SurpUsed) { surprisingTriplets -= 1; } } int topScores = 0; for (Integer pointNo : iSet.keySet()) { List<Integer> points = iSet.get(pointNo); //System.out.print("\nNo: " + pointNo + ", Scores: "); boolean topScoreFoundAlready = false; for (Integer p : points) { if (p >= bestScore && !topScoreFoundAlready) { topScores++; topScoreFoundAlready = true; } //System.out.print(" " + p); } //System.out.println(); } System.out.println("Case #" + lineNo + ": " + topScores); } private static boolean compute(int pt, int bestScore, int surprisingTriplets, Map<Integer, List<Integer>> iSet, int nthNo) { List<Integer> points = new ArrayList<Integer>(); boolean surpUsed = false; int no1 = 0, no2 = 0, no3 = 0; int mean = Math.round(pt / 3); int rem = pt % 3; if (0 == rem) { if (mean < bestScore) { if (surprisingTriplets > 0 && (mean + 1) >= bestScore && (mean - 1) >= 0 && (mean + 1) <= 10) { surpUsed = true; no1 = mean; no2 = mean + 1; no3 = mean - 1; } else { no1 = mean; no2 = mean; no3 = mean; } } else { no1 = mean; no2 = mean; no3 = mean; } } else if (1 == rem) { no1 = mean + 1; no2 = mean; no3 = mean; } else if (2 == rem) { if ((mean + 1) < bestScore) { if (surprisingTriplets > 0 && (mean + 2) >= bestScore && (mean + 2) <= 10) { surpUsed = true; no1 = mean + 2; no2 = mean; no3 = mean; } else { no1 = mean + 1; no2 = mean + 1; no3 = mean; } } else { no1 = mean + 1; no2 = mean + 1; no3 = mean; } } points.add(no1); points.add(no2); points.add(no3); iSet.put(nthNo, points); return surpUsed; } }
0
235
A12852
A10583
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileReader; import java.util.Scanner; /** * * @author Gershom */ public class DancingWithGooglers { public static void main(String[] args0) { try { File f = new File("example"); Scanner s = new Scanner(new FileReader(f)); int num = Integer.parseInt(s.nextLine()); for (int i = 0; i < num; i++) { String line = s.nextLine(); int[] dat = new int[3]; intList(line, dat); int numGooglers = dat[0]; int numSurprising = dat[1]; int p = dat[2]; int[] scoresTemp = new int[3 + numGooglers]; intList(line, scoresTemp); int[] scores = new int[numGooglers]; for (int j = 0; j < scores.length; j++) { scores[j] = scoresTemp[j + 3]; } System.out.println("Case #" + (i + 1) + ": " + calcNumBest(numSurprising, p, scores)); } } catch (Exception e) { e.printStackTrace(); } } static int calcNumBest(int sur, int p, int[] scores) { int numSurprisingRequired = 0; int num = 0; for (int i = 0; i < scores.length; i++) { switch (scoreBreakdown(scores[i], p)) { case 1: numSurprisingRequired++; break; case 2: num++; break; } } return num + Math.min(sur, numSurprisingRequired); } /** * 0 means target can't be met, 1 means it can be met if it's "surprising", * 2 means it can be met without being surprising. * @param best * @return */ static int scoreBreakdown(int score, int target) { //Remaining points assuming target was met int rem = score - target; if (rem < 0) { return 0; } int otherScores = rem / 2; int gap = target - otherScores; if (gap > 2) { return 0; } else if (gap == 2) { return 1; } return 2; } public static void intList(String s, int[] array) { int index = 0; String cur = ""; for (int i = 0; i < s.length() + 1; i++) { if (i == s.length() || s.charAt(i) == ' ') { array[index++] = Integer.parseInt(cur); if (index == array.length) { break; } cur = ""; } else { cur += s.charAt(i); } } } }
0
236
A12852
A11636
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.qual2; import java.io.BufferedReader; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.List; public class qual2 { public static void main(String[] args) { cNums h = new cNums(); FileInputStream fis; try { fis = new FileInputStream("B-small-attempt0.in"); FileOutputStream fos = new FileOutputStream("smallB.txt"); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); int lines = Integer.parseInt(br.readLine()); String outp = null; String inp; for(int i = 0; i < lines; i++) { inp = br.readLine(); String[] inpar = inp.split(" "); int lim = Integer.parseInt(inpar[2]); int surp = Integer.parseInt(inpar[1]); int numbestn = 0; int numpossbests = 0; for(int a = 3; a < inpar.length; a++) { int curr = Integer.parseInt(inpar[a]); if(h.bestn[curr] >= lim) numbestn++; else if(h.bests[curr] >= lim) numpossbests++; } outp = "Case #" + (i+1) + ": "; outp += (numbestn + Math.min(surp, numpossbests)); outp += "\n"; fos.write(outp.getBytes()); } fis.close(); fos.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } final class cNums { public int[] bestn; public int[] bests; public cNums() { bestn = new int[31]; bests = new int[31]; FindBests(); } private void FindBests() { bestn[0] = 0; bests[0] = 0; for(int i = 1; i < 31; i++) { int mod = i % 3; bestn[i] = i / 3; if(mod == 0) bests[i] = bestn[i] + 1; else if(mod == 1) bests[i] = ++bestn[i]; else if(mod == 2) bests[i] = ++bestn[i] + 1; } } }
0
237
A12852
A10781
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.Math.*; import static java.util.Arrays.fill; import static java.util.Arrays.binarySearch; import static java.util.Arrays.sort; public class Main { public static void main(String[] args) throws IOException { long prevTime = System.currentTimeMillis(); new Main().run(); System.err.println("Total time: " + (System.currentTimeMillis() - prevTime) + " ms"); System.err.println("Memory status: " + memoryStatus()); } // String inputFile = "sample.txt"; String inputFile = "input/B-small-attempt0.in"; // String inputFile = "input/B-large.in"; String outputFile = "output.txt"; void run() throws IOException { in = new BufferedReader(new FileReader(inputFile)); out = new PrintWriter(outputFile); solve(); out.close(); } void solve() throws IOException { for (int testCase = 1, testCases = nextInt(); testCase <= testCases; testCase++) { solve(testCase); } } void solve(int testCase) throws IOException { int n = nextInt(); int s = nextInt(); int p = nextInt(); int[] t = nextIntArray(n); int ans = 0; for (int i = 0; i < n; i++) { if (good(t[i], p)) { ans++; } else if (s > 0 && canMakeGood(t[i], p)) { ans++; s--; } } out.println("Case #" + testCase + ": " + ans); } boolean good(int t, int p) { return (t + 2) / 3 >= p; } boolean canMakeGood(int t, int p) { int add = min(2, t); int rst = t - add; return (rst / 3 + add) >= p; } /*************************************************************** * Input **************************************************************/ BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } int[] nextIntArray(int size) throws IOException { int[] ret = new int [size]; for (int i = 0; i < size; i++) ret[i] = nextInt(); return ret; } long[] nextLongArray(int size) throws IOException { long[] ret = new long [size]; for (int i = 0; i < size; i++) ret[i] = nextLong(); return ret; } double[] nextDoubleArray(int size) throws IOException { double[] ret = new double [size]; for (int i = 0; i < size; i++) ret[i] = nextDouble(); return ret; } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } /*************************************************************** * Output **************************************************************/ void printRepeat(String s, int count) { for (int i = 0; i < count; i++) out.print(s); } void printArray(int[] array) { if (array == null || array.length == 0) return; for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(long[] array) { if (array == null || array.length == 0) return; for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(double[] array) { if (array == null || array.length == 0) return; for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.print(array[i]); } out.println(); } void printArray(double[] array, String spec) { if (array == null || array.length == 0) return; for (int i = 0; i < array.length; i++) { if (i > 0) out.print(' '); out.printf(Locale.US, spec, array[i]); } out.println(); } void printArray(Object[] array) { if (array == null || array.length == 0) return; boolean blank = false; for (Object x : array) { if (blank) out.print(' '); else blank = true; out.print(x); } out.println(); } @SuppressWarnings("rawtypes") void printCollection(Collection collection) { if (collection == null || collection.isEmpty()) return; boolean blank = false; for (Object x : collection) { if (blank) out.print(' '); else blank = true; out.print(x); } out.println(); } /*************************************************************** * Utility **************************************************************/ static String memoryStatus() { return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB"; } static void checkMemory() { System.err.println(memoryStatus()); } static long prevTimeStamp = Long.MIN_VALUE; static void updateTimer() { prevTimeStamp = System.currentTimeMillis(); } static long elapsedTime() { return (System.currentTimeMillis() - prevTimeStamp); } static void checkTimer() { System.err.println(elapsedTime() + " ms"); } }
0
238
A12852
A13034
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package y2012; import java.io.*; import java.util.Arrays; public class Glob { /** * Fetch the entire contents of a text file, and return it in a String. * This style of implementation does not throw Exceptions to the caller. * * @param aFile is a file which already exists and can be read. */ static public void IOwork() { //...checks on aFile are elided try { //use buffering, reading one line at a time //FileReader always assumes default encoding is OK! BufferedReader input = new BufferedReader(new FileReader(new File("F:\\file.in"))); Writer output = new BufferedWriter(new FileWriter(new File("F:\\file.out"))); try { String line = null; //not declared within while loop /* * readLine is a bit quirky : * it returns the content of a line MINUS the newline. * it returns null only for the END of the stream. * it returns an empty String if two newlines appear in a row. */ line = input.readLine(); int NoOfCases = Integer.parseInt(line); for (int i = 0; i < NoOfCases; i++) { line = input.readLine(); String[] v1 = line.split(" "); int t = Integer.parseInt(v1[0]); int s = Integer.parseInt(v1[1]); int p = Integer.parseInt(v1[2]); int answer = 0; System.out.println(t); System.out.println(s); System.out.println(p); for (int j = 3; j < v1.length; j++) { int temp = Integer.parseInt(v1[j]); if (temp > 0) { switch (temp%3) { case 0 : { if (temp/3 >= p) answer++; else if (temp/3+1 == p && s > 0) { answer++; s--; } break; } case 1 : { if (temp/3+1 >= p) answer++; break; } case 2 : { if (temp/3+1 >= p) answer++; else if (temp/3+2 == p && s > 0) { answer++; s--; } break; } } } else if (p == 0) answer++; } output.write("Case #"+(i+1)+": "+answer+"\n"); } } finally { input.close(); output.close(); } } catch (IOException ex){ ex.printStackTrace(); } } private static int rope(int[][] lines) { int ans = 0; for (int i = 0; i < lines.length-1; i++){ for (int j = i+1; j < lines.length; j++) { if ((lines[i][0] > lines[j][0] && lines[i][1] < lines[j][1])||(lines[i][0] < lines[j][0] && lines[i][1] > lines[j][1])) ans++; } } return ans; } public static void main (String[] aArguments) throws IOException { IOwork(); } }
0
239
A12852
A10123
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 atm; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.*; /** * * @author Antonio Lievano */ public class Googlers { public static void main (String[]Args) throws FileNotFoundException { FileReader reader = new FileReader("C:\\Users\\Antonio Lievano\\Desktop\\B-small-attempt4.in"); Scanner in = new Scanner(reader); int cases = Integer.parseInt(in.nextLine()); for (int i = 0; i<cases; i++) { System.out.print("Case #" + (i+1) + ": "); String line = in.nextLine(); String [] temp = line.split(" "); int n = Integer.parseInt(temp[0]); int s = Integer.parseInt(temp[1]); int p = Integer.parseInt(temp[2]); int answer = 0; int counter = 0; int [] points = new int [temp.length-3]; for (int x = 0; x<temp.length-3; x++){ points[x] = Integer.parseInt(temp[x+3]); } for (int j = 0; j<points.length; j++) { if (points[j]>((p*3)-3)) { points[j] = -9999; answer++; } } for (int k = 0; k<points.length; k++){ if (counter==s) break; if (((p*3)-5)<0) break; if (points[k]>((p*3)-5)){ points[k] = -9999; answer++; counter++; } } System.out.print(answer); System.out.println(); } } }
0
240
A12852
A12184
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; public class GooglersDancer { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub InputStreamReader converter = new InputStreamReader(System.in); BufferedReader in = new BufferedReader(converter); if (in == null) { return; } String numTest = in.readLine(); int maxCases = Integer.valueOf(numTest); for(int i=1;i<= maxCases;i++){ String linea = in.readLine(); String[] datos = linea.split(" "); Integer googlers = Integer.valueOf(datos[0]); Integer sospechosos = Integer.valueOf(datos[1]); Integer p = Integer.valueOf(datos[2]); Integer puntuacion; Integer personas = 0; ArrayList<Integer> puntuaciones = new ArrayList<Integer>(); for(int j=0;j<googlers;j++){ puntuacion = Integer.valueOf(datos[3+j]); puntuaciones.add(puntuacion); } Integer[] pOrdenado = null; pOrdenado = (Integer[]) puntuaciones.toArray(new Integer[puntuaciones.size()]); Arrays.sort(pOrdenado); int j; for(j=pOrdenado.length-1;j>=0;j--){ if(pOrdenado[j] >= p*3-2){ personas += 1; }else{ break; } } int posibles = j+1-sospechosos; for(;j>=posibles && j>= 0;j--){ if(pOrdenado[j] >= p*3-4 && pOrdenado[j] > p){ personas += 1; }else{ break; } } System.out.println("Case #"+i+": "+personas); } } }
0
241
A12852
A11604
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Test2 { final static String INPUT_FILE_NAME = "input2"; int T = 0; int q = 0; public static void main(String args[]) { try { Test2 tst = new Test2(); tst.getInput(); } catch (Exception e) { e.printStackTrace(); } } private void getInput() throws Exception { File file = new File(INPUT_FILE_NAME); FileReader fis = new FileReader(file); BufferedReader br = new BufferedReader(fis); String strT = br.readLine(); T = getInt(strT); for (int i=0; i<T; i++) { String strHead = br.readLine(); String[] strHairetsu = strHead.split(" "); int N = getInt(strHairetsu[0]); int S = getInt(strHairetsu[1]); int P = getInt(strHairetsu[2]); int[] t = new int[N]; for (int j=0; j<N; j++) { t[j] = getInt(strHairetsu[3+j]); } //list kakunou execuse(i, N, S, P, t); } } private void execuse(int num, int N, int S, int P,int[] t) { int count =0; for (int i=0; i<N; i++) { int mod3 =t[i] % 3; if (mod3==0) { if (t[i] == 0) { if (P==0) { count++; } } else if (t[i]/3 >= P) { count++; } else if ((t[i]/3 >= (P-1)) && S>0) { S--; count++; } } else if (mod3 ==2) { if (t[i]/3 >= P-1) { count++; } else if ((t[i]/3 >= (P-2)) && S>0) { S--; count++; } } else { if (t[i]/3 >= P-1) { count++; } } } System.out.println("Case #"+(num+1)+": "+count); //System.out.println("Hello WorldI"); } private int getInt(String a) { return Integer.parseInt(a, 10); } private int getIntx(String a) { if (a.equals(".")) { return 0; } return 1; } }
0
242
A12852
A10284
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* * Anand Oza * Apr 14, 2012 */ import java.util.*; import java.io.*; public class B_DancingWithTheGooglers { public static void main(String[] args) throws IOException { long startTime = System.nanoTime(); BufferedReader reader = new BufferedReader(new FileReader("B_DancingWithTheGooglers.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("B_DancingWithTheGooglers.out"))); StreamTokenizer in = new StreamTokenizer(reader); in.nextToken(); int T = (int) in.nval; for (int testcase = 1; testcase <= T; testcase++) { in.nextToken(); int N = (int) in.nval; in.nextToken(); int S = (int) in.nval; in.nextToken(); int P = (int) in.nval; int unsurprisingThreshold = 2 * Math.max((P - 1), 0) + P; int surprisingThreshold = 2 * Math.max((P - 2), 0) + P; int countUnsurprising = 0; int countSurprising = 0; for (int i = 0; i < N; i++) { in.nextToken(); int t = (int) in.nval; if (t >= unsurprisingThreshold) countUnsurprising++; else if (t >= surprisingThreshold) countSurprising++; } int ans = countUnsurprising + Math.min(S, countSurprising); out.format("Case #%d: %d%n", testcase, ans); } out.close(); System.out.println("Time (ms): " + (double) (System.nanoTime() - startTime) / 1000000); System.exit(0); } }
0
243
A12852
A10176
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class GoogleDancers { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); int numberOfTestCases = Integer.parseInt(s); StringBuffer output = new StringBuffer(); for (int i = 1; i <= numberOfTestCases; i++) { String testCase = br.readLine().trim(); String[] inputparams = testCase.split(" "); long N, S, p; long totalPoints[] = new long[110]; N = Long.parseLong(inputparams[0]); S = Long.parseLong(inputparams[1]); p = Long.parseLong(inputparams[2]); for (int j = 3; j <= N + 2; j++) { totalPoints[j - 3] = Long.parseLong(inputparams[j]); } String outputString = solveTestCase(N, S, p, totalPoints); if (i != 1) { output.append("\n"); } output.append("Case #" + i + ": "); output.append(outputString); } System.out.println(output); } private static String solveTestCase(long N, long S, long p, long[] totalPoints) { long maxNoOfBest = 0; long possibleSuprises = 0; for (int i = 0; i < N; i++) { int totalPnts = (int) totalPoints[i]; int oneScore = totalPnts / 3; int mod = totalPnts % 3; if (mod >= 1) { if (oneScore >= p || (oneScore + 1) >= p) { maxNoOfBest++; } else if (oneScore + mod >= p) { possibleSuprises++; } } else { if (oneScore >= p) { maxNoOfBest++; } else if (oneScore > 0 && oneScore + 1 >= p) { possibleSuprises++; } } } if (possibleSuprises < S) { maxNoOfBest = maxNoOfBest + possibleSuprises; } else { maxNoOfBest = maxNoOfBest + S; } return String.valueOf(maxNoOfBest); } }
0
244
A12852
A11476
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.A.jam2011; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; /* 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 */ public class C { static int S; static int p; static int min; public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); int T = in.nextInt(); File f = new File("output.txt"); FileWriter fw = new FileWriter(f); in.nextLine(); for (int j = 0; j < T; j++) { S = in.nextInt(); p = in.nextInt(); min = in.nextInt(); String s = in.nextLine(); // System.out.println(S+"\n"+p+"\n"+min); s = s.substring(1); // System.out.println(s); fw.write("Case #" + (j + 1) + ": " + passed(s) + "\n"); // System.out.println("Case #" + (j + 1) + ": " + passed(s) + "\n"); } fw.flush(); fw.close(); } private static int passed(String s) { String[] v = s.split(" "); // int[] intv=new int[v.length]; int total = 0; for (int i = 0; i < v.length; i++) { // intv[i]=Integer.parseInt(v[i]); total += calc(Integer.parseInt(v[i])); } return total; } private static int calc(int parseInt) { int base = parseInt / 3; switch (parseInt % 3) { case 0: { if (base >= min) { return 1; } else { if (p > 0 && base > 0 && base + 1 >= min) { p--; return 1; } } break; } case 1: { if (base >= min || base + 1 >= min) { return 1; } else { if (p > 0 && base > 0 && base + 1 >= min) { p--; return 1; } } break; } case 2: { if (base + 1 >= min || base >= min) { return 1; } else { if (p > 0 && base > 0 && base + 2 >= min) { p--; return 1; } } break; } } /* * if(parseInt<min) return 0; //System.out.println(parseInt); if (base * >= min) { return 1; } if (base == min - 1) { if (parseInt % 3 != 0) { * return 1; } } if (p > 0) { if (base >= min - 2) { if (parseInt % 3 >= * 0) { p = p - 1; return 1; } * * } if (base == min - 1) { if (parseInt % 3 == 0) { p = p - 1; return * 1; } * * } * * } */ return 0; } }
0
245
A12852
A11285
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Qualifying_B { public static void main(String[] args) throws Exception { BufferedReader input = new BufferedReader(new FileReader(args[0])); int T = Integer.parseInt(input.readLine()); for (int t = 1; t <= T; t++) { String[] tokens = input.readLine().split(" "); int N = Integer.parseInt(tokens[0]); int S = Integer.parseInt(tokens[1]); int p = Integer.parseInt(tokens[2]); int[][] Googlers = new int[N][3]; for (int n = 0; n < N; n++) { Googlers[n][0] = Integer.parseInt(tokens[3 + n]); Googlers[n][1] = Googlers[n][0] / 3 + ((Googlers[n][0] % 3 != 0) ? 1 : 0); Googlers[n][2] = (Googlers[n][0] < 2 || Googlers[n][0] > 28) ? -1 : (Googlers[n][0] - 2) / 3 + 2; } int m = 0; for (int n = 0; n < N; n++) { if (Googlers[n][1] >= p) m++; else if (Googlers[n][2] >= p && S > 0) { S--; m++; } } System.out.println("Case #" + t + ": " + m); } } }
0
246
A12852
A12284
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package com.brootdev.gcj2012.common; import java.io.BufferedReader; import java.io.IOException; import java.io.PrintWriter; public class DataUtils { public static long readLongLine(BufferedReader in) throws IOException { return Long.valueOf(in.readLine()); } public static long[] readLongsArrayLine(BufferedReader in) throws IOException { String[] numsS = in.readLine().split("\\s+"); long[] nums = new long[numsS.length]; for (int i = 0; i < nums.length; i++) { nums[i] = Long.valueOf(numsS[i]); } return nums; } public static void writeCaseHeader(PrintWriter out, long case_) { out.print("Case #"); out.print(case_ + 1); out.print(": "); } }
0
247
A12852
A12898
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; public class dancingWithTheGooglers { public static void main (String[] args) throws IOException { File file = new File("in.txt"); Scanner input = null; try { input = new Scanner(file); } catch(IOException e){} int T = input.nextInt(); int N, S, p, t[]; int scoreDiv, scoreMod; int score[] = new int[3]; int solution; for (int i = 0; i < T; i++) { N = input.nextInt(); S = input.nextInt(); p = input.nextInt(); t = new int[N]; solution = 0; for (int j = 0; j < N; j++) { t[j] = input.nextInt(); scoreDiv = t[j] / 3; scoreMod = t[j] % 3; score[0] = scoreDiv; score[1] = scoreDiv; score[2] = scoreDiv; for (int k = 0; k < scoreMod; k++) { score[k]++; } if(score[0] >= p || score[1] >= p || score[2] >= p) solution++; else { if (S > 0) { if (scoreMod == 0 || scoreMod == 2) { if (score[1] > 0) { score[0]++; score[1]--; } if (score[0] >= p) { solution++; S--; } } else if (scoreMod == 1) { if (score[2] > 0) { score[1]++; score[2]--; } if (score[0] >= p) { solution++; S--; } } } } } System.out.println("Case #" + (i + 1) + ": " + solution); } } }
0
248
A12852
A11496
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.stub; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; import com.google.jam.eaque.qualif.b.Small; public class Main { /** * @param args */ public static void main(String[] args) { if (args.length != 2) { System.out.println("args length : " + args.length); System.exit(0); } Stub body = new Small(); body.setOutputFileName(args[1]); try { InputFileManager ifm = new InputFileManager(args[0]); BufferedWriter bw = new BufferedWriter(new FileWriter( body.getOutputFileName())); long nbTestCases = ifm.readLong(); for (long i = 0; i < nbTestCases; i++) { bw.write("Case #" + (i + 1) + ":" + body.runTestCase(ifm)); bw.newLine(); } ifm.close(); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
0
249
A12852
A11872
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package qualificationround; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; public class ProblemBDancingGooglers { public ProblemBDancingGooglers() { try { FileReader fr = new FileReader("B-small-attempt0.in"); BufferedReader br = new BufferedReader(fr); FileWriter fw = new FileWriter("B-small-attempt0.out"); BufferedWriter bw = new BufferedWriter(fw); int numCases = Integer.parseInt(br.readLine()); int caseNum = 1; String line = br.readLine(); while (line != null) { System.out.println(line); int numGooglers = getNumGooglersFromLine(line); int numSurprises = getNumSurprisesFromLine(line); int bestScore = getBestScoreFromLine(line); int[] scores = getScoresFromLine(line, numGooglers); int possibles = 0; for (int i=0; i<scores.length; i++) { int withSurprise = bestScoreWithSurprise(scores[i]); int withoutSurprise = bestScoreNoSurprise(scores[i]); if (withoutSurprise >= bestScore) { possibles++; } else if (withSurprise >= bestScore && numSurprises > 0) { possibles++; numSurprises--; } } String output = "Case #"+ caseNum; output += ": "+possibles; System.out.println(output); bw.append(output); if (caseNum != numCases) bw.newLine(); caseNum++; line = br.readLine(); } bw.flush(); bw.close(); br.close(); } catch(Exception e) { e.printStackTrace(); } } public int[] getScoresFromLine(String line, int numScores) { int[] scores = new int[numScores]; int firstSpace = line.indexOf(" "); int secondSpace = line.indexOf(" ",firstSpace + 1); int thirdSpace = line.indexOf(" ",secondSpace + 1); line = line.substring(thirdSpace + 1); String[] scoreStrings = line.split(" "); for (int i=0; i<scoreStrings.length; i++) { scores[i] = Integer.parseInt(scoreStrings[i]); } return scores; } public int getNumGooglersFromLine(String line) { String[] split = line.split(" "); return Integer.parseInt(split[0]); } public int getNumSurprisesFromLine(String line) { String[] split = line.split(" "); return Integer.parseInt(split[1]); } public int getBestScoreFromLine(String line) { String[] split = line.split(" "); return Integer.parseInt(split[2]); } /** * * @param totalScore * @return the best possible score without a surprise */ public int bestScoreNoSurprise(int totalScore) { return Math.min(totalScore, (totalScore + 2) / 3); } /** * * @param totalScore * @return the best possible score with a surprise */ public int bestScoreWithSurprise(int totalScore) { return Math.min(totalScore,Math.min((totalScore + 4) / 3,10)); } public static void main(String[] args) { new ProblemBDancingGooglers(); } }
0
250
A12852
A10324
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 ex2; import java.io.*; import java.util.ArrayList; /** * * @author Jean-Nicolas */ public class Ex2 { private static ArrayList<ArrayList<Integer>> getCombinaisons(int p, int n) { return getCombinaisons(p, n, new ArrayList<Integer>()); } private static ArrayList<ArrayList<Integer>> getCombinaisons(int p, int n, ArrayList<Integer> currentCombinaison) { if (p == 0) { ArrayList<ArrayList<Integer>> result = new ArrayList<>(); result.add(currentCombinaison); return result; } else { ArrayList<ArrayList<Integer>> result = new ArrayList<>(); // on trouve le max actuel de la liste int currentMax; if (currentCombinaison.isEmpty()) { currentMax = -1; } else { currentMax = currentCombinaison.get(currentCombinaison.size() - 1); } for (int i = currentMax + 1; i < n; i++) { ArrayList<Integer> newCurrentCombinaison = (ArrayList<Integer>) currentCombinaison.clone(); newCurrentCombinaison.add(i); result.addAll(getCombinaisons(p - 1, n, newCurrentCombinaison)); } return result; } } private static int getMaxScoreFromPoints(int totalPoints, boolean surprising) { if (surprising) { if (totalPoints < 2) { return 0; } else { int totalPointsTmp; if (totalPoints % 3 == 2) { totalPointsTmp = totalPoints + 1; } else if (totalPoints % 3 == 1) { totalPointsTmp = totalPoints - 1; } else { totalPointsTmp = totalPoints; } int avg = totalPointsTmp / 3; int maxScore = avg + 1; return maxScore; } } else { if (totalPoints < 1) { return 0; } else { int totalPointsTmp; if (totalPoints % 3 == 1) { totalPointsTmp = totalPoints + 2; } else if (totalPoints % 3 == 2) { totalPointsTmp = totalPoints + 1; } else { totalPointsTmp = totalPoints; } int maxScore = totalPointsTmp / 3; return maxScore; } } } public static int resultCount(int[] totalPoints, int nbSurprising, int bestResultMin) { ArrayList<ArrayList<Integer>> combinaisons = getCombinaisons(nbSurprising, totalPoints.length); int maxCount = 0; for (int i = 0; i < combinaisons.size(); i++) { int countThisCombinaison = 0; for (int j = 0; j < totalPoints.length; j++) { int maxScore = getMaxScoreFromPoints(totalPoints[j], combinaisons.get(i).contains(j)); if (maxScore >= bestResultMin) { countThisCombinaison++; } } maxCount = Math.max(maxCount, countThisCombinaison); } return maxCount; } public static String readFile(File file) { String result = ""; try { InputStream ips = new FileInputStream(file); InputStreamReader ipsr = new InputStreamReader(ips); BufferedReader br = new BufferedReader(ipsr); String line; while ((line = br.readLine()) != null) { result += line + "\n"; } br.close(); result.substring(0, Math.max(0, result.length() - 1)); // Deletion of the last \n } catch (Exception e) { System.out.println(e.toString()); } return result; } public static void writeFile(File file, String data) { try { BufferedWriter out = new BufferedWriter(new FileWriter(file)); out.write(data); out.close(); } catch (IOException ex) { System.out.println("Exception "); } } public static void main(String[] args) { String resultStr = ""; String data = readFile(new File("data.txt")); String[] lines = data.split("\n"); for (int i = 1; i < lines.length; i++) { String[] values = lines[i].split(" "); int nbSurprising = Integer.parseInt(values[1]); int bestResultMin = Integer.parseInt(values[2]); int[] totalPoints = new int[values.length - 3]; for (int j = 0; j < totalPoints.length; j++) { totalPoints[j] = Integer.parseInt(values[j + 3]); } int result = resultCount(totalPoints, nbSurprising, bestResultMin); resultStr += "Case #" + i + ": " + result + "\n"; } resultStr = resultStr.substring(0, resultStr.length() - 1); System.out.println(resultStr); writeFile(new File("result.txt"), resultStr); } }
0
251
A12852
A12101
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class dancing { public static void main(String[] args) { dancing dance = new dancing(); dance.readFile("test.txt"); } public void readFile(String filename){ int i = 1; BufferedReader reader = null; try { reader = new BufferedReader(new FileReader(filename)); } catch (FileNotFoundException e) { e.printStackTrace(); } String newLine; try { newLine = reader.readLine(); while ((newLine = reader.readLine()) != null) { evalline(newLine,i); i++; } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void evalline(String line,int casenum){ int len = line.length(); Scanner sc = new Scanner(line); int n = sc.nextInt(); int s= sc.nextInt(); int score = sc.nextInt(); int good = 0; int maybe = 0; int minscore = 2 * (score-1) + score; int minscorespecial = minscore - 2; System.out.print("Case #" + casenum + ": "); while(sc.hasNextInt()){ int curr = sc.nextInt();; if(curr >= score){ if(curr >= minscore){ good++; } else if(curr >= minscorespecial){ maybe++; } } } int tot = good + Math.min(maybe, s); System.out.println(tot); } }
0
252
A12852
A11621
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; public class Solver { public int getMaximumNumberOfPHavers(int numberOfSurprises, int bestResult, Integer... totals){ List<PossibleSurpriseCase> allCases = buildCases(numberOfSurprises, Arrays.asList(totals)); int maxPHavers = 0; for (PossibleSurpriseCase surpriseCase : allCases) { maxPHavers = Math.max(surpriseCase.getMaximumPHavers(bestResult), maxPHavers); } return maxPHavers; } private List<PossibleSurpriseCase> buildCases(int numberOfSurprises, List<Integer> totals) { if (totals.isEmpty()) return Collections.singletonList(PossibleSurpriseCase.trivial()); List<PossibleSurpriseCase> surprise = combine(true, totals.get(0), buildCases(numberOfSurprises-1, totals.subList(1, totals.size()))); if (numberOfSurprises == totals.size()) return surprise; List<PossibleSurpriseCase> noSurprise = combine(false, totals.get(0), buildCases(numberOfSurprises, totals.subList(1, totals.size()))); if (numberOfSurprises <= 0) return noSurprise; return append(surprise, noSurprise); } private List<PossibleSurpriseCase> append( List<PossibleSurpriseCase> one, List<PossibleSurpriseCase> two) { List<PossibleSurpriseCase> r = new ArrayList<PossibleSurpriseCase>(one.size() + two.size()); r.addAll(one); r.addAll(two); return r; } public static List<PossibleSurpriseCase> combine(boolean isSurprise, int score, List<PossibleSurpriseCase> cases) { List<PossibleSurpriseCase> r = new ArrayList<PossibleSurpriseCase>(cases.size()); for (PossibleSurpriseCase surpriseCase : cases) { r.add(PossibleSurpriseCase.combine(isSurprise, score, surpriseCase)); } return r; } }
0
253
A12852
A13036
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; public class ProjectB { public static void main(String [] args) { new ProjectB(); } public ProjectB() { try { String [] inputFiles = { "B-small" };//,"B-large" }; BufferedReader in; PrintWriter out; for(int i = 0 ; i < inputFiles.length; i++) { in = new BufferedReader(new FileReader(inputFiles[i])); out = new PrintWriter(new FileWriter(inputFiles[i]+".out"),true); int numCases = Integer.parseInt(in.readLine()); int numDancers = 0, surprises = 0, p = 0; String [] items = null; for(int j = 0 ; j < numCases; j++) { items = in.readLine().split("\\s+"); numDancers = Integer.parseInt(items[0]); surprises = Integer.parseInt(items[1]); p = Integer.parseInt(items[2]); int nonSurprisingScore = (p*3) - 2; int numScores = 0; for(int k = 0; k < numDancers; k++) { int score = Integer.parseInt(items[k+3]); if(score >= nonSurprisingScore) numScores++; else if(surprises > 0 && score !=0 && score + 2 >= nonSurprisingScore) { numScores++; surprises--; } } out.println("Case #" + (j+1) + ": " + numScores); } in.close(); out.close(); } } catch(Exception e) { e.printStackTrace(); } } }
0
254
A12852
A12396
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 possible { int Anom; int High; int count = 0; possible(int anom, int high){ Anom = anom; High = high; } public void canDo(int score){ int Score = score; if(High > 0 && Score - High - (2 * (High- 1 )) >= 0){ ++count; }else if( Anom > 0 && High > 1 && Score - High - (2 * (High- 2 )) >= 0 ){ ++count; --Anom; }else if( High == 0){ ++count; } } }
0
255
A12852
A11541
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.File; import java.io.FileNotFoundException; import java.util.ArrayList; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws FileNotFoundException { int cases; Scanner scan = new Scanner(new File("B.small.in")); cases = scan.nextInt(); for (int i = 1; i <= cases; i++) { int googlers = scan.nextInt(); int surprising = scan.nextInt(); int p = scan.nextInt(); int totals[] = new int[googlers]; for (int j = 0; j < googlers; j++) { totals[j] = scan.nextInt(); } int isSurprising = 0; int possible = 0; for (int j = 0; j < googlers; j++) { if (p - (totals[j] / 3) <= 0) { possible++; } else if (p - (totals[j] / 3) == 1) { /* avg = 5, p = 6 */ if (totals[j] % 3 == 0 && totals[j] > 0) { possible++; /* 0 */ isSurprising++; } else if (totals[j] % 3 == 1) { possible++; } else if (totals[j] % 3 == 2) { possible++; } } else if (p - (totals[j] / 3) == 2) { if (totals[j] % 3 == 0) { } else if (totals[j] % 3 == 1) { } else if (totals[j] % 3 == 2) { possible++; isSurprising++; } } } if (isSurprising > surprising) { possible -= isSurprising - surprising; } System.out.println("Case #" + i + ": " + possible); } } }
0
256
A12852
A11169
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.exercise.WR1B2012; import java.util.ArrayList; import java.util.List; public class TripletSet { List<Triplet> tripletList = new ArrayList<Triplet>(); //SumÀ» ³ÖÀ¸¸é °¡´ÉÇÑ Valid Triplet Á¶ÇÕÀ» »ý¼ºÇÑ´Ù. public TripletSet(long numberSum) { double numberSumDouble = (double) numberSum; long minValue = (long)Math.round(numberSumDouble/3-1); if (minValue < 0) { minValue = 0; } if (minValue + (minValue) + (minValue) == numberSum) { tripletList.add(new Triplet(minValue, minValue, minValue)); } if (minValue + (minValue) + (minValue+1) == numberSum) { tripletList.add(new Triplet(minValue, minValue, minValue+1)); } if (minValue + (minValue) + (minValue+2) == numberSum) { tripletList.add(new Triplet(minValue, minValue, minValue+2)); } if (minValue + (minValue+1) + (minValue+1) == numberSum) { tripletList.add(new Triplet(minValue, minValue+1, minValue+1)); } if (minValue + (minValue+1) + (minValue+2) == numberSum) { tripletList.add(new Triplet(minValue, minValue+1, minValue+2)); } if (minValue + (minValue+2) + (minValue+2) == numberSum) { tripletList.add(new Triplet(minValue, minValue+2, minValue+2)); } if ((minValue+1) + (minValue+1) + (minValue+1) == numberSum) { tripletList.add(new Triplet(minValue+1, minValue+1, minValue+1)); } if ((minValue+1) + (minValue+1) + (minValue+2) == numberSum) { tripletList.add(new Triplet(minValue+1, minValue+1, minValue+2)); } if ((minValue+1) + (minValue+2) + (minValue+2) == numberSum) { tripletList.add(new Triplet(minValue+1, minValue+2, minValue+2)); } } public boolean isSurprising(int index) { Triplet triplet = (Triplet)tripletList.get(index); boolean result = (triplet).isSurprising(); return result; } public long maxValue(int index) { Triplet triplet = (Triplet)tripletList.get(index); return triplet.getNumberMax(); } public int size() { return tripletList.size(); } public static final void main(String[] args) { System.out.println(Math.round(1.3)); System.out.println(Math.round(1.8)); System.out.println(Math.round(-1.3)); System.out.println(Math.round(-1.8)); } }
0
257
A12852
A10561
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.PrintWriter; import java.util.*; public class B { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(new File("B.in")); PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("B.out"))); int C = sc.nextInt(); for(int i=1;i<=C;i++){ int N = sc.nextInt(); int S = sc.nextInt(); int B = sc.nextInt(); boolean[] pass = new boolean[N]; boolean[] wierd = new boolean[N]; troll:for(int a=0;a<N;a++){ int P = sc.nextInt(); for(int b=0;b<=10;b++){ for(int c=b-2;c<=b+2;c++){ if(c>10||c<0)continue; for(int d=b-2;d<=b+2;d++){ if(d>10||d<0)continue; if(b+c+d!=P)continue; int small = Math.min(Math.min(b,c),d); int big = Math.max(Math.max(b,c),d); // System.out.println(b+" "+c+" "+d); if(big>=B){ if(big-small==2){ // System.out.println(b+" "+c+" "+d); wierd[a]=true; } else if(big-small<2){ pass[a]=true; // System.out.println(b+" "+c+" "+d); continue troll; } } } } } } // System.out.println(Arrays.toString(pass)); // System.out.println(Arrays.toString(wierd)); int ans = 0; int used = 0; for(int a=0;a<N;a++){ if(pass[a]){ ans++; continue; } if(wierd[a]){ if(used<S)ans++; used++; } } out.println("Case #"+i+": "+ans); } out.close(); } }
0
258
A12852
A12197
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 q2012; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.PrintWriter; import java.util.Scanner; public class DancingWiththeGooglers { public static void main(String[] args) throws Exception { String input = "B-small-attempt0.in"; String output = "B-small-attempt0.out"; Scanner scan = new Scanner(new BufferedReader(new FileReader(input))); PrintWriter pw = new PrintWriter(new BufferedWriter( new FileWriter(output))); int T = Integer.parseInt(scan.nextLine()); for (int t = 1; t <= T; t++) { String[] info = scan.nextLine().split(" "); int N = Integer.parseInt(info[0]); int S = Integer.parseInt(info[1]); int p = Integer.parseInt(info[2]); int[] score = new int[N]; for (int i = 0; i < N; i++) score[i] = Integer.parseInt(info[3 + i]); int countp = 0; int counts = 0; int must = p + 2 * Math.max(0, p - 1); int might = p + 2 * Math.max(0, p - 2); for (int i = 0; i < N; i++) if (score[i] >= must) countp++; else if (score[i] >= might) counts++; int res = countp + Math.min(counts, S); pw.println("Case #" + t + ": " + res); } scan.close(); pw.close(); } }
0
259
A12852
A10455
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
/* ID: yourID LANG: JAVA TASK: Dancing_With_the_Googlers */ import java.io.*; import java.math.*; import java.util.*; /*public class Dancing_With_the_Googlers { } */ public class Dancing_With_the_Googlers implements Runnable { // based on Petr's template boolean localDebug = false; private void solve() throws IOException { int n = this.nextInt(); int s = this.nextInt(); int p = this.nextInt(); int res = 0; for ( int i = 0; i < n; i ++ ){ int in = this.nextInt(); if ( in >= p * 3 - 2 ){ res ++; continue; } if ( p < 2 ) continue; if ( in >= p * 3 - 4 && s > 0 ){ res ++; s --; } } writer.println( res ); } public static void main(String[] args) { new Dancing_With_the_Googlers().run(); } BufferedReader reader; StringTokenizer tokenizer; PrintWriter writer; public void run() { try { if (localDebug) { reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(new OutputStreamWriter(System.out)); } else { writer = new PrintWriter(new BufferedWriter(new FileWriter( "B-small-attempt0.out"))); reader = new BufferedReader(new FileReader( "B-small-attempt0.in")); } tokenizer = null; int t = this.nextInt(); for ( int i = 1; i <= t; i ++ ){ writer.print( "Case #" + i + ": " ); solve(); } reader.close(); writer.close(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } boolean hasNext() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { String nextLine = reader.readLine(); if (nextLine == null) return false; tokenizer = new StringTokenizer(nextLine); } return true; } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { return reader.readLine(); } String nextToken() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return tokenizer.nextToken(); } BigInteger nextBigInteger() throws IOException { while (tokenizer == null || !tokenizer.hasMoreTokens()) { tokenizer = new StringTokenizer(reader.readLine()); } return new BigInteger(tokenizer.nextToken()); } }
0
260
A12852
A10812
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.math.*; import java.io.*; import static java.lang.System.*; import static java.lang.Math.*; import static java.lang.Integer.*; import static java.lang.Double.*; import static java.lang.Long.*; public class QB { static String[] parts(BufferedReader br) throws Exception { String line = br.readLine(); if (line == null) return null; return line.trim().split("\\s+"); } public static void main (String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(in)); int z = parseInt(br.readLine().trim()); int v[] = new int[11111]; for (int cas = 1; cas <= z; cas++) { String p[] = parts(br); int nums = parseInt(p[0]); int surp = parseInt(p[1]); int best = parseInt(p[2]); for (int i = 3, j = 0; j < nums; i++, j++) { v[j] = parseInt(p[i]); } //Arrays.sort(v, 0, nums); int count = 0; for (int i = nums - 1; i >= 0; i--) { int a = v[i]; /*0 <= k <= 2 x + x + 2 + x + k = a 3x + 2 + k = a 3x + k = a - 2 a - 3 x + 2 >= best*/ if ((a + 2) / 3 >= best) { count++; // out.println("A: " + a); } else if (surp > 0 && a >= 2 && (a - 2) / 3 + 2 >= best) { // out.println("B: " + a); count++; surp--; } } out.println("Case #" + cas + ": " + count); } } }
0
261
A12852
A12727
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.*; import java.util.Scanner; public class DancingGoogler { static String outputFile, inputFile; public static void main(String[] args) throws IOException { if (args.length != 2) return; inputFile = args[0]; outputFile = args[1]; // Create FileReader Object FileReader inputFileReader = new FileReader(inputFile); FileWriter outputFileReader = new FileWriter(outputFile); // Create Buffered/PrintWriter Objects BufferedReader inputStream = new BufferedReader(inputFileReader); PrintWriter outputStream = new PrintWriter(outputFileReader); Scanner scanner; String inLine = null; int cases = Integer.parseInt(inputStream.readLine().trim()); int num, surprising, score; int[] scores; for (int i = 1; i < cases + 1; i++) { inLine = inputStream.readLine().trim(); scanner = new Scanner(inLine); num = scanner.nextInt(); surprising = scanner.nextInt(); score = scanner.nextInt(); scores = new int[num]; for (int j=0; j<num; j++){ scores[j] = scanner.nextInt(); } outputStream.println("Case #"+i+": "+getBestDancers(scores, surprising, score)); } outputStream.close(); } private static int getBestDancers(int[] scores, int surprising, int targetSc ){ int totalTarget = 3*targetSc; int numBest = 0; if (totalTarget==0) return scores.length; for (int i=0; i<scores.length; i++){ if (scores[i]>= totalTarget-2) numBest++; else if (totalTarget > 3 && scores[i] >= totalTarget-4 ) { if (surprising>0){ numBest++; surprising--; } } } return numBest; } }
0
262
A12852
A11338
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.DataInputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.io.Reader; public class Util { public int testcases; BufferedReader br; public Util(String file) throws FileNotFoundException { FileInputStream fstream = new FileInputStream(file); Reader r = new BufferedReader(new InputStreamReader(fstream)); //while(st.nextToken()) DataInputStream in = new DataInputStream(fstream); br = new BufferedReader(new InputStreamReader(in)); String str=""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } testcases = Integer.parseInt(str); } public String nextLine() throws IOException { return br.readLine(); } protected void finalize() { try {br.close();}catch(IOException e){} } }
0
263
A12852
A11485
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 javaapplication1; import java.io.*; import java.util.StringTokenizer; public class JavaApplication1 { public static void main(String[] args) throws FileNotFoundException, IOException { if(args.length <= 0) System.out.println("Invalid input"); String filename = args[0]; BufferedReader br = new BufferedReader(new FileReader(filename)); int numLines = Integer.parseInt(br.readLine()); int higher,surprise,ans; for(int i=1; i<=numLines; i++) { higher = 0; surprise = 0; String line = br.readLine(); StringTokenizer st = new StringTokenizer(line); int n = Integer.parseInt(st.nextToken()); int s = Integer.parseInt(st.nextToken()); int p = Integer.parseInt(st.nextToken()); int p1 = 3*p-3; int p2 = 3*p-4; for(int j=1; j<=n; j++) { int t = Integer.parseInt(st.nextToken()); if(p>1) { if(t>p1) higher++; else if(t>=p2) surprise++; } else { if(t>=p) higher++; } } ans = higher+(surprise>s?s:surprise); System.out.println("Case #"+i+": "+ans); } } }
0
264
A12852
A10224
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 PracticeB { /* ‚±‚±‚©‚ç•ÒW */ private static final String fname = "B-small-attempt0.in"; // “ü—Í—p‚̃tƒ@ƒCƒ‹–¼ public static void solve() { int T = sc.nextInt(); for (int i = 1; i <= T; i++) { int N = sc.nextInt(); int S = sc.nextInt(); int p = sc.nextInt(); int tp[] = new int[N]; int cnt = 0; for (int j = 0; j < N; j++)tp[j] = sc.nextInt(); Arrays.sort(tp); int[][] ti = new int[N][3]; for (int j = ti.length - 1; j >= 0; j--) { int tv = tp[j] / 3; double val = tp[j] / 3.0; if(val - tv < 0.5) { ti[j][0] = tv; ti[j][1] = tv; ti[j][2] = tv + 1; }if(val - tv > 0.5) { ti[j][0] = tv; ti[j][1] = tv + 1; ti[j][2] = tv + 1; }if(val - tv == 0) { ti[j][0] = tv; ti[j][1] = tv; ti[j][2] = tv; } // for (int k = 0; k < 3; k++) System.out.print(ti[j][k] + " "); // System.out.println(); if(ti[j][2] >= p) { cnt++; continue; } if(val - tv < 0.5) { ti[j][0] = tv - 1; ti[j][1] = tv + 1; ti[j][2] = tv + 1; if(ti[j][2] > 10 || ti[j][0] < 0) { ti[j][0]++; ti[j][2]--; } }if(val - tv > 0.5) { ti[j][0] = tv; ti[j][1] = tv; ti[j][2] = tv + 2; while(ti[j][2] > 10 || ti[j][0] < 0) { ti[j][0] = tv++; ti[j][2] = tv--; } }if(val - tv == 0) { ti[j][0] = tv - 1; ti[j][1] = tv; ti[j][2] = tv + 1; if(ti[j][2] > 10 || ti[j][0] < 0) { ti[j][0]++; ti[j][2]--; } } if(S > 0 && ti[j][2] >= p) { cnt++; S--; } } // System. out.println("Case #" + i + ": " + cnt); } } /* ‚±‚±‚Ü‚Å */ private static Scanner sc; private static PrintWriter out; public static void main(String args[]) { try { sc = new Scanner(new File(fname)); // sc = new Scanner(System.in); out = new PrintWriter(new BufferedWriter(new FileWriter(new File(fname + "_out.dat")))); } catch (Exception e) { e.printStackTrace(); } solve(); out.close(); } }
0
265
A12852
A10724
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 home.lviv; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; public class Main { public static void proA(BufferedReader reader, BufferedWriter writer) throws NumberFormatException, IOException { Map<Character, Character> map = new HashMap<Character, Character>(32); String text = "zejp mysljylc kd kxveddknmc re jsicpdrysi" + "rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd" + "de kr kd eoya kw aej tysr re ujdr lkgc jvq", mapping = "qour language is impossible to understand" + "there are twenty six factorial possibilities" + "so it is okay if you want to just give upz"; for (int i = 0; i < text.length(); i++) { map.put(Character.valueOf(text.charAt(i)), Character.valueOf(mapping.charAt(i))); } int T; T = Integer.parseInt(reader.readLine()); for (int t = 0; t < T; t++) { String in, out = ""; in = reader.readLine(); for (int i = 0; i < in.length(); i++) { if (map.get(in.charAt(i)) == null) { System.out.println("null is " + in.charAt(i)); } out += map.get(in.charAt(i)); } writer.write("Case #" + (t + 1) + ": " + out + "\n"); } } public static void proB(BufferedReader reader, BufferedWriter writer) throws NumberFormatException, IOException { int T = Integer.parseInt(reader.readLine()); for (int t = 0; t < T; t++) { String[] temp = reader.readLine().split(" "); int N = Integer.parseInt(temp[0]), S = Integer.parseInt(temp[1]), p = Integer .parseInt(temp[2]), G = 0; int[] n = new int[N]; ArrayList<Integer> integers = new ArrayList<Integer>(N); for (int i = 0; i < N; i++) { n[i] = Integer.parseInt(temp[3 + i]); if (((n[i] / 3) >= p)) { G++; continue; } else { if (((n[i] / 3) >= p - 1) && (n[i] > 0) && (n[i] % 3 > 0)) { G++; continue; } if (((n[i] / 3) >= p - 1) && (n[i] > 0) && (S > 0)) { G++; S--; continue; } if (((n[i] / 3) >= p - 2) && (n[i] > 0) && (n[i] % 3 > 1) && (S > 0)) { G++; S--; continue; } } } writer.write("Case #" + (t + 1) + ": " + (G) + "\n"); } } public static void main(String[] args) throws IOException { BufferedReader input = new BufferedReader(new InputStreamReader( new FileInputStream("/home/taras/codejam/data.in"))); BufferedWriter output = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("/home/taras/codejam/data.out"))); proB(input, output); input.close(); output.close(); } }
0
266
A12852
A10252
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class B { public static void main(String[] args) { new B(); } public B() { Scanner scan = new Scanner(System.in); int NCASES = scan.nextInt(); for (int ZZ = 1; ZZ <= NCASES; ZZ++) { System.out.print("Case #"+ZZ+": "); int N = scan.nextInt(); int S = scan.nextInt(); int p = scan.nextInt(); int count = 0; for (int i = 0; i < N; i++) { int t = scan.nextInt(); if (t < p) continue; if (t > (p-1)*3) { count++; } else if (t >= p*3-4 && S > 0) { count++; S--; } } System.out.println(count); } } }
0
267
A12852
A10230
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam2.dancing; import java.util.Scanner; import codejam2.CodejamCase; import codejam2.CodejamRunner; public class Dancing extends CodejamRunner implements CodejamCase { private int nGooglers; private int surprising; private int pointMin; private int[] points; private String result; @Override public void compute() { int ns = 0; int s = 0; for(int i = 0; i < nGooglers; i++) { if(points[i] >= 3*pointMin-2) ns++; else if(pointMin>1 && points[i] >= 3*pointMin-4) s++; } result = String.valueOf(ns + Math.min(s, surprising)); } @Override public String getOutput() { return result; } @Override public CodejamCase parseCase(Scanner s) { Dancing d = new Dancing(); d.nGooglers = s.nextInt(); d.surprising = s.nextInt(); d.pointMin = s.nextInt(); d.points = new int[d.nGooglers]; for(int i = 0; i < d.nGooglers; i++) d.points[i] = s.nextInt(); return d; } /** * @param args */ public static void main(String[] args) { new Dancing().run(args); } }
0
268
A12852
A12064
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; import util.MyUtil; public class ProblemB { /** * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws Exception { String title = "B-small-attempt0.in"; BufferedReader reader = MyUtil.getReader(title); int caseNumber = Integer.parseInt(reader.readLine()); BufferedWriter writer = MyUtil.getWriter(title); for (int i = 0 ; i < caseNumber; i++){ String line = reader.readLine(); String result = subRoutine(line); writer.write("Case #" + (i + 1) + ": " + result + "\n"); System.out.println("Case #" + (i + 1) + ": " + result); } writer.flush(); } private static String subRoutine(String line){ StringBuilder sb = new StringBuilder(); String[] elements = line.split(" "); // The first integer will be N, the number of Googlers. long N = Long.parseLong(elements[0]); // the second integer will be S, the number of surprising triplets of scores long B = Long.parseLong(elements[1]); // The third integer will be p, a best result of at least p long P = Long.parseLong(elements[2]); long count = 0; for (int i = 3 ; i < elements.length; i++){ long total = Long.parseLong(elements[i]); long ok1 = Math.min(1, total); long ok2 = Math.min(2, total); long remains = total - P; long least = P - ok1; long doubleLeast = least * 2; if (remains >= doubleLeast ){ count ++; } else if (remains + ok2 >= doubleLeast && B > 0){ count++; B--; } } sb.append(count); return sb.toString(); } }
0
269
A12852
A12115
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.Vector; public class question2CodeJam { public int N = 0; public int S = 0; public int P = 0; Vector<Integer> Scores = new Vector<Integer>(); public int scoreValidCount=0; public int computeAtLeastP(){ for(int i=0;i<N;i++){ int currentScore = Scores.get(i); if(currentScore%3==0){ int minVal = currentScore/3; if(minVal>=P){ scoreValidCount++; continue; } if(minVal == 0 && P == 0){ scoreValidCount++; continue; } else if (minVal==0 && P!= 0){ continue; } if((minVal+1) >= P && S > 0){ //minVal + 1 would introduce 2 ka gap scoreValidCount++; S--; continue; } } if(currentScore%3==1){ int minVal = currentScore/3; if(minVal>=P){ scoreValidCount++; continue; } if((minVal+1) >= P){ scoreValidCount++; continue; } } if(currentScore%3==2){ int minVal = currentScore/3; if((minVal+1) >= P){ scoreValidCount++; continue; } if(((minVal+2) >= P)&&(S>0)){ S--; scoreValidCount++; continue; } } } return (int) scoreValidCount; } public static void main(String[] args){ try{ File file = new File(args[0]); FileWriter fstream = new FileWriter(args[1]); BufferedWriter out = new BufferedWriter(fstream); BufferedReader in = new BufferedReader(new FileReader(file)); String line = in.readLine(); //here line is the number of rounds int counter=0; int testCase = Integer.parseInt(line); while (counter<testCase) { question2CodeJam tmp = new question2CodeJam(); String inline = in.readLine(); String[] val = inline.split(" "); //initializing tmp.N = Integer.parseInt(val[0]); tmp.S = Integer.parseInt(val[1]); tmp.P = Integer.parseInt(val[2]); for(int i=3;i<val.length;i++){ tmp.Scores.add(Integer.parseInt(val[i])); } ++counter; //System.out.println("Case #" + counter + ": " + tmp.computeAtLeastP()); //out.write(inline); out.write("Case #" + counter + ": " + tmp.computeAtLeastP()); out.write("\n"); } out.close(); in.close(); } catch(IOException e){ System.out.println("IO Error"); } catch (ArrayIndexOutOfBoundsException e){ System.out.println("Array Error"); e.printStackTrace(); } } }
0
270
A12852
A12293
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 Java{ public static void main(String[] args) { try { BufferedReader in = new BufferedReader(new FileReader("B-small-attempt1.in")); int cases = Integer.parseInt(in.readLine()); for (int i = 1; i <= cases; i ++){ String[] temp = (in.readLine()).split(" "); int players = Integer.parseInt(temp[0]); int surprise = Integer.parseInt(temp[1]); int best = Integer.parseInt(temp[2]); int[] totals = new int [players]; for (int k = 0; k < players; k ++) totals[k] = Integer.parseInt(temp[k+3]); logic(players, surprise, best, totals, i); } in.close(); } catch (IOException e) { System.out.println("INPUT ERROR"); } } public static void logic(int numOfPlayers, int surprise, int bestScore, int[] totals, int caseNum){ int result = 0; int maybe = 0; for (int i = 0; i < numOfPlayers; i ++){ int min = totals[i]/3; if (min >= bestScore) result ++; else if (totals[i] != 0) { int x = totals[i] - (2 * min); if (x >= bestScore && ((x-1 == min) || (x-1 == bestScore))) result ++; else if ((x >= bestScore) || ((x == min) && (x+1 == bestScore) && (bestScore - min < 2))) maybe ++; } } if (maybe > surprise) System.out.println("Case #" + caseNum + ": " + (result + surprise)); else System.out.println("Case #" + caseNum + ": " + (result + maybe)); } }
0
271
A12852
A11031
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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; /** * Convenience class for declaring a method inside a method, so as to avoid code duplication without having to declare a new method * in the class. This also keeps functions closer to where they are applied. It's butt-ugly but it's about the best you can do in * Java. */ public interface Lambda4<P, Q, R, S, V> { public V apply(P param1, Q param2, R param3, S param4); }
0
272
A12852
A11319
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.util.HashMap; /* * To change this template, choose Tools | Templates and open the template in * the editor. */ /** * * @author Anuj */ public class DanceWithGoogle { int cases; String temp[]; int magic, judges, surp; int num; public DanceWithGoogle() { cases = 0; magic = 2; judges = 3; surp =0; } public void go() { try { int z; BufferedReader br = new BufferedReader(new FileReader("B-small-attempt2.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt")); cases = Integer.parseInt(br.readLine()); // System.out.println("Case : " + cases); for (z = 0; z < cases; z++) { int i, j; temp = br.readLine().split(" "); int players = Integer.parseInt(temp[0]); surp = Integer.parseInt(temp[1]); int thresh = Integer.parseInt(temp[2]); int count = 0; // System.out.println("Case : " + n); //m = Integer.parseInt(temp[1]); //System.out.println("Case : " + (z+1) + "thres : "+thresh); for (i = 0; i < players; i++) { int score = Integer.parseInt(temp[i + 3]); if (check(score, thresh)) { count++; } } //System.out.println("Case #" + (z + 1) + ": " + count); bw.write("Case #" + (z + 1) + ": " + count); bw.newLine(); } br.close(); bw.close(); } catch (java.io.FileNotFoundException e) { } catch (java.io.IOException e) { } } private boolean check(int sc, int th) { int non = 0; int sur = 0; if (sc != 0) { non = (sc + 2) / 3; sur = (sc + 4) / 3; } if (non >= th) { return true; } else if (surp > 0) { if (sur >= th) { //System.out.println("surp:" + sur + "su:" + surp + " for sc:" + sc + "thres:" + th); surp--; return true; } return false; } else { return false; } } public static void main(String[] args) { DanceWithGoogle codeJam = new DanceWithGoogle(); codeJam.go(); } }
0
273
A12852
A11008
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package dancing; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class Main { public static void main(String[] args) throws IOException { File file = new File("B-small-attempt0.in"); FileReader fr = new FileReader(file); BufferedReader in = new BufferedReader(fr); String line = in.readLine(); String[] tokens; int num = Integer.parseInt(line); int i = 1, N, s, p, t, minAlways, minSurprising, always, surprising, finalCount; while (i <= num) { line = in.readLine(); tokens = line.split(" "); N = Integer.parseInt(tokens[0]); s = Integer.parseInt(tokens[1]); p = Integer.parseInt(tokens[2]); if (p >= 2) { minAlways = 3 * p - 2; minSurprising = 3 * p - 4; } else { minAlways = p; minSurprising = 1; } always = 0; surprising = 0; for (int j = 0; j < N; j++) { t = Integer.parseInt(tokens[3 + j]); if (t >= minAlways) { always++; } else if (t >= minSurprising) { surprising++; } } finalCount = always + Math.min(s, surprising); System.out.println("Case #" + i + ": " + finalCount); i++; } } }
0
274
A12852
A11270
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class Main extends AbstractCodeJam { @Override protected Problem readProblem(Scanner scan) { ProblemSample pb = new ProblemSample(); // PARAMETRES A LIRE !!! pb.setGooglers(scan.nextInt()); pb.setSurprises(scan.nextInt()); pb.setNote(scan.nextInt()); for (int i = 0; i < pb.getGooglers(); i++) { pb.getSums().add(scan.nextInt()); } scan.nextLine(); return pb; } /** * @param args */ public static void main(String[] args) { new Main().solveProblems(System.in, System.out); } }
0
275
A12852
A10450
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 qr; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class B { public static void main(String[] args) throws FileNotFoundException { Scanner scanner = new Scanner(new File("B-small-attempt3.in")); int tcn = scanner.nextInt(); int tc = 1; while (tc <= tcn) { int n = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); // int[] base = new int[n]; int y = 0; for (int i = 0; i < n; i++) { int t = scanner.nextInt(); int base = t / 3; int mmm = t % 3; if (mmm != 0) { base++; } if (base >= p) { if (mmm == 0 && t >= 0) y++; if (mmm == 1 && t >= 1) y++; if (mmm == 2 && t >= 2) y++; } else if (s > 0) { if (base + 1 == p) { if (mmm == 0 && t >= 3) { y++; s--; } // if (mmm == 1 && t >= 4) { // y+=0; // s--; // } if (mmm == 2 && t >= 2) { y++; s--; } } } } System.out.printf("Case #%d: %d\n", tc, y); // base >= p -> ok // base -1 -> can be ok tc++; } } }
0
276
A12852
A10751
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 gcj2012qual; import java.io.*; import java.util.*; public class Dancing { /** * @param args */ public static void main(String[] args) throws Exception{ // TODO Auto-generated method stub Scanner input = new Scanner(new File("B-small-attempt0.in")); PrintWriter output = new PrintWriter(new FileWriter("output")); // Scanner in = new Scanner(System.in); int case_num = input.nextInt(); //String word = in.nextLine(); int[][] surprising = new int[31][11]; int[][] normal = new int[31][11]; //int i = 0; for(int score = 0; score <= 30; score++) for(int s = 0; s <= 10; s++){ if(s == 0 && score == 0){ surprising[score][s] = 0; normal[score][s] = 1; continue; } if(score == 0){ surprising[score][s] = 0; normal[score][s] = 0; continue; } if(s == 0){ surprising[score][s] = 0; normal[score][s] = 1; continue; } if(score < s){ surprising[score][s] = 0; normal[score][s] = 0; continue; } if(score >= s * 3){ surprising[score][s] = 1; normal[score][s] = 1; continue; } if(s == 1 && score == 1){ surprising[score][s] = 0; normal[score][s] = 1; continue; } if(s == 1 && score == 2){ surprising[score][s] = 1; normal[score][s] = 1; continue; } if(score >= s + (s - 2) * 2){ surprising[score][s] = 1; if(score > s + (s - 2) * 2 + 1){ normal[score][s] = 1; }else{ normal[score][s] = 0; } continue; }else{ surprising[score][s] = 0; normal[score][s] = 0; continue; } } for(int i = 0; i < case_num; i++){ int n = input.nextInt(); int s = input.nextInt(); int p = input.nextInt(); int[] t = new int[n]; int total = 0; int only_surprising = 0; for(int j = 0; j < n; j++){ t[j] = input.nextInt(); if(surprising[t[j]][p] == 1 || normal[t[j]][p] == 1) total = total + 1; if(surprising[t[j]][p] == 1 && normal[t[j]][p] == 0) only_surprising = only_surprising + 1; } output.println("Case #" + (i + 1) + ": " + (total - Math.max(0, (only_surprising - s)))); } input.close(); output.flush(); output.close(); } }
0
277
A12852
A10644
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 net.anzix.learn.codejam.qr12; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.PrintStream; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class DancingWithTheGooglers { private InputStream input; private PrintStream output; public DancingWithTheGooglers() { } public DancingWithTheGooglers(InputStream input, PrintStream output) { super(); this.input = input; this.output = output; } public DancingWithTheGooglers(File inputFile, File outputFile) throws Exception { this.input = new FileInputStream(inputFile); output = new PrintStream(outputFile); } public void run() throws Exception { Scanner scanner = new Scanner(input); int lines = scanner.nextInt(); for (int i = 0; i < lines; i++) { int n = scanner.nextInt(); int s = scanner.nextInt(); int p = scanner.nextInt(); List<Integer> maxs = new ArrayList<Integer>(); for (int j = 0; j < n; j++) { maxs.add(scanner.nextInt()); } output.println("Case #" + (i + 1) + ": " + getNoOfBigger(maxs, s, p)); } output.close(); } public static void main(String[] args) { try { new DancingWithTheGooglers(new File(args[0]), new File(args[1])) .run(); } catch (Exception e) { e.printStackTrace(); } } public int getNoOfBigger(List<Integer> maxPoints, int noOfSuprisings, int limit) { int no = 0; for (Integer point : maxPoints) { if (point == 0) { if (limit == 0) { no++; } } else { int ns = maxNo(point, false); int s = maxNo(point, true); if (noOfSuprisings < 1 && ns >= limit) { no++; } if (noOfSuprisings > 0) { if (ns < limit && s >= limit) { noOfSuprisings--; no++; } else if (ns >= limit) { no++; } } } } return no; } public int maxNo(int sumPoint, boolean suprising) { int c = sumPoint % 3; if (suprising) { switch (c) { case 0: return (sumPoint + 3) / 3; case 1: return (sumPoint + 2) / 3; case 2: return (sumPoint + 4) / 3; } } else { switch (c) { case 0: return (sumPoint + 0) / 3; case 1: return (sumPoint + 2) / 3; case 2: return (sumPoint + 1) / 3; } } throw new IllegalArgumentException(); } }
0
278
A12852
A11339
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 Problem2; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.StringTokenizer; /** * * @author Mohammed */ public class NewDancers { static int in[][], out[]; private static void readFile(String fileName) throws FileNotFoundException, IOException { BufferedReader br = new BufferedReader(new FileReader(fileName)); String line; int x = Integer.parseInt(br.readLine()); in = new int[x][103]; out = new int[x]; for (int i = 0; i < x; i++) { line = br.readLine(); StringTokenizer st = new StringTokenizer(line); int j = 0; while (st.hasMoreTokens()) { in[i][j++] = Integer.parseInt(st.nextToken()); } } } private static void writeOutput(String string) throws IOException { BufferedWriter bw = new BufferedWriter(new FileWriter(string)); for (int i = 0; i < out.length; i++) { bw.write("Case #" + (i + 1) + ": " + out[i]); if (i != out.length - 1) { bw.write("\r\n"); } } bw.close(); } public static void main(String[] args) throws FileNotFoundException, IOException { readFile("data"); for (int i = 0; i < in.length; i++) { int googlers = in[i][0]; int surp = in[i][1]; int p = in[i][2]; int minCountedTriplet = 3 * p - 2; int minCountedTripletWithSur = 3 * p - 4; int output = 0; for (int j = 3; j < googlers + 3; j++) { int temp = in[i][j]; if (temp >= minCountedTriplet) { output++; } else { if (surp > 0 && temp >= minCountedTripletWithSur && minCountedTripletWithSur >= 0) { output++; surp--; } } } out[i] = output; } writeOutput("output.txt"); } }
0
279
A12852
A11722
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; public class CodeJamTextInputReader { private final BufferedReader reader; private final int numberOfTestCases; private int lastReadTestCase = 0; public CodeJamTextInputReader(File inputFile) throws IOException, InvalidInputException { reader = new BufferedReader(new FileReader(inputFile)); numberOfTestCases = readInNumberOfTestCases(); } private int readInNumberOfTestCases() throws IOException, InvalidInputException { String firstLine = reader.readLine(); try { return Integer.parseInt(firstLine); } catch (NumberFormatException e) { throw new InvalidInputException("Expected first line to be number of test cases", e); } } public boolean hasNextTestCase() { return numberOfTestCases != lastReadTestCase; } public String readNextLine() throws IOException { ++lastReadTestCase; return reader.readLine(); } public int getLastReadTestCaseNumber() { return lastReadTestCase; } public void close() throws IOException { this.reader.close(); } }
0
280
A12852
A11238
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; public class B { static int[] a; static int[][] dp; static int n, s, p; public static void main(String args[]) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); for(int ca=1;ca <= T;ca++) { n = scan.nextInt(); s = scan.nextInt(); p = scan.nextInt(); a = new int[n]; for(int i=0;i < n;i++) a[i] = scan.nextInt(); dp = new int[n][s+1]; for(int i=0;i < n;i++) Arrays.fill(dp[i], -1); System.out.println("Case #" + ca + ": " + f(0, s)); } } public static int f(int K, int S) { if(K == n) return S == 0 ? 0 : -999999; if(dp[K][S] != -1) return dp[K][S]; int rtn = 0; boolean[] b = new boolean[4]; //nobeat nosup, nobeat sup, beat nosup, beat sup for(int i=0;i <= 10;i++) for(int j=0;j <= i;j++) { if(i+j > a[K]) continue; int k = a[K] - (i+j); if(k > j) continue; if(i-k > 2) continue; //System.out.println(i + " " + j + " " + k + " " + a[K]); if(i >= p && i-k == 2) b[3] = true; if(i >= p && i-k < 2) b[2] = true; if(i < p && i-k == 2) b[1] = true; if(i < p && i-k < 2) b[0] = true; } if(S == 0 && !b[0] && !b[2]) return -999999; if(S > 0 && b[1]) rtn = Math.max(rtn, f(K+1, S-1)); if(S > 0 && b[3]) rtn = Math.max(rtn, f(K+1, S-1)+1); if(b[0]) rtn = Math.max(rtn, f(K+1, S)); if(b[2]) rtn = Math.max(rtn, f(K+1, S)+1); //System.out.println(K + " " + S + " " + rtn); return dp[K][S] = rtn; } }
0
281
A12852
A11267
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.ArrayList; import java.util.List; public class ProblemSample implements Problem { private int solution; private int googlers; private int surprises; private int note; private List<Integer> sums = new ArrayList<Integer>(); @Override public void solve() { int resultat = 0; for (int i = 0; i < sums.size(); i++) { if (note == 0) { // Ils ont tous eu au moins 0... resultat = this.googlers; } else if (note == 1) { // Tous ceux qui ont eu au moins 1 ont eu au moins la note de 1. if (sums.get(i) >= 1) { resultat++; } } else { if ((sums.get(i) == 3 * note - 4 || sums.get(i) == 3 * note - 3) && sums.get(i) > note) { // S'ils sont tout juste, ils ont utilisé une surprise. surprises--; // Et on les compte que si il restait des surprises à consommer if (surprises >= 0) { resultat++; } } if (sums.get(i) >= 3 * note - 2 && sums.get(i) > note) { // Ok sans surprise. resultat++; } } } this.setSolution(resultat); } @Override public void print() { System.out.println(googlers + " " + surprises + " " + note + " " + sums.toString()); } @Override public Object getSolution() { return solution; } public void setSolution(int solution) { this.solution = solution; } public int getGooglers() { return googlers; } public int getSurprises() { return surprises; } public int getNote() { return note; } public List<Integer> getSums() { return sums; } public void setGooglers(int googlers) { this.googlers = googlers; } public void setSurprises(int surprises) { this.surprises = surprises; } public void setNote(int note) { this.note = note; } public void setSums(List<Integer> sums) { this.sums = sums; } }
0
282
A12852
A10115
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 source; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class DancingGooglers { /** * @param args */ public static void main(String[] args) throws IOException{ Scanner scan = new Scanner(new File("B-small-attempt5.in")); BufferedWriter bw = new BufferedWriter(new FileWriter("B-small-attempt5.out")); int testCases = scan.nextInt(); Map<Double, Integer> mapa = new HashMap<Double, Integer>(); mapa.put(3d,2); mapa.put(6d,3); mapa.put(9d,4); mapa.put(12d,5); mapa.put(15d,6); mapa.put(18d,7); mapa.put(21d,8); mapa.put(24d,9); mapa.put(27d,10); for(int i=0; i < testCases; i++){ int googlers = scan.nextInt(); int s = scan.nextInt(); int p = scan.nextInt(); int bestResults = 0; for(int j=0; j < googlers; j++){ double qual = scan.nextInt(); double firstSecond = Math.round(qual/3d); double third = qual-(firstSecond*2); if(firstSecond >= p || third >= p) { bestResults++; } else if(s > 0 && p-third <= 2 && third <= firstSecond && !(((third+2)-(firstSecond-1)) > 2) && (third+2) <= 10) { bestResults++; s--; } else if(third == firstSecond && mapa.get(qual) != null && mapa.get(qual) >= p && s > 0){ bestResults++; s--; } } bw.write("Case #"+(i+1)+": "+bestResults+"\n"); } bw.flush(); bw.close(); } }
0
283
A12852
A12222
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.Scanner; public class DancingWithGooglers { public static void main(String[] args) throws IOException{ String path = "C:\\Users\\Rapol Tongchenchitt\\Documents\\CodeJam\\"; String year = "Qual2012\\"; String test = "input.txt"; String outPath = "output.txt"; String a = ""; String A = ""; String b = "B-small-attempt0.in"; String B = "B-small-attempt0.out"; String c = ""; String C = ""; String d = ""; String D = ""; String inName = path+year+b; String outName = path+year+B; Scanner in = new Scanner(new FileInputStream(inName)); BufferedWriter out = new BufferedWriter(new FileWriter(outName)); int caseCount = in.nextInt(); int currentCase = 0; while(currentCase++ < caseCount){ int dancerCount = in.nextInt(); int surpriseCount = in.nextInt(); int minScore = in.nextInt(); int goodCount = 0; int maybeCount = 0; for(int i = 0; i < dancerCount; i++){ int now = in.nextInt(); int min; switch(now%3){ case 0: min = now/3; if(min == 0){ if (minScore == 0){ goodCount++; } }else if(min >= minScore){ goodCount++; }else if(min + 1 == minScore){ maybeCount++; } break; case 1: min = (now/3) + 1; if(min >= minScore){ goodCount++; } break; case 2: min = (now/3) + 1; if(min >= minScore){ goodCount++; }else if(min + 1 == minScore){ maybeCount++; } break; } } goodCount += Math.min(maybeCount, surpriseCount); out.write("Case #" + currentCase + ": " + goodCount); out.newLine(); } out.close(); } }
0
284
A12852
A12544
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 problem1; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Arrays; public class Problem1 { public static void main(String[] args) throws FileNotFoundException, IOException{ try { TextIO.readFile("L:\\Coodejam\\Input\\Input.txt"); } catch (IllegalArgumentException e) { System.out.println("Can't open file "); System.exit(0); } FileOutputStream fout = new FileOutputStream("L:\\Coodejam\\Output\\output.txt"); PrintStream ps=new PrintStream(fout); int cases=TextIO.getInt(); int googlers=0,surprising=0,least=0; for(int i=0;i<cases;i++){ int counter=0; googlers=TextIO.getInt(); surprising=TextIO.getInt(); least=TextIO.getInt(); int score[]=new int[googlers]; for(int j=0;j<googlers;j++){ score[j]=TextIO.getInt(); } Arrays.sort(score); int temp=0; int sup[]=new int[surprising]; for(int j=0;j<googlers && surprising>0;j++){ if(biggestNS(score[j])<least && biggestS(score[j])==least){ surprising--; counter++; } } for(int j=0;j<googlers;j++){ if(surprising==0)temp=biggestNS(score[j]); else { temp=biggestS(score[j]); surprising--; } if(temp>=least)counter++; } ps.println("Case #"+(i+1)+": "+counter); } } static int biggestNS(int x){ if(x==0)return 0; if(x==1)return 1; return ((x-1)/3)+1; } static int biggestS(int x){ if(x==0)return 0; if(x==1)return 1; return ((x-2)/3)+2; } }
0
285
A12852
A12774
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; public class DancingGooglers { public static void main(String[] args) throws IOException { BufferedReader fInput = new BufferedReader(new FileReader("res/inputB.in")); PrintWriter fOutput = new PrintWriter(new BufferedWriter(new FileWriter( "res/outputB.out"))); new DancingGooglers().run(fInput, fOutput); fOutput.close(); } private void run(BufferedReader fInput, PrintWriter fOutput) throws IOException { int T = Integer.parseInt(fInput.readLine()); for (int i=0; i<T; i++) { int count = 0; String[] inputS = fInput.readLine().split(" "); int N = Integer.parseInt(inputS[0]); int S = Integer.parseInt(inputS[1]); int p = Integer.parseInt(inputS[2]); for (int j=3; j<N+3; j++) { int t = Integer.parseInt(inputS[j]); int base = t/3; int max = t%3==0? base : base+1; if (max >= p) { count++; continue; } if (S == 0 || t<2 || t%3==1) continue; max = t%3==0? base+1 : base+2; if (max >= p) { count++; S--; } } fOutput.println("Case #" + (i+1) + ": " + count); } } }
0
286
A12852
A10980
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package org.moriraaca.codejam; public enum OutputDestination { STDOUT, FILE; }
0
287
A12852
A12434
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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.FileOutputStream; import java.io.FileReader; import java.io.IOException; import java.io.OutputStreamWriter; public class DancingGooglers { /** * Google Code Jam 2012: Problem B. Dancing With the Googlers * @author hullarb * @param args * @throws IOException * @throws NumberFormatException */ public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader input = new BufferedReader(new FileReader(args[0])); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(args[0].contains("in")?args[0].replace("in", "out"):args[0] + ".out")); int testCases = Integer.parseInt(input.readLine()); for(int i = 0; i < testCases; i++) { String[] parts = input.readLine().split(" "); int N = Integer.parseInt(parts[0]); int S = Integer.parseInt(parts[1]), p = Integer.parseInt(parts[2]); // System.out.println("N: " + N + " S: " + S + " p: " +p); int t[] = new int[N]; int bests[] = new int[N]; for(int j = 0; j < N; j++) { t[j] = Integer.parseInt(parts[3 + j]); bests[j] = notSurp(t[j]); //System.out.println("NotSurp(" +t[j] + "): " + bests[j]); } for(int j = 0; j < N; j++) { if(S == 0) break; if((t[j] > 1 && t[j] < 29) && (bests[j] == -1 || bests[j] < p)) { int ns = surp(t[j]); //System.out.println("Surp(" +t[j] + "): " + ns); if(bests[j] == -1 && ns == -1) { System.err.print("Something went wrong with t: " + t[j]); continue; } if(ns >= p) { bests[j] = ns; S--; }else{ if(bests[j] == -1){ S--; } } } } int result = 0; for(int j = 0; j < N; j++) if(bests[j] >= p) result++; out.write("Case #" + (i + 1) + ": " + result + "\n"); } out.close(); input.close(); } private static int surp(int i) { if(i == 2) return 2; if((i - 2) % 3 == 0) return (i - 2) / 3 + 2; if((i - 3) % 3 == 0) return (i - 3) / 3 + 2; if(i > 3 && (i - 4) % 3 == 0) return (i - 4) / 3 + 2; return -1; } private static int notSurp(int i) { if(i == 0) return 0; if(i < 3 ) return 1; if((i - 2) % 3 == 0) return (i - 2) / 3 + 1; if((i - 1) % 3 == 0) return (i - 1) / 3 + 1; if(i % 3 == 0) return i / 3; return -1; } }
0
288
A12852
A10991
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam2012; import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.HashMap; import java.util.Scanner; /** * Created by IntelliJ IDEA. * User: Jimmy * Date: 4/14/12 * Time: 10:17 PM */ public class DancingWithTheGooglers implements Runnable { Scanner scanner; PrintWriter pw; public static void main(String arguments[]) { new Thread(new DancingWithTheGooglers()).start(); } public static boolean isSurprising(int points) { return points > 1 && points < 29; } public static int ms(int points) { return (points + 4) / 3; } public static int mn(int points) { return (points + 2) / 3; } public void solution() { int t = scanner.nextInt(); int i, n, s, p, j; int points; int d; int r = 0; int result; for(i = 1; i <= t; i++) { n = scanner.nextInt(); s = scanner.nextInt(); p = scanner.nextInt(); System.out.println(n + " " + s + " " + p); int sum1 = 0; int sum2 = 0; for(j = 0; j < n; j++) { r = 0; points = scanner.nextInt(); if(isSurprising(points)) { int ms = ms(points); int mn = mn(points); if (ms >= p && mn < p) sum1++; else if (mn >= p) sum2++; } else { if (mn(points) >= p) sum2++; } } System.out.println("******************************************************"); pw.println("Case #" + i + ": " + (Math.min(s, sum1) + sum2)); } } public void run() { scanner = new Scanner(System.in); try { pw = new PrintWriter(new File("output.txt")); } catch (FileNotFoundException e) { e.printStackTrace(); } solution(); pw.close(); scanner.close(); } }
0
289
A12852
A11696
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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 dg.gcj.bdancing; import java.lang.reflect.Array; import java.util.Arrays; /** * Created by IntelliJ IDEA. * User: Dmitry * Date: 15.04.12 * Time: 0:03 * To change this template use File | Settings | File Templates. */ public class Triplet { int[] sorted; public Triplet(int[] sorted) { this.sorted = Arrays.copyOf(sorted, sorted.length); } public int getTotal() { return sorted[0] + sorted[1] + sorted[2]; } public boolean isSurprising() { return this.sorted[2] - this.sorted[1] > 1 || this.sorted[1] - this.sorted[0] > 1 || this.sorted[2] - this.sorted[0] > 1; } public int getMaximumScore() { return sorted[2]; } @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; Triplet triplet = (Triplet) o; return Arrays.equals(sorted, triplet.sorted); } @Override public int hashCode() { return Arrays.hashCode(this.sorted); } @Override public String toString() { return "{" + this.sorted[2] + ", " + this.sorted[1] + ", " + this.sorted[0] + '}'; } }
0
290
A12852
A11360
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 GCJ2012QualB{ public static void main(String args[]){ Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int mon=1;mon<=t; mon++){ int nplayer=s.nextInt(); int nsuprise=s.nextInt(); int nscore=s.nextInt(); int ans=0; int scores[]; scores = new int [nplayer]; for (int i=0; i<nplayer; i++){ scores[i]=s.nextInt(); } // java.util.Arrays.sort(scores); int limsup=nscore-2; if(limsup<0){ limsup=0; } int limsupall=nscore+limsup+limsup; int limnormal=nscore-1; if(limnormal<0){ limnormal=0; } int limnormalall=nscore+limnormal+limnormal; for (int i=0; i<nplayer; i++){ int checkscore=scores[i]; if(checkscore>=limnormalall){ ans+=1; } else if(checkscore>=limsupall){ if (nsuprise>0){ ans+=1; nsuprise-=1; } } } System.out.println("Case #"+ mon+": "+ans); } } }
0
291
A12852
A12194
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); 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 QB { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); in.nextLine(); for(int cas=0; cas<T; cas++) { int n = in.nextInt(); int s = in.nextInt(); int p = in.nextInt(); int ans = 0; for(int i=0; i<n; i++) { int score = in.nextInt(); if(score>=p && score>=3*p-2) ans++; else if(score>=p && score>=3*p-4 && s>0) { ans++; s--; } } System.out.println("Case #"+(cas+1)+": "+ans); } } }
0
292
A12852
A10584
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.*; import java.io.*; public class B { public static int solve(int T, int P) { int[] score = new int[3]; score[0] = T/3; score[1] = (T-score[0]) / 2; score[2] = (T-score[0]-score[1]); Arrays.sort(score); int dif = score[2] - score[0]; if (dif > 2) { System.err.println("ERROR"); System.exit(-1); } //System.err.println("BEFORE ARRANGE NUM "+T+": "+score[0]+" "+score[1]+" "+score[2]); if (score[2] >= P) { if (dif == 2) return 1; else return 0; } // try to make it interesting if (dif < 2) { score[2]++; score[1]--; Arrays.sort(score); dif = score[2] - score[0]; } if (score[0] < 0 || score[0] > 10 || score[1] < 0 || score[1] > 10 || score[2] < 0 || score[2] > 10 || dif > 2) { return -1; } //System.err.println("AFTER ARRANGE NUM "+T+": "+score[0]+" "+score[1]+" "+score[2]); if (score[2] >= P) { if (dif == 2) return 1; else return 0; } return -1; } public static void main(String[] args) throws Exception{ Scanner in = new Scanner(System.in); int T = in.nextInt(); int N, S, P, used, can; for(int caseNo = 1;caseNo <= T; caseNo++) { N = in.nextInt(); S = in.nextInt(); P = in.nextInt(); used = 0; can = 0; for(int i=0;i<N;i++) { int ret = solve(in.nextInt(), P); if (ret == 0) { // didint need surprise can++; } else if (ret == 1 && used < S) { // need surprise used++; can++; } } System.out.println("Case #"+caseNo+": "+can); } } }
0
293
A12852
A13091
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().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.B; import java.io.File; import java.io.FileWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; import java.util.Scanner; /** * * @author Rymbu VV */ public class DancingWithGooglers { private Scanner sc; private PrintWriter pw; private int CASES; public static void main(String[] args) { DancingWithGooglers suk = new DancingWithGooglers("c:\\b.in", "c:\\b.out"); suk.execute(); } public DancingWithGooglers(String fileIn, String fileOut) { try{ sc = new Scanner(new File(fileIn)); pw = new PrintWriter(new FileWriter(fileOut)); CASES = sc.nextInt(); }catch(Exception e){System.out.println("In Constructor "+e);} } public void execute(){ int N, S, p, count; for(int ncase = 1; ncase <= CASES; ncase++){ pw.print("Case #"+ncase+": "); N = sc.nextInt(); S = sc.nextInt(); p = sc.nextInt(); count = 0; for (int i=0; i<N; i++){ int t = sc.nextInt(); if (t>=p && (t/3) >= p ){ count++; continue; } int tmp = t-p; if (t>=p && (p-(tmp/2)) <= 1){ count++; continue; } if (S>0 && t>=p && (p-(tmp/2)) <= 2){ count++; S--; } } pw.println(count); } pw.flush(); pw.close(); sc.close(); } }
0
294
A12852
A11460
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.util.Scanner; public class problemB { private static final StringBuilder output = new StringBuilder(); private static int i = 1; public static void main(String[] args) { Scanner s = new Scanner(System.in); int tests = s.nextInt(); s.nextLine(); for (int i = 0; i < tests; i++) { addLine(String.valueOf(getMaxDancers(s.nextLine()))); } System.out.println(showLine()); } private static int getMaxDancers(String line) { String[] values = line.split(" "); int surprising = Integer.parseInt(values[1]); int score = Integer.parseInt(values[2]); int minScore = score * 3 - 2; int minSurp = minScore - 2; int numOfDancers = 0; for(int i = 3; i < values.length; i++){ int sumOfPoints = Integer.parseInt(values[i]); if(sumOfPoints >= minScore){ numOfDancers++; } else if(sumOfPoints > 1 && sumOfPoints >= minSurp && surprising > 0){ numOfDancers++; surprising--; } } return numOfDancers; } private static void addLine(String s){ output.append("Case #"); output.append(i); output.append(": "); output.append(s); output.append("\n"); i++; } public static String showLine(){ return output.toString(); } }
0
295
A12852
A10691
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.FileWriter; import java.io.InputStreamReader; public class SolutionJamB { /** * @param args */ public static void main(String[] args) { try { FileInputStream fisEntrada = new FileInputStream("src/entrada1.in"); FileWriter fwSalida = new FileWriter("src/salida4.out"); BufferedWriter bwSalida = new BufferedWriter(fwSalida); DataInputStream disEntrada = new DataInputStream(fisEntrada); String sEntrada; String arrsEntrada[]; String sSalida; int participantes; int sorpresas; int pMinimo; int resultado; int resultadoIndividual; int cocienteResultado; int residuoResultado; StringBuilder sbParteSalida; BufferedReader brEntrada = new BufferedReader(new InputStreamReader(disEntrada)); int contador; try { contador = Integer.parseInt(brEntrada.readLine()); for(int i = 1; i<=contador; i++) { sEntrada = brEntrada.readLine(); arrsEntrada = sEntrada.split(" "); participantes = Integer.parseInt(arrsEntrada[0]); sorpresas = Integer.parseInt(arrsEntrada[1]); pMinimo = Integer.parseInt(arrsEntrada[2]); resultado = 0; for(int j = 1; j <= participantes; j++) { resultadoIndividual = Integer.parseInt(arrsEntrada[2+j]); cocienteResultado = (int)Math.floor(resultadoIndividual / 3 ); residuoResultado = (pMinimo * 3) - resultadoIndividual; if(cocienteResultado >= pMinimo) { resultado++; } else if( residuoResultado <= 2 && resultadoIndividual != 0) { resultado++; } else if( sorpresas > 0 ) { if(residuoResultado <= 4 && resultadoIndividual != 0) { resultado++; sorpresas--; } } } sSalida = "Case #" + i + ": " + resultado + "\n"; bwSalida.write(sSalida); } bwSalida.close(); } catch(Exception e) { e.getMessage(); bwSalida.close(); } } catch(Exception e) { e.getMessage(); } } }
0
296
A12852
A12261
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.util.LinkedList; import java.util.StringTokenizer; public class Principal { public static void main(String [] args) throws IOException { FileReader fr = new FileReader("B-small-attempt0.in"); BufferedReader bf = new BufferedReader(fr); FileWriter bw = new FileWriter("B-small-attempt0.out"); int res; int times = Integer.parseInt(bf.readLine()); LinkedList<Integer> l = new LinkedList<Integer>(); String str = bf.readLine(); int i = 1; StringTokenizer st; while(i <= times) { st = new StringTokenizer(str); while(st.hasMoreTokens()) { l.add(Integer.parseInt(st.nextToken()) ); } bw.write("Case #"); bw.write(String.valueOf(i)); bw.write(": "); l.pop(); int s = l.pop(); int p = l.pop(); res = Triplet.triplete(l, p, s); bw.write(Integer.toString(res)); bw.write("\n"); str = bf.readLine(); i++; l = new LinkedList<Integer>(); } bw.close(); bf.close(); } }
0
297
A12852
A11153
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; public class Countscores { public static int processLine(String data) { int result = 0; String[] info = data.split(" "); // for (int i = 0; i < info.length; i++) { // System.out.print(info[i] + " "); // } // System.out.println(); int N = Integer.parseInt(info[0]); if (info.length < 3 + N) { System.err.println("insufficient arguments!"); return -1; } int surprises = Integer.parseInt(info[1]); int surprisecount = 0; int threshold = 3 * Integer.parseInt(info[2]); for (int i = 0; i < N; i++) { int totalscore = Integer.parseInt(info[3 + i]); if (totalscore >= threshold - 2) { result++; } else if (totalscore > Math.max(threshold - 5, 0) && surprisecount < surprises) { result++; surprisecount++; } } return result; } public static void countScores(String input) { try { BufferedReader br = new BufferedReader(new FileReader(input)); int cases = Integer.parseInt(br.readLine()); int idx = 0; while (idx < cases) { idx++; System.out.println("Case #" + idx + ": " + processLine(br.readLine())); } br.close(); } catch (Exception e) { e.printStackTrace(); } } public static void main(String[] args) { String input = "C:/Users/hattori/Downloads/B-small-attempt0.in"; countScores(input); } }
0
298
A12852
A11975
package com.techy.rajeev; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class DancingGame2 { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new FileReader("techyrajeev.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("myoutput.out")); int num=Integer.valueOf(in.readLine().trim()); int count = 0, l = 1; while (num > 0) { int arrtemp[]=toIntArray(in.readLine()); int N = arrtemp[0]; int S = arrtemp[1]; int p=arrtemp[2]; for(int i=3;i<arrtemp.length;i++){ int base=arrtemp[i]/3; switch(arrtemp[i]%3){ case 0:{ if(base>=p){ count++; }else{ if(S>0 && base>0 && base+1>=p){ count++; S--; } } }break; case 1:{ if(base>=p || base+1>=p){ count++; }else{ if(S>0 && base+1>=p){ count++; S--; } } }break; case 2:{ if(base+1>=p || base>=p){ count++; }else{ if(S>0 && base+2>=p){ count++; S--; } } }break; } } num--; System.out.println("Case #"+l+": "+count); bw.write("Case #"+l+": "+count); bw.newLine(); count=0; l++; } in.close(); bw.close(); } public static int[] toIntArray(String line){ String[] p = line.trim().split("\\s+"); int[] out = new int[p.length]; for(int i=0;i<out.length;i++) out[i] = Integer.valueOf(p[i]); return out; } }
package codejam; import java.util.HashMap; import java.util.Scanner; public class DanceScores { public static void main(String[] args) { HashMap<Integer,int[]> best = new HashMap<Integer, int[]>(); best.put(1 , new int[]{1,1}); best.put(2 , new int[]{2,3}); best.put(3 , new int[]{4,6}); best.put(4 , new int[]{7,9}); best.put(5 , new int[]{10,12}); best.put(6 , new int[]{13,15}); best.put(7 , new int[]{16,18}); best.put(8 , new int[]{19,21}); best.put(9 , new int[]{22,24}); best.put(10, new int[]{25,27}); Scanner in = new Scanner(System.in); int cases = in.nextInt(); for(int i=1; i<=cases; i++){ int n = in.nextInt(); //Number of scores int s = in.nextInt(); //Number of surprising score triplets int p = in.nextInt(); //The minimum criterion /********* Boundary Cases ********/ if(p==0){ System.out.println("Case #"+i+": "+n); in.nextLine(); //Ignore remaining line continue; } int[] range = best.get(p); //The range where the best score p can be achieved only in case of surprising triplet. int definite = 0, probable=0; for(int j=0;j<n;j++){ int score = in.nextInt(); //Reading individual scores if(score>=range[0] && score <=range[1]) probable++; else if(score>range[1]) definite++; } System.out.println("Case #"+i+": "+(definite+Math.min(probable, s))); } } }
0
299