杭电1030 http://acm.hdu.edu.cn/showproblem.php?pid=1030
AC代码:
#include<iostream>
#include<cmath>
using namespace std;
const int MAXN = 1e5 + 10;
int a[MAXN],t[MAXN],b[MAXN];
int n,m;
int a1,a2,a3;
int b1,b2,b3;
int ans;
int main() {while(cin >> n >> m){a1 = sqrt(n - 1) + 1;a2 = (n - (a1 -1) * (a1 -1) + 1 )/2;a3 = (fabs(n - a1 * a1) + 2) / 2;b1 = sqrt(m - 1) + 1;b2 = (m -(b1 -1) * (b1 -1) + 1 )/2;b3 = (fabs(m - b1 * b1) + 2) / 2;ans = fabs(a1 - b1) + fabs(a2 - b2) + fabs(a3 - b3);cout << ans << endl;}return 0;
}