先算出lcm(a,b),如果lcm>=n,则直接暴力解决:否则分段,求出0-lcm内的+0-n%lcm内的值. 再就是连续相同的一起计算!! #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #include<s…
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 322    Accepted Submission(s): 114 Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and n…
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 25    Accepted Submission(s): 8 Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and numbe…
http://acm.hdu.edu.cn/showproblem.php?pid=4710 Balls Rearrangement Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 735    Accepted Submission(s): 305 Problem Description Bob has N balls and A b…
Integer Partition Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 524 Accepted Submission(s): 238 Problem Description Given n, k, calculate the number of different (unordered) partitions of n such…
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 954 Accepted Submission(s): 545 Problem Description How many ways can the numbers 1 to 15 be added together to make 15? The technical term…
ACM ICPC Central Europe Regional Contest 2013 Jagiellonian University Kraków Problem A: Rubik’s RectangleProblem B: What does the fox say?Problem C: Magical GCDProblem D: SubwayProblem E: EscapeProblem F: DraughtsProblem G: History courseProblem H: C…
Partition Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 954 Accepted Submission(s): 545 Problem Description How many ways can the numbers 1 to 15 be added together to make 15? The technical term…
HDU 4611 Balls Rearrangement 令lcm=LCM(a,b),gcd=GCD(a,b).cal(n,a,b)表示sum(abs(i%a-i%b)),0<=i<n. 显然,答案就是cal(lcm,a,b)*(n/lcm)+cal(n%lcm,a,b). cal(n,a,b)可以通过暴力得到,即对i%a和i%b的值分段,连续的一段(遇到0终止)可以直接得到值. 因此,每段的长度将直接影响到时间复杂度. 当lcm较小时,cal中的n不会很大,即使每段长度很小也无所谓. 当lc…
HDU-4611 Balls Rearrangement 题意:具体题意不大清楚,最后要处理一个这样的表达式:sum{ |i % a - i % b| },0 <= i < N 的取值很大,a.b均小于10^5. 分析:观察|i % a|和|i % b|可以发现其均为被模数的一个滚动剩余系,且中间的某些段的值是恒定的.再注意到其实处理到a和b的最小公倍数的时候又可以把最小公倍数循环的部分处理出来.我的做法就是维护好两个数,分别表示a和b两边谁出现最进出现 i % a 或者是 i % b 等于0…