ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1308. Dean's Pyramid

Please, give me anyone idea, my prog always WA11!!!
Posted by xurshid_n 3 Apr 2010 23:18
here my code
#include<stdio.h>
#include<math.h>
#define R  1.3660254037844
#define R2 2.7320508075689
#define PI 3.1415926535898
#define H  2.3660254037844

double xShift[] = {R2, R, -R, -R2, -R, R };
double yShift[] = {0, H, H, 0, -H, -H};

double dist(double x1, double y1, double x2, double y2){
    x2 -= x1 ;
    y2 -= y1 ;
    return sqrt(x2*x2 + y2*y2);
}
double calc(double xUse, double yUse){
    int i,j,k;
    double x, y, L, RadiusI, alpha;
    double mL = 1000;//dist( 0, 0, xUse+R, yUse);
    for (k = 0; k<6;k++){
            L = dist(xUse, yUse, xShift[k]/2.0, yShift[k]/2.0);
            mL = (mL<L)?mL:L;
    }

    for (i = 1; i<10;i++){
        RadiusI = R2*i;
        alpha = PI/3.0/i;
        for (j = 0; j<6*i;j++){
            x = RadiusI * cos(alpha * j ) ;
            y = RadiusI * sin(alpha * j ) ;

            for (k = 0;k<6;k++){
                L = dist(xUse, yUse, xShift[k]/2.0 + x, yShift[k]/2.0+y);
                mL = (mL<L)?mL:L;
            }
        }
    }
    return mL;
}
int main(){

    double xCenter , yCenter;
    scanf("%lf",&xCenter);
    scanf("%lf",&yCenter);

    xCenter = fabs(xCenter);
    yCenter = fabs(yCenter);

    double L1 = calc(xCenter - R, yCenter);
    double L2 = calc(yCenter - R, xCenter);
    double minL = (L1 < L2)?L1:L2;
    minL = fabs(minL);


    printf("%.4lf",minL);

    return 0;
}