sgu 133 分类: sgu 2015-03...

本文提供了一种解决SGU133编程问题的方法,使用C++实现了一个算法,该算法通过比较节点的属性来确定答案。代码中定义了一个结构体用于存储节点信息,并使用了标准模板库中的sort函数进行排序。

水题

#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>

#define INF 1<<30

const int MAXN = 16005;

struct node{int a,b;}mp[MAXN] = {0};

bool cmp(const node &x,const node &y)
{
    return ((x.a < y.a) || (x.a == y.a && x.b < y.b));
}
int main()
{
    int n , ans = 0 ,maxb = -INF;

#ifndef ONLINE_JUDGE    
    freopen("sgu133.in","r",stdin);
    freopen("sgu133.out","w",stdout);
#endif  

    scanf("%d",&n);

    for(int i = 1; i <= n ; i++) scanf("%d%d",&mp[i].a, &mp[i].b);

    std::sort(mp + 1, mp + n + 1,cmp);

    for(int i = 2; i <= n ; i++)
    {
        if(mp[i - 1].a < mp[i].a){maxb = std::max(maxb , mp[i - 1].b);}

        if(mp[i].b < maxb) ans ++;

    }

    printf("%d",ans);

#ifndef ONLINE_JUDGE    
    fclose(stdin);
    fclose(stdout);
#endif  
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/dashgua/p/4723097.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值