标签:stream ++ 结构体 int style 排序 name ret pac
对结构体排序
‘‘‘ #include<iostream> #include<algorithm> using namespace std; const int si= 101; struct segment { int l, r; bool operator < (const segment v) { return l < v.l; } }seg[si];int main() {
int L, M;
cin >> L >> M;
for (int i=0; i < M; i++) cin >> seg[i].l >> seg[i].r;
sort(seg, seg+M);
int la=seg[0].l, r=seg[0].r;
int sum=0;
for (int i=1; i < M; i++) {
if (r >= seg[i].l) r = max(seg[i].r, r);
else {
sum += r-la+1;
la=seg[i].l, r=seg[i].r;
}
}
sum += r-la+1;
cout << L-sum+1 << endl;
return 0;
}
‘‘‘
标签:stream ++ 结构体 int style 排序 name ret pac
原文地址:https://www.cnblogs.com/smatrchen/p/14287625.html