Simulation
Authors: Darren Yao, Allen Li
Directly simulating the problem statement, which many Bronze problems allow you to do.
Resources | |||
---|---|---|---|
IUSACO | This module is based on Chapter 5 of Darren Yao's book |
Since there's no formal algorithm involved, the intent of the problem is to assess competence with one's programming language of choice and knowledge of built-in data structures. At least in USACO Bronze, when a problem statement says to find the end result of some process, or to find when something occurs, it's usually sufficient to simulate the process naively.
Example 1
Statement
Alice and Bob are standing on a 2D plane. Alice starts at the point , and Bob starts at the point (). Every second, Alice moves units to the right, and units up. Every second, Bob moves units to the left, and units down. (). Determine if Alice and Bob will ever meet (be at the same point at the same time), and if so, when.
Input Format
The first line of the input contains and .
The second line of the input contains , , , and .
Output Format
Please output a single integer containing the number of seconds after the start at which Alice and Bob meet. If they never meet, please output .
Solution
Solution
Example 2
Statement
There are buckets (), each with a certain capacity (). One day, after a rainstorm, each bucket is filled with units of water (). Charlie then performs the following process: he pours bucket into bucket , then bucket into bucket , and so on, up until pouring bucket into bucket . When Charlie pours bucket into bucket , he pours as much as possible until bucket is empty or bucket is full. Find out how much water is in each bucket once Charlie is done pouring.
Input Format
The first line of the input contains .
The second line of the input contains the capacities of the buckets, .
The third line of the input contains the amount of water in each bucket .
Output Format
Please print one line of output, containing space-separated integers: the final amount of water in each bucket once Charlie is done pouring.
Solution
Solution
Problems
Easier
Status | Source | Problem Name | Difficulty | Tags | Solution |
---|---|---|---|---|---|
Bronze | Easy | Show TagsNested Loop | External Sol | ||
Bronze | Easy | Show TagsSingle Loop | External Sol | ||
Bronze | Easy | Show TagsNested Loop | External Sol | ||
Bronze | Easy | Show TagsSingle Loop | External Sol | ||
Bronze | Easy | External Sol |
Harder
Status | Source | Problem Name | Difficulty | Tags | Solution |
---|---|---|---|---|---|
Bronze | Normal | ||||
Bronze | Normal | ||||
Bronze | Normal | External Sol | |||
Bronze | Normal | ||||
Bronze | Normal | ||||
Bronze | Hard | External Sol | |||
Bronze | Hard |