• <input id="auww4"></input>
  • <input id="auww4"><acronym id="auww4"></acronym></input>
  • <input id="auww4"><u id="auww4"></u></input>
    <object id="auww4"><acronym id="auww4"></acronym></object>
    <menu id="auww4"></menu><input id="auww4"><u id="auww4"></u></input>
    <input id="auww4"><u id="auww4"></u></input>
  • F.A.Q
    Hand In Hand
    Online Acmers
    Forum | Discuss
    Statistical Charts
    Problem Archive
    Realtime Judge Status
    Authors Ranklist
     
         C/C++/Java Exams     
    ACM Steps
    Go to Job
    Contest LiveCast
    ICPC@China
    Best Coder beta
    VIP | STD Contests
    Virtual Contests
        DIY | Web-DIY beta
    Recent Contests
    Author ID 
    Password 
     Register new ID

    Re:為何海倫公式不行?樣例能過,也帶了兩個凹多邊形也是對的,所以錯在哪里了?或者求人給反例數據,謝謝

    Posted by 17540220 at 2018-03-06 20:41:34 on Problem 2036
    (119)  


    #include <stdio.h>
    #include <math.h>
    double areas(double x1, double y1, double x2, double y2, double x3, double y3) {
        /*計算三邊長度*/
        double a = sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
        double b = sqrt(pow(x2 - x3, 2) + pow(y2 - y3, 2));
        double c = sqrt(pow(x3 - x1, 2) + pow(y3 - y1, 2));
        /*海倫公式*/
        double p = (a + b + c) / 2.0;
        double s = sqrt(p*(p-a)*(p-b)*(p-c));
        return s;
    }
    
    int main() {
        int n;
        double arr[300];
        int i;
        double s;
        while (scanf("%d", &n)!=EOF) {
            if (n == 0) {
                break;
            }
            s = 0;
            for (i = 0; i < n * 2; i++) {
                scanf("%lf", &arr[i]);
            }
            arr[i] = arr[0];
            arr[i+1] = arr[1];
            for (i = 0; i < n * 2; i+=4) {
                s += areas(arr[i] ,arr[i + 1], arr[i + 2], arr[i + 3], arr[i + 4], arr[i + 5]);
            }
            printf("%.1lf\n", s);
        }
        return 0;
    }
    ----------------------------------------------------------------------------------


    Post your reply here:

    Author ID
    Password
    Title
    Content  
     
    Hangzhou Dianzi University Online Judge 3.0
    Copyright © 2005-2021 HDU ACM Team. All Rights Reserved.
    Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
    Total 0.015600(s) query 5, Server time : 2021-01-21 10:54:01, Gzip enabled
    棋牌