数论 矩阵交集
Posted someonezero
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数论 矩阵交集相关的知识,希望对你有一定的参考价值。
参考网址 https://www.cnblogs.com/yzm10/p/10963692.html
输入
2 2 0 0 1 1 1 1 2 2 3 0 0 2 6 1 1 4 4 1 3 3 9
输出
0 0 0 0 2 6 2 5 2 5
求矩阵的交集个数和交集面积
画出两个矩阵的交集即可,在草稿纸上画出,找出横纵坐标的大小关系,进行比较
#include<bits/stdc++.h> using namespace std; typedef long long ll; struct Node{ int x1,y1,x2,y2; }a[5005]; int calc(int a1x1,int a1y1,int a1x2,int a1y2,int a2x1,int a2y1,int a2x2,int a2y2){ int c=0; ll m1=max(min(a1x1,a1x2),min(a2x1,a2x2)); ll n1=max(min(a1y1,a1y2),min(a2y1,a2y2)); ll m2=min(max(a1x1,a1x2),max(a2x1,a2x2)); ll n2=min(max(a1y1,a1y2),max(a2y1,a2y2)); if(m2>m1&&n2>n1) return 1; return 0; } ll cals(int a1x1,int a1y1,int a1x2,int a1y2,int a2x1,int a2y1,int a2x2,int a2y2){ int c=0; ll m1=max(min(a1x1,a1x2),min(a2x1,a2x2)); ll n1=max(min(a1y1,a1y2),min(a2y1,a2y2)); ll m2=min(max(a1x1,a1x2),max(a2x1,a2x2)); ll n2=min(max(a1y1,a1y2),max(a2y1,a2y2)); if(m2>m1&&n2>n1) return (m2-m1)*(n2-n1); return 0; } int main() { int t,n,i,j; scanf("%d",&t); while(t--){ scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%d%d%d",&a[i].x1,&a[i].y1,&a[i].x2,&a[i].y2); } for(i=1;i<=n;i++){ int c=0; ll s=0; for(j=1;j<=n;j++){ if(i==j) continue; c+=calc(a[i].x1,a[i].y1,a[i].x2,a[i].y2,a[j].x1,a[j].y1,a[j].x2,a[j].y2); s+=cals(a[i].x1,a[i].y1,a[i].x2,a[i].y2,a[j].x1,a[j].y1,a[j].x2,a[j].y2); } printf("%d %lld ",c,s); } } return 0; }
以上是关于数论 矩阵交集的主要内容,如果未能解决你的问题,请参考以下文章