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
290
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
400
オンラインジャッジシステムの実装
kagamiz
0
1.2k
AOJ 0022 Maximum Sum Sequence 解説
kagamiz
1
1.5k
AOJ 0557 A First Grader 解説
kagamiz
0
970
JOI2013 本選1 Illumination 解説
kagamiz
0
340
Other Decks in Programming
See All in Programming
ビカム・ア・コパイロット
ymd65536
1
180
イベントソーシングとAIの親和性ー物語とLLMに理解できるデータ
tomohisa
0
150
データと事例で振り返るDevin導入の"リアル" / The Realities of Devin Reflected in Data and Case Studies
rkaga
3
3.1k
Proxmoxをまとめて管理できるコンソール作ってみました
karugamo
1
360
Boast Code Party / RubyKaigi 2025 After Event
lemonade_37
0
120
マイコンでもRustのtestがしたい/KernelVM Kansai 11
tnishinaga
1
980
2025年のz-index設計を考える
tak_dcxi
13
5.1k
マテリアルって何者?RealityKitで扱うマテリアル入門
nao_randd
0
130
最速Green Tea 🍵 Garbage Collector
kuro_kurorrr
1
170
コンポーネントライブラリで実現する、アクセシビリティの正しい実装パターン
schktjm
1
450
TypeScript だけを書いて Tauri でデスクトップアプリを作ろう / Tauri with only TypeScript
tris5572
2
410
TypeScript Language Service Plugin で CSS Modules の開発体験を改善する
mizdra
PRO
3
1.4k
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
23
1.6k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
137
33k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
34
3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.7k
Writing Fast Ruby
sferik
628
61k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
357
30k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
Raft: Consensus for Rubyists
vanstee
137
6.9k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.8k
Bash Introduction
62gerente
613
210k
Being A Developer After 40
akosma
91
590k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
248
1.3M
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"); }