• <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>
            二分水面高度,然后求總水量(就是求多邊形面積)

            /*************************************************************************
            Author: WHU_GCC
            Created Time: 2007-8-10 13:49:09
            File Name: pku3334.cpp
            Description: 
            ***********************************************************************
            */

            #include 
            <algorithm>
            #include 
            <iostream>
            #include 
            <sstream>
            #include 
            <string>
            #include 
            <queue>
            #include 
            <list>
            #include 
            <set>
            #include 
            <map>
            #include 
            <cmath>
            #include 
            <vector>
            #include 
            <cctype>
            #include 
            <cstring>
            using namespace std;
            #define out(x) (cout<<#x<<": "<<x<<endl)
            const int maxint=0x7FFFFFFF;
            const long long maxlonglong=0x7FFFFFFFFFFFFFFFLL;
            const double inf = 1e200;
            const double eps = 1e-9;
            template
            <class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
            template
            <class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}

            const int maxn = 2000;

            typedef 
            struct
            {
                
            double x, y;
            }
             point_t;

            point_t ga[maxn], gb[maxn];
            int cnt_ga, cnt_gb;
            int bottom_a, bottom_b;
            int v_water;

            point_t p[maxn];
            int cnt_p;

            double cross(point_t a, point_t b)
            {
                
            return a.x * b.y - a.y * b.x;
            }


            double count_area()
            {
                
            double ret = 0.0;
                
            for (int i = 0; i < cnt_p; i++)
                
            {
                    ret 
            += cross(p[i], p[(i + 1% cnt_p]) / 2.0;
                }

                
            return ret;
            }


            bool ok(double h)
            {
                
            double area = 0.0;
                cnt_p 
            = 0;
                
            for (int i = 0; i < bottom_a; i++)
                
            {
                    
            if (cnt_p > 0)
                    
            {
                        p[cnt_p] 
            = ga[i];
                        cnt_p
            ++;
                    }

                    
            if (ga[i].y >= h && ga[i + 1].y < h)
                    
            {
                        
            double t = (ga[i].y - h) / (h - ga[i + 1].y);
                        
            double x = (ga[i].x + t * ga[i + 1].x) / (t + 1);
                        p[
            0].x = x;
                        p[
            0].y = h;
                        cnt_p
            ++;
                    }

                }

                
            for (int i = bottom_a; i < cnt_ga; i++)
                
            {
                    
            if (cnt_p > 0)
                    
            {
                        p[cnt_p] 
            = ga[i];
                        cnt_p
            ++;
                    }

                    
            if (ga[i].y < h && ga[i + 1].y >= h)
                    
            {
                        
            double t = (ga[i].y - h) / (h - ga[i + 1].y);
                        
            double x = (ga[i].x + t * ga[i + 1].x) / (t + 1);
                        p[cnt_p].x 
            = x;
                        p[cnt_p].y 
            = h;
                        cnt_p
            ++;
                        
            break;
                    }

                }

                area 
            += count_area();
                cnt_p 
            = 0;
                
            for (int i = 0; i < bottom_b; i++)
                
            {
                    
            if (cnt_p > 0)
                    
            {
                        p[cnt_p] 
            = gb[i];
                        cnt_p
            ++;
                    }
                    
                    
            if (gb[i].y >= h && gb[i + 1].y < h)
                    
            {
                        
            double t = (gb[i].y - h) / (h - gb[i + 1].y);
                        
            double x = (gb[i].x + t * gb[i + 1].x) / (t + 1);
                        p[
            0].x = x;
                        p[
            0].y = h;
                        cnt_p
            ++;
                    }

                }

                
            for (int i = bottom_b; i < cnt_gb; i++)
                
            {
                    
            if (cnt_p > 0)
                    
            {
                        p[cnt_p] 
            = gb[i];
                        cnt_p
            ++;
                    }

                    
            if (gb[i].y < h && gb[i + 1].y >= h)
                    
            {
                        
            double t = (gb[i].y - h) / (h - gb[i + 1].y);
                        
            double x = (gb[i].x + t * gb[i + 1].x) / (t + 1);
                        p[cnt_p].x 
            = x;
                        p[cnt_p].y 
            = h;
                        cnt_p
            ++;
                        
            break;
                    }

                }

                area 
            += count_area();
                
            if (area >= v_water) return false;
                
            else return true;
            }



            double work()
            {
                
            double up, down;
                up 
            = min(min(ga[0].y, ga[cnt_ga - 1].y), min(gb[0].y, gb[cnt_gb - 1].y));
                
            double t1 = inf, t2 = inf;
                
            for (int i = 0; i < cnt_ga; i++if (ga[i].y < t1)
                
            {
                    t1 
            = ga[i].y;
                    bottom_a 
            = i;
                }

                
            for (int i = 0; i < cnt_gb; i++if (gb[i].y < t2)
                
            {
                    t2 
            = gb[i].y;
                    bottom_b 
            = i;
                }

                down 
            = min(t1, t2);
                
                
            while (fabs(up - down) > eps)
                
            {
                    
            double mid = (up + down) / 2.0;
                    
            if (ok(mid))
                        down 
            = mid;
                    
            else up = mid;
                }

                
            return up;
            }


            int main()
            {
                
            int ca;
                
            for (scanf("%d"&ca); ca--;)
                
            {
                    scanf(
            "%d"&v_water);
                    scanf(
            "%d"&cnt_ga);
                    
            for (int i = 0; i < cnt_ga; i++) scanf("%lf%lf"&ga[i].x, &ga[i].y);
                    scanf(
            "%d"&cnt_gb);
                    
            for (int i = 0; i < cnt_gb; i++) scanf("%lf%lf"&gb[i].x, &gb[i].y);
                    
            double ans = work();
                    printf(
            "%.3lf\n", ans);
                }

                
            return 0;
            }
            posted on 2007-08-15 08:59 Felicia 閱讀(457) 評論(1)  編輯 收藏 引用 所屬分類: 計算幾何
            Comments
            • # re: [計算幾何]pku3334
              babt
              Posted @ 2011-05-14 15:42
              代碼有點小問題。
              這組數據過不去。
              31
              6
              -45 23 -40 22 -30 20 -20 19 -10 18 -5 22
              6
              0 22 10 21 20 20 30 19 40 20 42 22
              應該是19.964  回復  更多評論   
             
            亚洲狠狠综合久久| 伊人 久久 精品| 国产精品久久久久久五月尺| 青草影院天堂男人久久| 久久人人爽人人爽人人AV东京热| 久久男人中文字幕资源站| 久久精品成人| 国内精品久久人妻互换| 伊人久久大香线蕉av一区| 综合久久给合久久狠狠狠97色| 亚洲国产成人精品女人久久久| 久久99精品国产麻豆蜜芽| 精品一区二区久久久久久久网站| …久久精品99久久香蕉国产| 97久久精品国产精品青草| 久久九九有精品国产23百花影院| 国产精品18久久久久久vr| 99久久国产综合精品成人影院| 91久久香蕉国产熟女线看| 久久se精品一区二区影院| 亚洲精品无码久久久久AV麻豆| 久久亚洲国产精品成人AV秋霞| 亚洲日韩中文无码久久| 久久亚洲AV成人无码国产| 99久久精品久久久久久清纯| 欧美亚洲另类久久综合婷婷| 2020国产成人久久精品| 久久精品夜夜夜夜夜久久| 99久久无码一区人妻| 久久99热这里只频精品6| 亚洲AV无码1区2区久久| 亚洲午夜久久久精品影院| 思思久久好好热精品国产| 国产综合久久久久久鬼色| 久久精品视频91| 精品国产一区二区三区久久久狼| 久久精品成人免费国产片小草| 久久久女人与动物群交毛片| 久久一区二区三区99| 91精品国产91久久久久福利| 亚洲国产成人乱码精品女人久久久不卡|