Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
测试案例都通过,数组也开的够大了,怎么是Runtime Error啊?请教哪位高手啊!#include<iostream> #include<cmath> using namespace std; struct point { double x; double y; }; point bt[1000][1000]; point lr[1000][1000]; point save[1000][1000]; void init(int vertis) //初始化 { int i; for(i=1;i<=vertis;i++) { cin>>bt[i][0].x; } for(i=1;i<=vertis;i++) { cin>>bt[i][1].x; } for(i=1;i<=vertis;i++) { cin>>lr[i][0].y; } for(i=1;i<=vertis;i++) { cin>>lr[i][1].y; bt[i][0].y=0; bt[i][1].y=1; lr[i][0].x=0; lr[i][1].x=1; } save[0][0].x=save[0][0].y=save[0][vertis+1].x=save[vertis+1][0].y=0; save[0][vertis+1].y=save[vertis+1][vertis+1].x=save[vertis+1][vertis+1].y=save[vertis+1][0].x=1; for(i=1;i<=vertis;i++) { save[0][i]=lr[i][0]; save[vertis+1][i]=lr[i][1]; save[i][0]=bt[i][0]; save[i][vertis+1]=bt[i][1]; } } point coner(point p1,point p2,point p3,point p4)//求交点 { double A1=p2.y-p1.y; double B1=p1.x-p2.x; double C1=p1.y*(p2.x-p1.x)-p1.x*(p2.y-p1.y); double A2=p4.y-p3.y; double B2=p3.x-p4.x; double C2=p3.y*(p4.x-p3.x)-p3.x*(p4.y-p3.y); point P; P.x=(C2*B1-C1*B2)/(A1*B2-A2*B1); P.y=(C2*A1-C1*A2)/(B1*A2-B2*A1); return P; } double area_polygon(point p1,point p2,point p3, point p4)//求面积 { point p[10]; p[0]=p1; p[1]=p2; p[2]=p4; p[3]=p3; double s1=0,s2=0; int i; for (i=0;i<4;i++) s1+=p[(i+1)%4].y*p[i].x,s2+=p[(i+1)%4].y*p[(i+2)%4].x; return fabs(s1-s2)/2; } int main() { int vertis,i,j,k; double mianji[100],max; while(cin>>vertis&&vertis!=0) { max=0; k=0; init(vertis); for(i=1;i<=vertis;i++) for(j=1;j<=vertis;j++) save[i][j]=coner(bt[i][0],bt[i][1],lr[j][0],lr[j][1]); for(i=0;i<=vertis;i++) for(j=0;j<=vertis;j++) mianji[k++]=area_polygon(save[i][j],save[i][j+1], save [i+1][j],save[i+1][j+1]); for(i=0;i<(vertis+1)*(vertis+1);i++) { if(max<mianji[i]) max=mianji[i]; } printf("%.6f\n",max); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator