惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
C
CERT Recently Published Vulnerability Notes
C
Cisco Blogs
Cloudbric
Cloudbric
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Application and Cybersecurity Blog
Application and Cybersecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
V2EX - 技术
V2EX - 技术
H
Heimdal Security Blog
S
Security Affairs
L
Lohrmann on Cybersecurity
Hacker News - Newest:
Hacker News - Newest: "LLM"
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
小众软件
小众软件
Security Latest
Security Latest
AWS News Blog
AWS News Blog
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
Engineering at Meta
Engineering at Meta
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
F
Full Disclosure
S
Schneier on Security
L
LangChain Blog
MyScale Blog
MyScale Blog
Know Your Adversary
Know Your Adversary
P
Privacy International News Feed
Google Online Security Blog
Google Online Security Blog
Scott Helme
Scott Helme
Stack Overflow Blog
Stack Overflow Blog
爱范儿
爱范儿
A
Arctic Wolf
Martin Fowler
Martin Fowler
B
Blog RSS Feed
大猫的无限游戏
大猫的无限游戏
博客园 - 三生石上(FineUI控件)
The Register - Security
The Register - Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
博客园_首页
Latest news
Latest news
F
Fortinet All Blogs
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
Hacker News: Ask HN
Hacker News: Ask HN

hayato

Chromium's DOM Deep Dive: Understanding Shadow DOM and Tree Structures - hayato Introducing the Task Scheduler in Chromium's Network Stack: A 0.3% Improvement in Loading Speed - hayato 出版のお知らせ 「普通の人が資産運用で99点をとる方法とその考え方」 - hayato Resource loading with Content Addressable Bundles - hayato 普通の人が資産運用で99点をとる方法とその考え方 - hayato Imperative Shadow DOM Distribution API - hayato Google にソフトウェアエンジニアとして入社して 10 年と 10 日がたちました - hayato Web のつくりかた: ソフトウェアエンジニアリングと雰囲気で理解する Web 標準とブラウザのつくりかた - hayato ブラウザのしくみ: データ構造とアルゴリズムと雰囲気で理解する DOM と Shadow DOM - hayato Rust が最強のプログラミング言語である証明 - hayato 六本木ではたらくソフトウェアエンジニアへのよくある質問とその答え (FAQ) (2015 - 2017) - hayato What's New in Shadow DOM v1 (by examples) - hayato Simple timer application for the pomodoro technique - hayato Google の面接試験で出る (はずがない)「海賊と金貨」問題を空気を読まないでプログラムで解いてみる - hayato hayato.io (4topcoder) - hayato SRM432 - hayato SRM405 - hayato SRM386 - hayato SRM385 - hayato SRM384 - ゲーム - hayato SRM369 - hayato SRM368 - hayato SRM366 - typo 2 連発 - hayato Python - generator で素数生成 - hayato New Launguage - 新言語追加の予定? - hayato lxml で HTML スクレーピング - hayato SRM358 - Today is a Bad Day (-50). - hayato SRM349 FizzBuzz 問題が簡単すぎるそんなあなたへ。「赤いマーブル問題」。 - hayato Suffix Array - hayato google-code-prettify を導入してみる - hayato Subset の生成 - hayato 2006 年のまとめ - SRM332 - hayato Google Code Jam 2006 - Championship Round - hayato Blogger Beta に移行 - hayato Google Code Jam 2006 - Round1 に挑戦 - Generics と AutoBoxing - hayato Google Code Jam 2006 - Qualification Round 通過 - hayato Google Code Jam 2006 - Qualification Round に挑戦 - hayato Google Code Jam 2006 - Practice1 - hayato Google Code Jam 2006 - 開催決定 - hayato Stay tuned... Global Google Code Jam 2006 - 秋に開催? - hayato SRM308 - Hard DP - hayato SRM304 - 条件付確率 - hayato JavaWorld に寄稿しました - hayato 2006 TopCoder Open Final Round - hayato IBM Rational Software Development Forum Tokyo で講演します - hayato SRM298 - ひとふで書き - hayato SRM293 - ビンゴ - hayato 2006 TopCoder Open - Round1 撃墜 - hayato 2006 TopCoder Open - Odds 発表 - hayato 2006 TopCoder Open Qualification Round - hayato SRM291 - OutOfMemory - hayato デブサミ 2006 で講演します - hayato SRM287 - 気分は中学生?連立2元方程式 - hayato SRM281 - 2006 年はポイントゼロスタート - hayato SRM280 - Challenge 祭り - hayato SRM277 - 初賞金げっと - hayato マラソン・マッチ - hayato reStructuredText で blogger - hayato 2006 TopCoder Open - NSA がスポンサーに - hayato SRM273 - bit 演算は int で行われるのね - hayato SRM272 - Division1 - 4 度目の正直 - hayato JavaOne Tokyo で講演します - hayato SRM270 - Integer == Integer - hayato SRM268 - Division2 脱出 - hayato SRM266 - NASA, we have a problem... - hayato SRM265 - Division2 落ち... - hayato SRM262 - 初 Division1 は Typo に終わる - hayato SRM260 - TopCoder への挑戦のはじまり - hayato
SRM276 - お買い物は楽しく DP で - hayato
2005-12-08 · via hayato

