数组:一旦被定义,它的维数和维界就不再该改变。
行优先:先储存行号较小的元素,行号相等先储存列号较小的元素。
列优先:反之
压缩存储:多个值相同的元素只分配一个储存空间。对零元素不分配储存空间。 In order to save space.
特殊矩阵:具有许多相同元素或零元素,且有一定的分布规律性。如:对称矩阵,上下三角矩阵等。
特殊矩阵压缩方法:找出分布规律,把那些呈现规律性分布的、值相同的多个矩阵元素压缩到一个储存空间中。
矩阵元素远小于矩阵存储数量。
合并区间:
1.一个相同的结构体数组来存储最终结果,将所有区间左端点从小到大排序,以便于一次性从小到大合并区间。(注意快排的使用★)
2.从第一个区间开始判断,如果第二个区间的左端点小于第一个区间的右端点,那么两者重合可以合并。并且判断两个区间右端点的大小,取大值。
3.否则两者不重合重新定义区间左右端点、
#include <bits/stdc++.h> using namespace std; struct node{ int first; int last; }a[100]; struct node2{ int first; int last; }b[100]; bool rule(node a, node b) { if(a.first!=b.first) return a.first<b.first; else return a.last<b.last; } int main() { int n; cin>>n; for(int i=0;i<n;i++) { cin>>a[i].first>>a[i].last; } sort(a,a+n,rule); b[0].first=a[0].first; b[0].last=a[0].last; int count=0; for(int i=1;i<n;i++) { if(a[i].first<=b[count].last) { if(a[i].last>b[count].last) { b[count].last=a[i].last; } } else { count++; b[count].first=a[i].first; b[count].last=a[i].last; } } for(int i=0;i<=count;i++) { cout<<b[i].first<<" "<<b[i].last<<endl; } return 0; }