1 / 6

HKOI 2014 Junior

HKOI 2014 Junior. Magic Stone Problem Prepared By Sampson Lee. Problem. Given four operation Type Ti = 1: Buy Ai magic stones. Type Ti = 2: The system gives you Ai magic stones. Type Ti = 3: Dr. Jones uses Ai magic stones.

chidi
Download Presentation

HKOI 2014 Junior

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. HKOI 2014 Junior Magic Stone Problem Prepared By Sampson Lee

  2. Problem • Given four operation • Type Ti = 1: Buy Ai magic stones. • Type Ti = 2: The system gives you Ai magic stones. • Type Ti = 3: Dr. Jones uses Ai magic stones. • Type Ti = 4: Query: Among the magic stones Dr. Jones currently has, at most how many of them were bought? And at least how many of them were bought? • Simulate the above process

  3. Observation • At most how many of them were bought? • If we always use the stones system gave us, it must be the best way to preserve the stones that were bought • At least how many of them were bought? • If we always use the stones that were bought, it must be the best way to preserve the stones that were given by the system

  4. Solution • Maintain four variables, namely p, q, r, s • p : number of stones given by the system if we always use the stones given by the system first • q : number of stones bought if we always use the stones given by the system first • r: number of stones given by the system if we always use the stones we bought first • s : number of stones bought if we always use the stones we bought first

  5. Solution • How to maintain? • Type Ti = 1: add Ai to q and s • Type Ti = 2: add Ai to p and r • Type Ti = 3: • Subtract Ai from p and s until there are no stone within, and subtract the residue stone from r and q • Type Ti = 4: Output q and r

  6. END

More Related