• <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>

            oyjpArt ACM/ICPC算法程序設(shè)計空間

            // I am new in programming, welcome to my blog
            I am oyjpart(alpc12, 四城)
            posts - 224, comments - 694, trackbacks - 0, articles - 6

            PKU1948 Triangular Pastures

            Posted on 2007-02-15 15:51 oyjpart 閱讀(960) 評論(1)  編輯 收藏 引用

            Triangular Pastures
            Time Limit:1000MS? Memory Limit:30000K
            Total Submit:1213 Accepted:291

            Description
            Like everyone, cows enjoy variety. Their current fancy is new shapes for pastures. The old rectangular shapes are out of favor; new geometries are the favorite.

            I. M. Hei, the lead cow pasture architect, is in charge of creating a triangular pasture surrounded by nice white fence rails. She is supplied with N (3 <= N <= 40) fence segments (each of integer length Li (1 <= Li <= 40) and must arrange them into a triangular pasture with the largest grazing area. Ms. Hei must use all the rails to create three sides of non-zero length.

            Help Ms. Hei convince the rest of the herd that plenty of grazing land will be available.Calculate the largest area that may be enclosed with a supplied set of fence segments.

            Input
            * Line 1: A single integer N

            * Lines 2..N+1: N lines, each with a single integer representing one fence segment's length. The lengths are not necessarily unique.

            Output
            A single line with the integer that is the truncated integer representation of the largest possible enclosed area multiplied by 100. Output -1 if no triangle of positive area may be constructed.

            Sample Input

            5
            1
            1
            3
            3
            4
            

            Sample Output

            692
            

            Hint
            [which is 100x the area of an equilateral triangle with side length 4]

            Source
            USACO 2002 February

            由于數(shù)據(jù)量不大 利用可行性的狀態(tài) 進(jìn)行DP Heron公式
            搜索也能過 呵呵 需要預(yù)先找到一個較好解 大->小搜 加一定的剪枝

            #include <stdio.h>
            #include <algorithm>
            #include <functional>
            #include <math.h>
            using namespace std;
            const int N = 40;
            const int M = 1000; //邊的最大可能長度(三角形性質(zhì))
            bool s[N][M][M];
            int seg[N+1];

            inline double heron(double a, double b, double c) {
            ?double p = (a+b+c)/2.0;
            ?return sqrt(p*(p-a)*(p-b)*(p-c));
            }

            int main() {
            ?int i, j, k, ns, tot = 0;
            ?double best = 0, tmp;
            ?scanf("%d", &ns);
            ?for(i = 1; i <= ns; i++) {?scanf("%d", seg+i);?tot += seg[i];?}
            ?s[0][0][0] = 1;
            ?int bound = tot/2+1;
            ?for(i = 1; i <= ns; i++)
            ??for(j = 0; j<=bound; j++)
            ???for(k = 0; k <=bound; k++)
            ????s[i][j][k] = s[i-1][j][k] || j >= seg[i] && s[i-1][j-seg[i]][k] || k >= seg[i] && s[i-1][j][k-seg[i]];
            ?for(j = 1; j<=bound; j++)
            ??for(k = 1; k <=bound; k++) {
            ???int m = tot-j-k;
            ???if(s[ns][j][k] && j + k > m && j + m > k && m + k > j && (tmp = heron(j, k, m)) > best)
            ????best = tmp;
            ??}
            ?if(best == 0) printf("-1\n");
            ?else printf("%d\n", (int)(best*100));
            ?return 0;
            }

            Feedback

            # re: PKU1948 Triangular Pastures   回復(fù)  更多評論   

            2007-04-22 13:10 by oiuy
            原來是這樣dp的,謝謝~

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            狠狠色婷婷久久综合频道日韩| 欧美久久久久久| 一级做a爰片久久毛片16| 99久久国产亚洲高清观看2024| 97久久精品人人澡人人爽 | 久久精品中文无码资源站| 国产午夜精品理论片久久影视| 久久久WWW成人免费毛片| 三上悠亚久久精品| 久久久久国产日韩精品网站| 蜜臀av性久久久久蜜臀aⅴ| 99久久精品国产一区二区蜜芽| 伊色综合久久之综合久久| 久久er99热精品一区二区| 香蕉久久夜色精品国产2020| 久久亚洲国产午夜精品理论片 | 国产激情久久久久影院| 欧美va久久久噜噜噜久久| 亚洲国产成人乱码精品女人久久久不卡 | 久久66热人妻偷产精品9| 中文字幕无码久久人妻| 国产精品99久久久久久宅男| 成人免费网站久久久| 综合网日日天干夜夜久久 | 久久99亚洲网美利坚合众国| 久久www免费人成看国产片| 国产日产久久高清欧美一区| 亚洲AV无码久久精品色欲| 2020国产成人久久精品| 亚洲欧美国产精品专区久久| 国产亚洲色婷婷久久99精品91 | 久久中文精品无码中文字幕| 97久久综合精品久久久综合| 国产精品视频久久久| 久久婷婷成人综合色综合| 久久久一本精品99久久精品88| 日韩久久久久久中文人妻| 久久人爽人人爽人人片AV| 久久久久人妻精品一区| 99久久精品毛片免费播放| 国产一区二区精品久久|