SRM276 に挑戦.かなーり,眠かったので,スルーしようかと思ったのですが,挑戦しました.

250 点問題. お買い物です.たとえば,

  • 1 個なら 4$
  • 3 個まとめて買うと 10$
  • 20 個まとめて買うと 48$

だったとします.50 個,買いたいとします.最低何$ですむか?という問題です. この例だと

20 個 x 2 + 3 個 x 3 + 1 個 x 1= 50 個 (48$ x 2 + 10$ x 3 + 4$ x 1 = 130$)

がベストな買い方で,答えは 130 です.しかし,50 個ではなく,55 個買いたいとすると,ベストな買い方は

20 個 x 2 + 3 個 x 5 = 55 個 (48$ x 2 + 10$ x 5 = 146$)

ではなく

20 個 x 3 = 60 個 ( 48$ x 3 = 144$)

です.答えは,144 になります. SRM 中は,入力条件が緩いので Brute-Force で十分いけると思って Submit しました.チャレンジタイムでは,Memoization なしの Brute-Force ではタイムアウトすると思われたのか, 2 回チャレンジをうけました.チャレンジで使用された入力は

SRM276 Challenge

と明らかに 2 秒タイムオーバー狙いです.チャレンジタイム後に,チャレンジしてきた人に質問されました. 2 秒以内に終わったのが,信じられなかったようです.

SRM276 Chat

その後, HiltonLange さんには,さらに

{"51 1","1 99"}, 99 だと,失敗するんじゃない?

と指摘されました.そのとおりです.この入力だと 51 個 x2=101 個,2 ドルが正解ですが,Submit した Code では

for (int i = 0; q + i * unit[n] < 100; i++) {

このように上限を 100 にしていたため,51 x 1 + 99 * 48 = 4803 ドルを出力していまいます. 上限は,最低 200 じゃないと.System Test に落ちますね...

for (int i = 0; q + i * unit[n] < 200; i++) {

このように上限 200 にしておくと,2 秒近くかかりますが,なんとか System Test に通っていました.それでも無駄だらけなので,無駄をなくすと共に,Memoization を併用すれば,劇的に早くなります.以下のようになります.

int go(int q, int n) {
   if (n == N) {
       if (q < quantity) return 1000000;
       return 0;
   }
   if (cache[q][n] != 0) return cache[q][n];
   int min = Integer.MAX_VALUE;
   for (int i = 0;; i++) {
       min = Math.min(min, cost[n] * i + go(q + unit[n] * i, n+1));
       if (q + i * unit[n] >= quantity) break;
   }
   return cache[q][n] = min;
}

この手の問題は,やはり DP(Dynamic Programming)を使うのが常套手段でしたね. SRM 後に書いてみました.

public int bestDeal(String[] priceList, int quantity) {
    int N = priceList.length;
    int[] unit = new int[N];
    int[] cost = new int[N];
    for (int i = 0; i < N; i++) {
        unit[i] = Integer.parseInt(priceList[i].split(" ")[0]);
        cost[i] = Integer.parseInt(priceList[i].split(" ")[1]);
    }

    int[] best = new int[300];
    Arrays.fill(best, Integer.MAX_VALUE);
    best[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < quantity; j++) {
            if (best[j] != Integer.MAX_VALUE) {
                if (best[j] + cost[i] < best[j + unit[i]]) {
                    best[j+unit[i]] = best[j] + cost[i];
                }
            }
        }
    }

    int min = Integer.MAX_VALUE;
    for (int i = quantity; i < quantity + 100; i++) {
        min = Math.min(min, best[i]);
    }
    return min;
}

ほとんどの人は,さくっと躊躇することなく DP を使用していました.さすが,Division1.

500 点問題. レーシングカーの試験走行をします.ただし,時間帯により制限速度の条件がいくつか与えられます.

  • [5 秒から 10 秒の間は,10 m/s 以上スピードを出してはいけない ]
  • [15 秒から 20 秒の間は,15 m/s 以上スピードを出してはいけない ]
  • [30 秒から 40 秒の間は,5 m/s 以上スピードを出してはいけない ]

というふうにです. 入力として

  • レーシングカーの加速度 a (m / s^2 ) (減速度(?) も兼ねています.)
  • 試験走行の時間 (duratation) が与えられます.

この条件のもとで,レーシングカーが出せる最高速度はいくつになるかという問題です. SRM 中は,途中で方針が間違っていたことことにきずき,お手上げでした.(つぎのつぎの制限速度の変更を考慮していなかったため減速が間に合わない.)

1000 点問題. Open しませんでした.

結果

System Test の結果です. ( Room Statistics )

Room Statistics

レーティングは低下.今日は,敗北感が強いな..

今日の教訓

  • DP をちゃんとマスターしておく