标签:
http://acm.hdu.edu.cn/showproblem.php?pid=4710
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 735 Accepted Submission(s): 305
分析:
模拟,每次增加 step ,一次可以放一块。
AC代码:
1 #include<iostream> 2 #include<stdio.h> 3 #include<math.h> 4 #define min(a,b) a>b?b:a 5 using namespace std; 6 int main() 7 { 8 int T,n,a,b; 9 cin>>T; 10 while(T--) 11 { 12 cin>>n>>a>>b; 13 if(a==b) 14 printf("0\n"); 15 else 16 { 17 __int64 ans=0,step=1,i; 18 for(i=0;i<n;i=i+step) 19 { 20 int stepa=a-i%a; 21 int stepb=b-i%b; 22 step=min(stepa,stepb); 23 __int64 dis=abs(i%a-i%b); 24 if(i+step>=n) 25 dis=dis*(n-i); 26 else 27 dis=dis*step; 28 ans=ans+dis; 29 } 30 printf("%I64d\n",ans); 31 } 32 } 33 return 0; 34 }
hduoj 4710 Balls Rearrangement 2013 ACM/ICPC Asia Regional Online —— Warmup
标签:
原文地址:http://www.cnblogs.com/jeff-wgc/p/4467570.html