zoukankan      html  css  js  c++  java
  • HDU 4710 Balls Rearrangement

    Balls Rearrangement

    Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 93    Accepted Submission(s): 35


    Problem Description
    Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and numbers the boxes from 0 to A-1. To find the balls easily, he puts the ball numbered x into the box numbered a if x = a mod A.
    Some day Bob buys B new boxes, and he wants to rearrange the balls from the old boxes to the new boxes. The new boxes are numbered from 0 to B-1. After the rearrangement, the ball numbered x should be in the box number b if x = b mod B.
    This work may be very boring, so he wants to know the cost before the rearrangement. If he moves a ball from the old box numbered a to the new box numbered b, the cost he considered would be |a-b|. The total cost is the sum of the cost to move every ball, and it is what Bob is interested in now.
     
    Input
    The first line of the input is an integer T, the number of test cases.(0<T<=50)
    Then T test case followed. The only line of each test case are three integers N, A and B.(1<=N<=1000000000, 1<=A,B<=100000).
     
    Output
    For each test case, output the total cost.
     
    Sample Input
    3 1000000000 1 1 8 2 4 11 5 3
     
    Sample Output
    0 8 16
     
    Source
     
    Recommend
    liuyiding
     

    多校2的原题

    移步:

    http://www.cnblogs.com/kuangbin/p/3214791.html

  • 相关阅读:
    Linux下安装Mysql
    mssql 查询效率
    查看apache是否安装及版本
    centos(linux)切换用户
    mysql操作命令(linux)
    远程连接MySql连不上1130
    JAVA环境配置
    SQLSERVER2012数据库还原
    ASP连接ACCESS数据库
    ODOO 常用widget
  • 原文地址:https://www.cnblogs.com/kuangbin/p/3308691.html
Copyright © 2011-2022 走看看