2021年8月5日11:51:27
区间贪心
21春Lab Access Scheduling
int camp(node a, node b){
return a.start>b.start;
}
开始进行排序,见122
#include<bits/stdc++.h>
using namespace std;
struct node{
string start,end;
}p[2001];
int camp(node a, node b){
return a.start>b.start;
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>p[i].start>>p[i].end;
}
sort(p,p+n,camp);
string laststart=p[0].start;
int ans=1;
for(int i=1;i<n;i++){
if(p[i].end<=laststart){
ans++;
laststart=p[i].start;
}
}
cout<<ans;
return 0;
}