Google Code Jam 2018 Qualification Round通過

今日はひたすらデータベーススペシャリストの勉強をしていました。
Google Code Jam 2018 Qualification Roundの結果も出ていました。ABC通で通過です。

A問題は後ろでShootされるほど痛いってことに気づけば、右側からスワップしていけばよいことに気づく。
import java.io.*;public class Solution {public static void main(String args[]) throws Exception{//BufferedReader input = new BufferedReader(new FileReader("../GCJ2018/io/input.txt"));    BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));//pw = new PrintWriter(new FileWriter("../GCJ2018/io/output.txt"));int T = Integer.parseInt(stdReader.readLine());for(int i = 0 ; i < T ; i++){String[] strs = stdReader.readLine().split(" ");int D = Integer.parseInt(strs[0]);String s = strs[1];int replacetime = 0;if(simulation(s, D)) {System.out.println("Case #"+(i+1)+": "+ 0);}else {boolean canreduce = false;for(int j = s.length() - 1 ; j > 0; j--) {if(s.charAt(j - 1) == 'C' && s.charAt(j) == 'S') {s = s.substring(0, j - 1) + s.charAt(j) + s.charAt(j - 1) + s.substring(j + 1, s.length());replacetime++;if(simulation(s, D)) {System.out.println("Case #"+(i+1)+": "+ replacetime);canreduce = true;break;}j = s.length();}}if(!canreduce) {System.out.println("Case #"+(i+1)+": IMPOSSIBLE");}}System.out.println();}stdReader.close();}public static boolean simulation(String s,int D) {int dmg = 1;int sum = 0;for(int j = 0 ; j < s.length(); j++) {if(s.charAt(j) == 'C') {dmg *= 2;}else {sum += dmg;}}//System.out.println("sum"+sum+","+"D"+D+","+s);if(sum <= D) return true;return false;}}
B問題は、偶数番目と奇数番目の配列を作り、それぞれソートしたうえで順番に見て、昇順になっているかで判断する
import java.io.*;import java.util.Arrays;public class Solution {public static void main(String args[]) throws Exception{    BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));int T = Integer.parseInt(stdReader.readLine());for(int i = 0 ; i < T ; i++){int N = Integer.parseInt(stdReader.readLine());String[] strs = stdReader.readLine().split(" ");int[] odds = new int[N / 2];int[] evens = new int[N / 2 + N % 2];for(int j = 0 ; j < N ; j++) {if(j % 2 == 0) {evens[j / 2] = Integer.parseInt(strs[j]);}else {odds[j / 2] = Integer.parseInt(strs[j]);}}Arrays.sort(odds);Arrays.sort(evens);int now = -1;boolean isok = true;int wrongnum = -1;for(int j = 0 ; j < N ; j++) {if(j % 2 == 0) {if(now <= evens[j / 2]) {now = evens[j / 2];}else {wrongnum = j;isok = false;}}else{if(now <= odds[j / 2]) {now = odds[j / 2];}else{wrongnum = j;isok = false;}}if(!isok)break;}if(!isok) {System.out.println("Case #"+(i+1)+": "+(wrongnum - 1));}else {System.out.println("Case #"+(i+1)+": OK");}System.out.println();}stdReader.close();}}
C問題は、塗りつぶす長方形をあらかじめ決めて、塗りきる
import java.io.*;import java.util.Scanner;public class Solution {public static void main(String args[]) throws Exception{    BufferedReader stdReader = new BufferedReader(new InputStreamReader(System.in));int T = Integer.parseInt(stdReader.readLine());for(int i = 0 ; i < T ; i++){int A = Integer.parseInt(stdReader.readLine());int x = 500;int y = 500;int height = Math.max(3, (int)Math.sqrt(A));int width = A % height == 0 ? A / height : A / height + 1;int count = 0;//debugboolean[][] xy = new boolean[Math.max(3, width)][Math.max(3, height)];//x,yint canstamp_x = 500 + Math.max(3, width) - 3;int canstamp_y = 500 + Math.max(3, height) - 3;boolean isok = false;//500,500 is centerwhile(true) {for(int j = 0 ; j < xy.length ; j++) {for(int k = 0 ; k < xy[0].length ; k++) {if(!xy[j][k]) {if(j == 0) {x = 500;}else if(j == canstamp_x - 498) {x = canstamp_x;}else {x = j + 499;}if(k == 0) {y = 500;}else if(k == canstamp_y - 498) {y = canstamp_y;}else {y = k + 499;}System.out.println(x+" "+y);String res = stdReader.readLine();String[] x_and_y = res.split(" ");//String[] x_and_y = returnnum(x, y, xy).split(" ");int ret_x = Integer.parseInt(x_and_y[0]) - 499;int ret_y = Integer.parseInt(x_and_y[1]) - 499;count++;if(ret_x == -499 && ret_y == -499) {isok = true;break;}else if(ret_x == -500 && ret_y == -500) {System.out.println("Error");System.exit(0);}xy[ret_x][ret_y] = true;/*if(isFinish(xy)) {isok = true;break;}*/}if(isok)break;}if(isok)break;}if(isok)break;}//System.out.println("OK"+","+count);}stdReader.close();}public static String returnnum(int x,int y, boolean[][] xy) {int randx = (int)(Math.random() * 3);int randy = (int)(Math.random() * 3);for(int j = 0 ; j < xy.length ; j++) {for(int k = 0 ; k < xy[0].length ; k++) {if(!xy[j][k]) {return (x - 1 + randx)+" "+(y - 1 + randy);}}}return "0 0";}public static boolean isFinish(boolean[][] xy) {for(int j = 0 ; j < xy.length ; j++) {for(int k = 0 ; k < xy[0].length ; k++) {if(!xy[j][k]) {return false;}}}return true;}}
Dはよくわかりませんでした。

ゲーセンは18時ぐらいから。
Google Code Jam 2018 Qualification Round通過_f0019846_17595460.jpg
まずはボルテ。VILE CAT EXH 9393011 AA
Google Code Jam 2018 Qualification Round通過_f0019846_18000139.jpg
ワールズエンド・ダンスホール MXM 9426188 AA
Google Code Jam 2018 Qualification Round通過_f0019846_18005037.jpg
そしてリフレク。判定はMASTER判定で。Sephirot WH 90.0% AAA フルコン
Google Code Jam 2018 Qualification Round通過_f0019846_18005653.jpg
StrayedCatz WH 86.8% AA フルコン
Google Code Jam 2018 Qualification Round通過_f0019846_18005960.jpg
Triple Counter WH miss2 79.2% A
Google Code Jam 2018 Qualification Round通過_f0019846_18015476.jpg
結果、第32回ランキングクエストは暫定55位と9人抜きました。

  by ddrer-yossi | 2018-04-08 17:57 | reflec beat

<< 仕事の疲弊。モチベーションもない。 スヌーピーミュージアムとよろにく >>

SEM SKIN - DESIGN by SEM EXE