契約を結びし日。Facebook Hacker Cup 2018 Qualification Round全完

今日の朝食兼昼食
契約を結びし日。Facebook Hacker Cup 2018 Qualification Round全完_f0019846_16212713.jpg
17時くらいに某所を散策。ゲーセンに向かうなどもしていた。
色々と見つつ、夜は急ピッチで契約を進めさせられた。
大体策略にハマったといえば正しいだろうか。落ち着いて吟味する時間もなく。
契約を結びし日。Facebook Hacker Cup 2018 Qualification Round全完_f0019846_16233898.jpg
こういう大金がおさらばしていきましたからねえ。

契約を結びし日。Facebook Hacker Cup 2018 Qualification Round全完_f0019846_16240740.jpg
夜は鶏そばを食べる。しかし、その後思い返してみるとこちらに不利な契約を色々と結ばされていて、
地獄や…つらい><って思うことに。


あと、Facebook Hacker Cup 2018 Qualification Roundは満点で通過していました。
A.Tourist
N個のアトラクションがあり、そのうちK個のアトラクションに乗る予定。
ただしV-1回はすでに訪れているので、V回目にどのアトラクションを乗るか、人気順に表示せよという問題。
K * V - 1の余剰を計算しつつ、乗る予定のやつを人気順にappendすればよい。


import java.io.*;
import java.util.Arrays;

public class QR25 {
static PrintWriter pw;
public static void main(String args[]) throws Exception{
BufferedReader input = new BufferedReader(new FileReader("../FHC2018/io/tourist.txt"));
pw = new PrintWriter(new FileWriter("../FHC2018/io/output.txt"));
int T = Integer.parseInt(input.readLine());
for(int i = 0 ; i < T ; i++){
String[] str = input.readLine().split(" ");
int N = Integer.parseInt(str[0]);
int K = Integer.parseInt(str[1]);
long V = Long.parseLong(str[2]);
String[] attractions = new String[N];
for(int j = 0 ; j < N ; j++) {
attractions[j] = input.readLine();
}
int startac = (int)((long)(K * (V - 1)) % N);
int indexcount = 0;
int[] attraction_index = new int[K];
StringBuilder sb = new StringBuilder();
while(indexcount != K) {
attraction_index[indexcount] = startac;
startac++;
indexcount++;
if(startac == N)startac = 0;
}
Arrays.sort(attraction_index);
for(int j = 0 ; j < K ; j++) {
if(j != K - 1) {
sb.append(attractions[attraction_index[j]]).append(" ");
}else {
sb.append(attractions[attraction_index[j]]);
}
}
pw.println("Case #"+(i+1)+": "+sb.toString());
pw.flush();
}
input.close();
pw.close();
}
}

B.Interception
奇遇で分けてみると、最終的に解があるのがx=0の場合しかない。そこに気づけば簡単。

import java.io.*;
import java.util.Arrays;

public class QR30 {
static PrintWriter pw;
public static void main(String args[]) throws Exception{
BufferedReader input = new BufferedReader(new FileReader("../FHC2018/io/interception.txt"));
pw = new PrintWriter(new FileWriter("../FHC2018/io/output.txt"));
int T = Integer.parseInt(input.readLine());
for(int i = 0 ; i < T ; i++){
int N = Integer.parseInt(input.readLine());
for(int j = 0 ; j <= N ; j++) {
input.readLine();
}
if(N % 2 == 1) {
pw.println("Case #"+(i+1)+": "+1);
pw.println("0.0");
}else {
pw.println("Case #"+(i+1)+": "+0);
}
pw.flush();
}
input.close();
pw.close();
}
}

C.Ethan Searches for a String

これは気づきゲー。文字列Aの前に、Aの先頭文字で終わるようなAのprefixを重ねて(そこで続くように)置いてみて、
ethanのアルゴリズムで部分文字列を検出できなければそれを返す。そういうのがなければImpossibleとなる。

import java.io.*;
import java.util.Arrays;

public class QR45 {
static PrintWriter pw;
public static void main(String args[]) throws Exception{
BufferedReader input = new BufferedReader(new FileReader("../FHC2018/io/ethan_searches_for_a_string.txt"));
pw = new PrintWriter(new FileWriter("../FHC2018/io/output.txt"));
int T = Integer.parseInt(input.readLine());
for(int i = 0 ; i < T ; i++){
String s = input.readLine();
if(s.lastIndexOf(s.substring(0,1)) != 0){
int second = s.indexOf(s.substring(0,1),1);
String news = s.substring(0, second) + s;
if(news.indexOf(s) == news.lastIndexOf(s)) {
pw.println("Case #"+(i+1)+": "+news);
}else {
pw.println("Case #"+(i+1)+": Impossible");
}
}else {
pw.println("Case #"+(i+1)+": Impossible");
}
pw.flush();
}
input.close();
pw.close();
}
}


  by ddrer-yossi | 2018-07-10 16:21 | 日常生活

<< 契約から一夜明け、色々と気づく。 忙しき日々 >>

SEM SKIN - DESIGN by SEM EXE