JD 1463:招聘会 and JD 1434:今年暑假不AC

5 篇文章 0 订阅

本来这都是简单题的,今天奇了怪了。。。动态规划求最长递增子序列的长度 可以 A1434不能A1463 ,一直以为这种题用dp做的,今天发现有问题。。毁三观了。其实还是自己太蠢 。

不用dp的话,那就贪心吧。

要使得参加的最多,也就要使能结束的早点结束,后面才能有更多的选择,于是根据结束时间递增排序,前面一个结束,后面一个开始。

JD 1463:招聘会:click here~~

AC_CODE

const int maxn = 10008 ;
const int inf = 1<<30 ;
int n , m ;
struct Node{
    int from , to ;
    bool friend operator<(const Node &A , const Node &B){
        return A.to < B.to ;
    }
}node[maxn];
int dp[maxn] ;
int main(){
    int i , j , k ;
    while(cin >> n){
        for(i = 0;i < n;i++){
            scanf("%d%d",&node[i].from , &node[i].to) ;
        }
        sort(node , node + n) ;
        int cnt = 0 , t = -1 ;
        for(i = 0;i < n;i++){
            if(node[i].from >= t){
                cnt++ ;
                t = node[i].to ;
            }
        }
        printf("%d\n",cnt) ;
    }
    return 0 ;
}


 JD 1434:今年暑假不AC

AC_CODE

const int maxn = 10008 ;
const int inf = 1<<30 ;
int n , m ;
struct Node{
    int from , to ;
    bool friend operator<(const Node &A , const Node &B){
        return A.to < B.to ;
    }
}node[maxn];
int dp[maxn] ;
int main(){
    int i , j , k ;
    while(cin >> n){
        if(n == 0) break ;
        for(i = 0;i < n;i++){
            scanf("%d%d",&node[i].from , &node[i].to) ;
        }
        sort(node , node + n) ;
        int cnt = 0 , t = -1 ;
        for(i = 0;i < n;i++){
            if(node[i].from >= t){
                cnt++ ;
                t = node[i].to ;
            }
        }
        printf("%d\n",cnt) ;
    }
    return 0 ;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值