• <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
            亚洲AⅤ优女AV综合久久久| 亚洲中文字幕无码久久精品1| 亚洲伊人久久大香线蕉苏妲己| 久久亚洲国产午夜精品理论片| 超级碰久久免费公开视频| 亚洲一区精品伊人久久伊人| 97精品久久天干天天天按摩| 久久久久一本毛久久久| 成人综合伊人五月婷久久| 手机看片久久高清国产日韩| 成人久久综合网| 伊色综合久久之综合久久| 久久夜色tv网站| 伊人久久大香线蕉AV色婷婷色| 久久99国产精品久久99| 亚洲精品国精品久久99热一| 精品无码久久久久久国产| 东京热TOKYO综合久久精品 | 色综合久久无码五十路人妻| 精品久久久久久无码国产| 久久99国内精品自在现线| 亚洲精品国产第一综合99久久| 国产成人精品久久二区二区| 久久久久久久久久久| 亚洲美日韩Av中文字幕无码久久久妻妇 | 亚洲?V乱码久久精品蜜桃 | 久久亚洲精精品中文字幕| 少妇人妻综合久久中文字幕| 国产ww久久久久久久久久| 久久中文娱乐网| 99久久婷婷国产一区二区| 精品久久一区二区| 久久国产精品-国产精品| 国产精品久久久久影视不卡| 国产精品美女久久久m| 91精品国产高清久久久久久io| 久久久久亚洲AV无码永不| 婷婷五月深深久久精品| 2022年国产精品久久久久| 久久精品国产福利国产秒| 国产ww久久久久久久久久|