标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 7539 Accepted Submission(s):
2914
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 using namespace std; 6 int abs(int a) 7 { 8 return a>0?a:-a; 9 } 10 int main() 11 { 12 int n,m,i,j,cm,cn,rm,rn,lm,ln; 13 while(~scanf("%d%d",&m,&n)) 14 { 15 cm=(int)ceil(sqrt(m));//ceil为向上取整函数“math.h” 16 cn=(int)ceil(sqrt(n)); 17 rm=(m-(cm-1)*(cm-1)-1)/2+1; 18 rn=(n-(cn-1)*(cn-1)-1)/2+1; 19 lm=(cm*cm-m)/2+1; 20 ln=(cn*cn-n)/2+1; 21 int sum=(int)abs(cm-cn)+abs(rm-rn)+abs(lm-ln); 22 printf("%d\n",sum); 23 } 24 return 0; 25 }
标签:
原文地址:http://www.cnblogs.com/pshw/p/5351630.html