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

200的数据范围。。。直接暴力,又快又稳

Posted by hzoi2017_zyc at 2018-03-02 17:11:27 on Problem 1151
贴一下暴力代码(码风辣鸡,能过凑合看吧)
#include<cstdio>
#include<cstring>
#include<algorithm>
struct jl{
	double x1,y1,x2,y2;
};
jl dt[105];
int n,s;
double a;
double x[205],y[205];
bool p[205][205];
int main(){
	while(scanf("%d",&n),n){
		memset(p,0,sizeof(p));
		a=0.0;
		for(int i=1;i<=n;i++){
			scanf("%lf%lf%lf%lf",&dt[i].x1,&dt[i].y1,&dt[i].x2,&dt[i].y2);
			x[i*2]=dt[i].x1;
			x[i*2-1]=dt[i].x2;
			y[i*2]=dt[i].y1;
			y[i*2-1]=dt[i].y2;
		}
		std::sort(x+1,x+1+n*2);
		std::sort(y+1,y+1+n*2);
		for(int i=1;i<=n;i++){
			for(int j=1;j<n*2;j++){
				if(dt[i].x2<=x[j])break;
				if(dt[i].x1>=x[j+1])continue;
				for(int k=1;k<n*2;k++){
					if(dt[i].y2<=y[k])break;
					if(dt[i].y1>=y[k+1])continue;
					p[j][k]=true;
				}
			}
		}
		for(int i=1;i<n*2;i++){
			double b=x[i+1]-x[i];
			for(int j=1;j<n*2;j++){
				if(p[i][j]){
					a+=((double)y[j+1]-y[j])*b;
				}
			}
		}
		printf("Test case #%d\nTotal explored area: %.2f\n\n",++s,a);
	}
	return 0;
}
(记得两个换行\n\n)

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