【HDOJ】2056 Rectangles
水题,比较烦,搞清楚计算公式即可。
#include <stdio.h> double mymax(double a, double b) { return a>b ? a:b; } double mymin(double a, double b) { return a<b ? a:b; } int main() { double x1,y1,x2,y2; double x3,y3,x4,y4; double tmp; while (scanf("%lf%lf%lf%lf%lf%lf%lf%lf", &x1,&y1,&x2,&y2,&x3,&y3,&x4,&y4) != EOF){ tmp = mymax(x1, x2); x1 = x1+x2-tmp; x2 = tmp; tmp = mymax(x3, x4); x3 = x3+x4-tmp; x4 = tmp; tmp = mymax(y1, y2); y1 = y1+y2-tmp; y2 = tmp; tmp = mymax(y3, y4); y3 = y3+y4-tmp; y4 = tmp; x1 = mymax(x1, x3); x2 = mymin(x2, x4); y1 = mymax(y1, y3); y2 = mymin(y2, y4); tmp = (x2-x1) * (y2-y1); if(x2>=x1 && y2>=y1) printf("%.2lf\n",tmp); else printf("0.00\n"); } return 0; }