解题思路:
注意事项:
参考代码:
#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
int start,end;
}p[1005];
bool cmp(Node a,Node b){return a.end < b.end;}//升序
int main()
{
int n; cin >> n;
int count = 1;
for(int i = 0; i < n; i++)
{
cin >> p[i].start >> p[i].end;
}
sort(p, p + n, cmp);
int temp = p[0].end;
for(int j = 1; j < n; j++)
{
if(p[j].start >= temp)
{
temp = p[j].end;
count++;
}
}
cout << count;
return 0;
}
0.0分
1 人评分
C语言训练-求函数值 (C语言代码)浏览:917 |
简单的a+b (C语言代码)浏览:723 |
C语言程序设计教程(第三版)课后习题8.1 (Java代码)浏览:781 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:612 |
WU-字符串比较 (C++代码)浏览:756 |
C语言程序设计教程(第三版)课后习题6.5 (C++代码)浏览:457 |
简单的a+b (C语言代码)浏览:531 |
C语言程序设计教程(第三版)课后习题9.8 (C语言代码)浏览:616 |
C语言程序设计教程(第三版)课后习题11.5 (C语言代码)浏览:1479 |
复数求和 (C语言代码)浏览:926 |