P3090 [USACO13NOV]空荡荡的摊位Empty Stalls

    • 182通过
    • 508提交
  • 题目提供者 FarmerJohn2
  • 评测方式 云端评测
  • 标签 动态规划,动规,dp 状态压缩,状压 USACO 2013 高性能
  • 难度 普及+/提高
  • 时空限制 1000ms / 128MB


  • 提示:收藏到任务计划后,可在首页查看。
  • 最新讨论 显示

    推荐的相关题目 显示


    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 to this question does not depend on the order in which the cows return to the barn.

    In order to avoid issues with reading huge amounts of input, the input to this problem is specified in a concise format using K lines (1 <= K <= 10,000) each of the form:

    X Y A B

    One of these lines 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.

    约翰的谷仓中有N(2 <= N <=3,000,000)个房间,编号0到N-1,这些房间排布成环状,编号0的和编号N-1的相邻。



    为避免输入内容过多。本题的输入数据采用一种简洁的方式:一共K(1 <= K <=10,000)行,每行格式如下:

    X Y A B

    表示有Y批奶牛,每批X头,也就是总共X*Y只奶牛喜欢的房间号。Y批奶牛编号1到Y,第i批X头奶牛喜欢的房间号为(A*i+B) Mod N.





    * 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.


    * Line 1: The minimum index of an unoccupied stall.


    输入样例#1: 复制
    10 3 
    3 2 2 4 
    2 1 0 1 
    1 1 1 7 
    输出样例#1: 复制


    There are 10 stalls in the barn, numbered 0..9. The second line of input states that 3 cows prefer stall (2*1+4) mod 10 = 6, and 3 cows prefer stall (2*2+4) mod 10 = 8. The third line states that 2 cows prefer stall (0*1+1) mod 10 = 1. Line four specifies that 1 cow prefers stall (1*1+7) mod 10 = 8 (so a total of 4 cows prefer this stall).

    All stalls will end up occupied except stall 5.