No older revisions available
No older revisions available
4301786 2006-02-02 05:29:25 Accepted 0.023 Minimum 28565 C++ 10233 - Dermuba Triangle
~cpp #include <iostream> #include <math.h> using namespace std; void process(int num1, int num2) { cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint); cout.precision(3); double num1_x, num1_y, num2_x, num2_y, height = sqrt(3)/2, temp; int i; for(i = 0; num1 - i > 0; i +=2) { num1 -= i; if(i == 0) i++; } i /= 2; if(i != 0) num1 -= i + 1; else num1 = 0; num1_x = num1 *0.5; temp = i; if(i !=0) { num1_y = height*(temp-1.0/3.0); if((i + num1)%2 == 0) num1_y += height/3; } else num1_y = 0; for(i = 0; num2 - i > 0; i +=2) { num2 -= i; if(i == 0) i++; } i /= 2; if(i != 0) num2 -= i + 1; else num2 = 0; num2_x = num2 *0.5; temp = i; if(i !=0) { num2_y = height*(temp-1.0/3.0); if((i + num2)%2 == 0) num2_y += height/3; } else num2_y = 0; num1_x -= num2_x; num1_y -= num2_y; cout << sqrt(pow(num1_x,2) + pow(num1_y,2)) << endl; } int main() { // cout << sqrt(pow(sqrt(3)*5/6,2) + 0.25); int num1, num2; while(cin >> num1 >> num2) process(num1,num2); return 0; }