zoukankan      html  css  js  c++  java
  • 洛谷P2970 [USACO09DEC]自私的放牧Selfish Grazing

    洛谷P2970 [USACO09DEC]自私的放牧Selfish Grazing

    一道贪心题

     1 #include <cstdio> 
     2 #include <cmath>
     3 #include <cstdlib>
     4 #include <cstring>
     5 #include <iostream> 
     6 #include <iomanip> 
     7 #include <string> 
     8 #include <algorithm> 
     9 #define For(i,j,k) for(int i=j;i<=k;i++) 
    10 #define Dow(i,j,k) for(int i=j;i>=k;i--) 
    11 using namespace std ;  
    12 
    13 const int N = 50011 ; 
    14 struct node{
    15     int s,t ; 
    16 }seg[N];
    17 int n,ans ; 
    18 int dp[N] ; 
    19 
    20 inline int read() 
    21 {
    22     int x = 0 , f = 1 ; 
    23     char ch = getchar() ; 
    24     while(ch<'0'||ch>'9') { if(ch=='-') f = -1 ; ch = getchar(); } 
    25     while(ch>='0'&&ch<='9') { x = x * 10+ch-48 ; ch = getchar(); } 
    26     return x * f ; 
    27 }
    28 inline bool cmp(node a,node b) 
    29 {
    30     if(a.t!=b.t) return a.t < b.t ; 
    31     return a.s < b.s ; 
    32 }
    33 int main() 
    34 {
    35     n = read() ; 
    36     For(i,1,n) seg[i].s = read() , seg[i].t = read() ; 
    37     sort(seg+1,seg+n+1,cmp) ; 
    38     
    39     int id ; 
    40     For(i,1,n) 
    41        if(i==1 || seg[id].t<=seg[i].s ) ans++,id=i ; 
    42     printf("%d
    ",ans) ; 
    43     return 0 ; 
    44 }
  • 相关阅读:
    Git删除不存在对应远程分支的本地分支
    Git删除远程分支
    将博客搬至CSDN
    HttpStatus
    Mysql 日期
    jekyll开发静态网站
    修改maven默认的jdk版本
    使用@Value进行静态常量的值注入
    妙笔生花处,惊艳四座
    Integer 和 int 值比较
  • 原文地址:https://www.cnblogs.com/third2333/p/7622422.html
Copyright © 2011-2022 走看看