• <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 閱讀(461) 評論(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  回復  更多評論   
             
            青青草国产精品久久| 久久天天躁夜夜躁狠狠躁2022| 久久久www免费人成精品| 亚洲欧美一区二区三区久久| 久久夜色精品国产欧美乱| 岛国搬运www久久| 色诱久久久久综合网ywww | 中文字幕成人精品久久不卡| 久久久久av无码免费网| 久久九九全国免费| 亚洲а∨天堂久久精品| 国产成人综合久久精品尤物| 久久夜色精品国产| 久久久久国色AV免费观看| 亚洲欧美精品伊人久久| 2021国内久久精品| 日韩人妻无码一区二区三区久久99| 精品国产乱码久久久久久呢| 国产精品99久久久久久宅男| 中文字幕日本人妻久久久免费 | 国产精品熟女福利久久AV| 亚洲精品白浆高清久久久久久| 怡红院日本一道日本久久 | 久久综合九色综合网站| 欧美日韩成人精品久久久免费看 | 深夜久久AAAAA级毛片免费看 | 日本久久中文字幕| 99久久99久久精品国产片| 久久亚洲私人国产精品| 久久久久久久97| 香蕉99久久国产综合精品宅男自| 99久久婷婷免费国产综合精品| 99久久综合狠狠综合久久止| 久久久高清免费视频| 中文字幕久久精品| 亚洲精品无码久久千人斩| 久久人人爽人人澡人人高潮AV | 热久久这里只有精品| 97久久精品午夜一区二区| 成人久久综合网| 久久777国产线看观看精品|