Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

C++AC,G++WA。附拙劣代码

Posted by Ren_Bocheng at 2015-10-01 11:01:42 on Problem 1408
#include<stdio.h>
#include<math.h>

struct point
{
    double x,y;
} p[40][40];

double cross(point a, point b, point c)
{
    return 0.5*fabs((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
}

double area(point a, point b, point c, point d)
{
    return cross(a, b, c)+cross(d, c, b);
}

int main()
{
    int n;
    double a[40],b[40],c[40],d[40];
    while(~scanf("%d", &n)&&n)
    {
        p[0][0].x = p[0][0].y = 0;
        p[0][n+1].x = 1,p[0][n+1].y = 0;
        p[n+1][0].x = 0,p[n+1][0].y = 1;
        p[n+1][n+1].x = p[n+1][n+1].y = 1;
        for(int i = 1; i <= n; ++i)
        {
            scanf("%lf", &a[i]);
            p[0][i].x = a[i];
            p[0][i].y = 0;
        }
        for(int i = 1; i <= n; ++i)
        {
            scanf("%lf", &b[i]);
            p[n+1][i].x = b[i];
            p[n+1][i].y = 1;
        }
        for(int i = 1; i <= n; ++i)
        {
            scanf("%lf", &c[i]);
            p[i][0].x = 0;
            p[i][0].y = c[i];
        }
        for(int i = 1; i <= n; ++i)
        {
            scanf("%lf", &d[i]);
            p[i][n+1].x = 1;
            p[i][n+1].y = d[i];
        }
        for(int i = 1; i <= n; ++i)
            for(int j = 1; j <= n; ++j)
            {
                p[i][j].x = ((b[j]-a[j])*c[i]+a[j])/(1.0-(b[j]-a[j])*(d[i]-c[i]));
                p[i][j].y = p[i][j].x*(d[i]-c[i])+c[i];
            }
        double ans = 0;
        for(int i = 0; i <= n; ++i)
            for(int j = 0; j <= n; ++j)
            {
                double temp = area(p[i][j], p[i][j+1], p[i+1][j], p[i+1][j+1]);
                if(temp > ans)
                    ans = temp;
            }
        printf("%.6lf\n", ans);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator