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
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
kagamiz
March 29, 2013
Programming
330
0
Share
AOJ 0186 Aizu Chicken 解説
OkNCT-ICT 2013 春合宿 Day5(らしい) に解説したもの.
kagamiz
March 29, 2013
More Decks by kagamiz
See All by kagamiz
KCS v2. の開発
kagamiz
0
290
internship final presentation
kagamiz
0
1.3k
internship-middle term presentation
kagamiz
0
1.2k
すうがくのまほう
kagamiz
0
380
ご当地料理の紹介
kagamiz
0
490
オンラインジャッジシステムの実装
kagamiz
0
1.2k
AOJ 0022 Maximum Sum Sequence 解説
kagamiz
1
1.6k
AOJ 0557 A First Grader 解説
kagamiz
0
1k
JOI2013 本選1 Illumination 解説
kagamiz
0
400
Other Decks in Programming
See All in Programming
Making the RBS Parser Faster
soutaro
0
690
ソースコード→AST→オペコード、の旅を覗いてみる
o0h
PRO
1
130
決定論 vs 確率論:Gemini 3 FlashとTF-IDFを組み合わせた「法規判定エンジン」の構築
shukob
0
160
いつか誰かが、と思っていた フロントエンド刷新5年間の実践知
kiichisugihara
1
270
サークル参加から学ぶ、小さな事業の回し方
yuzneri
0
160
AI時代だからこそ「Bloc」を採用する価値があるのかもしれない
takuroabe
0
150
Liberating Ruby's Parser from Lexer Hacks
ydah
2
2.7k
実践ハーネスエンジニアリング:ステアリングループを実例から読み解く / Practical Harness Engineering: Understanding Steering Loops Through Real-World Examples
nrslib
5
5.1k
Road to RubyKaigi: Play Hard(ware)
makicamel
1
560
Symfony AI in Action - SymfonyLive Berlin 2026
chr_hertel
1
140
How We Benchmarked Quarkus: Patterns and anti-patterns
hollycummins
1
190
mruby on C#: From VM Implementation to Game Scripting (RubyKaigi 2026)
hadashia
2
1.7k
Featured
See All Featured
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Docker and Python
trallard
47
3.8k
Faster Mobile Websites
deanohume
310
31k
What does AI have to do with Human Rights?
axbom
PRO
1
2.1k
Sam Torres - BigQuery for SEOs
techseoconnect
PRO
0
260
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
230
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.6k
The Organizational Zoo: Understanding Human Behavior Agility Through Metaphoric Constructive Conversations (based on the works of Arthur Shelley, Ph.D)
kimpetersen
PRO
0
320
The Language of Interfaces
destraynor
162
26k
Typedesign – Prime Four
hannesfritz
42
3k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
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"); }