Empty Stalls
의견: 0
Farmer John's new barn consists of a huge circle of N stalls (2 <= N <= 3,000,000), numbered 0..N-1, with stall N-1 being adjacent to stall 0.
At the end of each day, FJ's cows arrive back at the barn one by one, each with a preferred stall they would like to occupy. However, if a cow's preferred stall is already occupied by another cow, she scans forward sequentially from this stall until she finds the first unoccupied stall, which she then claims. If she scans past stall N-1, she continues scanning from stall 0.
Given the preferred stall of each cow, please determine the smallest index of a stall that remains unoccupied after all the cows have returned to the barn. Notice that the answer does not depend on the order in which the cows return.
In order to avoid huge input, the input is specified concisely using K lines (1 <= K <= 10,000) each of the form "X Y A B": this specifies the preferred stall for XY total cows: X cows prefer each of the stalls f(1) .. f(Y), where f(i) = (Ai + B) mod N. The values of A and B lie in the range 0...1,000,000,000.
Do not forget the standard memory limit of 64MB for all problems.
Line 1: Two space-separated integers: N and K.
Lines 2..1+K: Each line contains integers X Y A B, interpreted as above. The total number of cows specified by all these lines will be at most N-1. Cows can be added to the same stall by several of these lines.
The minimum index of an unoccupied stall.
empty.inempty.out10 3
3 2 2 4
2 1 0 1
1 1 1 75Output details: All stalls end up occupied except stall 5.
riseoj 작성
출처 올림피아드 > USACO > 2013-2014 > November > Gold
평가 및 의견
Empty Stalls
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
Empty Stalls