hdu4611 Balls Rearrangement】的更多相关文章

Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1682 Accepted Submission(s): 634 Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and number…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4611 先求出循环节,然后比较A和B的大小模拟过去... //STATUS:C++_AC_15MS_436KB #include <functional> #include <algorithm> #include <iostream> //#include <ext/rope> #include <fstream> #include <sstr…
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…
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 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4611 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…
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…
Balls Rearrangement Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 945    Accepted Submission(s): 380 Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and n…
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, a…
http://acm.hdu.edu.cn/showproblem.php?pid=4611 从A中向B中移动和从B中向A中移动的效果是一样的,我们假设从B中向A中移动 而且A>B 我们先求出所有在B[0]上的点移动到A上的分布情况 可以求出花费 当我们要求B[1]上的点移动到A上的分布情况时 相当于B[0]在A上的分布情况水平右移一个单位 由于B[1]点对于B[0]也向后移动了一个单位 所有相对位置没有移动 但是A中有一个地方需要改动 那就是每次A中最后一个位置的点需要移动到A[0]位置(因为…
先算出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…
http://acm.hdu.edu.cn/showproblem.php?pid=4710 [code]: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; #define N 1000151 ]; ]; ]; ]; ; int lowbit(int i) { return i&-i; } void add(i…
以前好像是在UVa上貌似做过类似的,mod的剩余,今天比赛的时候受baofeng指点,完成了此道题 此题题意:求sum(|i%A-i%B|)(0<i<N-1) A.B的循环节不同时,会有重叠,重叠后的区间里的数的值相等(可以证明,这里不给出了),然后压缩区间端点值,直接求区间和即可 #include <iostream> #include <stdio.h> #include <string.h> #include <math.h> #inclu…
题意就不说了,刚开始做我竟然傻傻地去模拟,智商捉急啊~~超时是肯定的 求出 a ,b 的最小公倍数,因为n够长的话,就会出现循环,所以就不要再做不必要的计算了.如果最小公倍数大于n的话,就直接计算n吧. 除了可以应用循环来节省计算,还可以成段计算来节省. #include<stdio.h> #include<string.h> #define i64 __int64 i64 abs(i64 x) { ) return -x; return x; } i64 gcd(i64 a,i6…
这个公倍数以后是循环的很容易找出来,然后循环以内的计算是打表找的规律,规律比较难表述,自己看代码吧.. #include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; long long n,a,b; long long lcd(int a,int b) { long long ret=a; ret*=b; int tmp; whil…
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4611 题意:给你一个N.A.B,要你求 AC代码: #include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cstdlib> #include <cmath> #include <vector> #include…
意甲冠军:那是,  从数0-n小球进入相应的i%a箱号.然后买一个新的盒子. 今天的总合伙人b一个盒子,Bob试图把球i%b箱号. 求复位的最小成本. 每次移动的花费为y - x ,即移动前后盒子编号的差值的绝对值. 算法: 题目就是要求                  watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMjg0MTg0NQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissol…
题意:求∑|i%a-i%b|,0≤i<n 思路:复杂度分析比较重要,不细想还真不知道这样一段段跳还真的挺快的=.= 令p=lcm(a,b),那么p就是|i%a-i%b|的循环节.考虑计算n的答案,令答案为f(n),则最后的结果可以表示为n/p*f(p)+f(n%p) 考虑计算f(n),设两个指针i.j,表示当前累加答案的起始位置分别对a和b取模的结果,则每次i与j中间的一个可以变成0,跳过的一段区间中答案是相同的. 复杂度分析,令a<b,则每次跳过的区间长度近似等于a,则总的复杂度为O(n/a…
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…
Balls Rearrangement Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 1661    Accepted Submission(s): 627 Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and…
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…
1003 Rotation Lock Puzzle 找出每一圈中的最大值即可 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> #define ll __int64 #define pi acos(-1.0) #…
Balls Rearrangement Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 344    Accepted Submission(s): 165 Problem Description Bob has N balls and A boxes. He numbers the balls from 0 to N-1, and n…
C. Kyoya and Colored Balls Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d      Java class name: (Any) Submit Status Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labele…
今天讨论的是称球问题. No.3 13 balls problem You are given 13 balls. The odd ball may be either heavier or lighter. Find out the odd ball in 3 weightings. 分析与解答: 看到这道题,就想起来高中时候数学老师的一句话:“真正难的题不是那些很长的题,而是那些就几句话的题!!!”现在想想真是良训啊.又想到很多老师的话,感觉到失去方显弥足珍贵的名言,不禁唏嘘啊…… 有人认为…
C16H:Magical Balls 总时间限制:  1000ms 内存限制:  262144kB 描述 Wenwen has a magical ball. When put on an infinite plane, it will keep duplicating itself forever. Initially, Wenwen puts the ball on the location (x0, y0) of the plane. Then the ball starts to dup…
Dragon Balls Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2909    Accepted Submission(s): 1125 Problem Description Five hundred years later, the number of dragon balls will increase unexpecte…
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9641 Accepted: 2636 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share the…
Labeling Balls Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 11893 Accepted: 3408 Description Windy has N balls of distinct weights from 1 unit to N units. Now he tries to label them with 1 to N in such a way that: No two balls share the…
 Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Description 题目描述 Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he thr…
C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from…