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
|
---|---|---|---|---|---|
A11759 | A10372 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.anuragkapur.jam2012.qr.B;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* @author anuragkapur
*
*/
public class DancingWithGooglers {
boolean lifelineAvailable = true;
int noOfSurprisingTripletsAllowed = -1;
public void writeOutputToFile(String output, String filepath)
throws IOException {
FileWriter fstream = new FileWriter(filepath);
BufferedWriter out = new BufferedWriter(fstream);
out.write(output);
out.flush();
out.close();
}
// methods for algorithm logic here
public boolean checkIfTotalScoreMeetsCriteria(int score, int requiredBestScore) {
boolean solution = false;
int perfectTotal = requiredBestScore * 3;
if (score == 0) {
if (requiredBestScore == 0) {
solution = true;
}else {
solution = false;
}
}else if (perfectTotal == score) {
// Perfect case. No problems here.
solution = true;
}else {
// First try not to use lifeline
int difference = perfectTotal - score;
if (difference > 2) {
// Check if this is doable at all
if (difference > 4) {
// No way, this is not doable
solution = false;
}else {
// Can't do without lifeline. Check if lifeline is available
if (noOfSurprisingTripletsAllowed > 0) {
// Uselifeline and done.
noOfSurprisingTripletsAllowed --;
solution = true;
}else {
// No lifeline available
solution = false;
}
}
}else {
// Can do without lifeline
solution = true;
}
}
return solution;
}
public int solveTestCase(String input) {
System.out.println("\n\n\n\nWill solve input string :: " + input);
StringTokenizer tokenizer = new StringTokenizer(input, " ");
int noOfGooglers = -1;
int bestScore = -1;
int solution = 0;
int tokenCount = 0;
while (tokenizer.hasMoreElements()) {
tokenCount ++;
String token = (String) tokenizer.nextElement();
if (tokenCount == 1) {
lifelineAvailable = true;
noOfGooglers = Integer.parseInt(token);
System.out.println("no of googlers :: " + noOfGooglers);
}else if (tokenCount == 2) {
noOfSurprisingTripletsAllowed = Integer.parseInt(token);
System.out.println("no of surprising triplets allowed :: " + noOfSurprisingTripletsAllowed);
}else if (tokenCount == 3) {
bestScore = Integer.parseInt(token);
System.out.println("required best score :: " + bestScore);
}else {
// This is a googlers score. Check if it meets criteria
int perfectTotal = bestScore * 3;
int score = Integer.parseInt(token);
boolean didMeetCriteria = false;
if (perfectTotal == score) {
didMeetCriteria = true;
}else if(perfectTotal > score) {
didMeetCriteria = checkIfTotalScoreMeetsCriteria(Integer.parseInt(token), bestScore);
}else if (perfectTotal < score) {
int difference = score - perfectTotal;
while(difference > 4) {
perfectTotal += 3;
difference = score - perfectTotal;
}
didMeetCriteria = checkIfTotalScoreMeetsCriteria(Integer.parseInt(token), bestScore);
}
System.out.println("check if score meets criteria :: " + score);
if (didMeetCriteria) {
solution ++;
System.out.println("Criteria met, solution count :: " + solution);
}else {
System.out.println("Didnt meet criteria");
}
}
}
return solution;
}
/**
* @param args
*/
public static void main(String[] args) {
if (args.length < 2) {
System.out.println("Not enough command line arguments specified. Need 2 (Input and output file paths)");
return;
}
String inputFilePath = args[0];
try {
// String buffer for storing the output
StringBuffer output = new StringBuffer();
// Instantiate object to use non static methods
DancingWithGooglers dance = new DancingWithGooglers();
// read and parse input file
FileInputStream fstream = new FileInputStream(inputFilePath);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
int lineNumber = 0;
int noOfTestCases = -1;
int activeTestCaseNumber = 0;
while ((strLine = br.readLine()) != null) {
if (lineNumber == 0) {
noOfTestCases = Integer.parseInt(strLine);
} else {
noOfTestCases ++;
activeTestCaseNumber ++;
// Now that a test case has been parsed, compute output for
// this test case
// Invoke algorithm here
int solutionToTestCase = dance.solveTestCase(strLine);
// Prepare output string
System.out.println(solutionToTestCase);
output.append("Case #" + activeTestCaseNumber + ": " + solutionToTestCase);
output.append("\n");
}
lineNumber++;
}
in.close();
// Pass output string to method to write to file
dance.writeOutputToFile(output.toString(), args[1]);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
// File read cleanup
}
}
} | 0 | 1,189,000 |
A11759 | A10666 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.PrintWriter;
import java.util.Scanner;
public class ProblemB {
public static void main(String[] args) {
final Scanner in = new Scanner(System.in);
final PrintWriter out = new PrintWriter(System.out);
final int t = in.nextInt();
for (int tt = 0; tt < t; tt++) {
final int n = in.nextInt();
final int s = in.nextInt();
final int p = in.nextInt();
int surprisesLeft = s;
int googlersCount = 0;
for (int nn = 0; nn < n; nn++) {
final int totalScore = in.nextInt();
if (canAchieveScoreIfNormal(totalScore, p)) {
googlersCount++;
} else if (surprisesLeft > 0 && canAchieveScoreIfSurprising(totalScore, p)) {
googlersCount++;
surprisesLeft--;
}
}
out.write("Case #" + (tt + 1) + ": " + googlersCount + "\n");
}
out.flush();
}
private static boolean canAchieveScoreIfNormal(int totalScore, int score) {
return totalScore >= (3 * score - 2);
}
private static boolean canAchieveScoreIfSurprising(int totalScore, int score) {
if (score == 1)
return totalScore >= 1;
else
return totalScore >= (3 * score - 4);
}
}
| 0 | 1,189,001 |
A11759 | A12940 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package dancing.with.the.googlers;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.util.Scanner;
public class DancingWithTheGooglers {
private static String INPUT_FILE = "B-small-attempt0.in";
private static String OUTPUT_FILE = "B-small-attempt0.out";
private static BufferedReader getInput() {
return new BufferedReader(new InputStreamReader(DancingWithTheGooglers.class.getResourceAsStream(INPUT_FILE)));
}
private static PrintWriter getOutput() throws URISyntaxException, FileNotFoundException {
File inputFile = new File(DancingWithTheGooglers.class.getResource(INPUT_FILE).toURI());
File packageDirectory = inputFile.getParentFile();
File outputFile = new File(packageDirectory, OUTPUT_FILE);
return new PrintWriter(outputFile);
}
public static void main(String[] args) throws Throwable {
BufferedReader br = getInput();
PrintWriter pw = getOutput();
int numTestCases = new Integer(br.readLine().trim());
for (int testCase = 1; testCase <= numTestCases; testCase++) {
String line = br.readLine();
Scanner read = new Scanner(line);
int numGooglers = read.nextInt();
int numSurprisingTriplets = read.nextInt();
int bestResult = read.nextInt();
int doesNotRequireSurprising = 0;
int requiresSurprising = 0;
int neverMeetsBestResult = 0;
for (int googler = 0; googler < numGooglers; googler++) {
int total = read.nextInt();
int avg = total / 3;
int diff = total - (avg * 3);
if (total == 0 && bestResult > 0) {
neverMeetsBestResult++;
}
else if (bestResult <= avg) {
doesNotRequireSurprising++;
}
else if (bestResult == (avg + 1)) {
switch (diff) {
case 0:
requiresSurprising++;
break;
case 1:
doesNotRequireSurprising++;
break;
case -1:
requiresSurprising++;
break;
case 2:
doesNotRequireSurprising++;
break;
case -2:
requiresSurprising++;
break;
default:
neverMeetsBestResult++;
break;
}
}
else if (bestResult == (avg + 2)) {
switch (diff) {
case 2:
requiresSurprising++;
break;
default:
neverMeetsBestResult++;
break;
}
}
else {
neverMeetsBestResult++;
}
}
System.out.println("does not requires: " + doesNotRequireSurprising);
System.out.println("requires: " + requiresSurprising);
System.out.println("never: " + neverMeetsBestResult);
int maxGooglersWithBestResult = doesNotRequireSurprising;
if (numSurprisingTriplets < requiresSurprising) {
maxGooglersWithBestResult += numSurprisingTriplets;
}
else {
maxGooglersWithBestResult += requiresSurprising;
}
pw.println("Case #" + testCase + ": " + maxGooglersWithBestResult);
}
pw.close();
br.close();
}
}
| 0 | 1,189,002 |
A11759 | A11584 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Googlers {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
String l;
l=read.readLine();
int a=Integer.parseInt(l);
for (int i = 0; i < a; i++) {
Scanner scn=new Scanner(read.readLine());
int n=scn.nextInt();
int s=scn.nextInt();
int p=scn.nextInt();
int sum=0;
for (int j = 0; j < n; j++) {
int m=scn.nextInt();
if(m >= p+Math.max(0,(p-1)+(p-1)))
{
sum++;
//System.out.println(m+"..");
}else{
if(s>0)
{
if(m>=p+Math.max(0,(p-2)+(p-2)))
{
s--;
sum++;
//System.out.println(m+" "+p);
}
}
}
}
System.out.println("Case #"+(i+1)+": "+sum);
}
}
}
| 0 | 1,189,003 |
A11759 | A10504 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package gcj2012.qualification;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class GooglerDance {
public static void main(String[] args) throws Exception {
GooglerDance main = new GooglerDance(args[0]);
main.solve();
}
private final BufferedReader in;
public GooglerDance(String input) throws Exception {
in = new BufferedReader(new FileReader(this.getClass().getResource(input).getFile()));
}
private void solve() throws Exception {
int T = getInt();
for (int c = 1; c <= T; c++) {
List<Integer> n = getIntegers();
long ans = solveOne(n);
System.out.println("Case #" + c + ": " + ans);
}
}
private int solveOne(List<Integer> n) {
int sum = 0;
int N = n.remove(0).intValue();
int S = n.remove(0).intValue();
int p = n.remove(0).intValue();
for (Integer candid : n) {
if (candid.intValue() >= p * 3 - 2) {
sum++;
} else if (candid.intValue() >= p * 3 - 4 && S > 0 && p >= 2) {
S--;
sum++;
}
}
return sum;
}
/*
* File processing
*/
private int getInt() throws Exception {
return Integer.valueOf(in.readLine()).intValue();
}
private List<Integer> getIntegers() throws Exception {
List<Integer> list = new ArrayList<Integer>();
for (String s : getStrs()) {
list.add(Integer.valueOf(s));
}
return list;
}
private List<String> getStrs() throws Exception {
return Arrays.asList(in.readLine().split(" "));
}
}
| 0 | 1,189,004 |
A11759 | A12192 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
public class Dancing {
public static void main(String[] args) {
try{
BufferedWriter output = new BufferedWriter(new FileWriter("output.txt"));
BufferedReader input = new BufferedReader(new FileReader("B-small-attempt2.in"));
int i = 0;
int j = Integer.parseInt(input.readLine());
while(i < j) {
//get the line
String line = input.readLine();
//split into data
String[] splitLine = line.split(" ");
//get the useful data out of the line
int n = Integer.parseInt(splitLine[0]);
int s = Integer.parseInt(splitLine[1]);
int p = Integer.parseInt(splitLine[2]);
int[] scores = new int[n];
//get out the total score
for(int foo = 0; foo < n; foo++) {
scores[foo] = Integer.parseInt(splitLine[foo + 3]);
}
//setup the output value
int caseValue = 0;
for(int score: scores) {
//if total score is less then value needed there is no chance
if(score >= p){
int average = score / 3;
//if the average is higher then the scores are then 1 value is definately higher then p
if (average >= p) {
caseValue++;
//if average is 1 less then scores are there is a possibilty of a hit
} else if(average+1 == p) {
//if it's scores are not divisible by 3 at least one is higher then average
if(score % 3 != 0) {
caseValue++;
//if the total score is divisible by 3 then only a surprising score can make up difference
} else {
if(s>0){
caseValue++;
s--;
}
}
//there is also a very specific case when the average is 2 less that you can use a surprising case to make up the difference
} else if (average+2 == p && score % 3 == 2 && s >0) {
caseValue++;
s--;
}
}
}
System.out.println();
output.write("Case #" + (i+1) +": " + caseValue);
output.newLine();
i++;
}
output.close();
input.close();
} catch(Exception e) {System.out.println(e);}
}
}
| 0 | 1,189,005 |
A11759 | A10486 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class dancing {
static int surprising;
/**
* @param args
*/
public static final int regexOccur(String text, String regex) {
Matcher matcher = Pattern.compile(regex).matcher(text);
int occur = 0;
while(matcher.find()) {
occur ++;
}
return occur;
}
public static int solve(BufferedReader reader) throws IOException {
int cpt = 0;
String ligne = reader.readLine();
int taille = regexOccur(ligne, Pattern.quote(" ")) + 1;
String[] entiers = new String[taille];
entiers = ligne.split(" ");
int N = Integer.parseInt(entiers[0]);
int S = Integer.parseInt(entiers[1]);
int p = Integer.parseInt(entiers[2]);
surprising = 0;
for(int i = 0; i < N; i++) {
cpt += best_result(p, Integer.parseInt(entiers[i + 3]));
}
if(S - surprising > 0) return cpt;
else return cpt + S - surprising;
}
public static int best_result(int p, int note) throws IOException {
int a;
a = note/3;
if(a >= p) return 1;
else {
if(note - a > 0) {
if(note%3 == 0 && a + 1 >= p) {
surprising++;
return 1;
}
if(note%3 == 1 && a + 1 >= p) return 1;
if(note%3 == 2) {
if(a + 1 >= p) return 1;
if(a + 2 >= p) {
surprising++;
return 1;
}
}
}
}
return 0;
}
public static void main(String[] args) {
try {
InputStream ips = new FileInputStream("dancing.in");
InputStreamReader ipsr = new InputStreamReader(ips);
BufferedReader br = new BufferedReader(ipsr);
int cases = Integer.valueOf(br.readLine());
for (int i = 1; i <= cases; i++) {
imprimer(i, solve(br));
}
} catch (IOException x) {
System.err.println(x);
} catch (NumberFormatException x) {
System.err.println(x);
}
}
static void imprimer(int numero, int resultat) {
try {
FileWriter fw = new FileWriter ("dancing.out",true);
BufferedWriter bw = new BufferedWriter (fw);
PrintWriter fichierSortie = new PrintWriter (bw);
fichierSortie.println ("Case #" + numero + ": " + resultat);
fichierSortie.close();
}
catch (Exception e){
System.out.println(e.toString());
}
}
}
| 0 | 1,189,006 |
A11759 | A10274 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.PrintWriter;
import java.util.Scanner;
public class B {
int ref;
int[] scores = new int[3];
int max1=0;
int max2=0;
public B(int ref, int suma) {
super();
this.ref = ref;
scores[0] = suma/3;
suma-=scores[0];
scores[1] = suma/2;
scores[2] = suma-scores[1];
max1 = scores[2]>=ref?1:0;
if (suma>=2 && suma <= 28)
max2 = (scores[2]+1)>=ref?1:0;
else
max2=-1;
//System.out.println(Arrays.toString(scores));
/*if(ref==scores[0])
max2--;
if(scores[1]>=ref)
max2++;
if((scores[2]+1)>=ref)
max2++;
int tmpMax = 0;
if(ref==scores[0])
tmpMax--;
if(scores[1]+1>=ref)
tmpMax++;
if((scores[2])>=ref)
tmpMax++;
if(tmpMax>max2)
max2=tmpMax;
*/
}
public static void main(String[] args) throws Exception{
Scanner sc = new Scanner(new File("inputb.in"));
PrintWriter pw = new PrintWriter(new File("outputb.out"));
int cases = sc.nextInt();
for (int i = 0; i < cases; i++) {
int n = sc.nextInt();
int s = sc.nextInt();
int ref = sc.nextInt();
B[] scores = new B[n];
boolean[] excep = new boolean[n];
for (int j = 0; j < n; j++) {
scores[j] = new B(ref,sc.nextInt());
}
for (int j = 0; j < s; j++) {
int max = -10;
int index = -1;
for (int k = 0; k < excep.length; k++) {
if(excep[k])
continue;
if(scores[k].max2-scores[k].max1 > max){
max = scores[k].max2-scores[k].max1;
index = k;
}
}
excep[index]=true;
}
int res=0;
for (int j = 0; j < excep.length; j++) {
if(excep[j])
res+=scores[j].max2;
else
res+=scores[j].max1;
}
//System.out.println(Arrays.toString(excep));
pw.println("Case #"+(int)(i+1)+": "+res);
}
pw.close();
}
}
| 0 | 1,189,007 |
A11759 | A10777 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.ArrayList;
public class TestCase {
private int scoreCount;
private int suprisingCount;
private int pScore;
private ArrayList<Triplet> triplets;
public TestCase(String s) {
String[] result = s.split(" ");
scoreCount = Integer.parseInt(result[0]); // N
suprisingCount = Integer.parseInt(result[1]); // S
pScore = Integer.parseInt(result[2]); // P
triplets = new ArrayList<Triplet>(scoreCount);
for (int i = 0; i < scoreCount; i ++) {
triplets.add(new Triplet(Integer.parseInt(result[i+3])));
}
}
public int getScoreCount() {
return scoreCount;
}
public int getSuprisingCount() {
return suprisingCount;
}
public int getpScore() {
return pScore;
}
public ArrayList<Triplet> getTriplets() {
return triplets;
}
}
| 0 | 1,189,008 |
A11759 | A11403 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package dancingwiththegooglers;
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;
public class DancingWithTheGooglers {
public static void main(String[] args) throws IOException {
BufferedReader br=new BufferedReader(new FileReader(new File("./dancingwiththegooglers/b-small-attempt1.in")));
BufferedWriter bw=new BufferedWriter(new FileWriter(new File("./dancingwiththegooglers/small1.out")));
int numberOfCase=Integer.parseInt(br.readLine());
StringBuilder out=new StringBuilder();
for(int i=1;i<=numberOfCase;i++){
int count=0;
out.append("Case #"+i+": ");
String[]input=br.readLine().split(" ");
int surprising=Integer.parseInt(input[1]);
int goal=Integer.parseInt(input[2]);
int googlers=Integer.parseInt(input[0]);
for(int j=3;j<3+googlers;j++){
int result=check(Integer.parseInt(input[j]),goal,surprising);
if(result==0){
count++;
surprising--;
}
if(result==1)
count++;
}
out.append(count);
if(i<numberOfCase)
out.append("\n");
}
bw.write(out.toString());
br.close();
bw.close();
}
/*
* return 1 - possible to achieve goal and is not surprising
* 0 - possible to achieve goal and is surprising
* -1 - impossible to achieve goal
*/
public static int check(int totalScore,int goal,int surprising){
if(totalScore<goal)
return -1;
int r=totalScore%3;
int max=-1;
if(r==0)
max=totalScore/3;
if(r==1)
max=(int)Math.ceil(totalScore/3.0);
if(r==2)
max=(int)Math.ceil(totalScore/3.0);
if(max<goal)
if(surprising==0)
return -1;
else{
if(totalScore>=goal+(goal-2)+(goal-2))
return 0;
else
return -1;
}
else
return 1;
}
}
| 0 | 1,189,009 |
A11759 | A11065 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class b {
public static void main(String[] args) throws IOException {
BufferedReader bd= new BufferedReader(new InputStreamReader(System.in));
int li= Integer.parseInt(bd.readLine());
for (int i = 1; i <=li; i++) {
String[] cadena=bd.readLine().split(" ");
int n=Integer.parseInt(cadena[0]);
int s=Integer.parseInt(cadena[1]);
int p=Integer.parseInt(cadena[2]);
int ps=p-s;
int pss=p+s;
int min=p+(2*(p-1));
int max=p+(2*(p+1));
int mins=(p+(2*(p-2))<0)?1:(p+(2*(p-2)));
int maxs=p+(2*(p+2));
//System.out.println(min+" "+max+" "+mins+" "+maxs );
int[] c = new int[n];
int res=0;
for (int j = 0; j < n; j++) {
c[j]=Integer.parseInt(cadena[3+j]);
if(c[j]>=min){
res++;
//System.out.println(c[j]);
}
else if((c[j]>=mins)&&s>0){
res++;
s--;
//System.out.println(c[j]);
}
}
System.out.println("Case #"+i+": "+res);
}
}
static boolean saleConP(int t,int p){
return false;
}
static boolean saleConPS(int t,int p){
return false;
}
}
| 0 | 1,189,010 |
A11759 | A10248 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
/**
* User: Andrii Baranov
* Date: 14.04.12
* Time: 12:59
*/
public class DancingGooglers {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("B-small-attempt0.in"));
int testCases = Integer.parseInt(br.readLine());
int[] maximumGooglers = new int[testCases];
String paramString;
int surprising, maxRes, googlersNumber;
for (int i = 0; i < testCases; ++i) {
paramString = br.readLine();
String params[] = paramString.split(" ");
googlersNumber = Integer.parseInt(params[0]);
surprising = Integer.parseInt(params[1]);
maxRes = Integer.parseInt(params[2]);
int[] sumOfResults = new int[googlersNumber];
for (int j = 0; j < googlersNumber; ++j) {
sumOfResults[j] = Integer.parseInt(params[3 + j]);
}
maximumGooglers[i] = numOfBestResults(googlersNumber, surprising, maxRes, sumOfResults);
}
br.close();
BufferedWriter bw = new BufferedWriter(new FileWriter("B-small-out.txt"));
for (int i = 0; i < maximumGooglers.length; i++) {
bw.write("Case #" + (i + 1) + ": " + maximumGooglers[i]);
if (i + 1 < maximumGooglers.length) {
bw.write("\n");
}
}
bw.close();
}
private static int numOfBestResults(int googlersNumber, int surprising, int maxRes, int[] sumOfResults) {
int res = 0;
int transformSurprising = 0;
if(maxRes == 0){
return googlersNumber;
}
if(maxRes == 1){
for(int i =0; i < googlersNumber; i++){
if (sumOfResults[i]> 0){
res++;
}
}
return res;
}
for (int i = 0; i < googlersNumber; ++i) {
if ((sumOfResults[i] / 3 + 1) >= maxRes) {
if ((sumOfResults[i] % 3 == 0) && ((sumOfResults[i] / 3 + 1) == maxRes)) {
transformSurprising++;
res++;
} else {
res++;
}
} else if ((sumOfResults[i] % 3 == 2) && ((sumOfResults[i] / 3 + 2) == maxRes)) {
transformSurprising++;
res++;
}
}
if (transformSurprising > surprising) {
return res - (transformSurprising - surprising);
}
return res;
}
}
| 0 | 1,189,011 |
A11759 | A12958 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Arrays;
import java.util.Scanner;
public class ProblemB {
public static void main(String[] args) throws IOException {
new ProblemB();
}
private int numOfTest;
private static final int ATTEMPT_NO = 0;
private static int SOLVE_HARD = 0;
int n, s, p;
int[] a = new int[128];
int ans;
public ProblemB() throws IOException {
// Scanner input = new Scanner(new File("input.txt"));
Scanner input = new Scanner(new File("B-small-attempt" + ATTEMPT_NO + ".in"));
Writer output = new FileWriter("B-small-attempt" + ATTEMPT_NO + ".out");
if (SOLVE_HARD != 0) {
input = new Scanner(new File("B-large.in"));
output = new FileWriter("B-large.in");
}
//output = new BufferedWriter(new OutputStreamWriter(System.out));
numOfTest = input.nextInt();
for (int test = 1; test <= numOfTest; test++) {
// read from input
n = input.nextInt();
s = input.nextInt();
p = input.nextInt();
for (int i = 0; i < n; i++) {
a[i] = input.nextInt();
}
process();
output.write("Case #" + test + ": " + ans + "\n");
}
input.close();
output.flush();
output.close();
}
private void process() {
Arrays.sort(a, 0, n);
ans = 0;
for (int i = n - 1; i >= 0; i--) {
int k = a[i] / 3;
int m = k;
if (k * 3 < a[i]) {
m++;
}
if (m >= p) {
ans++;
continue;
}
if (s == 0) {
break;
}
if (a[i] <= 1) {
break;
}
k = (a[i] - 2) / 3;
m = k + 2;
if (m >= p) {
ans++;
s--;
continue;
}
break;
}
}
} | 0 | 1,189,012 |
A11759 | A13149 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package dance;
import java.io.*;
import java.util.*;
/**
*
* @author karam.yaaqna
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String line ;
StringTokenizer st ;
try{
int num = 0;
int s = 0;
int p = 0;
int minLimit = 0;
int maxLimit = 0;
int score = 0;
int out =0 ;
BufferedReader reader = new BufferedReader(new FileReader("B-small-attempt1.in"));
PrintWriter writer = new PrintWriter(new FileOutputStream("output.txt"));
int testCase = Integer.parseInt(reader.readLine());
line = reader.readLine();
st = new StringTokenizer(line);
for(int tc = 1;tc<=testCase;tc++){
st = new StringTokenizer(line);
num = Integer.parseInt(st.nextToken());
s = Integer.parseInt(st.nextToken());
p = Integer.parseInt(st.nextToken());
minLimit = p * 3 - 4;
maxLimit = p*3 - 2;
// System.out.println("im here"+num);
while(st.hasMoreTokens()){
score = Integer.parseInt(st.nextToken());
if(score>=maxLimit){
out++;
}else
{if (score>=minLimit )
if(p>1 && s>0){
out++;
s--;
}
}
}
// System.out.println(out);
writer.println("Case #"+tc+": "+out);
line = reader.readLine();
out = 0;
}
writer.close();
}catch(Exception e){
}
}
}
| 0 | 1,189,013 |
A11759 | A10941 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class Dancing {
/**
* @param args
*/
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int cases = Integer.parseInt(sc.nextLine());
for(int i = 0; i < cases; i++) {
Scanner line = new Scanner(sc.nextLine());
int triplets = line.nextInt();
int surprise = line.nextInt();
int threshold = line.nextInt();
int enough = 0;
int borderline = 0;
while(line.hasNextInt()) {
int score = line.nextInt();
if(score == 0) {
if(threshold == 0) {
enough++;
}
}
else if(score == 1) {
if(threshold <= 1) {
enough++;
}
}
else {
int maxS, maxNS;
int mod = score % 3;
int div = score / 3;
if(mod == 0) {
maxS = div+1;
maxNS = div;
}
else if(mod == 1) {
maxS = div+1;
maxNS = div+1;
}
else {
maxS = div+2;
maxNS = div+1;
}
if(threshold <= maxNS) {
enough++;
}
else {
if(threshold <= maxS) {
borderline++;
}
}
}
}
System.out.printf("Case #%d: %d\n", i+1, enough + Math.min(borderline, surprise));
}
}
}
| 0 | 1,189,014 |
A11759 | A12282 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class Prob2 {
public static PrintStream out;
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new File("in.txt"));
out = new PrintStream(new File("out.txt"));
int numCases = Integer.parseInt(sc.nextLine());
int caseNum = 1;
while(caseNum<=numCases)
solve(sc.nextLine(), caseNum++);
}
public static void solve(String input, int caseNum){
StringTokenizer st = new StringTokenizer(input, " ");
int numPeople = Integer.parseInt(st.nextToken());
int numSurprising = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
LL scores = new LL();
for(int i=0; i<numPeople; i++)
scores.push(Integer.parseInt(st.nextToken()));
Collections.sort(scores);
int surePass = removeSurePassed(scores, p);
removeSureUnsurprised(scores);
int canPass = countCanPass(scores, p);
int answer = surePass + Math.min(canPass, numSurprising);
out.println("Case #"+caseNum+": "+answer);
caseNum++;
}
public static void removeSureUnsurprised(LL scores){
while(!scores.isEmpty() && scores.getFirst()<=1)
scores.removeFirst();
}
public static int removeSurePassed(LL scores, int p){
int surePassLimit = 3*p-2;
int origLength = scores.size();
while(!scores.isEmpty() && scores.getLast()>=surePassLimit)
scores.removeLast();
return origLength - scores.size();
}
public static int countCanPass(LL scores, int p){
int canpass = 0;
for(int i=0; i<scores.size(); i++){
int cur = scores.get(i);
if(cur%3==0){
if(cur/3+1 >= p)
canpass++;
}else if(cur%3==2){
if((cur-2)/3+2 >= p)
canpass++;
}
}
return canpass;
}
public static class LL extends LinkedList<Integer>{}
}
| 0 | 1,189,015 |
A11759 | A12918 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package lt.kasrud.gcj.ex2;
import lt.kasrud.gcj.common.io.Reader;
import lt.kasrud.gcj.common.io.Writer;
import java.io.IOException;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
List<String> iData = Reader.readFile("B-small-attempt0.in");
Writer.writeFile("out2.txt", process(iData.subList(1, iData.size())));
}
private static List<String> process(List<String> data) {
List<String> result = new ArrayList<String>(data.size());
for(String record : data){
List<String> tokens = Arrays.asList(record.trim().split(" "));
result.add(calculate(Integer.valueOf(tokens.get(1)), Integer.valueOf(tokens.get(2)), tokens.subList(3, tokens.size())));
}
return result;
}
private static String calculate(Integer surpCnt, Integer maxValue, List<String> totPoints) {
int cnt = 0;
int minDiff = maxValue > 0 ? 1 : maxValue;
int maxDiff = maxValue > 1 ? 2 : maxValue;
int maxTotal = maxValue * 3 - 2 * minDiff;
int surpTotal = maxValue * 3 - 2 * maxDiff;
for (String t : totPoints) {
int total = Integer.valueOf(t);
if (total >= maxTotal){
cnt++;
}else if(total >= surpTotal && surpCnt > 0){
cnt++;
surpCnt--;
}
}
return String.valueOf(cnt);
}
}
| 0 | 1,189,016 |
A11759 | A13086 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.nbarraille.gcj;
import java.io.IOException;
public class GCJ extends GCJHelper {
protected static final String TEST_CASE = "B-small"; // CHANGE THIS WHEN CHANGING PROBLEM
protected static final boolean RUN_ALL_CASES = true;
protected static final boolean DEBUG = true;
// DO WHATEVER TO SOLVE THE CASE
// AND APPEND THE OUTPUT TO SB
protected static void solveCase() throws IOException {
long[] input = readLongArray();
int nbDancers = (int)input[0];
int nbSurprises = (int)input[1];
int minScore = (int) input[2];
long[] totals = new long[nbDancers];
System.arraycopy(input, 3, totals, 0, nbDancers);
int nbOk = 0;
int nbOkWithS = 0;
for (long t : totals) {
if (minScore == 0) {
nbOk++;
} else if (minScore == 1) {
if (t >= 1) {
nbOk++;
}
} else if (t >= 3 * minScore - 2) {
nbOk++;
} else if (t >= 3 * minScore - 4) {
nbOkWithS++;
}
}
sb.append(nbOk + Math.min(nbSurprises, nbOkWithS));
}
// DONT TOUCH THIS
public static void main(String[] args) throws Exception {
run();
}
}
| 0 | 1,189,017 |
A11759 | A10159 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
public class B {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int T = s.nextInt();
for (int ca = 1; ca <= T; ca++) {
int N = s.nextInt(), S = s.nextInt(), p = s.nextInt();
int good = 0, used =0;
for (int j = 0; j < N; j++) {
int t = s.nextInt();
int x = t/3;
if (t%3==0) {
if (p==x+1 && x>0 && x<10 && used<S) {
good++;
used++;
} else if (p<x+1) {
good++;
}
} else if (t%3==1) {
if (p<=x+1) good++;
} else {
if (p==x+2 && x<9 && used<S) {
good++;
used++;
} else if (p<x+2) {
good++;
}
}
}
System.out.printf("Case #%d: %d",ca,good);
System.out.println();
}
}
}
| 0 | 1,189,018 |
A11759 | A10049 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package QualificationRound.dancingwiththegooglers;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Scoring {
private List<String> inputLines = new ArrayList<String>();
private List<String> outputLines = new ArrayList<String>();
private static final String INPUT_FILE_NAME = "B-small-attempt0.in";
private static final String OUTPUT_FILE_NAME = "output.txt";
private List<SingleCase> cases = new ArrayList<Scoring.SingleCase>();
public static void main(String[] args) {
Scoring s = new Scoring();
s.readLines();
s.parseLines();
s.generateOutput();
s.outputLines();
}
private void readLines() {
try {
BufferedReader reader = new BufferedReader(new FileReader(INPUT_FILE_NAME));
String line = reader.readLine();
line = reader.readLine();
while (line != null) {
inputLines.add(line);
line = reader.readLine();
}
reader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
private void parseLines() {
for (String inputLine : inputLines) {
int readNumbers = 0;
SingleCase singleCase = new SingleCase();
String[] split = inputLine.split(" ");
for (String s : split) {
switch (readNumbers) {
case 0:
singleCase.numberOfGooglers = Integer.parseInt(s);
break;
case 1:
singleCase.numberOfSurprises = Integer.parseInt(s);
break;
case 2:
singleCase.minBestResult = Integer.parseInt(s);
break;
default:
singleCase.scores.add(Integer.parseInt(s));
}
readNumbers++;
}
cases.add(singleCase);
}
}
private void generateOutput() {
int caseNumber = 1;
for (SingleCase singleCase : cases) {
outputLines.add(getOutputPrefix(caseNumber++) + singleCase.getResult());
}
}
private void outputLines() {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(OUTPUT_FILE_NAME, false));
for (String line : outputLines) {
writer.write(line);
if (!line.equals(outputLines.get(outputLines.size() - 1))) {
writer.write("\n");
}
}
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private class SingleCase {
@SuppressWarnings("unused") //unnecessary. Just use number of scores
private int numberOfGooglers = 0;
private int numberOfSurprises = 0;
private int minBestResult = 0;
private List<Integer> scores = new ArrayList<Integer>();
private int getResult() {
int clearPasses = 0;
int potentialSurprises = 0;
//Minimum clear pass is x + x-1 + x-1 where x is the minBestResult
int minForClearPass = (minBestResult * 3) - 2;
//Minimum surprise pass is x + x-2 + x-2 where x is the minBestResult
int minForSurprisePass = (minBestResult * 3) - 4;
if (minForSurprisePass < 1) {
if (minBestResult == 0) {
minForSurprisePass = 0;
}
else {
minForSurprisePass = 1;
}
}
for (int score : scores) {
if (score >= minForClearPass) {
clearPasses++;
}
else if (score >= minForSurprisePass) {
potentialSurprises++;
}
}
return clearPasses + (Math.min(potentialSurprises, numberOfSurprises));
}
}
private String getOutputPrefix(int number) {
return "Case #" + number + ": ";
}
}
| 0 | 1,189,019 |
A11759 | A12767 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package tw.csc.gcj;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
public class Main {
/**
* @param args
*/
public static String str1 = "abcdefghijklmnopqrstuvwxyz";
public static String str2 = "ynficwlbkuomxsevzpdrjgthaq";
public static void main(String[] args) {
try {
goB();
} catch (Exception e) {
}
}
public static void goB() throws NumberFormatException, IOException{
File fin = new File("B-small-attempt0.in");
File fout = new File("B-small-attempt0.out");
BufferedReader br = new BufferedReader(new FileReader(fin));
FileOutputStream fos = new FileOutputStream(fout);
int c = Integer.parseInt(br.readLine());
String op = "";
for (int i = 0 ; i < c ;i ++ ){
op+="Case #"+ (i+1)+": ";
String[] strin = br.readLine().split("[ ]");
int n = Integer.parseInt(strin[0]);
ArrayList<Integer> arr = new ArrayList<Integer>();
for (int k = 3 ; k< n+3 ; k++){
arr.add(Integer.parseInt(strin[k]));
}
op += testB(n, Integer.parseInt(strin[1]), Integer.parseInt(strin[2]), arr) + "\n";
}
fos.write(op.getBytes());
fos.close();
}
public static String testB(int n , int s, int p, ArrayList<Integer> arrt ){
if (p == 0)
return "" + n;
if (p == 1){
int c = 0;
for (Integer t : arrt){
if (t > 0)
c++;
}
return ""+c;
}
int c = 0;
int cs = 0;
for (Integer t : arrt){
if (t >= p*3-2)
c++;
else if (t >= p*3-4)
cs++;
}
if (cs >= s)
c += s;
else
c += cs;
return "" +c;
}
public static void goC() throws NumberFormatException, IOException {
File fin = new File("C-large.in");
File fout = new File("C-large.out");
BufferedReader br = new BufferedReader(new FileReader(fin));
FileOutputStream fos = new FileOutputStream(fout);
int c = Integer.parseInt(br.readLine());
String op = "";
for (int i = 0 ; i < c ;i ++ ){
op+="Case #"+ (i+1)+": ";
String[] strin = br.readLine().split("[ ]");
op += test(Integer.parseInt(strin[0]), Integer.parseInt(strin[1])) + "\n";
}
fos.write(op.getBytes());
fos.close();
}
public static String test(int a , int b){
String ret = "";
HashSet<String> set = new HashSet<String>();
for (int n = a ; n <=b ; n++){
String strn = String.valueOf(n);
for (int i = 1 ; i < strn.length() ; i ++){
String strtest = strn.substring(strn.length() - i, strn.length() ) + strn.substring(0 , strn.length() -i);
int m = Integer.parseInt(strtest);
if (m > n && m <= b){
set.add(strn+String.valueOf(m));
}
}
}
return ret + set.size();
}
public static void goA() throws NumberFormatException, IOException {
HashMap map = new HashMap();
for (int i = 0 ; i < str1.length() ; i ++){
map.put(str2.charAt(i), str1.charAt(i));
}
File fin = new File("A-small-attempt1.in");
File fout = new File("A-small-attempt1.out");
BufferedReader br = new BufferedReader(new FileReader(fin));
FileOutputStream fos = new FileOutputStream(fout);
int c = Integer.parseInt(br.readLine());
String op = "";
for (int i = 0 ; i < c ;i ++ ){
op+="Case #"+ (i+1)+": ";
String strin = br.readLine();
String strout = "";
for (int k = 0 ;k < strin.length() ;k ++){
if (strin.charAt(k) == ' '){
strout+=" ";
}
else{
strout+= map.get(strin.charAt(k));
}
}
op+=strout+"\n";
}
fos.write(op.getBytes());
fos.close();
};
}
| 0 | 1,189,020 |
A11759 | A11742 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.google.code;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
public abstract class GCJ {
private BufferedReader input;
private BufferedWriter output;
String inputLine;
String[] brokenUpInputLine;
public static final String FOLDER = "/tmp/";
protected GCJ() throws IOException {
String subclass = this.getClass().getSimpleName();
input = new BufferedReader(new FileReader(new File(FOLDER, subclass+".in")));
output = new BufferedWriter(new FileWriter(new File(FOLDER, subclass+".out")));
}
public void run() throws NumberFormatException, IOException {
int loop = Integer.valueOf(input.readLine());
for (int i = 0; i < loop; i++)
answering(i+1);
output.flush();
}
protected void write(String s) throws IOException {
System.out.print(s);
output.write(s);
}
protected void writeln(String s) throws IOException {
System.out.println(s);
output.write(s+"\n");
}
protected void writeln() throws IOException {
System.out.println();
output.write("\n");
}
protected void write(int s) throws IOException {
System.out.print(String.valueOf(s));
output.write(String.valueOf(s));
}
protected void writeln(int s) throws IOException {
System.out.println(String.valueOf(s));
output.write(String.valueOf(s)+"\n");
}
protected void readLine() throws IOException {
inputLine = input.readLine();
brokenUpInputLine = inputLine.split(" ");
}
protected String getStringInput(int i) {
return brokenUpInputLine[i];
}
protected int getIntInput(int i) {
return Integer.parseInt(brokenUpInputLine[i]);
}
protected long getLongInput(int i) {
return Long.parseLong(brokenUpInputLine[i]);
}
protected double getDoubleInput(int i) {
return Double.parseDouble(brokenUpInputLine[i]);
}
private void answering(int ordinalityOfProblem) throws IOException {
writeOrdinalityOfAnswer(ordinalityOfProblem);
code(ordinalityOfProblem);
}
private void writeOrdinalityOfAnswer(int ordinalityOfProblem) throws IOException {
write("Case #"+ordinalityOfProblem+": ");
}
protected abstract void code(int count) throws IOException;
}
| 0 | 1,189,021 |
A11759 | A10056 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package google.code.jam.dancing.with.the.googlers;
import java.util.ArrayList;
/**
*
* @author Lucas
*/
public class BestResultFinder {
public ArrayList<Integer> findBestResult(ArrayList<ArrayList> list) {
ArrayList<Integer> result = new ArrayList<Integer>();
ArrayList<Integer> current;
int total;
int surprising;
int min;
int value;
for (int n = 0; n < list.size(); n++) {
current = list.get(n);
total = 0;
surprising = current.get(1);
min = current.get(2);
for (int m = 0; m < current.get(0); m++) {
value = current.get(3 + m) / 3;
switch (current.get(3 + m) % 3) {
// (n, n, n) -> Regular
// (n - 1, n , n + 1) -> Surprising
case 0: {
if (value >= min) {
total++;
} else if ((surprising > 0) && (value > 0) && (value + 1 >= min)) {
total++;
surprising--;
}
break;
}
// (n, n, n + 1) -> Regular
// (n - 1, n + 1, n + 1) -> Surprising
case 1: {
if ((value >= min) || (value + 1 >= min)) {
total++;
} else if ((surprising > 0) && (value + 1 >= min)) {
total++;
surprising--;
}
break;
}
// (n, n + 1, n + 1) -> Regular
// (n, n, n + 2) -> Surprising
case 2: {
if ((value >= min) || (value + 1 >= min)) {
total++;
} else if ((surprising > 0) && (value + 2 >= min)) {
total++;
surprising--;
}
break;
}
}
}
result.add(total);
}
return result;
}
}
| 0 | 1,189,022 |
A11759 | A11910 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.Arrays;
public class GoogleCodeJam2
{
public static void main(String[] args) throws IOException
{
FileInputStream fstreami = new FileInputStream("input.txt");
DataInputStream in = new DataInputStream(fstreami);
FileWriter fstreamo = new FileWriter("output.txt");
BufferedWriter out = new BufferedWriter(fstreamo);
int testCases = Integer.parseInt(in.readLine());
int i = 0;
while(i < testCases)
{
String test = in.readLine();
String [] testInput = test.split(" ");
int [] input = new int[testInput.length-3];
int googlers = Integer.parseInt(testInput[0]);
int allowed = Integer.parseInt(testInput[1]);
int max = Integer.parseInt(testInput[2]);
int possible = 0;
for (int j = 0; j < testInput.length-3; j++)
input[j] = Integer.parseInt(testInput[3+j]);
Arrays.sort(input);
for (int j = googlers-1; j >= 0; j--)
{
if (input[j]%3 == 0)
{
if (input[j]/3 >= max)
possible++;
else if ((input[j]+3)/3 >= max && allowed>=1 && input[j]>=3)
{
possible++;
allowed--;
}
else ;
}
else if (input[j]%3 == 1)
{
if (((input[j]+2)/3) >= max && input[j]>=1)
possible++;
else ;
}
else
{
if (((input[j]+1)/3) >= max && input[j]>=2)
possible++;
else if (((input[j]+4)/3) >= max && allowed>=1 && input[j]>=2)
{
possible++;
allowed--;
}
else ;
}
}
System.out.println("Done");
out.write("Case #" + (i+1) + ": " + possible + "\n");
i++;
}
in.close();
out.close();
}
} | 0 | 1,189,023 |
A11759 | A13102 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.math.BigInteger;
public class Binomial {
private int[] a;
private int n;
private int r;
private BigInteger numLeft;
private BigInteger total;
//------------
// Constructor
//------------
public Binomial (int n, int r) {
if (r > n) {
throw new IllegalArgumentException ();
}
if (n < 1) {
throw new IllegalArgumentException ();
}
this.n = n;
this.r = r;
a = new int[r];
BigInteger nFact = getFactorial (n);
BigInteger rFact = getFactorial (r);
BigInteger nminusrFact = getFactorial (n - r);
total = nFact.divide (rFact.multiply (nminusrFact));
reset ();
}
//------
// Reset
//------
public void reset () {
for (int i = 0; i < a.length; i++) {
a[i] = i;
}
numLeft = new BigInteger (total.toString ());
}
//------------------------------------------------
// Return number of combinations not yet generated
//------------------------------------------------
public BigInteger getNumLeft () {
return numLeft;
}
//-----------------------------
// Are there more combinations?
//-----------------------------
public boolean hasMore () {
return numLeft.compareTo (BigInteger.ZERO) == 1;
}
//------------------------------------
// Return total number of combinations
//------------------------------------
public BigInteger getTotal () {
return total;
}
//------------------
// Compute factorial
//------------------
private static BigInteger getFactorial (int n) {
BigInteger fact = BigInteger.ONE;
for (int i = n; i > 1; i--) {
fact = fact.multiply (new BigInteger (Integer.toString (i)));
}
return fact;
}
//--------------------------------------------------------
// Generate next combination (algorithm from Rosen p. 286)
//--------------------------------------------------------
public int[] getNext () {
if (numLeft.equals (total)) {
numLeft = numLeft.subtract (BigInteger.ONE);
return a;
}
int i = r - 1;
while (a[i] == n - r + i) {
i--;
}
a[i] = a[i] + 1;
for (int j = i + 1; j < r; j++) {
a[j] = a[i] + j - i;
}
numLeft = numLeft.subtract (BigInteger.ONE);
return a;
}
} | 0 | 1,189,024 |
A11759 | A12289 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
public class problem2 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
FileInputStream fstream = new FileInputStream("C:\\Profiles\\sys4qa\\Desktop\\in.txt");
// Get the object of DataInputStream
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
Integer T= 0;
int N=0;
int S=0;
int p=0;
ArrayList score=new ArrayList();
ArrayList inputList =new ArrayList();
ArrayList input =new ArrayList();
while ((strLine = br.readLine()) != null) {
if (T==0)
{
T= Integer.parseInt(strLine);
}
else
{
String s[]=strLine.split(" ");
inputList =new ArrayList();
for(int i=0;i<s.length;i++)
inputList.add(Integer.parseInt(s[i]));
input.add(inputList);
}
}
//Close the input stream
in.close();
FileWriter fstream1 = new FileWriter("C:\\Profiles\\sys4qa\\Desktop\\out.txt");
BufferedWriter out = new BufferedWriter(fstream1);
int id=0;
Iterator iter=input.iterator();
while (iter.hasNext()) {
ArrayList ip= (ArrayList) iter.next();
N = (Integer)ip.get(0);
S= (Integer) ip.get(1);
p=(Integer) ip.get(2);
score=new ArrayList();
Iterator iter1= ip.subList(3, N+3).iterator();
while (iter1.hasNext()) {
score.add(iter1.next());
}
int output= execute(score,N,S,p);
id++;
out.write("Case #"+id+": "+output+"\n");
}
//Close the output stream
out.close();
}
static int execute(ArrayList score,int N,int S, int p) {
int count=0;
int min=0;
if (p>=2)
min =(p-1)*3+1;
else
min=p*3;
int surpiseMin = min-2;
for (int i=0;i<N;i++)
{
if ((Integer)score.get(i)>=min)
count++;
else if (((Integer)score.get(i)>=surpiseMin) && S>0)
{
S--;
count++;
}
}
return count;
}
}
| 0 | 1,189,025 |
A11759 | A12172 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package hk.polyu.cslhu.codejam.solution.impl.qualificationround;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import hk.polyu.cslhu.codejam.solution.Solution;
import org.apache.log4j.Logger;
public class SpeakingInTongues extends Solution {
private Map<String, String> codeMap;
private String oriText;
private void setCodeMap() {
this.codeMap = new HashMap<String, String>();
codeMap.put("y", "a");
codeMap.put("e", "o");
codeMap.put("q", "z");
codeMap.put("z", "q");
List<String> oriTextList = new ArrayList<String>();
oriTextList.add("ejp mysljylc kd kxveddknmc re jsicpdrysi");
oriTextList.add("rbcpc ypc rtcsra dkh wyfrepkym veddknkmkrkcd");
oriTextList.add("de kr kd eoya kw aej tysr re ujdr lkgc jv");
List<String> encodedTextList = new ArrayList<String>();
encodedTextList.add("our language is impossible to understand");
encodedTextList.add("there are twenty six factorial possibilities");
encodedTextList.add("so it is okay if you want to just give up");
for (int i = 0; i < oriTextList.size(); i++) {
String oriText = oriTextList.get(i);
String encodedText = encodedTextList.get(i);
for (int j = 0; j < oriText.length(); j++) {
String ori = oriText.substring(j, j + 1);
String encoded = encodedText.substring(j, j + 1);
if (ori.equals(" "))
continue;
if (! codeMap.containsKey(ori))
codeMap.put(ori, encoded);
else if (! codeMap.get(ori).equals(encoded))
logger.error("Found duplicate encoded string for input " + ori);
}
}
logger.info("The size of code map is " + this.codeMap.size());
}
@Override
public void setProblem(List<String> problemDesc) {
// TODO Auto-generated method stub
this.oriText = problemDesc.get(0);
}
@Override
public void solve() {
// TODO Auto-generated method stub
this.setCodeMap();
this.result = "";
for (int i = 0; i < this.oriText.length(); i++) {
String ori = this.oriText.substring(i, i + 1);
if (ori.equals(" "))
this.result += ori;
else if (this.codeMap.containsKey(ori))
this.result += this.codeMap.get(ori);
else
logger.error("Failure to find the encoded string for " + ori);
}
}
}
| 0 | 1,189,026 |
A11759 | A11871 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class b{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for(int tc = 1; tc <= t; tc++){
int n = sc.nextInt(), s = sc.nextInt(), p = sc.nextInt(), r = 0;
int mn = p + (Math.max(0,p-1)<<1), ms = p + (Math.max(0,p-2)<<1);
for(int i = 0; i < n; i++){
int tp = sc.nextInt();
if(tp >= mn) r++;
else if(s > 0 && tp >= ms) { r++; s--; }
}
System.out.println("Case #" + tc + ": " + r);
}
}
}
//n** {{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}}
| 0 | 1,189,027 |
A11759 | A12328 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Scanner;
/**
*
* @author linlin
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException {
// TODO code application logic here
File file=new File("B-small-attempt0.in");
FileOutputStream o=new FileOutputStream("a.txt");
Scanner s=new Scanner(file);
int t=Integer.valueOf(s.nextLine());
for(int i=1;i<=t;i++){
int out=0;
String line=s.nextLine();
String[] num=line.split(" ");
int n=Integer.valueOf(num[0]);
int s1=Integer.valueOf(num[1]);
int p=Integer.valueOf(num[2]);
int high=p*3;
for(int k=0;k<2;k++){
if(high>0)
high--;
}
int low=high;
for(int k=0;k<2;k++){
if(low>0)
low--;
}
int m=2;
for(int j=0;j<n;j++){
m++;
int score=Integer.valueOf(num[m]);
if(score<p)
continue;
if(score>=high)
out++;
else if((score>=low)){
if(s1>0){
s1--;
out++;
}
}
}
String output="Case #"+i+": "+out+"\r\n";
o.write(output.getBytes());
}
}
}
| 0 | 1,189,028 |
A11759 | A11356 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | //package com.GoogleCodeJam.y2012.Qualification.DancingWithTheGooglers;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
public class DancingWithTheGooglers {
public static void main(String[] args) {
try {
BufferedReader in = new BufferedReader(new FileReader(new File("B-small-attempt0.in")));
int numCases = Integer.parseInt(in.readLine());
for (int caseNum = 1; caseNum <= numCases; caseNum++) {
String[] caseInput = in.readLine().split(" ");
int numFound = getNumOverBar(caseInput);
System.out.println("Case #"+ caseNum + ": " + numFound);
}
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static int getNumOverBar(String[] caseInput) {
int numGooglers = Integer.parseInt(caseInput[0]);
int surprisingRemaining = Integer.parseInt(caseInput[1]);
int minThreshhold = Integer.parseInt(caseInput[2]);
int numFound = 0;
for (int scoreId = 3; scoreId < (numGooglers + 3); scoreId ++) {
int givenScore = Integer.parseInt(caseInput[scoreId]);
int checkedScore = givenScore %3 == 0 ? givenScore : (givenScore + 3 - givenScore %3);
if (checkedScore/3 >= minThreshhold) {
numFound ++;
} else if (givenScore == 0) {
if (minThreshhold == 0) {
numFound++;
}
} else if (surprisingRemaining > 0) {
if (givenScore % 3 == 2) {
if ((givenScore + 4)/3 >= minThreshhold) {
numFound ++;
surprisingRemaining --;
}
} else if (givenScore % 3 == 0) {
if ((givenScore+3) / 3 >= minThreshhold) {
numFound ++;
surprisingRemaining --;
}
}
}
}
return numFound;
}
}
| 0 | 1,189,029 |
A11759 | A13070 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.vp.impl;
import java.util.Arrays;
import com.vp.common.CommonUtility;
import com.vp.iface.Problem;
public class DancingWithGooglers implements Problem {
private static int currentNoOfSurprises;
private static int eligibleGooglers;
private static final int noOfJudges = 3;
private static int noOfGooglers;
private static int noOfSurprises;
private static int bestScore;
@Override
public String solve(String[] dataset) {
String strReturnValue ="";
String strDanceData = dataset[0];
String strDanceDataArr[] = strDanceData.split(" ");
int iDanceDataArr[] = CommonUtility.convertStringArraytoIntArray(strDanceDataArr);
noOfGooglers = iDanceDataArr[0];
noOfSurprises = iDanceDataArr[1];
bestScore = iDanceDataArr[2];
eligibleGooglers = 0;
currentNoOfSurprises =0;
int totalScore;
int googlers[] = new int [noOfGooglers];
int index =0 ;
int scoreSplit[] = new int[noOfJudges];
CommonUtility.print(iDanceDataArr);
for (int i = 3; i < iDanceDataArr.length; i++ )
{
googlers[index] = iDanceDataArr[i];
index++;
}
Arrays.sort(googlers);
for (int i = 0; i < googlers.length; i++ )
{
totalScore = googlers[i];
if(isEligible(totalScore))
{
scoreSplit= split(totalScore);
if(isEligibleAfterConversion(scoreSplit))
{
eligibleGooglers++;
CommonUtility.printWithoutExtrLine(scoreSplit);
System.out.println("Eligible Googler #" + eligibleGooglers);
}
}
}
System.out.println("Output: " + strReturnValue + eligibleGooglers);
return strReturnValue + eligibleGooglers;
}
private boolean isEligibleAfterConversion(int[] scoreSplit)
{
boolean bReturn = false;
if(currentNoOfSurprises == noOfSurprises)
{
return true;
}
int surpriseScore[]= convertToSurpriseScore(scoreSplit);
for(int i=0;i<surpriseScore.length;i++)
{
if(surpriseScore[i] >= bestScore)
{
bReturn = true;
break;
}
}
return bReturn;
}
private int[] convertToSurpriseScore(int[] scoreSplit)
{
int diff = scoreSplit[1] - scoreSplit[0];
int diff1 = scoreSplit[2] - scoreSplit[1];
int diff2 = scoreSplit[2] - scoreSplit[0];
String strDiff = diff+""+diff1+""+diff2;
//System.out.println("strDiff: " + strDiff);
if (strDiff.equals("000"))
{
if ((scoreSplit[2] - 1) >= 0)
{
scoreSplit[0] = scoreSplit[0] + 1;
scoreSplit[2] = scoreSplit[2] - 1;
}
}
else if(strDiff.equals("011"))
{
if((scoreSplit[0] - 1) >= 0)
{
scoreSplit[0] = scoreSplit[0] - 1;
scoreSplit[1] = scoreSplit[1] + 1;
}
}
else if(strDiff.equals("101"))
{
if((scoreSplit[1] - 1) >= 0)
{
scoreSplit[1] = scoreSplit[1] - 1;
scoreSplit[2] = scoreSplit[2] + 1;
}
}
Arrays.sort(scoreSplit);
if(isSurpriseScore(scoreSplit))
{
currentNoOfSurprises ++;
CommonUtility.printWithoutExtrLine(scoreSplit);
System.out.println(" Surprise#: "+currentNoOfSurprises);
}
return scoreSplit;
}
private boolean isSurpriseScore(int[] scoreSplit)
{
int diff = scoreSplit[1] - scoreSplit[0];
int diff1 = scoreSplit[2] - scoreSplit[1];
int diff2 = scoreSplit[2] - scoreSplit[0];
// System.out.println("isSurprise diff" + diff + " " + diff1 + " "+ diff2);
return ((diff + diff1 + diff2) == 4);
}
private static int [] split(int totalScore)
{
int avgScore = totalScore / 3;
int remScoreAvg = (totalScore - avgScore) / 2;
int remScore = remScoreAvg;
int remScore1 = remScoreAvg;
int iReturn[] = new int[3];
int mod = (totalScore - avgScore) % 2;
if(mod == 1)
{
remScore++;
}
iReturn[0] = avgScore;
iReturn[1] = remScore;
iReturn[2] = remScore1;
Arrays.sort(iReturn);
CommonUtility.printWithoutExtrLine(iReturn);
//System.out.println(" : Total Score :" + totalScore);
return iReturn;
}
/*private boolean isSurprisingScore(int totalScore)
{
boolean bReturn = false;
int bs1 = bestScore;
int bs2 = bestScore -1;
int bs3 = bestScore -2;
if(bs1 >=0 && bs2 >=0 && bs3>=0 )
{
bReturn = (bestScore + ( bestScore -1 ) + (bestScore -2)) == totalScore;
if(bReturn)
System.out.println("Eligible Googler : [" + bestScore +", "+ ( bestScore -1 )+", " + (bestScore -2) +"] = " + totalScore + " (Surprise#" + (currentNoOfSurprises + 1)+")" );
if(!bReturn)
{
bReturn = (bestScore + (( bestScore -2 ) * 2)) == totalScore;
if (bReturn)
System.out.println("Eligible Googler : [" + bestScore +", "+ ( bestScore -2 )+", " + (bestScore -2) +"] = " + totalScore + " (Surprise#" + (currentNoOfSurprises + 1)+")" );
}
}
int bs4 = bestScore;
int bs5 = bestScore +1;
int bs6 = bestScore +2;
if(bs1 <=10 && bs2 <=10 && bs3<=10 && !bReturn)
{
bReturn = (bestScore + ( bestScore +1 ) + (bestScore +2)) == totalScore;
if(bReturn)
System.out.println("Eligible Googler : [" + bestScore +", "+ ( bestScore +1 )+", " + (bestScore +2) +"] = " + totalScore + " (Surprise#" + (currentNoOfSurprises + 1)+")" );
if(!bReturn)
{
bReturn = (bestScore + (( bestScore +2 ) * 2)) == totalScore;
if (bReturn)
System.out.println("Eligible Googler : [" + bestScore +", "+ ( bestScore +2 )+", " + (bestScore +2) +"] = " + totalScore + " (Surprise#" + (currentNoOfSurprises + 1)+")" );
}
}
if (bReturn)
{
currentNoOfSurprises++;
}
return bReturn;
}
*/
private boolean isEligible(int totalScore)
{
boolean bReturn = false;
if(noOfSurprises == 0 || currentNoOfSurprises >= noOfSurprises)
{
// System.out.println("isEligibleIn: " + (bestScore + ((bestScore -1) * 2)) + " : " + totalScore);
bReturn = (bestScore + ((bestScore -1) * 2)) <= totalScore;
}
else
{
// System.out.println("isEligibleOut: " + (bestScore + ((bestScore -2) * 2)) + " : " + totalScore);
bReturn = (bestScore + ((bestScore -2) * 2)) <= totalScore;
}
//System.out.println("isEligible: " + bReturn);
return bReturn;
}
}
| 0 | 1,189,030 |
A11759 | A10346 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | 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.Arrays;
import java.util.StringTokenizer;
public class B {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int n; // # googlers
int s; // surprising
int p; // score
int scores[];
int max;
int min;
int ret;
BufferedReader br = new BufferedReader(new FileReader("b.in"));
BufferedWriter bw = new BufferedWriter(new FileWriter("b.out"));
StringTokenizer tk;
int tests = Integer.parseInt(br.readLine().trim());
for (int t = 1; t <= tests; t++) {
tk = new StringTokenizer(br.readLine());
n = Integer.parseInt(tk.nextToken());
s = Integer.parseInt(tk.nextToken());
p = Integer.parseInt(tk.nextToken());
max = 3 * p - 2;
min = 3 * p - 4;
ret = 0;
scores = new int[n];
for (int j = 0; j < scores.length; j++)
scores[j] = Integer.parseInt(tk.nextToken());
Arrays.sort(scores);
if (p >= 2)
for (int i = scores.length - 1; i >= 0; i--) {
if (scores[i] >= max)
ret++;
else if (scores[i] < min)
break;
else {
if (s==0)break;
ret++;
s--;
}
}
else {
if (p == 0)
ret += scores.length;
else
for (int i = scores.length-1; i>=0; i--) {
if (scores[i] > 0)
ret++;
else
break;
}
}
// System.out.println("Case #" + t + ": " + ret);
bw.write("Case #" + t + ": " + ret);
bw.newLine();
}
bw.close();
}
}
| 0 | 1,189,031 |
A11759 | A10571 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.Scanner;
public class Main {
public static void main (String[] args) {
int i = 1;
try{
BufferedReader in = new BufferedReader(new FileReader("input.txt"));
String ligne;
ligne = in.readLine();
ligne = in.readLine();
while (ligne != null) {
System.out.print("Case #" + i + ": ");
Scanner sc = new Scanner(ligne);
int nbDanseurs = sc.nextInt();
int nbSurprises = sc.nextInt();
int objectif = sc.nextInt();
int rep = 0;
int minSansSurprise = objectif + 2*Math.max(0, objectif-1);
int minAvecSurprise = objectif + 2*Math.max(0, objectif-2);
for (int j=0;j<nbDanseurs;j++) {
int score = sc.nextInt();
if (score >= minSansSurprise) {
rep++;
} else if (score >= minAvecSurprise && nbSurprises > 0) {
rep++;
nbSurprises--;
}
}
i++;
System.out.println(rep);
ligne = in.readLine();
}
in.close();
}
catch (Exception e){
System.err.println("Erreur !");
}
}
}
| 0 | 1,189,032 |
A11759 | A12776 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | public class main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
//Texter.writeFile();
Texter.setupReader();
Logic.solve();
}
}
| 0 | 1,189,033 |
A11759 | A13109 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | 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 Dancing {
public static void main(String[] args) {
try{
//Input
FileInputStream fstream = new FileInputStream("input.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
//Output
FileWriter ostream = new FileWriter("output.out");
BufferedWriter out = new BufferedWriter(ostream);
String str;
//Read header & get num cases
str = br.readLine();
int numCases = Integer.parseInt(str);
//Read File Line By Line
for(int i = 1;i<=numCases;i++){
str = br.readLine();
String[] splitStr = str.split(" ");
int N = Integer.parseInt(splitStr[0]); //Num googlers
int S = Integer.parseInt(splitStr[1]); //Num suprising scores
int best = Integer.parseInt(splitStr[2]); //Best score
int numNormal = 0;
int numSpecial = 0;
for(int j = 3;j<splitStr.length;j++){
int tot = Integer.parseInt(splitStr[j]);
if(tot<best){
continue;
}else if(tot>=((3*best)-2)){
numNormal++;
}else if(tot>=((3*best)-4)){
numSpecial++;
}else{
continue;
}
}
int numPossible = 0;
if(numSpecial<S){
numPossible = numNormal+numSpecial;
}else{
numPossible = numNormal+S;
}
String op = "Case #"+i+": "+numPossible;
System.out.println(op);
out.write(op);
if(i!=numCases){
out.newLine();
}
}
//Close the input stream
in.close();
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
}
| 0 | 1,189,034 |
A11759 | A10761 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class Dancing {
public static void main(String[] args) throws FileNotFoundException {
Scanner console = new Scanner(System.in);
// gets the filename to work with
Scanner input = getInput(console);
// gets the name of file to output to
PrintStream output = getOutput(console);
int numOfCases = input.nextInt();
for (int i = 1; i <= numOfCases; i++) {
int numOfDancers = input.nextInt();
int surprisingScore = input.nextInt();
int passingMark = input.nextInt();
int lowestPassingScore = passingMark * 3 - 2;
if (lowestPassingScore < 0) {
lowestPassingScore = 0;
}
int lowestAidedPassingScore = passingMark * 3 - 4;
if (lowestAidedPassingScore < 0 ) {
lowestAidedPassingScore = 0;
}
//output.println(lowestPassingScore + ":" + lowestAidedPassingScore);
int passingDancers = 0;
for (int dancer = 0; dancer < numOfDancers; dancer++) {
int dancerScore = input.nextInt();
if (dancerScore >= lowestPassingScore) {
// passes without surprising score
passingDancers++;
} else if (dancerScore == 0) {
// do nothing
} else if (dancerScore == 1) {
// do nothing
} else if (dancerScore >= lowestAidedPassingScore) {
// needs surprising score to pass
if (surprisingScore > 0) {
// uses up a surprising score to pass
surprisingScore--;
passingDancers++;
}
}
}
output.println("Case #" + i +": " + passingDancers);
}
}
public static int lineSearcher(String sentence, String welcomeString) {
if (welcomeString.length() == 0) {
return 1;
} else if (sentence.length() == 0) {
return 0;
} else {
if (sentence.substring(0,1).equals(welcomeString.substring(0,1))){
return lineSearcher(sentence.substring(1), welcomeString.substring(1))
+ lineSearcher(sentence.substring(1), welcomeString);
} else {
return lineSearcher(sentence.substring(1), welcomeString);
}
}
}
public static Scanner getInput(Scanner console) {
Scanner input = null;
while(input == null) {
System.out.print("Input file name: ");
String name = console.nextLine();
try {
input = new Scanner(new File(name));
} catch (FileNotFoundException e) {
}
}
return input;
}
// gets the filename to output to (if blank, outputs to console)
public static PrintStream getOutput(Scanner console) throws FileNotFoundException{
System.out.print("Output file name: ");
String output = console.nextLine();
if (output.equals("")) {
return new PrintStream(System.out);
} else {
return new PrintStream(new File(output));
}
}
} | 0 | 1,189,035 |
A11759 | A12827 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
import java.util.regex.*;
import java.text.*;
import java.math.*;
import java.io.*;
public class DancingWiththeGooglers {
private final static String FILE_IN = DancingWiththeGooglers.class
.getSimpleName() + ".in";
private final static String FILE_OUT = DancingWiththeGooglers.class
.getSimpleName() + ".out";
public static void main(String[] args) throws Exception {
final Scanner in = new Scanner(new File(FILE_IN));
final PrintWriter out = new PrintWriter(FILE_OUT);
final Map<Integer, Set<Integer>> ok = new HashMap<Integer, Set<Integer>>();
for (int i = 0; i <= 10; ++i) {
add(ok, i, i, i);
if (i < 10) {
add(ok, i, i, i + 1);
add(ok, i, i + 1, i + 1);
}
}
final Map<Integer, Set<Integer>> totalOk = new HashMap<Integer, Set<Integer>>();
for (int i = 0; i <= 10; ++i) {
for (int j = i; j <= Math.min(10, i + 2); ++j) {
for (int k = j; k <= Math.min(10, i + 2); ++k) {
add(totalOk, i, j, k);
}
}
}
for (int i = 9; i >= 0; --i) {
ok.get(i).addAll(ok.get(i + 1));
totalOk.get(i).addAll(totalOk.get(i + 1));
}
final int testCnt = in.nextInt();
for (int caseNum = 1; caseNum <= testCnt; ++caseNum) {
final int n = in.nextInt();
final int s = in.nextInt();
final int p = in.nextInt();
final int[] a = new int[n];
for (int i = 0; i < n; ++i) {
a[i] = in.nextInt();
}
Arrays.sort(a);
int result = 0;
int left = s;
for (int score : a) {
if (ok.get(p).contains(score)) {
++result;
} else if (left > 0 && totalOk.get(p).contains(score)) {
--left;
++result;
}
}
out.println(String.format("Case #%d: %d", caseNum, result));
}
in.close();
out.close();
}
private final static void add(final Map<Integer, Set<Integer>> col,
final int a, final int b, final int c) {
final int s = a + b + c;
final int max = Math.max(a, Math.max(b, c));
if (!col.containsKey(max)) {
col.put(max, new HashSet<Integer>());
}
col.get(max).add(s);
}
}
| 0 | 1,189,036 |
A11759 | A12104 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | 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;
public class DancingWithTheGooglers {
public static void main(String[] args) {
try {
// t@CIuWFNg𶬷é
FileInputStream fileInputStream =
new FileInputStream("B-small-attempt0.in");
InputStreamReader inputStreamReader =
new InputStreamReader(fileInputStream);
BufferedReader bufferedReader =
new BufferedReader(inputStreamReader);
// t@C©çêsÇÝæé
String lines = bufferedReader.readLine();
int len = Integer.parseInt(lines);
String[] str = new String[len];
for(int i = 0; i < len; i++){
str[i] = bufferedReader.readLine();
}
// t@CIuWFNgðjü·é
bufferedReader.close();
inputStreamReader.close();
fileInputStream.close();
FileOutputStream fileOutputStream =
new FileOutputStream("answerDWG.txt");
OutputStreamWriter outputStreamWriter =
new OutputStreamWriter(fileOutputStream);
BufferedWriter bufferedWriter =
new BufferedWriter(outputStreamWriter);
//\bhú»
DancingWithTheGooglers dwg = new DancingWithTheGooglers();
for(int i = 0; i < len; i++){
bufferedWriter.write("Case #" + (i+1) + ": " + dwg.keisan(str[i]) + "\n");
// t@CÉàeð«Þ
}
// t@CIuWFNgðjü·é
bufferedWriter.close();
outputStreamWriter.close();
fileOutputStream.close();
// êAÌt@CÍIOExceptionª¶·é
} catch (IOException ex) {
ex.printStackTrace();
}
}
private int keisan(String str){
String[] inp = str.split(" ",-1);
int i;
int N = Integer.parseInt(inp[0])+3;
int S = Integer.parseInt(inp[1]);
int p = Integer.parseInt(inp[2]);
int cnt = 0;
int s_cnt = 0;
for(i=3;i<N;i++){
int ttl = Integer.parseInt(inp[i]);
int a = ttl/3;
int b = ttl%3;
if(a >= p){
cnt++;
} else if(a == p-1){
if(b > 0){
cnt++;
} else {
if(a > 0 && s_cnt < S){
cnt++;
s_cnt++;
}
}
} else if(a == p-2){
if(b == 2 && s_cnt < S){
cnt++;
s_cnt++;
}
}
}
return cnt;
}
}
| 0 | 1,189,037 |
A11759 | A10551 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.gao.t2;
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.Arrays;
public class Main {
public static void main(String args[]){
try{
FileInputStream fin=new FileInputStream("C:\\Users\\Gao\\Downloads\\B-small-attempt4.in");
BufferedReader br=new BufferedReader(new InputStreamReader(fin));
FileOutputStream fout=new FileOutputStream("out.txt");
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fout));
int n=Integer.parseInt(br.readLine());
for(int i=0;i<n;i++){
int N,S,P;
int t[];
String []s=br.readLine().split(" ");
N=Integer.parseInt(s[0]);
S=Integer.parseInt(s[1]);
P=Integer.parseInt(s[2]);
t=new int[N];
for(int j=0;j<N;j++){
t[j]=Integer.parseInt(s[3+j]);
}
Arrays.sort(t);
int k=0;
int r=0;
for(int j=0;j<t.length;j++){
int b;
b=t[j]/3;
int xRe=t[j]%3;
if(k<S&&t[j]>=2){
if(xRe<=1){
if(b+1<=10&&b+1>=P){
k++;
r++;
}
} else if(xRe==2){
if(b+2<=10&&b+2>=P){
k++;
r++;
}
}
}else {
if(xRe>=1&&b<=9){
b++;
}
if(b>=P){
r++;
}
}
}
String str="Case #"+(i+1)+": "+r;
bw.write(str);
if(i<n-1){bw.newLine();}
}
br.close();
bw.close();
fin.close();
fout.close();
} catch(IOException e){
e.printStackTrace();
}
}
}
| 0 | 1,189,038 |
A11759 | A10549 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package gcj2012;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.StringTokenizer;
/**
* Google Code Jam 2012 B - Dancing With the Googlers
*
* @author Ruli Manurung (maruli@cs.ui.ac.id)
*/
public class QB
{
public static void main(String[] args) throws FileNotFoundException,
IOException
{
String fileName = args[0];
BufferedReader input = new BufferedReader(new FileReader(fileName));
StringTokenizer token = new StringTokenizer(input.readLine());
int t = Integer.parseInt(token.nextToken());
for (int ii = 0; ii < t; ii++)
{
token = new StringTokenizer(input.readLine());
int N = Integer.parseInt(token.nextToken());
int S = Integer.parseInt(token.nextToken());
int p = Integer.parseInt(token.nextToken());
int[] googlers = new int[N];
for(int jj=0; jj<N; jj++)
googlers[jj] = Integer.parseInt(token.nextToken());
System.out.println("Case #" + (ii + 1) + ": "
+ genMask("",S,googlers,p));
}
input.close();
}
static int genMask(String mask, int S, int[] googlers, int p)
{
if(mask.length() == googlers.length) // base case, compute!
{
return countP(mask,googlers,p);
}
else
{
int pad=googlers.length-mask.length();
if(S==0)
{
for (int ii=0; ii<pad; ii++)
mask+='0';
return countP(mask,googlers,p);
}
else if(pad==S)
{
for (int ii=0; ii<pad; ii++)
mask+='1';
return countP(mask,googlers,p);
}
else
{
if(googlers[mask.length()]<2 || googlers[mask.length()]>28)
return genMask(mask+"0",S, googlers, p);
else
return Math.max(genMask(mask+"1",S-1,googlers,p),
genMask(mask+"0",S,googlers,p));
}
}
}
static int countP(String mask, int[] googlers, int p)
{
int count=0;
for(int ii=0; ii<mask.length(); ii++)
{
if(max(googlers[ii],mask.charAt(ii)=='1')>=p)
count++;
}
return count;
}
static int max(int tot, boolean spc)
{
switch(tot)
{
case 0: return 0;
case 1: return 1;
case 2: return spc ? 2 : 1;
case 3: return spc ? 2 : 1;
case 4: return 2;
case 5: return spc ? 3 : 2;
case 6: return spc ? 3 : 2;
case 7: return 3;
case 8: return spc ? 4 : 3;
case 9: return spc ? 4 : 3;
case 10: return 4;
case 11: return spc ? 5 : 4;
case 12: return spc ? 5 : 4;
case 13: return 5;
case 14: return spc ? 6 : 5;
case 15: return spc ? 6 : 5;
case 16: return 6;
case 17: return spc ? 7 : 6;
case 18: return spc ? 7 : 6;
case 19: return 7;
case 20: return spc ? 8 : 7;
case 21: return spc ? 8 : 7;
case 22: return 8;
case 23: return spc ? 9 : 8;
case 24: return spc ? 9 : 8;
case 25: return 9;
case 26: return spc ? 10 : 9;
case 27: return spc ? 10 : 9;
case 28: return 10;
case 29: return 10;
case 30: return 10;
}
return -1;
}
}
| 0 | 1,189,039 |
A11759 | A10634 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class DancingGooglers {
private static String infile = "B-small-attempt1.in";
private static String outfile = "out.txt";
private static String encoding = "UTF-8";
public static void main(String[] args) {
try {
runTests();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
public static void runTests() throws IOException {
Scanner scanner = new Scanner(new FileInputStream(infile), encoding);
BufferedWriter writer = new BufferedWriter(new FileWriter(outfile));
int nCases = Integer.parseInt(scanner.nextLine());
for (int i = 0; i < nCases; i++) {
int val = testCase(scanner.nextLine());
writer.write("Case #" + (i + 1) + ": " + val + "\n");
}
writer.close();
}
public static int testCase(String input) {
String delimiter = " ";
String[] inputs = input.split(delimiter);
int nSurprising = Integer.parseInt(inputs[1]);
int maxScore = Integer.parseInt(inputs[2]) * 3;
int nQualifying = 0;
for (int i = 3; i < inputs.length; i++) {
int score = Integer.parseInt(inputs[i]);
if (score >= 2 && maxScore >= 6) {
if (score >= maxScore - 2) {
nQualifying++;
} else if (score >= maxScore - 4 && nSurprising > 0) {
nQualifying++;
nSurprising--;
}
} else if ((maxScore == 0) || (maxScore == 3 && score > 0)) {
nQualifying++;
}
}
return nQualifying;
}
}
| 0 | 1,189,040 |
A11759 | A10308 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package googlecodejam;
import java.util.ArrayList;
/**
*
* @author Matej
*/
public class ProblemB {
int googlers;
int surprises;
int targetScore;
ArrayList<Integer> scores = new ArrayList<>();
public ProblemB(int g, int s, int t, ArrayList<Integer> l) {
googlers = g;
surprises = s;
scores = l;
targetScore = t;
}
public int solve() {
int result = 0;
for (int score : scores) {
int last2scores = score - targetScore;
if (last2scores >= 0) {
if (last2scores >= (targetScore - 1) * 2) {
result++;
} else if (surprises > 0 && last2scores >= (targetScore - 2) * 2) {
surprises--;
result++;
}
}
}
return result;
}
}
| 0 | 1,189,041 |
A11759 | A11617 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class Googlers {
public static int surprise = 0;
public static int beatTarget = 0;
public static boolean bestScore(int totalScore, int targetScore) {
int bestNoSurprise = (int) Math.ceil(totalScore/3.0);
// If this googler beat the target score
if(bestNoSurprise>=targetScore) {
beatTarget += 1;
return true;
}
// These are scores that can be a surprise, if there is surprise left
else if(totalScore%3!=1&&totalScore>1&&totalScore<29&&surprise>0) {
// Test if surprising the score would help
if(bestNoSurprise<targetScore&&(bestNoSurprise+1)>=targetScore) {
surprise-=1;
beatTarget += 1;
return true;
}
}
// These are scores that had no hope
return true;
}
public static void main(String[] args) {
Scanner input = null;
PrintWriter output = null;
try {
output = new PrintWriter(new FileWriter("output.txt"));
input = new Scanner(new File("input.txt"));
} catch (FileNotFoundException h) {
System.out.println("File not found 1");
System.exit(0);
} catch (IOException e) {
System.out.println("File not found 2");
System.exit(0);
}
int count = Integer.parseInt(input.nextLine());
for(int i=0;i<count;i+=1) {
String[] line = input.nextLine().split("[ ]+");
beatTarget = 0;
int googlers = Integer.parseInt(line[0]);
surprise = Integer.parseInt(line[1]);
int targetScore = Integer.parseInt(line[2]);
for(int y=3;y<line.length;y+=1) {
bestScore(Integer.parseInt(line[y]),targetScore);
}
output.println("Case #" + (i+1) + ": " + beatTarget);
}
output.close();
}
}
| 0 | 1,189,042 |
A11759 | A11577 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.google.codejam.qualrnd.dncingglers;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class DancingGooglers {
public void resolve() {
DancingGooglersInputReader inputReader = new DancingGooglersInputReader();
DancingGooglersInput input = inputReader.read();
int noOfCases = input.getNoOfCases();
GooglersScoreboard[] allScoreboards = input.getScoreboards();
int[] result = null;
BufferedOutputStream outputStream = null;
try {
outputStream = new BufferedOutputStream(new FileOutputStream("out.txt"));
for (int caseIndex = 0; caseIndex < noOfCases; caseIndex++) {
List<int[]> bestAndSurprisingTriplets = new ArrayList<int[]>();
GooglersScoreboard scoreboard = allScoreboards[caseIndex];
int bestScore = scoreboard.getBestScore();
int expectedSurprising = scoreboard.getNoOfSurprisingScores();
int totalBestScores = 0;
int totalSurprising = 0;
int both = 0;
for (int score : scoreboard.getScores()) {
result = findTripletFor(score, 2);
if (isTripletBestResult(result, bestScore)) {
totalBestScores++;
}
if (isTripletSurprising(result)) {
totalSurprising++;
}
if (isTripletBestResult(result, bestScore)
&& isTripletSurprising(result)) {
both++;
bestAndSurprisingTriplets.add(result);
}
// System.out.printf("[%d, %d, %d] ", result[0], result[1], result[2]);
}
// System.out.printf("Best: %d, Surprising: %d, Both:%d %n", totalBestScores, totalSurprising, both);
if (totalSurprising > expectedSurprising) {
totalSurprising = totalSurprising - (totalSurprising - both);
}
if (totalSurprising > expectedSurprising) {
for (int[] tmpTriplet : bestAndSurprisingTriplets) {
if (isStillBestAfterNonSurprisable(tmpTriplet, bestScore)) {
totalSurprising--;
both--;
}
if (totalSurprising <= expectedSurprising) {
break;
}
}
}
if (totalSurprising > expectedSurprising) {
totalBestScores = totalBestScores - (totalSurprising - expectedSurprising);
}
outputStream.write(String.format("Case #%d: %s\n", caseIndex+1, totalBestScores).getBytes());
System.out.printf("Case #%d: %s%n", caseIndex+1, totalBestScores);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
private boolean isStillBestAfterNonSurprisable(int[] triplet, int bestScore) {
if ((triplet[0] - 1) >= bestScore) {
return true;
}
return false;
}
private int[] findTripletFor(int totalScore, int minDiff) {
return processTriplet(10, 10, 10, totalScore, minDiff);
}
private int[] processTriplet(int sc1, int sc2, int sc3, int targetScore, int minDiff) {
// System.out.printf("%d %d %d%n", sc1, sc2, sc3);
int tripletTotal = sc1 + sc2 + sc3;
if (tripletTotal == targetScore) {
return (new int[]{sc1, sc2, sc3});
}
if ((sc3 > 0) && (sc2 - sc3 < minDiff) && (sc1 - sc3 < minDiff)) {
return processTriplet(sc1, sc2, sc3-1, targetScore, minDiff);
} else if (sc2 > 0 && sc1 - sc2 < minDiff) {
return processTriplet(sc1, sc2-1, sc3, targetScore, minDiff);
} else {
return processTriplet(sc1-1, sc2, sc3, targetScore, minDiff);
}
}
private boolean isTripletSurprising(int[] triplet) {
return (triplet[0] - triplet[1] == 2
|| triplet[1] - triplet[2] == 2
|| triplet[0] - triplet[2] == 2);
}
private boolean isTripletBestResult(int[] triplet, int bestScore) {
return (triplet[0] >= bestScore
|| triplet[1] >= bestScore
|| triplet[2] >= bestScore);
}
public static void main(String[] args) {
new DancingGooglers().resolve();
}
}
| 0 | 1,189,043 |
A11759 | A12394 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} |
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Scanner;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Akash Agrawal
*/
public class DWG {
public static void main(String [] args) throws FileNotFoundException, IOException
{
Scanner scan= new Scanner(new File("inp.txt"));
int n=scan.nextInt();
//System.out.println(n);
int cas=1;
while(n--!=0)
{
int t=scan.nextInt();
int s=scan.nextInt();
int p=3*scan.nextInt();
int count =0;
for(int i=0;i<t;i++)
{
int temp = scan.nextInt();
//System.out.println(temp);
if(temp == 0 )continue;
else if(temp==1 && p==1) count++;
if(temp>=p-2)count++;
else if(temp>=p-4 && s>0 )
{count++;s--;}
}
System.out.println("Case #"+cas+++": "+count);
}
}
}
| 0 | 1,189,044 |
A11759 | A11321 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.ArrayList;
import java.util.Collections;
public class Solver {
int S;
int p;
ArrayList<Integer> scores;
Solver(int S, int p, ArrayList<Integer> scores) {
this.S = S;
this.p = p;
this.scores = scores;
}
static int getMaxScoreNoSuprise(int n) {
int base = n / 3 - 1;
if (base < 0)
base = 0;
int max = 0;
for (int i = base; i <= base + 3; i++)
for (int j = base; j < base + 3; j++)
for (int k = base; k < base + 3; k++) {
if (Math.abs(i - j) <= 1 && Math.abs(i - k) <= 1
&& Math.abs(j - k) <= 1 && (i + j + k) == n) {
max = Math.max(max, Math.max(i, Math.max(j, k)));
}
}
return max;
}
static int getMaxScoreWithSuprise(int n) {
int base = n / 3 - 1;
if (base < 0)
base = 0;
int max = 0;
for (int i = base; i <= base + 4; i++)
for (int j = base; j < base + 3; j++)
for (int k = base; k < base + 3; k++) {
if (Math.abs(i - j) <= 2 && Math.abs(i - k) <= 2
&& Math.abs(j - k) <= 2 && (i + j + k) == n) {
max = Math.max(max, Math.max(i, Math.max(j, k)));
}
}
return max;
}
int solve() {
Collections.sort(scores);
// for(int score : scores)
// System.out.println(getMaxScoreNoSuprise(score) + " " + getMaxScoreWithSuprise(score));
int surprises =0 ;
for(int i=0;i<scores.size();i++)
{
if (surprises < S && getMaxScoreWithSuprise(scores.get(i)) >= p && getMaxScoreNoSuprise(scores.get(i))<p ) //count only useful surprises
surprises++;
}
int pScores = 0;
for(int i=0;i<scores.size();i++)
{
if (getMaxScoreNoSuprise(scores.get(i))>=p )
pScores++;
}
return surprises + pScores;
}
}
| 0 | 1,189,045 |
A11759 | A13168 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
public class ProblemB {
public static void main(String... args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int t=1; t<=T; t++) {
String ans="";
int N = sc.nextInt();
int S = sc.nextInt();
int p = sc.nextInt();
List<Integer> list = new ArrayList<>();
int higher = 0;
int border = 0;
for (int n=0; n<N; n++) {
int point = sc.nextInt();
int ave = (int)(Math.ceil(point/3.0));
if ( ave >= p) higher++;
else if (p-1 != 0 && ave == p-1 && point%3 != 1) border++;
}
if(border >= S){
System.out.println("Case #" +t+ ": " +(higher+S));
} else {
System.out.println("Case #" +t+ ": " +(higher+border));
}
}
}
}
| 0 | 1,189,046 |
A11759 | A11486 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class Dancing {
public static void main(String[] args) throws IOException {
int count = 0;
int special = 0;
int googler = 0;
int best = 0;
int sp_co = 0;
int sat = 0;
Scanner scanInput = new Scanner(System.in);
String target = scanInput.next();
File inputFile = new File(target);
Scanner fileScan = new Scanner(inputFile);
String outpFileName = "output.txt";
FileWriter googlewriter = null;
googlewriter = new FileWriter(outpFileName);
PrintWriter diskFile = new PrintWriter(googlewriter);
count = fileScan.nextInt();
for (int i = 0; i < count; i++) {
googler = fileScan.nextInt();
special = fileScan.nextInt();
best = fileScan.nextInt();
sp_co = 0;
sat = 0;
int[][] scores = new int[googler][3];
int[] totscores = new int[googler];
for (int j = 0; j < googler; j++)
totscores[j] = fileScan.nextInt();
for (int j = 0; j < googler; j++) {
scores[j][0] = totscores[j] / 3;
scores[j][1] = totscores[j] / 3;
scores[j][2] = totscores[j] / 3;
}
for (int j = 0; j < googler; j++) {
if (scores[j][0] + scores[j][1] + scores[j][2] != totscores[j]) {
if (totscores[j] - scores[j][0] - scores[j][1]
- scores[j][2] == 2) {
scores[j][0]++;
scores[j][2]++;
}
if (totscores[j] - scores[j][0] - scores[j][1]
- scores[j][2] == 1) {
scores[j][0]++;
}
}
}
for (int m = 0; m < googler; m++) {
if (scores[m][0] >= best || scores[m][1] >= best
|| scores[m][2] >= best) {
}
else if (sp_co < special && scores[m][0] != 0 && scores[m][0] + 1 == best){
scores[m][0]--;
scores[m][2]++;
sp_co++;
}
}
for (int m = 0; m < googler; m++) {
if (scores[m][0] >= best || scores[m][1] >= best || scores[m][2] >= best )
sat++;
}
diskFile.print("Case #" + (i + 1) + ": " + sat + "\n");
}
diskFile.close();
} // end of main
} // end of class
| 0 | 1,189,047 |
A11759 | A10744 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.StringTokenizer;
public class DancingProblem {
private static final String INPUT_FILE_NAME = "/home/rponnu/codebase/codejam/first_round/data/input.txt";
private static final String OUTPUT_FILE_NAME = "/home/rponnu/codebase/codejam/first_round/data/output.txt";
public static void main(String args[]) throws IOException {
List<String> lines = readFile(INPUT_FILE_NAME);
Integer noOfInputs = readInputData(lines.get(0)).get(0);
System.out.println("No of Inputs:"+ noOfInputs);
List<String> outputLines = new ArrayList<String>();
for(int index=1;index<=noOfInputs.intValue();index++){
List<Integer> inputData = readInputData(lines.get(index));
outputLines.add("Case #"+index+": "+getNoOfBestResult(inputData));
}
File f = new File(OUTPUT_FILE_NAME);
FileUtils.writeLines(f,outputLines);
}
private static int getNoOfBestResult(List<Integer> inputData) {
Iterator<Integer> iterator = inputData.iterator();
Integer noOfPlayers = iterator.next();
Integer noOfSurprises = iterator.next();
Integer bestResult = iterator.next();
int noOfMaxScores = 0;
int count= 0;
int noOfMaxScoresWithSurprises = 0;
int maxValueForScore = getMaxValueForScore(bestResult);
int maxValueForScoreWithSurprises = getMaxValueForScoreWithSurprises(bestResult);
while (iterator.hasNext()){
int scoreSum = iterator.next();
if(scoreSum >= maxValueForScore) {
noOfMaxScores ++;
} else if( (maxValueForScore != maxValueForScoreWithSurprises) && scoreSum >= maxValueForScoreWithSurprises){
noOfMaxScoresWithSurprises ++;
}
}
count = noOfMaxScores;
if (noOfMaxScoresWithSurprises >= noOfSurprises) {
count += noOfSurprises;
} else if (noOfMaxScoresWithSurprises < noOfSurprises){
count += noOfMaxScoresWithSurprises;
}
return count;
}
private static int getMaxValueForScore(int bestScore){
int maxValue = bestScore;
if(bestScore-1 > 0) {
maxValue += 2 *(bestScore-1);
}
return maxValue;
}
private static int getMaxValueForScoreWithSurprises(int bestScore){
int maxVal = bestScore;
if(bestScore -2 > 0){
maxVal +=2 *(bestScore-2);
}
return maxVal;
}
private static List<Integer> readInputData(String line){
List<Integer> values = new ArrayList<Integer>();
StringTokenizer stringTokenizer = new StringTokenizer(line.trim());
while(stringTokenizer.hasMoreElements()){
values.add(Integer.parseInt((String) stringTokenizer.nextElement()));
}
return values;
}
private static List<String> readFile(String path) throws IOException {
List<String> lines = FileUtils.readLines(new File(path));
return lines;
}
}
| 0 | 1,189,048 |
A11759 | A11794 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
Sam1rm
Google Code Jam
*/
import java.io.*;
import java.util.*;
class ProblemB
{
public static void main (String [] args) throws IOException
{
String filename = args[0];
BufferedReader f = new BufferedReader(new FileReader(filename + ".in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename + ".out")));
int numberOfTests = Integer.parseInt(f.readLine());
for(int n = 1; n <= numberOfTests; n++)
{
int solution = 0;
String input = f.readLine();
solution = parseString(input);
out.println("Case #" + n + ": " + solution);
}
out.close();
System.exit(0);
}
public static int parseString(String input1) {
int solution = 0;
String[] input = input1.split(" ");
int N = Integer.parseInt(input[0]);
int S = Integer.parseInt(input[1]);
int P = Integer.parseInt(input[2]);
for (int i = 0; i < input.length - 3; i++) {
int current = Integer.parseInt(input[i + 3]);
if (current >= (P * 3 - 2)) {
solution++;
} else {
if ((S > 0) && current >= (P * 3 - 4) && (P * 3 - 4 > 0)) {
S--;
solution++;
}
}
}
return solution;
}
}
| 0 | 1,189,049 |
A11759 | A13137 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exercises;
/**
*
* @author dannocz
*/
public class Parser {
public static char parse(char character){
switch(character)
{
case ' ':
return ' ';
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';
default:
return ' ';
}
}
public static String parse(String cad){
// System.out.println(cad);
char[] chars = cad.toCharArray();
char[] newChars = new char[chars.length];
for (int i = 0; i < chars.length; i++) {
newChars[i]= parse(chars[i]);
}
return new String(newChars);
}
}
| 0 | 1,189,050 |
A11759 | A12860 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package exercise;
public class Solver {
private static int VOTES_NB = 3;
private static int VARIABLES_NB = 3;
public static Integer[] solve(Integer[][] input) {
Integer[] result = new Integer[input.length];
for (int cnt = 0; cnt < input.length; ++cnt)
result[cnt] = solve(input[cnt]);
return result;
}
public static int solve(Integer[] input) {
if (input == null || input.length < 3)
return 0;
int googlersNb = input[0];
int surprisingTriplets = input[1];
int target = input[2];
if (input.length < VARIABLES_NB + googlersNb)
return 0;
int result = 0;
Integer[] candidates = new Integer[surprisingTriplets];
for (int cnt = VARIABLES_NB; cnt < input.length; ++cnt) {
if (input[cnt] < target * VOTES_NB - (VOTES_NB - 1)) {
int minIndex = 0;
int min = -1;
for (int tmp = 0; tmp < candidates.length; ++tmp) {
if (candidates[tmp] == null || input[cnt] > candidates[tmp]) {
if (candidates[tmp] == null || min == -1 || candidates[tmp] < min) {
min = (candidates[tmp] == null) ? 0 : candidates[tmp];
minIndex = tmp;
}
}
}
if (min >= 0 && input[cnt] >= min)
candidates[minIndex] = input[cnt];
} else
++result;
}
if (candidates.length > 0) {
int surprisingTarget = target + target - 2 + target - 2;
if (surprisingTarget <= 0)
surprisingTarget = target;
if (candidates != null)
for (int cnt = 0; cnt < candidates.length; ++cnt)
if (candidates[cnt] != null && candidates[cnt] >= surprisingTarget)
result++;
}
return result;
}
}
| 0 | 1,189,051 |
A11759 | A11085 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class B {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new FileReader("B-small.in"));
PrintWriter pw = new PrintWriter(new FileWriter("B-small.out"));
int T = new Integer(br.readLine());
for(int cases =0;cases< T; cases ++)
{
String str = br.readLine();
StringTokenizer st = new StringTokenizer(str);
int N = new Integer(st.nextToken());
int S = new Integer(st.nextToken());
int p =new Integer(st.nextToken());
int count =0;
int[] scores = new int[N];
for(int i =0;i<N;i++)
scores[i] = new Integer(st.nextToken());
for(int j=0;j<N;j++)
{
int score = scores[j];
int l = score - 3*p;
if(l>=0)
{
count++;
}
else if(l==-1 || l==-2)
{
count++;
}
else if((l==-3 || l==-4) && S>0 && score >=3*p-4 && score>p)
{
count++;
S--;
}
}
pw.println("Case #" +(cases+1) +": " +count);
}
pw.close();
br.close();
}
}
| 0 | 1,189,052 |
A11759 | A10109 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package org.alaoui.googledance;
import java.io.IOException;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
/**
* Unit test for simple App.
*/
public class AppTest extends TestCase {
/**
* Create the test case
*
* @param testName
* name of the test case
*/
public AppTest(String testName) {
super(testName);
}
/**
* @return the suite of tests being tested
*/
public static Test suite() {
return new TestSuite(AppTest.class);
}
/**
* Rigourous Test :-)
*
* @throws IOException
*/
public void testApp() {
}
}
| 0 | 1,189,053 |
A11759 | A11019 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package fixjava;
import java.util.ArrayList;
import java.util.List;
public class Take<T> {
/** Return at most n items from the beginning of the Iterable. */
public static <T> ArrayList<T> head(Iterable<T> collection, int n) {
ArrayList<T> head = new ArrayList<T>();
int count = n;
if (n > 0)
for (T item : collection) {
head.add(item);
if (--count == 0)
break;
}
return head;
}
/** Return at most n items from the end of the List. */
public static <T> ArrayList<T> tail(List<T> list, int n) {
ArrayList<T> tail = new ArrayList<T>();
for (int len = list.size(), i = Math.max(len - n, 0); i < len; i++)
tail.add(list.get(i));
return tail;
}
}
| 0 | 1,189,054 |
A11759 | A10349 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.StringTokenizer;
public class DancingWiththeGooglers {
public static void main(String[] args) {
try {
BufferedReader ifStream = new BufferedReader(new FileReader("B.in"));
PrintWriter ofStream = new PrintWriter(new FileWriter("B.out"));
int numCase = Integer.parseInt(ifStream.readLine());
for (int i=1; i<=numCase; i++) {
ofStream.println("Case #"+i+": "+dancingWiththeGooglers(ifStream.readLine()));
}
ifStream.close();
ofStream.close();
}
catch (IOException e) {
System.out.println("IOException.");
}
}
private static int dancingWiththeGooglers(String input) {
StringTokenizer st = new StringTokenizer(input, " ", false);
int numGooglers = Integer.parseInt(st.nextToken());
int S = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
Googler[] Googlers = new Googler[numGooglers];
int result = 0;
int count = 0;
for (int i=0; i<numGooglers; i++) {
Googlers[i] = new Googler(Integer.parseInt(st.nextToken()));
if (Googlers[i].best >= p) {
result++;
}
if (Googlers[i].best == (p-1) && Googlers[i].remainder != 1 && Googlers[i].total != 0 && Googlers[i].total != 29 && Googlers[i].total != 30) {
count++;
}
}
if (count >= S) {
result += S;
}
else {
result += count;
}
return result;
}
}
class Googler {
int total;
int remainder;
int best;
public Googler(int total) {
this.total = total;
this.remainder = total % 3;
int n = total / 3;
switch (remainder) {
case 0: best = n; break; // This is an intermediate value.
case 1: best = n + 1; break;
case 2: best = n + 1; break; // So is this.
}
}
}
| 0 | 1,189,055 |
A11759 | A10687 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Scanner;
public class ProblemB {
public static void main(String[] args) throws FileNotFoundException {
PrintStream out = new PrintStream(new FileOutputStream(new File(
"b-small.out")));
Scanner in = new Scanner(new File("B-small-attempt0.in"));
int T = in.nextInt();
for (int i = 1; i <= T; i++) {
int N = in.nextInt();
int S = in.nextInt();
int p = in.nextInt();
int defCount = 0;
int surpCount = 0;
for (int j = 0; j < N; j++) {
int t = in.nextInt();
if (t % 3 == 0) { // (1,1,1) <-> (0,1,2)
if (t / 3 >= p)
defCount++;
else if (t / 3 >= p - 1 && t / 3 >= 1) // (0,0,0) cannot change
surpCount++;
}
if(t % 3 == 1){ // (0,0,1) -> no way to increase max score
if(t / 3 >= p - 1) // int div
defCount++;
}
if(t % 3 == 2){ // (0,1,1) <-> (0,0,2)
if(t / 3 >= p - 1) // int div
defCount++;
else if(t / 3 >= p - 2)
surpCount++;
}
//System.out.printf("total: %d, avg: %d, dC: %d, sC: %d\n", t, t/3, defCount, surpCount);
}
out.printf("Case #%d: %d\n", i, defCount + Math.min(surpCount, S));
//System.out.printf("\n\n");
}
in.close();
out.close();
}
}
| 0 | 1,189,056 |
A11759 | A12529 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | 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;
public class google_2 {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
FileInputStream fstream = new FileInputStream("D:/Rilsikane/Google2/src/B-small-attempt7.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
String s="";
while ((strLine = br.readLine()) != null) {
s+=(strLine);
s+="\n";
}
String x ="2 1 1 8 0";
compute(s);
}
public static void compute(String x) throws IOException{
String temp[] = x.split("\n");
int size = Integer.parseInt(temp[0]);
FileWriter fstream = new FileWriter("D:/Rilsikane/Google2/src/B-small-attempt7_output.txt");
BufferedWriter out = new BufferedWriter(fstream);
for(int k=1;k<=size;k++){
int result = 0;
int n = 0;
int s = 0;
int p = 0;
int[] score = new int[10];
for(int j=0;j<temp[k].length();j++){
String temp2[] =temp[k].split(" ");
n = Integer.parseInt(temp2[0]);
s = Integer.parseInt(temp2[1]);
p = Integer.parseInt(temp2[2]);
score = new int[n];
for(int i =0;i<n;i++){
score[i]=Integer.parseInt(temp2[3+i]);
}
//System.out.println("Case #"+k+":" +result);
}
System.out.println("Case #"+k+": "+calculate(n, s, p, score)+"\n");
out.write("Case #"+k+": "+calculate(n, s, p, score)+"\n");
}
out.close();
}
public static int calculate(int n, int s, int p,
int[] scores) {
int result = 0;
int index = 0;
for (int score : scores) {
int base = score / 3;
switch (score % 3) {
case 0:
if (base >= p) {
result++;
} else {
if (s > 0 && base > 0 && (base + 1) >= p) {
s--;
result++;
}
}
break;
case 1:
if (base >= p || base + 1 >= p) {
result++;
} else {
if (p > 0 && (base + 1) >= p) {
s--;
result++;
}
}
break;
case 2:
if (base >= p || base + 1 >= p) {
result++;
} else {
if (s > 0 && (base + 2) >= p) {
s--;
result++;
}
}
break;
}
index++;
}
// System.out.println("Result: " + result);
return result;
}
}
| 0 | 1,189,057 |
A11759 | A10848 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} |
import java.io.*;
import java.util.*;
class B{}
public class DanceG {
static Scanner scan;
static PrintWriter writer;
static HashMap<Integer, List<Integer>> map;
public static void readProcessOutput() throws Exception{
String outputStr = ""; String result = "";
int index = 1;
int testCases = Integer.parseInt(scan.nextLine());
//-------
//-------
while(index <= testCases ){ //runs testCases number of times
System.out.println("Running testcase : " + index);
int surprises = 0;
int count = 0;
//-----------
Scanner temp = new Scanner(scan.nextLine());
int N = temp.nextInt();
int S = temp.nextInt();
int p = temp.nextInt();
int scores[] = new int[N];
Integer triplet[][] = new Integer[N][3];
map = new HashMap<Integer, List<Integer>>();
for(int i =0; i < N; i++){
scores[i] = temp.nextInt();
int j = scores[i] / 3;
triplet[i][0] = j + scores[i] % 3;
if(triplet[i][0] <= 10)
triplet[i][1] = triplet[i][2] = j;
else{
triplet[i][0] = 10;
triplet[i][1] = j;
triplet[i][2] = j+1;
}
int min = (int) Collections.min(Arrays.asList(triplet[i]));
int max = (int) Collections.max(Arrays.asList(triplet[i]));
Arrays.sort(triplet[i]);
if(triplet[i][2] < p)
if(max - min == 0 && max != 0){
triplet[i][0]--;
triplet[i][2]++;
}
List<Integer> l = map.get(triplet[i][2]);
if(l == null)
l = new ArrayList<Integer>();
l.add(i);
map.put(triplet[i][2], l);
if(triplet[i][2] - triplet[i][0] == 2){
surprises++;
}
}
Object keys[] = map.keySet().toArray();
Arrays.sort(keys);
int m = 0; int n = p;
while((m = Arrays.binarySearch(keys, n++)) < 0 && n <= 10);
int r = m;
for(; m < keys.length && m >= 0; m++)
count += map.get(((Integer) keys[m])).size();
if(surprises > S){
int diff = surprises - S;
int j = 0, k = 0;
while(j < diff && ((Integer) keys[k]) < p){
//j += map.get(((Integer) keys[k++])).size();
List<Integer> t = map.get(((Integer) keys[k++]));
int u = t.size();
while(--u >= 0){
int v = t.get(u);
Arrays.sort(triplet[v]);
if(triplet[v][2] - triplet[v][0] == 2)
j++;
if(j == diff)
break;
}
}
if(k < keys.length && ((Integer) keys[k]) >= p){
//count -= (diff - j);
int un = diff - j;
int s = keys.length - 1;
while(un > 0){
List<Integer> l = map.get(((Integer) keys[s--]));
int q = 0;
while(q < l.size()){
int o = l.get(q++);
if(triplet[o][2] - triplet[o][0] == 2){
triplet[o][2]--;
triplet[o][0]++;
Arrays.sort(triplet[o]);
if(triplet[o][2] < p){
count--;
}
un--;
if(un == 0)
break;
}
}
}
}
}
else if(surprises < S){
// while(surprises < S){
// List<Integer> l = map.get(((Integer) keys[r++]));
//
// int q = 0;
// while(q < l.size()){
// int o = l.get(q++);
// Arrays.sort(triplet[o]);
//
// if(triplet[o][2] - triplet[o][0] < 2 && triplet[o][2] <10){
// triplet[o][2]++;
// triplet[o][0]--;
// surprises++;
// }
//
// if(triplet[o][2] < p){
// count--;
// }
//
// if(surprises == S)
// break;
//
// }
// }
//
}
//------------
outputStr = "Case #" + index + ": " + count;
writer.println(outputStr);
result = "";
outputStr = "";
index++;
}
scan.close();
writer.close();
}
static void setApart(Integer [] arr){
}
public static void main(String[] args) throws Exception {
Scanner in = new Scanner(System.in);
String className = B.class.getSimpleName() ;
int choice = 0;
do{
System.out.println("Enter your choice :");
System.out.println("1) Solve small");
System.out.println("2) Solve large");
System.out.print("Choice : ");
choice = in.nextInt();
switch(choice){
case 1 :
scan = new Scanner(new File(className + "-small-practice.in"));
writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(className +"small.txt"))));
readProcessOutput();
System.out.println("Solved successfully!\n");
break;
case 2 :
scan = new Scanner(new File(className + "-large-practice.in"));
writer = new PrintWriter(new BufferedWriter(new FileWriter(new File(className +"large.txt"))));
readProcessOutput();
System.out.println("Solved successfully!\n");
break;
}
}while (choice != 0);
System.out.println("Program finished!");
}
}
| 0 | 1,189,058 |
A11759 | A12750 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package loader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class InputReader {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
read("test1.in");
System.out.println(inputs);
}
int size;
static List<String> inputs = new ArrayList<String>();
public static void read(String path) {
try {
BufferedReader br;
br = new BufferedReader(new FileReader(path));
int a = Integer.parseInt(br.readLine());
String s = br.readLine();
while(s != null){
inputs.add(s);
s = br.readLine();
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
public List<String> getInputs() {
return inputs;
}
public void setInputs(List<String> inputs) {
this.inputs = inputs;
}
}
| 0 | 1,189,059 |
A11759 | A10234 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int ti = 0; ti < t; ti++) {
int n = sc.nextInt();
int s = sc.nextInt();
int p = sc.nextInt();
int result = 0;
List<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < n; i++)
list.add(sc.nextInt());
Collections.sort(list);
int ns = n - s;
for (int k = 0; k <= ns; k++) {
int tr = 0;
int j = 0;
for (; j < k; j++) {
int tmp;
if (list.get(j) <= 1)
tmp = list.get(j);
else
tmp = (list.get(j) - 1) / 3 + 1;
if (tmp >= p)
break;
}
tr += k - j;
for (j = list.size() - (ns - k); j < list.size(); j++) {
int tmp;
if (list.get(j) <= 1)
tmp = list.get(j);
else
tmp = (list.get(j) - 1) / 3 + 1;
if (tmp >= p)
break;
}
tr += list.size() - j;
for (j = k; j < list.size() - (ns - k); j++) {
int tmp;
if (list.get(j) <= 1)
tmp = -100;
else
tmp = (list.get(j) - 2) / 3 + 2;
if (tmp >= p)
break;
}
tr += list.size() - (ns - k) - j;
result = Math.max(result, tr);
}
System.out.printf("Case #%d: %d%n", ti + 1, result);
}
}
}
| 0 | 1,189,060 |
A11759 | A10879 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package org.klishu.googlers;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Application {
public static int solve(int N, int S, int p, int[] t) {
if (N == 0) {
return 0;
}
int diff;
for (int x = 0; x <= 10; x++) {
diff = t[N - 1] - x * 3;
switch (diff) {
case 0:
if (x >= p) {
return solve(N-1, S, p, t) + 1;
} else {
return solve(N-1, S, p, t);
}
case 1:
if (x + 1 >= p) {
return solve(N-1, S, p, t) + 1;
} else {
return solve(N-1, S, p, t);
}
case 2:
if (x < 9 && S > 0) {
return Math.max(solve(N-1, S-1, p, t) + (x + 2 >= p ? 1 : 0),
solve(N-1, S, p, t) + (x + 1 >= p ? 1 : 0));
} else {
return solve(N-1, S, p, t) + (x + 1 >= p ? 1 : 0);
}
case 3:
if (x < 9 && S > 0) {
return Math.max(solve(N-1, S-1, p, t) + (x + 2 >= p ? 1 : 0),
solve(N-1, S, p, t) + (x + 1 >= p ? 1 : 0));
} else {
return solve(N-1, S, p, t) + (x + 1 >= p ? 1 : 0);
}
default:
// Continue
}
}
return 0;
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
BufferedReader reader = null;
BufferedWriter writer = null;
try {
reader = new BufferedReader(new FileReader("B-small-attempt0.in"));
writer = new BufferedWriter(new FileWriter("B-small-attempt0.out"));
int T = Integer.parseInt(reader.readLine());
for (int i = 1; i <= T; i++) {
String input = reader.readLine();
String[] inputs = input.split(" ");
int N = Integer.parseInt(inputs[0]);
int S = Integer.parseInt(inputs[1]);
int p = Integer.parseInt(inputs[2]);
int[] t = new int[inputs.length - 3];
for (int j = 3; j < inputs.length; j++) {
t[j-3] = Integer.parseInt(inputs[j]);
}
writer.append("Case #" + i + ": " + solve(N, S, p, t));
writer.newLine();
}
} catch (IOException ex) {
Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
} finally {
try {
reader.close();
writer.close();
} catch (Exception ex) {
Logger.getLogger(Application.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
| 0 | 1,189,061 |
A11759 | A12557 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.nio.charset.Charset;
public class Main {
public static void main(String arg[])
{
try {
FileInputStream fIn = new FileInputStream("input.txt");
Charset cs = Charset.forName("UTF-8");
InputStreamReader iRd = new InputStreamReader(fIn,cs);
BufferedReader bRd = new BufferedReader(iRd);
String str = bRd.readLine();
Integer line = Integer.parseInt(str);
Writer output = null;
File file = new File("output.txt");
output = new BufferedWriter(new FileWriter(file));
for(int i = 0 ; i < line; ++i)
{
String inLine = bRd.readLine();
// System.out.println(inLine);
String[] nums = inLine.split(" ");
int n = Integer.parseInt(nums[0]);
int surprise = Integer.parseInt(nums[1]);
int point = Integer.parseInt(nums[2]);
int goal = point*3;
int pass = 0;
int sPass = 0;
for(int j = 0 ; j < n; ++j)
{
int num = Integer.parseInt(nums[j+3]);
int dif = goal - num;
if(dif <=2 ) ++pass;
else if( (dif ==3 || dif == 4) && goal > 3) ++sPass;
}
if( surprise >= sPass) pass += sPass;
else pass += surprise;
output.write("Case #" + (i+1) + ": " + pass + "\n");
}
output.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
| 0 | 1,189,062 |
A11759 | A11672 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Scanner;
public class SpeakingInTongues {
/**
* The first line of the input gives the number of test cases, T.
* T test cases follow.
* Each test case consists of a single line containing integers separated by single spaces.
* The first integer will be N, the number of Googlers, and the second integer will be S, the number of surprising triplets of scores.
* The third integer will be p, as described above. Next will be N integers ti: the total points of the Googlers.
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
// Reading the input file
Scanner in = new Scanner(new File("B-small-attempt3.in"));
// writting the input file
FileOutputStream fos = new FileOutputStream("B-small-attempt3.out");
PrintStream out = new PrintStream(fos);
//Close the output stream
int testCase=Integer.parseInt(in.nextLine());
for(int i=0;i<testCase;i++) {
out.print("Case #" + (i + 1) + ":\t");
int NoOfGooglers= in.nextInt();
int NoOfSurprisingResults = in.nextInt();
int atLeastP=in.nextInt();
ArrayList<Integer> scores= new ArrayList<Integer>();
int BestResults=0;
int Surprising=0;
for(int j=0;j<NoOfGooglers;j++)
{
scores.add(in.nextInt());
//System.out.print(scores.get(j));
int modulus=scores.get(j)%3;
int temp = scores.get(j);
switch (modulus) {
case 0:
if (((temp / 3) >= atLeastP)) {
BestResults++;
} else {
if (((((temp / 3) + 1) >= atLeastP) && ((temp / 3) >= 1))
&& (Surprising < NoOfSurprisingResults)) {
BestResults++;
Surprising++;
}
System.out.println("Case 0"+"itr:"+i+" surprising:"+temp);
}
break;
case 1:
if ((temp / 3) + 1 >= atLeastP) {
BestResults++;
continue;
}
break;
case 2:
if ((temp / 3) + 1 >= atLeastP) {
BestResults++;
} else {
if (((temp / 3) + 2 >= atLeastP)
&& (Surprising < NoOfSurprisingResults)) {
BestResults++;
Surprising++;
}
System.out.println("Case 2"+"itr:"+i+" surprising:"+temp);
}
break;
default:
System.out.println("Error");
}
}// Internal for
out.println(BestResults);
// System.out.println(BestResults);
System.out.println(Surprising);
BestResults = 0;
}// for
in.close();
out.close();
fos.close();
}
}
| 0 | 1,189,063 |
A11759 | A12551 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class DancingWithGooglers {
public static void main(String[] args) {
try {
FileWriter output = new FileWriter(new File("output.txt"));
Scanner s = new Scanner(new File("input.txt"));
int trials = s.nextInt();
s.nextLine();
for (int i = 0; i < trials; i++) {
int n = s.nextInt();
int numSupr = s.nextInt();
int minScore = s.nextInt();
int cutOff = minScore + Math.max((minScore - 1), 0) * 2;
int suprisingCutOff = minScore + Math.max((minScore - 2), 0)
* 2;
int totalCount = 0;
int numSuprising = 0;
for (int b = 0; b < n; b++) {
int num = s.nextInt();
if (num >= cutOff)
totalCount++;
else if (num >= suprisingCutOff) {
numSuprising++;
}
}
output.write("Case #" + (i + 1) + ": ");
output.write(""
+ (totalCount + Math.min(numSuprising, numSupr)));
output.write('\n');
}
s.close();
output.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
| 0 | 1,189,064 |
A11759 | A12963 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.StringTokenizer;
public class Main {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
//BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("c:\\input_B.txt")));
int cases = Integer.parseInt(reader.readLine());
for(int i=0; i<cases; i++){
String inputString = reader.readLine();
StringTokenizer st = new StringTokenizer(inputString);
int numOfGooglers = Integer.parseInt(st.nextToken());
int numOfSurprised = Integer.parseInt(st.nextToken());
int threshold = Integer.parseInt(st.nextToken());
ArrayList<Integer> total_points_list = new ArrayList<Integer>();
for(int j=0; j<numOfGooglers; j++){
total_points_list.add(Integer.parseInt(st.nextToken()));
}
Collections.sort(total_points_list);
Collections.reverse(total_points_list);
//System.out.println(total_points_list);
int numOfPassed = 0;
outloop:
for (Integer total_points : total_points_list) {
int avg = total_points / 3;
int remainder = total_points % 3;
if(avg >= threshold) {
++numOfPassed;
continue;
}
switch(remainder) {
case 0:
if( (threshold - avg) == 1 && numOfSurprised > 0 && avg > 0) {
--numOfSurprised;
++numOfPassed;
}
break;
case 1:
if( (threshold - avg) == 1)
++numOfPassed;
break;
case 2:
if( (threshold - avg) == 1)
++numOfPassed;
if( (threshold - avg) == 2 && numOfSurprised > 0) {
--numOfSurprised;
++numOfPassed;
}
break;
}
}
System.out.println("Case #"+(i+1)+": "+numOfPassed);
}
}
}
| 0 | 1,189,065 |
A11759 | A13195 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Arrays;
import java.util.Scanner;
/**
* @author Dmitry Levshunov (levshunov.d@gmail.com)
*/
public class TaskB {
private static final int INF = 1000 * 1000 * 1000;
private static final int[] BEST_NON_SURPRISING = new int[31];
private static final int[] BEST_SURPRISING = new int[31];
private static int n;
private static int p;
private static int[] scores = new int[100];
private static int[][] dp = new int[100][101];
public static void main(String[] args) throws Exception {
init();
Scanner scanner = new Scanner(System.in);
int tests = Integer.parseInt(scanner.nextLine().trim());
for (int test = 1; test <= tests; test++) {
n = scanner.nextInt();
int s = scanner.nextInt();
p = scanner.nextInt();
for (int i = 0; i < n; i++) {
scores[i] = scanner.nextInt();
}
for (int i = 0; i < n; i++) {
Arrays.fill(dp[i], -1);
}
System.out.printf("Case #%d: %s", test, get(0, s));
System.out.println();
}
scanner.close();
}
private static void init() {
for (int i1 = 0; i1 <= 10; i1++) {
for (int i2 = i1; i2 <= 10 && i2 - i1 <= 2; i2++) {
for (int i3 = i2; i3 <= 10 && i3 - i1 <= 2; i3++) {
int sum = i1 + i2 + i3;
if (i3 - i1 == 2) {
BEST_SURPRISING[sum] = Math.max(BEST_SURPRISING[sum], i3);
} else {
BEST_NON_SURPRISING[sum] = Math.max(BEST_NON_SURPRISING[sum], i3);
}
}
}
}
}
private static int get(int pos, int s) {
if (s < 0) {
return -INF;
}
if (pos == n) {
return s == 0 ? 0 : -INF;
}
if (dp[pos][s] != -1) {
return dp[pos][s];
}
int bestNonSurprising = BEST_NON_SURPRISING[scores[pos]];
int bestSurprising = BEST_SURPRISING[scores[pos]];
int result = get(pos + 1, s) + (bestNonSurprising >= p ? 1 : 0);
if (bestSurprising != -1) {
result = Math.max(result, get(pos + 1, s - 1) + (bestSurprising >= p ? 1 : 0));
}
return dp[pos][s] = result;
}
}
| 0 | 1,189,066 |
A11759 | A10839 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package be.mokarea.gcj.googledancers;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import be.mokarea.gcj.common.TestCaseReader;
public class GoogleDancerTestCaseReader extends
TestCaseReader<GoogleDancerTestCase> {
private final LineNumberReader lineReader;
private final int NUMBER_TEST_CASE;
private int currentCaseNumber;
public GoogleDancerTestCaseReader(InputStream inputStream) throws NumberFormatException, IOException {
lineReader = new LineNumberReader(new InputStreamReader(inputStream));
NUMBER_TEST_CASE = Integer.parseInt(lineReader.readLine());
currentCaseNumber = 0; }
@Override
public GoogleDancerTestCase nextCase() throws Exception {
String line = lineReader.readLine();
if (line != null) {
currentCaseNumber++;
String[] tokens = line.split(" ");
final int numberOfGooglers = Integer.parseInt(tokens[0]);
final int numberOfSurprisingTripletsOfScores = Integer.parseInt(tokens[1]);
final int scoreLowerBoundary = Integer.parseInt(tokens[2]);
final int scores[] = new int[numberOfGooglers];
for (int i = 3, j = 0 ; i < tokens.length ; i++, j++) {
scores[j] = Integer.parseInt(tokens[i]);
}
return new GoogleDancerTestCase(currentCaseNumber, numberOfGooglers, numberOfSurprisingTripletsOfScores, scoreLowerBoundary, scores);
}
return null; }
@Override
public int getMaxCaseNumber() {
return NUMBER_TEST_CASE;
}
}
| 0 | 1,189,067 |
A11759 | A12203 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
class Programa
{
static boolean alcanza2(int a,int b)
{
int j1=0,j2=0,j3=0;
for (int i=0;i<=30;i++)
{
if (i+(i+2)+(i+2)==a)
{
j1=i;
j2=i+2;
j3=i+2;
}
if (i+i+(i+2)==a)
{
j1=i;
j2=i+2;
j3=i;
}
if (i+(i+1)+(i+2)==a)
{
j1=i;
j2=i+2;
j3=i+1;
}
// System.out.println(" "+a+" -> "+j1+" "+j2+" "+j3);
}
if (j2>=b)
return true;
else
return false;
}
static boolean alcanza(int a,int b)
{
int j1=0,j2=0,j3=0;
for (int i=0;i<=30;i++)
{
if (i+(i+1)+(i+1)==a)
{
j1=i;
j2=i+1;
j3=i+1;
}
if (i+i+i==a)
{
j1=i;
j2=i;
j3=i;
}
if (i+i+(i+1)==a)
{
j1=i;
j2=i+1;
j3=i;
}
}
//System.out.println(" "+a+" -> "+j1+" "+j2+" "+j3);
if (j2>=b)
return true;
else
return false;
}
public static int procesar(String linea)
{
String vals[]=linea.split(" ");
int n,s,p;
int usados=0;
int puntajes[];
n=Integer.parseInt(vals[0]);
s=Integer.parseInt(vals[1]);
p=Integer.parseInt(vals[2]);
puntajes=new int[n];
for (int i=0;i<n;i++)
puntajes[i]=Integer.parseInt(vals[3+i]);
int resultado=0;
for (int i=0;i<n;i++)
{
if (alcanza(puntajes[i],p))
resultado++;
else
{
if (alcanza2(puntajes[i],p) && usados<s)
{
usados++;
resultado++;
}
}
}
return resultado;
}
public static void main(String args[])
{
try{
FileInputStream fstream = new FileInputStream(args[0]);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
strLine = br.readLine();
int casos=Integer.parseInt(strLine);
int caso=1;
int respuesta;
while ((strLine = br.readLine()) != null) {
respuesta=procesar(strLine);
System.out.println("Case #"+caso+": "+respuesta);
caso++;
}
//Close the input stream
in.close();
}catch (IOException e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}
}
} | 0 | 1,189,068 |
A11759 | A10469 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package QualifiactionRound;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
public class DancingWiththeGooglers {
/**
* @param args
*/
public static void writeToFile(String text) {
try {
BufferedWriter bw = new BufferedWriter(
new FileWriter(new File("C:\\B-small-attempt5.out"), true));
bw.write(text);
bw.newLine();
bw.close();
} catch (Exception e) {
}
}
static int[] detail(String ch){
int N=3;
/*if(ch.charAt(1)==' ') N=Integer.parseInt((String) ch.subSequence(0, 1)) ;
else if(ch.charAt(2)==' ') N=Integer.parseInt( (String) ch.subSequence(0, 2)) ;
else N=Integer.parseInt((String) ch.subSequence(0, 3)) ;
//System.out.println("N "+N);
*/
String dh ="";
int[] tab=new int[N+3];
int t=0;
for(int i=0;i<ch.length();i++){
if(ch.charAt(i)==' ') {
tab[t]= Integer.parseInt(dh) ;
dh="";
t++;
}
else
dh=dh+ch.charAt(i);
}
tab[t]= Integer.parseInt(dh) ;
//for(int i=0;i<tab.length;i++)
//System.out.println(tab[i]);
return tab;
}
public static void main(String[] args) {
// TODO Auto-generated method stub
try{
FileInputStream fstream = new FileInputStream("C:\\B-small-attempt5.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
int nbr=1;
strLine = br.readLine();
int T=Integer.parseInt(strLine);
System.out.println (T);
int tab[];
int N;
int S;
int p;
int result;
int k=0;
for(int i=0;i<T;i++){
strLine = br.readLine();
// System.out.println (strLine);
tab=detail(strLine);
N=tab[0];
S=tab[1];
p=tab[2];
result=0;
for(int j=0;j<N;j++){
System.out.println("val->: "+tab[3+j]);
if(tab[3+j]>=p){
if(tab[3+j]/3>=p) result++;
else if ((tab[3+j]-p)/2>=p-1) result++;
else if(((tab[3+j]-p)/2>=p-2) && S>0) {
result++;
S--;
}
}
}
writeToFile("Case #"+nbr+": "+result);
System.out.println ("Case #"+nbr+": "+result);
nbr++;
}
in.close();
}
catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
}
| 0 | 1,189,069 |
A11759 | A12458 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
class Dancing
{
public static void main(String[] args) throws IOException
{
Scanner s = new Scanner(new File(args[0]));
int numTests = s.nextInt();
for (int i = 1; i <= numTests; i++)
{
// Get rid of prepending newline.
s.nextLine();
int count = 0;
int N = s.nextInt();
int S = s.nextInt();
int p = s.nextInt();
for (int j = 0; j < N; j++)
{
int t = s.nextInt();
int a = t / 3 + ((t % 3 == 0) ? 0 : 1);
if (a >= p)
{
count++;
}
else if (a == p-1 && S > 0 && t > 1 && t % 3 != 1)
{
count++;
S--;
}
}
System.out.println("Case #" + i + ": " + count);
}
}
}
| 0 | 1,189,070 |
A11759 | A12079 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package com.renoux.gael.codejam.cj2012.qb;
import com.renoux.gael.codejam.fwk.Solver;
import com.renoux.gael.codejam.utils.ArrayUtils;
import com.renoux.gael.codejam.utils.Input;
import com.renoux.gael.codejam.utils.Output;
public class QB extends Solver {
public static void main(String... args) throws Exception {
new QB().run();
}
@Override
protected void solveCase(Input in, Output out) {
System.out.println();
int[] line = ArrayUtils.parseInts(in.readLine().split(" "));
int ctGooglers = line[0];
int ctSurprises = line[1];
int target = line[2];
int ctStars = 0;
for (int i = 3; i < line.length; i++) {
int totalScore = line[i];
int lowestScoreNoSurprise = Math.max(target - 1, 0);
int lowestScoreWithSurprise = Math.max(target - 2, 0);
int lowestTotalNoSurprise = target + 2 * lowestScoreNoSurprise;
int lowestTotalWithSurprise = target + 2 * lowestScoreWithSurprise;
if (lowestTotalNoSurprise <= totalScore) {
ctStars++;
System.out.println("Guy " + (i - 2) + " did great");
} else if (lowestTotalWithSurprise <= totalScore && ctSurprises > 0) {
ctStars++;
ctSurprises--;
System.out.println("Guy " + (i - 2) + " did ok");
}
}
out.writeLine(ctStars);
}
@Override
protected String getProblemName() {
return "QB";
}
@Override
protected boolean disableSmall() {
return true;
}
@Override
protected boolean disableLarge() {
return true;
}
}
| 0 | 1,189,071 |
A11759 | A12340 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class Googlers {
public static void main(String a[]){
Scanner in = new Scanner(System.in);
final int T = in.nextInt();
int[] n = new int[T];
int N, S, P, sum;
for(int i = 0; i < T; i++){
N = in.nextInt();
S = in.nextInt();
P = in.nextInt();
for(int j = 0; j < N; j++){
sum = in.nextInt();
//System.out.println(sum);
//System.out.println("S " + sum + " P " + P);
/*
if(sum <= P){
n[i]+= 0;
//System.out.println(sum + "cero");
}*/
//else {
//System.out.println("aasdfas");
//int resta = sum - P;
if(sum == 0 && P == 0){
n[i]++;
}
else if(sum == 0 && P > 0){
n[i]+=0;
}
else if(sum >= (P + (P-1) + P)){
//System.out.println("aasdf");
//System.out.println("1");
n[i]++;
}
else if(sum >= P + P + P){
n[i]++;
//System.out.println("2");
}
else if(sum >= P + 1 + P + 1 + P + 1){
n[i]++;
//System.out.println("3");
}
else if(sum >= P + 2 + P + 2 + P + 2){
n[i]++;
//System.out.println("4");
}
else if(sum >= (P-1) + (P-1) + P){
n[i]++;
//System.out.println("5");
}
else if(sum >= (P+1) + (P+1) + P){
n[i]++;
//System.out.println("6");
}
else if(sum >= (P+1) + P + P){
n[i]++;
//System.out.println("7");
}
else if((sum >= (P+1) + (P-1) + P) && S > 0){
n[i]++;
S--;
//System.out.println("8");
}
else if((sum >= (P + (P-1) + (P-2))) && S > 0){
n[i]++;
S--;
//System.out.println("9");
}
else if((sum >= (P + (P-2) + (P-2))) && S > 0){
n[i]++;
S--;
//System.out.println("10");
}
else if((sum >= (P + (P+1) + (P-1))) && S > 0){
n[i]++;
S--;
//System.out.println("11");
}
else if((sum >= (P + (P+2) + (P+2))) && S > 0){
n[i]++;
S--;
//System.out.println("12");
}
else if((sum >= (P + (P+2) + P)) && S > 0){
n[i]++;
S--;
//System.out.println("13");
}
else if((sum >= (P + (P+1) + (P+2))) && S > 0){
n[i]++;
S--;
//System.out.println("14");
}
/*
else if(Math.abs((resta / 2) - P) == 2){
if(S > 0){
S--;
n[i]++;
//System.out.println("s");
}
}
else if((resta / 2) - P == 0 || Math.abs(resta / 2 - P) ==1){
n[i]++;
//System.out.println("parejo");
}*/
}
}
//}
for(int i = 0; i < T; i++){
System.out.println("Case #" + (i+1) + ": " + n[i]);
}
}
}
| 0 | 1,189,072 |
A11759 | A12598 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
public class DancingGooglers {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
for (int i = 1; i <= T; i++) {
int N = in.nextInt();
int S = in.nextInt();
int p = in.nextInt();
List<Integer> scores = new ArrayList<Integer>();
for (int j = 0; j < N; j++)
scores.add(in.nextInt());
System.out.println("Case #" + i + ": " + result(S, p, scores));
}
}
private static int result(int S, int p, List<Integer> scores) {
Integer[] v = scores.toArray(new Integer[0]);
Arrays.sort(v);
int res = 0;
int nosup = p + 2*(Math.max(p-1, 0));
int sup = p + 2*(Math.max(p-2, 0));
for (int i = v.length-1; i >= 0; i--)
if (v[i] >= nosup)
res++;
else if (v[i] >= sup && S > 0) {
res++;
S--;
}
else
return res;
return res;
}
}
| 0 | 1,189,073 |
A11759 | A11429 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package qualification;
import java.util.Scanner;
public class Dancing {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
for(int i=0; i<num; i++)
{
int numOfGooglers = scan.nextInt();
int numOfSurprizes = scan.nextInt();
int score = scan.nextInt();
int[] totalScores = new int[numOfGooglers];
for(int j=0; j<numOfGooglers; j++)
totalScores[j] = scan.nextInt();
System.out.println("Case #" + (i+1) + ": " + solve(numOfSurprizes, totalScores, score));
}
}
private static int solve(int numOfSurprizes, int[] totalScores, int score) {
int count = 0;
int surprisesLeft = numOfSurprizes;
for(int i=0; i<totalScores.length; i++) {
if(totalScores[i]/3 + (totalScores[i]%3 != 0 ? 1 : 0) >= score)
count++;
else if(surprisesLeft > 0) {
if(totalScores[i] > 0 && (totalScores[i]/3 + (totalScores[i]%3 == 2 ? 2 : 0) >= score || totalScores[i]/3 + 1 >= score)) {
count++;
surprisesLeft--;
}
}
}
return count;
}
}
| 0 | 1,189,074 |
A11759 | A10973 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
public class ProblemB {
/**
* @param args
*/
public static void main(String[] args) {
BufferedReader br = null;
BufferedWriter bw=null;
String input=null;
StringBuffer output = null;
String [] splInput=null;
int N=0,thres=0,surpri=0;
int counter=0;
int []g=null;
try{
br=new BufferedReader(new FileReader(new File("C:/Users/DHAVAL/Downloads/InputY.txt")));
bw=new BufferedWriter(new FileWriter("outputB.txt"));
int count=Integer.parseInt(br.readLine());
for (int i = 0; i < count; i++) {
input=br.readLine();
output = new StringBuffer("Case #"+(i+1)+": ");
splInput=input.split(" ");
N=Integer.parseInt(splInput[0]);
thres=Integer.parseInt(splInput[2]);
surpri=Integer.parseInt(splInput[1]);
counter=0;
g=new int[N];
for (int j = 0; j < splInput.length-3; j++) {
g[j]=Integer.parseInt(splInput[j+3]);
}
for (int k = 0; k < g.length; k++) {
switch(g[k]%3){
case 0:
if(g[k]/3>=thres){
counter++;
}else if((g[k]/3+1)>=thres&&(g[k]/3-1)>=0&&surpri!=0){
surpri--;
counter++;
}
break;
case 1:
if((g[k]/3+1)>=thres){
counter++;
}
break;
case 2:
if((g[k]/3+1)>=thres){
counter++;
}
else if((g[k]/3+2)>=thres&&surpri!=0){
surpri--;
counter++;
}
break;
}
}
bw.write(output.toString()+counter);
bw.newLine();
}
bw.close();
}catch (Exception e) {
e.printStackTrace();
}
}
}
| 0 | 1,189,075 |
A11759 | A11064 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Dancer {
public static void main (String [] args) throws Exception {
FileInputStream fstreamIn = new FileInputStream ("B-small-attempt0.in");
DataInputStream in = new DataInputStream (fstreamIn);
BufferedReader is = new BufferedReader (new InputStreamReader(in));
FileWriter fstreamOut = new FileWriter ("dancer-output.out");
BufferedWriter out = new BufferedWriter (fstreamOut);
String line = is.readLine();
int num = Integer.parseInt(line);
for (int i = 0; i < num; i++) {
String str = is.readLine();
StringTokenizer st = new StringTokenizer (str);
int n = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
int p = Integer.parseInt(st.nextToken());
int max = 0;
for (int j = 0; j < n; j++) {
int totalScore = Integer.parseInt(st.nextToken());
if (totalScore == 0) {
if (p == 0) {
max += 1;
}
continue;
}
if (totalScore == 1) {
if (p <= 1) {
max += 1;
}
continue;
}
if (totalScore / 3 >= p) {
max += 1;
} else if (totalScore / 3 < (p-2)) {
continue;
} else {
int sumOfTwo = totalScore - p;
int rest = sumOfTwo - (p-1);
if (rest > p-2) {
max += 1;
continue;
}
rest = sumOfTwo - (p-2);
if (rest >= p-2) {
if (s != 0) {
max += 1;
s -= 1;
}
}
}
}
out.write("Case #" + (i+1) + ": " + max + "\n");
}
out.close();
}
} | 0 | 1,189,076 |
A11759 | A10730 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.StringTokenizer;
/**
* @author Ivan Romanov
*/
public class B {
private String solve(int n) throws IOException {
int s = nextInt();
int p = nextInt();
int[] t = new int[n];
for (int i = 0; i < n; i++) {
t[i] = nextInt();
}
int cool = 0;
for (int x : t) {
int rem3 = x % 3;
int max = x / 3;
if (rem3 > 0) {
max++;
}
// no surprise
if (max >= p) {
cool++;
} else if (s > 0) {
// try surprise
if (rem3 == 0 && x > 0) {
max++;
} else if (rem3 == 2) {
max++;
}
if (max >= p) {
cool++;
s--;
}
}
}
return "" + cool;
}
private BufferedReader reader;
private StringTokenizer tt = new StringTokenizer("");
private String nextToken() throws IOException {
while (!tt.hasMoreTokens()) {
tt = new StringTokenizer(reader.readLine());
}
return tt.nextToken();
}
private int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
private void run() throws IOException {
String problem = "B-small-attempt0";
reader = new BufferedReader(new FileReader(problem + ".in"));
PrintWriter writer = new PrintWriter(new File(problem + ".out"));
try {
int cases = nextInt();
int tc = 1;
while (tc <= cases) {
writer.print("Case #" + tc + ": ");
int n = nextInt();
writer.println(solve(n));
tc++;
}
} finally {
reader.close();
writer.close();
}
}
public static void main(String[] args) {
try {
new B().run();
} catch (IOException e) {
e.printStackTrace();
}
}
} | 0 | 1,189,077 |
A11759 | A11879 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} |
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;
public class QB {
public static void main(String[] args){
try{
Scanner sc = new Scanner(new File("B-small-attempt3.in"));
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("output.out")));
int t = sc.nextInt();
for(int i=0;i<t;i++){
int n = sc.nextInt();
int s = sc.nextInt();
int p = sc.nextInt();
int[] scores = new int[n];
for(int j=0;j<n;j++) scores[j] = sc.nextInt();
Arrays.sort(scores);
int r = 0;
for(int j=n-1;j>=0;j--){
int k = scores[j]%3;
int m = scores[j]/3;
if(scores[j]==0) s = 0;
if(k==0){
if(m>=p) r += 1;
else if ((m+1>=p)&&(s>0)){
r += 1;
s -= 1;
}
else break;
}else if(k==1){
if(m+1>=p) r += 1;
else break;
}else{
if(m+1>=p) r += 1;
else if ((m+2>=p)&&(s>0)){
r += 1;
s -= 1;
}
else break;
}
}
bw.write("Case #"+String.valueOf(i+1)+": ");
bw.write(String.valueOf(r));
bw.newLine();
bw.flush();
}
bw.close();
} catch (Exception ex) {
Logger.getLogger(QA.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
| 0 | 1,189,078 |
A11759 | A10579 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class Main {
static int solve( Scanner in ) {
int N, S, p, ti, sol=0;
double div = 0.0;
N = in.nextInt();
S = in.nextInt();
p = in.nextInt();
double req = 0.0;
double min = 0.0;
if(p>0) {
req = (p*3-2)/3.0;
if(p==1)
min = 1.0/3.0;
else
min = (p*3-4)/3.0;
}
while(N-->0) {
ti = in.nextInt();
if(ti>0)
div = ti/3.0;
else
div = 0.0;
if(div>=req) {
sol++;
}else if( S>0 && div>=min ) {
S--;
sol++;
}
}
return sol;
}
public static void main ( String args[] ) {
int T;
Scanner in = new Scanner(System.in);
T = in.nextInt();
int cnt=0;
int sol;
for( cnt=1; cnt<=T; cnt++ ) {
sol = solve( in );
System.out.printf("Case #%d: %d\n", cnt, sol);
}
}
}
| 0 | 1,189,079 |
A11759 | A10314 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class G_2 {
static int n, s, p;
static int[] tt;
public static void main(String[] args) throws IOException {
PrintWriter bw = new PrintWriter(new FileWriter("1.txt"));
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
scan.nextLine();
for (int i = 0; i < t; i++) {
n = scan.nextInt();
s = scan.nextInt();
p = scan.nextInt();
tt = new int[n];
int a = 3 * p - 4;
if (p == 1) {
a = 1;
}
if (p == 0) {
a = 0;
}
// int b = 3 * p + 4;
int c = 3 * p - 2;
// int d = 3 * p + 2;
int count = 0;
for (int j = 0; j < n; ++j) {
tt[j] = scan.nextInt();
if (c <= tt[j]) {
count++;
continue;
}
if (a <= tt[j] && s != 0) {
s--;
count++;
continue;
}
}
System.out.println(String.format("Case #%d: %d", (i + 1), count));
bw.write(String.format("Case #%d: %d\n", (i + 1), count));
}
bw.flush();
bw.close();
}
}
| 0 | 1,189,080 |
A11759 | A12344 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package teardrop.jam2012.qr.dancing;
import java.io.*;
public class Launcher {
public static void main(String[] args) {
if (args.length < 2) {
System.err.println("Enter input and output filenames");
System.exit(1);
}
try (
Reader reader = new InputStreamReader(new FileInputStream(args[0]), "UTF-8");
Writer writer = new OutputStreamWriter(new FileOutputStream(args[1]), "UTF-8")) {
SetSolver solver = new SetSolver(reader, writer);
solver.solve();
} catch (UnsupportedEncodingException e) {
System.err.println("Unsupported encoding: "+ e.getMessage());
} catch (FileNotFoundException e) {
System.err.println("Unable to open file: " + e.getMessage());
} catch (IOException e) {
System.err.println("IO error: " + e.getMessage());
}
}
}
| 0 | 1,189,081 |
A11759 | A11549 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.*;
import java.util.*;
public class DancingWithGooglers {
public static void main(String... args) throws Exception {
BufferedReader br = new BufferedReader(new FileReader(
System.getProperty("user.home") + "/Desktop/googlers.in"));
Map<Integer, TripleCounter> dictionary = new HashMap<Integer, TripleCounter>();
for (int x = 0; x <= 10; x++) {
dictionary.put(x + x + x, new TripleCounter(x, x, x, false));
if (x >= 10)
continue;
dictionary
.put(x + x + x + 1, new TripleCounter(x, x, x + 1, false));
dictionary.put(x + x + 1 + x + 1, new TripleCounter(x, x + 1,
x + 1, false));
}
Map<Integer, TripleCounter> specialdictionary = new HashMap<Integer, TripleCounter>();
for (int x = 0; x <= 8; x++) {
specialdictionary.put(x + x + x + 2, new TripleCounter(x, x, x + 2,
true));
specialdictionary.put(x + x + 2 + x + 2, new TripleCounter(x,
x + 2, x + 2, true));
specialdictionary.put(x + x + 1 + x + 2, new TripleCounter(x,
x + 1, x + 2, true));
}
int times = Integer.parseInt(br.readLine());
for (int i = 0; i < times; i++) {
googlers(br.readLine(), dictionary, specialdictionary, i + 1);
}
}
public static void googlers(String line,
Map<Integer, TripleCounter> dictionary,
Map<Integer, TripleCounter> specialdictionary, int num) {
String[] split = line.split(" ");
int special = Integer.parseInt(split[1]);
int p = Integer.parseInt(split[2]);
List<Integer> scores = new ArrayList<Integer>();
int count = 0;
for (int i = 3; i < split.length; i++) {
scores.add(Integer.parseInt(split[i]));
}
for (int i : scores) {
TripleCounter c = dictionary.get(i);
if (c != null && c.hasGreaterOrEqualTo(p)) {
count++;
continue;
}
c = specialdictionary.get(i);
if (special > 0) {
if (c != null && c.hasGreaterOrEqualTo(p)) {
count++;
special--;
}
}
}
System.out.println("Case #" + num + ": " + count);
}
}
class TripleCounter {
public int x, y, z;
public boolean special;
public TripleCounter(int x, int y, int z, boolean special) {
this.x = x;
this.y = y;
this.z = z;
this.special = special;
}
public boolean hasGreaterOrEqualTo(int num) {
return (x >= num || y >= num || z >= num);
}
@Override
public String toString() {
return "(" + x + ", " + y + ", " + z + ", " + special + ")";
}
}
| 0 | 1,189,082 |
A11759 | A13056 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Dancing {
/**
* @param args
*/
public static void main(String[] args) {
try {
// lets get the data in
FileInputStream fstream = new FileInputStream("E:/workspace_java/DancingWiththeGooglers/src/input.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
// open file for writing
FileWriter fwstream = new FileWriter("E:/workspace_java/DancingWiththeGooglers/src/output.out");
BufferedWriter out = new BufferedWriter(fwstream);
// declare variables
int i,j;
int numCases;
String[] strArr;
// get number of cases
strLine = br.readLine();
numCases = Integer.parseInt(strLine);
// declare specific vars
int numGooglers;
int numSurprises;
int surprisesTaken = 0;
int bestScore;
ArrayList<Integer> totalScores = new ArrayList<Integer>();
int tempScore;
int avg;
int aboveBest;
int one = 0, two = 0, three = 0;
int total;
// loop through cases
for(i=0;i<numCases;i++){
// read case
strLine = br.readLine();
strArr = strLine.split(" ");
numGooglers = Integer.parseInt(strArr[0]);
numSurprises = Integer.parseInt(strArr[1]);
bestScore = Integer.parseInt(strArr[2]);
// reset counter
aboveBest = 0;
surprisesTaken = 0;
//System.out.println(bestScore);
// read total scores
for(j=1; j<=numGooglers; j++) {
tempScore = Integer.parseInt(strArr[2+j]);
avg = (int) Math.floor(tempScore / 3);
if((3 * avg) == tempScore) {
// our average is evenly split
one = two = three = avg;
} else if((3 * avg) == (tempScore - 1)) {
// we need to increase one digit
one = two = avg;
three = avg + 1;
} else if((3 * avg) == (tempScore - 2)) {
// we need to increase two digits
one = avg;
two = avg + 1;
three = avg + 1;
}
// check if we are above best
if((one >= bestScore) || (two >= bestScore) || (three >= bestScore)){
aboveBest++;
} else if(surprisesTaken < numSurprises && tempScore != 0 && three < 10 && one > 0) {
// a surprise ultimately is just adding one to the highest and subtract one from lowest
three += 1;
one -= 1;
if(three >= bestScore) {
aboveBest++;
surprisesTaken++;
}
}
total = one + two + three;
//System.out.println(one + " " + two + " " + three);
}
System.out.print("Case #"+(i+1)+": ");
out.write("Case #"+(i+1)+": ");
System.out.println(aboveBest);
out.write(Integer.toString(aboveBest));
out.newLine();
}
//System.out.print("Case #"+(i+1)+": ");
//out.write("Case #"+(i+1)+": ");
//System.out.println(seanP2sum);
//out.write(Integer.toString(seanP2sum));
//out.newLine();
out.close();
in.close();
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | 0 | 1,189,083 |
A11759 | A10776 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
public class DacingScore {
public static String SMALL_IN_FILE_NAME = "./input.txt";
static PrintStream out = null;
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
File smallIn = new File(SMALL_IN_FILE_NAME);
BufferedReader br = new BufferedReader(new FileReader(smallIn));
String s = br.readLine();
int caseCount = Integer.parseInt(s);
File smallOut = new File("./output.txt");
smallOut.createNewFile();
out = new PrintStream(smallOut);
// out = System.out;
for (int i = 0; i < caseCount; i ++) {
out.printf("Case #%d: ", i+1);
s = br.readLine();
TestCase t = new TestCase(s);
out.println(solveTestCase(t));
}
System.out.println("Done");
}
private static int solveTestCase(TestCase t) {
int p = t.getpScore();
int sCount = t.getSuprisingCount();
ArrayList<Triplet> triplets = t.getTriplets();
ArrayList<Triplet> normal = new ArrayList<Triplet>();
ArrayList<Triplet> candidate = new ArrayList<Triplet>();
ArrayList<Triplet> failed = new ArrayList<Triplet>();
int sNormal = 0, sCandidate = 0, sFailed = 0;
for (Triplet triplet : triplets) {
if (triplet.getBest(false) >= p) {
normal.add(triplet);
if (triplet.isSuprisable()) {
sNormal ++;
}
} else if (triplet.getBest(true) >= p) {
candidate.add(triplet);
sCandidate++;
} else {
failed.add(triplet);
if (triplet.isSuprisable()) {
sFailed++;
}
}
}
int result = -1;
if (candidate.size() >= sCount) {
// plenty of candidates
result = normal.size() + sCount;
} else {
result = normal.size() + candidate.size();
}
return result;
}
}
| 0 | 1,189,084 |
A11759 | A11203 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package competition;
/**
*
* @author Sriram
*/
import java.util.Scanner;
import java.io.FileInputStream;
import java.io.PrintStream;
public class DancingWithGooglers_GCJ_2012 {
public static void main(String args[]) throws Exception
{
Scanner in = new Scanner(new FileInputStream("f:\\input.in"));
PrintStream out = new PrintStream("f:\\output.out");
int T = in.nextInt();
for(int i=0;i<T;i++)
{
int N = in.nextInt();
int S = in.nextInt();
int p = in.nextInt();
int result = 0;
int p1,p2,p3;
int[] scores = new int[N];
if(p>1)
{
p1 = (3*p)-4;
p2 = p1+1;
}
else
{
p1 = p2 = p;
}
for(int j=0;j<N;j++)
{
scores[j] = in.nextInt();
}
for(int j=0;(j<N)&&(S>0);j++)
{
if(scores[j]==p1)
{
result++;
S--;
}
}
for(int j=0;(j<N)&&(S>0);j++)
{
if(scores[j]==p2)
{
result++;
S--;
}
}
for(int j=0;j<N;j++)
{
if(scores[j]>p2)
{
result++;
}
}
if(p == 0)
result = scores.length;
out.printf("Case #%d: %d\n",(i+1),result);
}
}
}
| 0 | 1,189,085 |
A11759 | A11452 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package de.hg.codejam.tasks.io;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public abstract class Writer {
public static String generateOutputPath(String inputPath) {
return inputPath.substring(0, inputPath.lastIndexOf('.') + 1) + "out";
}
public static void print(String[] output) {
for (String s : output)
System.out.println(s);
}
public static void write(String[] output) {
for (int i = 0; i < output.length; i++)
System.out.println(getCase(i + 1, output[i]));
}
public static void write(String[] output, String path) {
try (BufferedWriter writer = new BufferedWriter(new FileWriter(path,
false))) {
for (int i = 0; i < output.length; i++) {
writer.append(getCase(i + 1, output[i]));
writer.newLine();
writer.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
}
private static String getCase(int number, String caseString) {
return "Case #" + (number) + ": " + caseString;
}
}
| 0 | 1,189,086 |
A11759 | A13006 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.*;
class Dance {
public static void main (String args[]) {
Scanner sc = new Scanner(System.in);
int numCases = sc.nextInt();
for (int i = 0; i < numCases; i++) {
int numScores = sc.nextInt();
int numSuprises = sc.nextInt();
int smallest = sc.nextInt();
int won = 0;
for (int k = 0; k < numScores; k++) {
int score = sc.nextInt();
if (smallest > score)
continue;
score -= smallest;
score /= 2;
if (score >= smallest - 1)
won++;
else if (score >= smallest - 2) {
if (numSuprises != 0) {
won++;
numSuprises--;
}
}
}
System.out.println("Case #" + (i + 1) + ": " + won);
}
}
} | 0 | 1,189,087 |
A11759 | A10660 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class B {
static int getMaxNumberTodlers(String input){
String[] inputs=input.split(" ");
int T=Integer.parseInt(inputs[0]);
int S=Integer.parseInt(inputs[1]);
int p=Integer.parseInt(inputs[2]);
int results[]=new int[T];
for (int i=0;i<T;i++)
results[i]=Integer.parseInt(inputs[3+i]);
int min=p*3-2;
int minSup=p*3-4;
if (minSup<2)
minSup=2;
int br=0;
System.out.println(min);
for (int i=0;i<T;i++)
if(results[i]>=min)
br++;
else if (results[i]>=minSup&&S>0){
br++;
S--;
}
return br;
}
public static void main(String[] args) throws NumberFormatException, IOException{
FileInputStream fstream = new FileInputStream("problemB.txt");
// Convert our input stream to a
// DataInputStream
DataInputStream in = new DataInputStream(fstream);
FileOutputStream out; // declare a file output object
PrintStream p; // declare a print stream object
out = new FileOutputStream("problemBout.txt");
p = new PrintStream( out );
int n=Integer.parseInt(in.readLine());
for (int i=0;i<n;i++)
p.println("Case #"+(i+1)+": "+B.getMaxNumberTodlers(in.readLine()));
in.close();
p.close();
}
}
| 0 | 1,189,088 |
A11759 | A10441 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Scanner;
public class Qual1b {
static int[] norm = { 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6,
6, 7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10 };
static int[] weird = { 0, 1, 1, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6,
7, 7, 7, 8, 8, 8, 9, 9, 9, 10, 10, 10, 10, 10 };
public static void main(String args[]) {
try {
FileWriter fstream = new FileWriter("outBSmall1.txt");
BufferedWriter out = new BufferedWriter(fstream);
Scanner scanner = new Scanner(new File("B-small-attempt0.in"));
int count = scanner.nextInt();
System.out.println(count);
for (int i = 1; i <= count; i++) {
int n = scanner.nextInt();
int s = scanner.nextInt();
int p = scanner.nextInt();
System.out.println("googlees " + n);
System.out.println("surprising " + s);
System.out.println("max score " + p);
int resultMax = 0;
// ArrayList<Integer> listOfNum = new ArrayList<Integer>();
for (int j = 0; j < n; j++) {
int temp = scanner.nextInt();
if (norm[temp] >= p) {
resultMax++;
} else if (weird[temp] >= p && s > 0) {
resultMax++;
s--;
}
}
out.write("Case #" + i + ": " + resultMax + "\n");
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
| 0 | 1,189,089 |
A11759 | A12706 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.PrintWriter;
public class B {
InputScanner s = new InputScanner(System.in);
PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) {
B program = new B();
program.begin();
}
int storage[][] = new int[110][4];
public void begin() {
int T = s.nextInt();
for(int t=1;t<=T;t++) {
int N = s.nextInt();
int S = s.nextInt();
int P = s.nextInt();
int initialCount = 0;
//int surpriseCount = 0;
int temp[] = new int[4];
for(int n=0;n<N;n++) {
int c = s.nextInt();
int div = Math.round(c/3.0f);
storage[n][0] = div;
storage[n][1] = div;
storage[n][2] = c - 2*div;
if(storage[n][0] >= P || storage[n][2] >= P)
{
//System.out.println(storage[n][0]+" "+storage[n][2]);
storage[n][3] = 1;
initialCount++;
}
else {
if(S>0) {
temp[0] = P;
int res = c - P;
if(res > 0) {
int div2 = res/2;
temp[1] = div2;
if(Math.abs(temp[0]-temp[1]) <= 2) {
temp[2] = res - div2;
if(Math.abs(temp[0]-temp[2]) <= 2 && Math.abs(temp[1]-temp[2]) <= 2) {
S--;
storage[n] = temp;
initialCount++;
}
}
}
}
}
}
/*System.out.println(initialCount);
for(int n=0;n<N;n++)
System.out.println(Arrays.toString(storage[n]));*/
out.printf("Case #%d: %d\n",t,initialCount);
}
out.close();
}
class InputScanner {
BufferedReader br;
StringTokenizer strtok = null;
public InputScanner(InputStream stream) {
br = new BufferedReader(new InputStreamReader(stream));
}
public InputScanner(File file) throws FileNotFoundException {
br = new BufferedReader(new FileReader(file));
}
public String next() {
if (strtok == null || !strtok.hasMoreTokens()) {
try {
strtok = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return strtok.nextToken();
}
public int nextInt() {
int i;
try {
i = Integer.parseInt(next());
} catch (NumberFormatException e) {
throw new RuntimeException(e);
}
return i;
}
public String nextLine() {
if (strtok == null || !strtok.hasMoreTokens()) {
try {
strtok = new StringTokenizer(br.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return strtok.nextToken("\n").trim();
}
}
} | 0 | 1,189,090 |
A11759 | A11007 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | /*
ID: t.lam1
LANG: JAVA
TASK: codejam
*/
import java.io.*;
import java.util.*;
import java.text.*;
import static java.lang.System.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.lang.Character.*;
import static java.util.Collections.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
class codejam {
public static void main (String [] args) throws IOException{
codejam a=new codejam();
a.run();
}
public void run()throws IOException
{
dancing();
}
public void recycle()throws IOException{
Scanner file = new Scanner(new File("codejam.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("codejam.out")));
int cases = file.nextInt();
file.nextLine();
ArrayList<String> done = new ArrayList<String>();
for(int x =0; x<cases; x++){
out.print("Case #"+(x+1)+": ");
int a = file.nextInt(), b = file.nextInt(), c = 0;
for(int n = a; n<=b; n++){
for(int m = n+1; m<=b; m++){
if(n<10||m<10)continue;
else if(done.contains(""+n+m)){
}
else{
String nn = ""+n, mm=""+m, temp = mm;
mm = mm.substring(mm.length()-1)+mm.substring(0,mm.length()-1);
while(!mm.equals(temp)){
if(mm.equals(nn)){
c++;
done.add(""+n+m);
break;
}
mm = mm.substring(mm.length()-1)+mm.substring(0,mm.length()-1);
}
}
}
}
out.println(c);
}
out.close();
}
public void dancing()throws IOException{
Scanner file = new Scanner(new File("codejam.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("codejam.out")));
int cases = file.nextInt();
file.nextLine();
for(int x =0; x<cases; x++){
out.print("Case #"+(x+1)+": ");
Scanner chop = new Scanner(file.nextLine());
int N = chop.nextInt(), S = chop.nextInt(), P = chop.nextInt(), nums = 0;
ArrayList<Integer> googlers = new ArrayList<Integer>();
for(int y = 0; y<N; y++){
googlers.add(chop.nextInt());
}
System.out.print(N+" "+S+" "+P+" ");
for(Integer a: googlers){
System.out.println();
System.out.println(a+" ");
int temp = a/3;
int temp2 = a;
if(S>0){
System.out.println("bye");
if(P-(temp2-P)/2==2){
S--;
nums++;
}
if(temp2-2*temp>=P&&(temp2-2*temp)-temp<2)nums++;
else{
temp++;
if((temp2-2*temp>=P||temp==P)&&temp-(temp2-2*temp)<2)nums++;
}
}
else{
System.out.println("hi");
if(temp2-2*temp>=P&&(temp2-2*temp)-temp<2)nums++;
else{
System.out.println("else");
temp++;
if((temp2-2*temp>=P||temp==P)&&temp-(temp2-2*temp)<2)nums++;
}
}
}
System.out.println("nums: "+nums);
out.println(nums);
}
out.close();
}
public void googleRese()throws IOException{
Scanner file = new Scanner(new File("codejam.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("codejam.out")));
int x = file.nextInt(); file.nextLine();
//ArrayList<String> cases = new ArrayList<String>();
Map<Character,Character> remap = new TreeMap<Character,Character>();
remap.put('a','y');
remap.put('b','h');
remap.put('c','e');
remap.put('d','s');
remap.put('e', 'o');
remap.put('f', 'c');
remap.put('g', 'v');
remap.put('h', 'x');
remap.put('i', 'd');
remap.put('j', 'u');
remap.put('k', 'i');
remap.put('l', 'g');
remap.put('m', 'l');
remap.put('n', 'b');
remap.put('o', 'k');
remap.put('p', 'r');
remap.put('r', 't');
remap.put('s', 'n');
remap.put('t', 'w');
remap.put('u', 'j');
remap.put('v', 'p');
remap.put('w', 'f');
remap.put('x', 'm');
remap.put('y','a');
remap.put('z','q');
remap.put('q','z');
remap.put(' ',' ');
for(int y = 1; y<=x; y++){
String temp = file.nextLine();
out.print("Case #"+y+": ");
for(Character a: temp.toCharArray()){
if(remap.get(a)==null)System.out.println(a);
out.print(remap.get(a));
}
out.println();
}
out.close();
}
}
| 0 | 1,189,091 |
A11759 | A10587 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package b;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
public class Dancing {
List<Integer> ss = new ArrayList<>();
int n;
int min;
int sp;
int cnt = 0;
public Dancing(int min, int sp, int[] sc) {
this.min = min;
this.n = sc.length;
this.sp = sp;
for(int s : sc) {
ss.add(s);
}
}
public static void main(String[] args) throws IOException {
// System.out.println(new Dancing(5, 1, new int[] {15, 13, 11}).solve());
// System.out.println(new Dancing(8, 0, new int[] {23, 22, 21}).solve());
// System.out.println(new Dancing(1, 1, new int[] {8, 0}).solve());
// System.out.println(new Dancing(8, 2, new int[] {29, 20, 8, 18, 18, 21}).solve());
BufferedReader br = new BufferedReader(new FileReader("src/b/B-small-attempt0.in"));
BufferedWriter bw = new BufferedWriter(new FileWriter("src/b/out"));
int row = Integer.parseInt(br.readLine());
System.out.println("ROW : " + row);
for(int i=0; i<row; i++) {
String[] line = br.readLine().split(" ");
int n = Integer.parseInt(line[0]);
int sp = Integer.parseInt(line[1]);
int min = Integer.parseInt(line[2]);
int[] sc = new int[n];
for(int j=0; j<n; j++) {
sc[j] = Integer.parseInt(line[3+j]);
}
String res = "Case #" + (i+1) + ": " + new Dancing(min, sp, sc).solve();
bw.write(res + "\n");
System.out.println(res);
}
bw.close();
br.close();
}
private int solve() {
for(Iterator<Integer> it = ss.iterator(); it.hasNext();) {
int s = it.next();
int rest = s - min;
if (rest < 0) continue;
if (rest /2 >= Math.max(min-1,0)) {
cnt++;
it.remove();
}
}
Collections.sort(ss, new Comparator<Integer>() {
public int compare(Integer o1, Integer o2) {
return o2- o1;
}
});
for(Iterator<Integer> it = ss.iterator(); it.hasNext();) {
int s = it.next();
int rest = s - min;
if (rest < 0) continue;
if (rest / 2 >= Math.max(min-2, 0) && sp > 0) {
cnt++;
sp--;
it.remove();
}
}
return cnt;
}
}
| 0 | 1,189,092 |
A11759 | A12031 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package jp.funnything.competition.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
public class Packer {
private static void add( final ZipArchiveOutputStream out , final File file , final int pathPrefix ) {
if ( file.isDirectory() ) {
final File[] children = file.listFiles();
if ( children.length > 0 ) {
for ( final File child : children ) {
add( out , child , pathPrefix );
}
} else {
addEntry( out , file , pathPrefix , false );
}
} else {
addEntry( out , file , pathPrefix , true );
}
}
private static void addEntry( final ZipArchiveOutputStream out , final File file , final int pathPrefix , final boolean isFile ) {
try {
out.putArchiveEntry( new ZipArchiveEntry( file.getPath().substring( pathPrefix ) + ( isFile ? "" : "/" ) ) );
if ( isFile ) {
final FileInputStream in = FileUtils.openInputStream( file );
IOUtils.copy( in , out );
IOUtils.closeQuietly( in );
}
out.closeArchiveEntry();
} catch ( final IOException e ) {
throw new RuntimeException( e );
}
}
public static void pack( final File source , final File destination ) {
try {
final ZipArchiveOutputStream out = new ZipArchiveOutputStream( destination );
add( out , source , FilenameUtils.getPath( source.getPath() ).length() );
out.finish();
out.close();
} catch ( final IOException e ) {
throw new RuntimeException( e );
}
}
}
| 0 | 1,189,093 |
A11759 | A13158 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
public class GoogleTriplet {
public static void main(String[] args) {
runTestCase();
}
public static void runTestCase() {
String fileName = "B-small-attempt0.in";// input file
String outFileName = "outputFile.txt";// output file
try {
FileInputStream fStream = new FileInputStream(fileName);
FileOutputStream fOutStream = new FileOutputStream(outFileName);
BufferedReader bf = new BufferedReader(new InputStreamReader(
fStream));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
fOutStream));
int i = 0;
int testSize = Integer.parseInt(bf.readLine());
while (i < testSize) {
String in = bf.readLine();
if (in.length() > 100) {
throw new Exception();
}
bw.write(findTriplets(in, ++i));
bw.newLine();
}
// close the two files.
bf.close();
bw.close();
} catch (Exception e) {
System.err.println("There was a error : " + e.toString());
}
}
public static String findTriplets(String inputData, int testCase) {
StringBuffer temp = new StringBuffer();
temp.append("Case #" + testCase + ": ");
String[] split = inputData.split(" ");
int noOfGooglers = Integer.parseInt(split[0]);
int surprise = Integer.parseInt(split[1]);
int p = Integer.parseInt(split[2]);
List<Integer> scores = new ArrayList<Integer>();
for (int i = 3; i < 3 + noOfGooglers; i++) {
int score = Integer.parseInt(split[i]);
if (score > 3 * p - 5) {
if (score >= 3 * p - 4 && score < 3 * p - 2 && surprise > 0) {
if (3 * p - 4 > 0) {
scores.add(score);
surprise--;
}
} else if (score >= 3 * p - 2 || p == 0) {
scores.add(score);
}
}
}
temp.append(scores.size());
return temp.toString();
}
}
| 0 | 1,189,094 |
A11759 | A11698 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package google.codejam.commons;
import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
public class Utils {
public static String[] readFromFile(String fileName) throws IOException {
String[] lines = null;
FileInputStream fstream = new FileInputStream(fileName);
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = br.readLine();
lines = new String[Integer.valueOf(strLine)];
int i = 0;
while ((strLine = br.readLine()) != null) {
lines[i++] = strLine;
}
in.close();
return lines;
}
public static void writeToFile(String[] lines, String fileName)
throws IOException {
FileWriter outFile = new FileWriter(fileName);
PrintWriter out = new PrintWriter(outFile);
for (String line : lines) {
out.println(line);
}
out.close();
}
}
| 0 | 1,189,095 |
A11759 | A13219 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
class Test{
int output;
char[] mapping;
String line;
int S;
int P;
int[] Ti;
public Test(String line){
Scanner lineReader = new Scanner(line);
int N = lineReader.nextInt();
S = lineReader.nextInt();
P = lineReader.nextInt();
Ti = new int[N];
for (int i = 0; i < N; i++){
Ti[i] = lineReader.nextInt();
}
}
public int getOutput(){
return output;
}
public void solve(){
for (int x: Ti){
if(P == 0){
output++;
}
else if((x >= P*3 -2 && x > 0)){
output++;
}
else if(x >= P*3 -4 && S > 0 && x > 0 && P > 1){
output++;
S--;
}
}
}
public char translate(char c){
if (c == ' '){
return c;
}
boolean changeCase = false;
if(c != Character.toLowerCase(c)){
c = Character.toLowerCase(c);
changeCase = true;
}
char toReturn = mapping[Character.valueOf(c) - Character.valueOf('a')];
if(changeCase){
toReturn = Character.toUpperCase(toReturn);
}
return toReturn;
}
}
public class ProblemB {
public static void main(String[] args) throws IOException{
File inputFile = new File("input.txt");
Scanner scan = new Scanner(inputFile);
int loopCount = scan.nextInt();
scan.nextLine();
FileWriter outputFile = new FileWriter("output.txt");
for(int i = 1; i <= loopCount; i++){
Test start = new Test(scan.nextLine());
start.solve();
outputFile.write("Case #"+i+": " + start.getOutput());
if(i < loopCount){
outputFile.write("\r\n");
}
}
outputFile.close();
}
}
| 0 | 1,189,096 |
A11759 | A10036 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | package SolnB;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.Test;
public class ProbBTest {
@Before
public void setUp() throws Exception {
}
@Test
public void test() {
fail("Not yet implemented");
}
}
| 0 | 1,189,097 |
A11759 | A12093 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
public class Dancing {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int numCases = sc.nextInt();
for (int i = 0; i < numCases; i++) {
int N = sc.nextInt();
int S = sc.nextInt();
int S_counter = S;
int p = sc.nextInt();
int numPassed = 0;
int minSurprise;
int minNoSurprise;
//special cases
if (p == 0) {
minSurprise = 0;
minNoSurprise = 0;
}
else if (p == 1) {
minSurprise = 1;
minNoSurprise = 1;
}
else {
minSurprise = p + 2*(p - 2);
minNoSurprise = p + 2*(p - 1);
}
if (minNoSurprise < 0) minNoSurprise = 0;
for (int j = 0; j < N; j++) {
int t = sc.nextInt();
if (t < minSurprise) continue;
else if (t < minNoSurprise &&
t >= minSurprise &&
S_counter <= 0) continue;
else if (t < minNoSurprise &&
t >= minSurprise &&
S_counter > 0) {
numPassed++;
S_counter--;
}
else if (t >= minNoSurprise)
numPassed++;
else
System.out.println("Something Broke");
}
System.out.println("Case #" + (i + 1) + ": " + numPassed);
}
}
}
| 0 | 1,189,098 |
A11759 | A11259 | import java.io.*;
import java.util.*;
public class Problem2
{
static ArrayList<Integer> scores;
public static void main(String args[])
{
try
{
FileInputStream fstream = new FileInputStream("B-small-attempt0.in");
DataInputStream in = new DataInputStream(fstream);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String line;
int total;
int i = 0, cases;
Scanner sc;
int number, surprising, minpoints;
while ((line = br.readLine()) != null)
{
if(i == 0)
{
total = Integer.parseInt(line);
i = 1;
continue;
}
sc = new Scanner(line);
scores = new ArrayList<Integer>();
number = sc.nextInt();
surprising = sc.nextInt();
minpoints = sc.nextInt();
cases = 0;
for(int j = 0; j < number; j++)
{
scores.add(sc.nextInt());
}
for(int score : scores)
{
int base = (int)(score/3);
switch(score%3)
{
case 0:
{
if(base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 1:
{
if(base>=minpoints | base + 1 >= minpoints)
{
cases++;
}
else if(surprising > 0 && base + 1 >= minpoints)
{
cases++;
surprising--;
}
break;
}
case 2:
{
if(base + 1>= minpoints | base>=minpoints)
{
cases++;
}
else if(surprising > 0 && base + 2 >= minpoints)
{
cases++;
surprising--;
}
break;
}
}
}
System.out.println("Case #"+i+": "+cases);
write("Case #"+i+": "+cases);
i++;
}
in.close();
}catch (Exception e){
System.err.println("Error: " + e.getMessage());
}
}
public static void write(String text)
{
try
{
BufferedWriter bw = new BufferedWriter(new FileWriter(new File("Problem2Output.out"), true));
bw.write(text);
bw.newLine();
bw.close();
}catch (Exception e) {
System.err.println("Error: " + e.getMessage());
}
}
} | import java.util.Scanner;
/*
* el resto es 0 --> puede ser caso especial y no
* 15 --> 5 5 5 ó 4 5 6
* el resto es 1 --> puede ser caso especial y no
* 16 --> 4 6 6 ó 5 5 6
* el resto es 2 --> puede ser caso especial y no
* 17 --> 5 7 7 ó 5 6 6
*/
public class B {
public static void main(String[] args) {
final int JUDGES = 3;
final int MINSCORE = 0;
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int i = 1; i <= t; i++) {
int n = in.nextInt();
int s = in.nextInt();
int p = in.nextInt();
int success = 0;
for (int j = 0; j < n; j++) {
int totalScores = in.nextInt();
int score = totalScores / JUDGES;
int rest = totalScores % JUDGES;
if (totalScores==MINSCORE) {
if (p==MINSCORE) {
success++;
}
} else if (score >= p || (score+1>=p && rest>=1)) {
success++;
} else if (score + 1 >= p && rest < 1 && s > 0) {
success++;
s--;
} else if (score + 2 >= p && rest == 2 && s > 0) {
success++;
s--;
}
}
System.out.format("Case #%d: %d\n", i, success);
}
}
} | 0 | 1,189,099 |