Created
December 26, 2011 15:03
-
-
Save hamadu/1521339 to your computer and use it in GitHub Desktop.
Codeforces #99(div2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemA { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.valueOf(s.readLine()); | |
String[] data = s.readLine().split(" "); | |
int[] days = new int[7]; | |
for (int i = 0 ; i < 7 ; i++) { | |
days[i] = Integer.valueOf(data[i]); | |
} | |
int pages = 0; | |
int ans = 0; | |
boolean cont = true; | |
while (cont) { | |
for (int i = 0 ; i < 7 ; i++) { | |
pages += days[i]; | |
if (pages >= n) { | |
cont = false; | |
ans = i+1; | |
break; | |
} | |
} | |
} | |
System.out.println(ans); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemB { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
int n = Integer.valueOf(s.readLine()); | |
int[][] room = new int[n][3]; | |
for (int i = 0 ; i < n ; i++) { | |
String[] data = s.readLine().split(" "); | |
for (int j = 0 ; j < 3 ; j++) { | |
room[i][j] = Integer.valueOf(data[j]); | |
} | |
} | |
int m = Integer.valueOf(s.readLine()); | |
int[][] wp = new int[m][3]; | |
for (int i = 0 ; i < m ; i++) { | |
String[] data = s.readLine().split(" "); | |
for (int j = 0 ; j < 3 ; j++) { | |
wp[i][j] = Integer.valueOf(data[j]); | |
} | |
} | |
int prices = 0; | |
for (int i = 0 ; i < n ; i++) { | |
int minp = Integer.MAX_VALUE; | |
int needslen = (room[i][0] + room[i][1]) * 2; | |
for (int w = 0 ; w < m ; w++) { | |
int canmakew = (int)(wp[w][0] / room[i][2]) * wp[w][1]; | |
if (canmakew > 0) { | |
int needs = ((needslen - 1) / canmakew) + 1; | |
minp = Math.min(minp, needs * wp[w][2]); | |
} | |
} | |
prices += minp; | |
} | |
System.out.println(prices); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Scanner; | |
public class ProblemC { | |
public static boolean[] vowel = new boolean[512]; | |
public static String Kth(String line, int k) { | |
int len = line.length(); | |
for (int i = len-1 ; i >= 0 ; i--) { | |
if (vowel[line.charAt(i)]) { | |
k--; | |
if (k == 0) { | |
return line.substring(i); | |
} | |
} | |
} | |
return ""; | |
} | |
public static void main(String[] args) throws IOException { | |
vowel['a'] = true; | |
vowel['i'] = true; | |
vowel['u'] = true; | |
vowel['e'] = true; | |
vowel['o'] = true; | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
String[] data = s.readLine().split(" "); | |
int n = Integer.valueOf(data[0]); | |
int K = Integer.valueOf(data[1]); | |
boolean[] scheme = new boolean[3]; | |
for (int i = 0 ; i < 3 ; i++) { | |
scheme[i] = true; | |
} | |
for (int i = 0 ; i < n ; i++) { | |
String[] kthv = new String[4]; | |
for (int j = 0 ; j < 4 ; j++) { | |
kthv[j] = Kth(s.readLine(), K); | |
if (kthv[j].length() == 0) { | |
kthv[j] += (char)('0' + j); | |
} | |
} | |
if (kthv[0].equals(kthv[1]) && kthv[2].equals(kthv[3])) { | |
} else { | |
scheme[0] = false; | |
} | |
if (kthv[0].equals(kthv[2]) && kthv[1].equals(kthv[3])) { | |
} else { | |
scheme[1] = false; | |
} | |
if (kthv[0].equals(kthv[3]) && kthv[1].equals(kthv[2])) { | |
} else { | |
scheme[2] = false; | |
} | |
} | |
if (scheme[0] && scheme[1] && scheme[2]) { | |
System.out.println("aaaa"); | |
return; | |
} | |
if (scheme[0]) { | |
System.out.println("aabb"); | |
return; | |
} | |
if (scheme[1]) { | |
System.out.println("abab"); | |
return; | |
} | |
if (scheme[2]) { | |
System.out.println("abba"); | |
return; | |
} | |
System.out.println("NO"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
import java.util.Arrays; | |
public class ProblemD { | |
public static void main(String[] args) throws IOException { | |
BufferedReader s = new BufferedReader(new InputStreamReader(System.in)); | |
String line = s.readLine(); | |
int len = line.length(); | |
int[] countA = new int[10]; | |
int[] countB = new int[10]; | |
for (int i = 0 ; i < len ; i++) { | |
int c = line.charAt(i) - '0'; | |
countA[c]++; | |
} | |
countB = countA.clone(); | |
int maxzero = 0; | |
int maxstart = -1; | |
for (int start = 1 ; start <= 5 ; start++) { | |
if (countA[start] >= 1 && countB[10-start] >= 1) { | |
int zero = 1; | |
countA[start]--; | |
countB[10-start]--; | |
for (int pair = 0; pair <= 4 ; pair++) { | |
zero += Math.min(countA[pair], countB[9-pair]); | |
} | |
if (maxzero < zero) { | |
maxzero = zero; | |
maxstart = start; | |
} | |
countA[start]++; | |
countB[10-start]++; | |
} | |
} | |
if (maxstart == -1) { | |
for (int times = 0 ; times <= 1 ; times++) { | |
for (int ct = 1 ; ct <= 10 ; ct++) { | |
int cx = ct % 10; | |
for (int x = 0 ; x < countA[cx] ; x++) { | |
System.out.print(cx); | |
} | |
} | |
System.out.println(); | |
} | |
return; | |
} | |
countA[maxstart]--; | |
countB[10-maxstart]--; | |
int fzero = countA[0] - countA[9]; | |
if (fzero >= 1) { | |
countA[0] -= fzero; | |
countB[0] -= fzero; | |
} | |
int[] uses = new int[10]; | |
for (int pair = 0; pair <= 9 ; pair++) { | |
int t = Math.min(countA[pair], countB[9-pair]); | |
uses[pair] = t; | |
countA[pair] -= t; | |
countB[9-pair] -= t; | |
} | |
{ | |
for (int ct = 1 ; ct <= 10 ; ct++) { | |
int cx = ct % 10; | |
for (int x = 0 ; x < countA[cx] ; x++) { | |
System.out.print(cx); | |
} | |
} | |
for (int pair = 0; pair <= 9 ; pair++) { | |
for (int t = 0 ; t < uses[pair] ; t++) { | |
System.out.print(pair); | |
} | |
} | |
System.out.print(maxstart); | |
if (fzero >= 1) { | |
for (int i = 0 ; i < fzero ; i++) { | |
System.out.print('0'); | |
} | |
} | |
System.out.println(); | |
} | |
{ | |
for (int ct = 1 ; ct <= 10 ; ct++) { | |
int cx = ct % 10; | |
for (int x = 0 ; x < countB[cx] ; x++) { | |
System.out.print(cx); | |
} | |
} | |
for (int pair = 0; pair <= 9 ; pair++) { | |
for (int t = 0 ; t < uses[pair] ; t++) { | |
System.out.print(9-pair); | |
} | |
} | |
System.out.print(10-maxstart); | |
if (fzero >= 1) { | |
for (int i = 0 ; i < fzero ; i++) { | |
System.out.print('0'); | |
} | |
} | |
System.out.println(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment