1 条题解

  • 2
    @ 2023-4-16 22:12:27

    骗分过样例,暴力出奇迹。

    爆搜挂着机,打表出省一。

    贪心题目

    #include <bits/stdc++.h>
    using namespace std;
    const int N=1000001;
    struct node{
    	int begin,end;
    }a[N];
    bool cmp(node x,node y){
    	return x.end<y.end;
    }
    int n,ans,last;
    int main(){
    	scanf("%d",&n);
    	for(int i=1;i<=n;i++){
    		scanf("%d%d",&a[i].begin,&a[i].end);
    	}
    	sort(a+1,a+n+1,cmp);
    	for(int i = 1; i <= n; i ++ ){
    		if(a[i].begin>=last){
    			++ans;
    			last=a[i].end;			
    		}
    	}
    	printf("%d",ans); 
    	return 0;
    }
    

    信息

    ID
    354
    时间
    1000ms
    内存
    512MiB
    难度
    8
    标签
    递交数
    216
    已通过
    30
    上传者