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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
kagamiz
March 29, 2013
Programming
340
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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.4k
internship-middle term presentation
kagamiz
0
1.2k
すうがくのまほう
kagamiz
0
380
ご当地料理の紹介
kagamiz
0
500
オンラインジャッジシステムの実装
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
420
Other Decks in Programming
See All in Programming
Cloudflare is Agents
chimame
0
130
使用 Meilisearch 建立新聞搜尋工具
johnroyer
0
220
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
200
FDEが実現するAI駆動経営の現在地
gonta
2
260
言葉の格闘技のススメ~紙とペンと言葉から始める、キャリアの描き方~
progresscicada
1
120
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
330
仕様駆動開発の消費期限
watany
12
5.3k
為什麼你並不需要ViewModel / No, you don't need a ViewModel
lovee
1
480
torikago - Ruby::Boxで照らすモジュラモノリスの実行境界
se4weed
1
340
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
530
メールのエイリアス機能を履き違えない
isshinfunada
0
220
jsmini JavaScript Engine を作ってみた話
yosuke_furukawa
PRO
0
290
Featured
See All Featured
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
710
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
450
KATA
mclloyd
PRO
35
15k
How to Think Like a Performance Engineer
csswizardry
28
2.7k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
650
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
580
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
230
Ethics towards AI in product and experience design
skipperchong
2
340
Believing is Seeing
oripsolob
1
180
AI Search: Implications for SEO and How to Move Forward - #ShenzhenSEOConference
aleyda
1
1.3k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
What does AI have to do with Human Rights?
axbom
PRO
1
2.3k
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"); }