博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 4710 Balls Rearrangement
阅读量:6235 次
发布时间:2019-06-22

本文共 1264 字,大约阅读时间需要 4 分钟。

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://dzqna.baihongyu.com/

你可能感兴趣的文章
多说评论一次导回 Typecho 本地数据库
查看>>
TechEd 2011微软技术大会热门课程曝光
查看>>
分布式锁之Redis实现
查看>>
【解惑】领略内部类的内部
查看>>
PHP的autoload机制的实现解析
查看>>
献给未来的自己
查看>>
MySQL:远程登录
查看>>
Oracle事务和常用数据对象
查看>>
Linux:xterm基本配置
查看>>
windows、mac桌面录制GIF
查看>>
Android应用Context详解及源码解析
查看>>
jquery采用JS实现高度自适应问题
查看>>
Ubuntu搭建nexus oss3.0私服
查看>>
学会透过现象看本质,即使现象有时候挺诡异
查看>>
oracle数据库的字符集更改
查看>>
让代码飞起来——高性能Julia学习笔记(一)
查看>>
慢连接***的原理和防范
查看>>
windows client连linux下的oracle server,ORA-12560: TNS: 协议适配器错误 一例
查看>>
Oracle物化视图之on prebuilt table
查看>>
radioButton空指针
查看>>