解题思路:
注意事项:
参考代码:
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; bool judge(int maxX1,int minX1,int maxY1,int minY1,int maxX2,int minX2,int maxY2,int minY2){ if(((minX2 >= minX1 && minX2 <= maxX1) || (maxX2 >= minX1 && maxX2 <= maxX1)) &&((minY2 >= minY1 && minY2 <=maxY1) || (maxY2 >= minY1 && maxY2 <=maxY1))) return true; else return false; } int main(void){ double x1,x2,x3,x4,y1,y2,y3,y4; cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4; double maxX1 = x1 > x2? x1 : x2; double maxY1 = y1 > y2? y1 : y2; double minX1 = x1 < x2? x1 : x2; double minY1 = y1 < y2? y1 : y2; double maxX2 = x3 > x4? x3 : x4; double maxY2 = y3 > y4? y3 : y4; double minX2 = x3 < x4? x3 : x4; double minY2 = y3 < y4? y3 : y4; double ans = 0; if(judge(maxX1,minX1,maxY1,minY1,maxX2,minX2,maxY2,minY2)){ double x1,x2,y1,y2; x1 = minX1 > minX2 ? minX1 : minX2; x2 = maxX1 < maxX2 ? maxX1 : maxX2; y1 = minY1 > minY2 ? minY1 : minY2; y2 = maxY1 < maxY2 ? maxY1 : maxY2; ans = (x2-x1)*(y2-y1); } printf("%.2lf",ans); return 0; }
0.0分
0 人评分
C语言程序设计教程(第三版)课后习题8.3 (C语言代码)浏览:1110 |
三角形 (C++代码)递归(存在大量重复计算,容易出现时间超限)浏览:836 |
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:487 |
简单的a+b (C语言代码)浏览:529 |
C二级辅导-等差数列 (C语言代码)浏览:806 |
C二级辅导-同因查找 (C语言代码)浏览:618 |
C二级辅导-计负均正 (C语言代码)浏览:524 |
简单的a+b (C语言代码)浏览:600 |
C语言训练-8除不尽的数 (C语言代码)浏览:1469 |
简单的a+b (C语言代码)浏览:531 |