This file contains hidden or 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
#include <condition_variable> | |
#include <mutex> | |
#include <queue> | |
template <typename T> | |
class blockingqueue { | |
public: | |
blockingqueue() {} | |
void enqueue(const T& item) { | |
std::lock_guard<std::mutex> lk(lk_); |
This file contains hidden or 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
(* POINT: 選べるチケットの中で帰国日が最も早いものを選ぶことを繰り返す。Greedy。 | |
アリ本P.43と同じ問題。 *) | |
(* OCaml *) | |
let try_fx f x = | |
try Some (f x) with | |
| _ -> None | |
let () = | |
(* 日付の比較は単に(month, day)のペアとする *) |
This file contains hidden or 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
//5578864439 | |
//ENV: F# | |
//POINT: 未使用の文字から何種類できるかについてメモ化再帰で全探索。メモのポイントは種類を無視して個数の組み合わせをキーにする。また、答えは32bitで桁あふれするので注意。 | |
//感想: 久しぶりの出題で楽しかったです。最初全部メモしてどうにも遅かったので回答をあきらめそうになりましたが純粋な再帰関数を作って呼ばれるパラメーターのダンプをみていたらメモする方法を思いつきました。ただの数え上げでは2時間くらいかかったけど、メモ化したら1秒以下になりました。 | |
let solve gems target = | |
let gems = List.ofSeq gems in | |
let target = List.ofSeq target in | |
let target_rev = target |> List.rev in | |
let memo = ref Map.empty in |
NewerOlder