原题链接:矩阵面积相交
#include<iostream>
//#include<bits/stdc++.h>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<malloc.h>
#include<sstream>
#include<string.h>
#include<ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
bool cmp(int a, int b) {
return a > b;
}
struct REC {
int x1;
int y1;
int x2;
int y2;
};
struct REC rec[10005];
int area_rec(struct REC a, struct REC b) {
int area;
int x1, y1;
int x2, y2;
x1 = max(a.x1, b.x1);
y1 = max(a.y1, b.y1);
x2 = min(a.x2, b.x2);
y2 = min(a.y2, b.y2);
if (x2 > x1 && y2 > y1) {
area = (x2 - x1) * (y2 - y1);
}
else
area = 0;
return area;
}
int main() {
int T;
int n;
int num[10005];
int region[10005];
memset(num, 0, sizeof(num));
memset(region, 0, sizeof(region));
cin >> T;
while (T--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> rec[i].x1 >> rec[i].y1 >> rec[i].x2 >> rec[i].y2;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (i != j) { //自己和自己不做判定
int area = area_rec(rec[i], rec[j]);
if (area != 0) {
region[i]++;
num[i] += area;
}
}
}
}
for (int i = 0; i < n; i++) {
cout << region[i] << " " << num[i] << endl;
}
}
return 0;
}
我打印出的结果是这样的,但是无法AC
0.0分
1 人评分
C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:
一点编程也不会写的:零基础C语言学练课程
解决困扰你多年的C语言疑难杂症特性的C语言进阶课程
从零到写出一个爬虫的Python编程课程
只会语法写不出代码?手把手带你写100个编程真题的编程百练课程
信息学奥赛或C++选手的 必学C++课程
蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程
手把手讲解近五年真题的蓝桥杯辅导课程
发表评论 取消回复