• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ivy-jie

            progress ...

            C++博客 首頁 新隨筆 聯(lián)系 聚合 管理
              9 Posts :: 41 Stories :: 6 Comments :: 0 Trackbacks

            問題背景

            如圖,一個(gè)半徑為1的圓周上有5個(gè)點(diǎn)。按角度制給出5個(gè)點(diǎn)的極角Ai (0<=Ai<360, i=1..5)。按下圖的方法連成一個(gè)五角星, 計(jì)算圓被切割成的11個(gè)部分面積的方差。


            具體地說, 假定11個(gè)區(qū)域的面積分別為S1,S2, ..., S11,那么面積的均值計(jì)算方法為:

            M = (S1+S2+...+S11 ) / 11


            面積的方差計(jì)算方法為:

            D = ((S1-M)2 + (S2-M)2 + ... + (S11-M)2) / 11

            輸入格式

            輸入僅一行,包含5個(gè)[0,359]內(nèi)的互不相等的整數(shù)。

            輸出格式

            輸出僅一行,包含一個(gè)實(shí)數(shù),即各部分面積的方差。輸出保留小數(shù)點(diǎn)后4位。

            樣例輸入

            0 144 72 288 216

            樣例輸出

            0.0144

            我對(duì)問題的分析

            1、把極角排序(有利于后續(xù)計(jì)算),轉(zhuǎn)化為直角坐標(biāo)系坐標(biāo)

            2、求五角星內(nèi)交點(diǎn)五個(gè)

            3、求五個(gè)個(gè)星頂三角形面積

            4、求出“弓形-三角形”面積,然后以五個(gè)小扇形為未知量解一個(gè)五元線性方程組,求出五個(gè)小扇形面積

            5、由圓的面積減去求出的十個(gè)面積,得到重心的五邊形面積

            6、根據(jù)方差公式求出答案

            【評(píng)價(jià)】這個(gè)方法基本屬于按部就班的方法,因?yàn)闆]有發(fā)掘到圓內(nèi)接五角星的特殊性質(zhì),所以并沒有涉及到什么技巧。

            我的代碼

            #include <stdio.h>
            #include <stdlib.h>
            #include <math.h>
            #define PI 3.1415926535898
            typedef struct POINT
            {
            double x;
            double y;
            }Point,*lpPoint;//點(diǎn)坐標(biāo)
            struct COMB
            {
            POINT p;
            POINT PL;//左交點(diǎn)
            POINT PR;//右交點(diǎn)
            };//五端點(diǎn)的附帶結(jié)構(gòu)
            COMB c[5];//結(jié)構(gòu)數(shù)組
            int arg[5];//角度
            double areaG[5];//弓形
            double area[11];//11個(gè)部分面積
            //選擇排序
            void sort(int arr[], int n)
            {
            int i, j, min, t;
            for (i = 0; i < n -1; i++)
            {
            min = i;
            for (j = i + 1; j < n; j++)
            {
            if (arr[min] > arr[j])
            {
            min = j;
            }
            }
            if (min != i)
            {
            t = arr[i];
            arr[i] = arr[min];
            arr[min] = t;
            }
            }
            }
            //兩線段交點(diǎn)
            POINT GetCrossPoint(POINT p1, POINT p2, POINT q1, POINT q2)
            {
            /*根據(jù)兩點(diǎn)式化為標(biāo)準(zhǔn)式,進(jìn)而求線性方程組*/
            POINT crossPoint;
            double tempLeft,tempRight;
            //求x坐標(biāo)
            tempLeft = (q2.x - q1.x) * (p1.y - p2.y) - (p2.x - p1.x) * (q1.y - q2.y);
            tempRight = (p1.y - q1.y) * (p2.x - p1.x) * (q2.x - q1.x) + q1.x * (q2.y - q1.y) * (p2.x - p1.x) - p1.x * (p2.y - p1.y) * (q2.x - q1.x);
            crossPoint.x =tempRight /tempLeft;
            //求y坐標(biāo)
            tempLeft = (p1.x - p2.x) * (q2.y - q1.y) - (p2.y - p1.y) * (q1.x - q2.x);
            tempRight = p2.y * (p1.x - p2.x) * (q2.y - q1.y) + (q2.x- p2.x) * (q2.y - q1.y) * (p1.y - p2.y) - q2.y * (q1.x - q2.x) * (p2.y - p1.y);
            crossPoint.y =tempRight / tempLeft;
            return crossPoint;
            }
            //求所有交點(diǎn)
            void cross()
            {
            int i;
            for (i=0;i<5;i++)
            {
            c[i].PL = GetCrossPoint(c[i].p,c[(i+3)%5].p,c[(i+1)%5].p,c[(i+4)%5].p);
            c[(i+4)%5].PR = c[i].PL;
            }
            }
            //void Helen();
            //double SideLength(POINT X,POINT Y);
            //點(diǎn)到點(diǎn)的距離
            double SideLength( POINT X,POINT Y )
            {
            double r=sqrt(((X.x-Y.x)*(X.x-Y.x)+(X.y-Y.y)*(X.y-Y.y)));
            return r;
            }
            //海倫公式求三角形面積
            void Helen()
            {
            double a,b,d;	//三邊長
            double p;		//平均值
            for (int i=0; i<5; i++)
            {
            a=SideLength(c[i].p,c[i].PL);
            b=SideLength(c[i].PR,c[i].PL);
            d=SideLength(c[i].p,c[i].PR);
            p=0.5*(a+b+d);
            area[i]=sqrt((p*(p-a)*(p-b)*(p-d)));
            }
            }
            //求五個(gè)弓形面積
            void Arch()
            {
            double x;
            double arc;
            double rui;
            for (int i=0;i<5;i++)
            {
            x=0.5*SideLength(c[(i+4)%5].p,c[(i+1)%5].p);
            rui = acos(x);
            arc=PI-2.0*acos(x);
            areaG[i]=0.5*arc-0.5*sin(arc);
            }
            }
            //解方程求弧邊的五塊小扇形面積
            void Equation()
            {
            double temp[5];
            //弓形減去三角(方程右邊)
            for (int i=0; i<5; i++)
            {
            temp[i] = areaG[i] - area[i];
            }
            //求解
            area[5] = (temp[0]+temp[2]+temp[4]-temp[1]-temp[3])/2;
            area[6] = (temp[0]+temp[1]+temp[3]-temp[2]-temp[4])/2;
            area[7] = (temp[1]+temp[2]+temp[4]-temp[0]-temp[3])/2;
            area[8] = (temp[0]+temp[2]+temp[3]-temp[1]-temp[4])/2;
            area[9] = (temp[1]+temp[3]+temp[4]-temp[0]-temp[2])/2;
            }
            //求最后中間一塊面積
            void LastArea()
            {
            double plus(0.0);
            for (int i=0;i<10;i++)
            {
            plus += area[i];
            }
            area[10] = PI - plus;
            }
            int main(void)
            {
            int i;
            for (i=0;i<5;i++)
            {
            scanf("%d",&arg[i]);
            }
            sort(arg,5);//排序
            double d[5];
            for (i=0;i<5;i++)
            {
            d[i] = (double)(arg[i])*PI/180.0;
            }
            //點(diǎn)坐標(biāo)
            for (i=0;i<5;i++)
            {
            c[i].p.x = cos(d[i]);
            c[i].p.y = sin(d[i]);
            }
            //求所有交點(diǎn)
            cross();
            //----------求面積--------------
            Helen();//五個(gè)三角形面積
            Arch();//弓形面積
            Equation();//解方程求弧邊的五塊小扇形面積
            LastArea();//求最后中間一塊面積
            //對(duì)area[11]求方差
            double aver = PI/11.0;
            //printf("%.4f\n",aver);
            double result = 0.0;//加和
            for (i=0;i<11;i++)
            {
            result = result + (area[i]-aver)*(area[i]-aver);
            }
            result = result/11.0;
            result = (float)((int)(result*10000+0.5))/10000.0;//四舍五入取四位
            printf("%.4f\n",result);
            return 0;
            }
            posted on 2009-05-20 09:22 ivy-jie 閱讀(661) 評(píng)論(0)  編輯 收藏 引用 所屬分類: arithmetic
            99国产欧美精品久久久蜜芽| 高清免费久久午夜精品| 色综合久久久久综合99| 久久99久久成人免费播放| 久久本道综合久久伊人| 久久久久免费精品国产| 精品熟女少妇a∨免费久久| 99国内精品久久久久久久| 一级做a爰片久久毛片看看| 久久精品人人槡人妻人人玩AV| 久久伊人精品青青草原高清| 中文字幕精品无码久久久久久3D日动漫 | 久久天天婷婷五月俺也去| 久久人人爽爽爽人久久久| 国产免费福利体检区久久| 色妞色综合久久夜夜| 久久亚洲高清观看| 久久亚洲精品国产精品| 色婷婷久久久SWAG精品| 亚洲成人精品久久| 久久丫精品国产亚洲av| 欧美伊人久久大香线蕉综合69| AV色综合久久天堂AV色综合在| 理论片午午伦夜理片久久| 久久综合九色综合欧美狠狠| 欧美噜噜久久久XXX| 日产久久强奸免费的看| 国产高清国内精品福利99久久| 久久狠狠爱亚洲综合影院| 久久综合九色欧美综合狠狠| 久久久国产精品福利免费 | 中文字幕无码久久人妻| 久久久精品免费国产四虎| 久久综合精品国产二区无码| 久久人人爽人人爽人人片av麻烦| 久久国产精品无码网站| 精品国产青草久久久久福利| 国产精品成人99久久久久| 91亚洲国产成人久久精品网址| A狠狠久久蜜臀婷色中文网| 久久精品国产亚洲精品2020|