• <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++博客 首頁 新隨筆 聯系 聚合 管理
              9 Posts :: 41 Stories :: 6 Comments :: 0 Trackbacks

            問題背景

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


            具體地說, 假定11個區域的面積分別為S1,S2, ..., S11,那么面積的均值計算方法為:

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


            面積的方差計算方法為:

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

            輸入格式

            輸入僅一行,包含5[0,359]內的互不相等的整數。

            輸出格式

            輸出僅一行,包含一個實數,即各部分面積的方差。輸出保留小數點后4位。

            樣例輸入

            0 144 72 288 216

            樣例輸出

            0.0144

            我對問題的分析

            1、把極角排序(有利于后續計算),轉化為直角坐標系坐標

            2、求五角星內交點五個

            3、求五個個星頂三角形面積

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

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

            6、根據方差公式求出答案

            【評價】這個方法基本屬于按部就班的方法,因為沒有發掘到圓內接五角星的特殊性質,所以并沒有涉及到什么技巧。

            我的代碼

            #include <stdio.h>
            #include <stdlib.h>
            #include <math.h>
            #define PI 3.1415926535898
            typedef struct POINT
            {
            double x;
            double y;
            }Point,*lpPoint;//點坐標
            struct COMB
            {
            POINT p;
            POINT PL;//左交點
            POINT PR;//右交點
            };//五端點的附帶結構
            COMB c[5];//結構數組
            int arg[5];//角度
            double areaG[5];//弓形
            double area[11];//11個部分面積
            //選擇排序
            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;
            }
            }
            }
            //兩線段交點
            POINT GetCrossPoint(POINT p1, POINT p2, POINT q1, POINT q2)
            {
            /*根據兩點式化為標準式,進而求線性方程組*/
            POINT crossPoint;
            double tempLeft,tempRight;
            //求x坐標
            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坐標
            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;
            }
            //求所有交點
            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);
            //點到點的距離
            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)));
            }
            }
            //求五個弓形面積
            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;
            }
            //點坐標
            for (i=0;i<5;i++)
            {
            c[i].p.x = cos(d[i]);
            c[i].p.y = sin(d[i]);
            }
            //求所有交點
            cross();
            //----------求面積--------------
            Helen();//五個三角形面積
            Arch();//弓形面積
            Equation();//解方程求弧邊的五塊小扇形面積
            LastArea();//求最后中間一塊面積
            //對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 閱讀(651) 評論(0)  編輯 收藏 引用 所屬分類: arithmetic
            久久久久无码专区亚洲av| 免费精品久久天干天干| 久久久久亚洲AV无码网站| 国产aⅴ激情无码久久| 久久久无码精品亚洲日韩蜜臀浪潮 | 久久AAAA片一区二区| 久久五月精品中文字幕| 国内精品久久久久影院薰衣草| 久久综合精品国产二区无码| 青青草国产精品久久| 伊人久久大香线蕉综合热线| 97久久超碰成人精品网站| 色诱久久av| 久久久久久久尹人综合网亚洲| 伊人久久国产免费观看视频 | 精品久久777| 久久久久国产精品三级网| 久久久久久久久久久精品尤物| 国产午夜精品理论片久久影视 | 91久久精品无码一区二区毛片| 无码国内精品久久人妻麻豆按摩| 亚洲va久久久噜噜噜久久男同 | 久久久久亚洲精品男人的天堂| 日本久久久久亚洲中字幕| 久久一本综合| 国内精品久久久久久不卡影院| 久久久久亚洲AV无码网站| 国内精品久久久久久久久电影网| 国产一区二区精品久久凹凸| 久久精品国产亚洲av高清漫画 | 久久九九久精品国产| 成人精品一区二区久久久| 久久久久久夜精品精品免费啦 | 亚洲AV成人无码久久精品老人| 久久人妻少妇嫩草AV无码蜜桃| 精品久久一区二区三区| 成人资源影音先锋久久资源网| 亚洲国产精品无码久久久秋霞2 | 色综合色天天久久婷婷基地| 日韩精品无码久久久久久| 久久亚洲精品国产亚洲老地址 |