Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
AOJ 0186 Aizu Chicken 解説
Search
kagamiz
March 29, 2013
Programming
0
310
AOJ 0186 Aizu Chicken 解説
OkNCT-ICT 2013 春合宿 Day5(らしい) に解説したもの.
kagamiz
March 29, 2013
Tweet
Share
More Decks by kagamiz
See All by kagamiz
KCS v2. の開発
kagamiz
0
250
internship final presentation
kagamiz
0
1.3k
internship-middle term presentation
kagamiz
0
1.1k
すうがくのまほう
kagamiz
0
340
ご当地料理の紹介
kagamiz
0
420
オンラインジャッジシステムの実装
kagamiz
0
1.2k
AOJ 0022 Maximum Sum Sequence 解説
kagamiz
1
1.5k
AOJ 0557 A First Grader 解説
kagamiz
0
980
JOI2013 本選1 Illumination 解説
kagamiz
0
350
Other Decks in Programming
See All in Programming
Hack Claude Code with Claude Code
choplin
3
960
XP, Testing and ninja testing
m_seki
3
240
来たるべき 8.0 に備えて React 19 新機能と React Router 固有機能の取捨選択とすり合わせを考える
oukayuka
2
920
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
Team operations that are not burdened by SRE
kazatohiei
1
310
Flutterで備える!Accessibility Nutrition Labels完全ガイド
yuukiw00w
0
160
#kanrk08 / 公開版 PicoRubyとマイコンでの自作トレーニング計測装置を用いたワークアウトの理想と現実
bash0c7
1
710
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
760
明示と暗黙 ー PHPとGoの インターフェイスの違いを知る
shimabox
2
480
LINEヤフー データグループ紹介
lycorp_recruit_jp
1
2.4k
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
610
WebViewの現在地 - SwiftUI時代のWebKit - / The Current State Of WebView
marcy731
0
110
Featured
See All Featured
Unsuck your backbone
ammeep
671
58k
Java REST API Framework Comparison - PWX 2021
mraible
31
8.7k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
46
9.6k
Thoughts on Productivity
jonyablonski
69
4.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
60k
Adopting Sorbet at Scale
ufuk
77
9.4k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
Building a Modern Day E-commerce SEO Strategy
aleyda
42
7.4k
KATA
mclloyd
30
14k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
How to train your dragon (web standard)
notwaldorf
94
6.1k
Transcript
AOJ 0186 Aizu Chicken 解説 @kagamiz
問題概要 • ?????? • 問題文クソ難しいんだよね ... • 頑張って読む
問題概要 • あなたには予算が b 円あります . • 会津地鶏が 1 個
c1 円 , ふつうの鶏肉が 1 個 c2 円で 買える . • ただし , 会津地鶏は q2 個までしか買えない .
問題概要 • 鶏肉が足りなくなると困るので、 q1 個以上の鶏肉を買 う . • 予算の許す範囲で会津地鶏をできるだけ多く買う (
会津 地鶏は 1 個以上買わなければならない ). • 会津地鶏を買った残りでふつうの鶏肉をできるだけ多く 買う ( 予算が足りなければ買わない ).
アルゴリズムの考察 • 1. まず , できるだけ会津地鶏を買う . • 2. 残ったお金で普通の鶏肉を買う
. • 3. q1 個より多くなるまで , 会津地鶏を 1 個ずつ売りな がら普通の鶏肉を買う . • 4. 会津地鶏が 0 個になったら , お母さんの言う通りに 買えないので NA を出力する . そうじゃなければ個 数を出力 .
アルゴリズムの計算量 • “3. q1 個より多くなるまで , 会津地鶏を 1 個ずつ売り ながら普通の鶏肉を買う
." • これやばそう? • 実はそうでもない ( 各変数 ≦ 10^6 なので , ループは 最悪でも 10^6 しか繰り返されない .)
実☆装 • できるだけ " アルゴリズムの考察 " の項に素直に . – 複雑な事をするとバグります
実☆装 • 1. まず , できるだけ会津地鶏を買う . • 2. 残ったお金で普通の鶏肉を買う
. – aChick... 会津地鶏 bchick... 普通の鶏肉 aChick = min(b / c1, q2); b -= aChick * c1; bChick = max(0, b / c2); b -= bChick * c2;
実☆装 • 3. q1 個より多くなるまで , 会津地鶏を 1 個ずつ売りな がら普通の鶏肉を買う
. while (aChick + bChick < q1 && aChick){ b += c1; b += bChick * c2; bChick = b / c2; b -= bChick * c2; aChick--; }
実☆装 • 4. 会津地鶏が 0 個になったら , お母さんの言う通りに 買えないので NA
を出力する . そうじゃなければ個 数を出力 . if (aChick){ printf("%d %d\n", aChick, bChick); } else { printf("NA\n"); }