2019山东省省赛H题 ---zoj4120

Tokens on the Segments
在这里插入图片描述
Sample Input
2
3
1 2
1 1
2 3
3
1 2
1 1
2 2
Sample Output
3
2
Hint
For the first sample test case, one can put three tokens separately on (1, 2), (2, 1) and (3, 3).

For the second sample test case, one can put two tokens separately on (1, 2) and (2, 3).
题目大意:
T组数据,每一组数据包含一个整数n,代表有n段,每一段的左右端点分别给出,该段的纵坐标就是当前第几段;
emmm,解释一下样例,第一个样例输入 1 2,代表连接从(1,1) 到(2,1)的线段;
再输入1 1 ,代表着连接(1,2)点 到(1,2)点 的一个线段(┗( ▔, ▔ )┛,当然这是一个点啦);
最后输入2 3,意思同上啦!!
每个段的整数点上都有一个叫做token的东东,需要去从这三个段上去取token,当然已经取的横坐标上的token不能再取了,问最多存在多少个段。
分析:
就题意来看,最多就存在n个段,不可能再多了,然后我们可以将其给出的每一个段,先按照右端点去从小到大去排序,如果右端点是相等的,那么就需要按照左端点从小到大去排序,然后再去暴力这n个段

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
#include <cstring>
#include <cmath>
#include <queue>
#include <cstdio>
#include <vector>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
const int N = 1e5+10;
const int INF=0x3f3f3f3f;
const ll LINF=0x3f3f3f3f3f3f3f3f;
const int MOD=1e9+7;
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define Abs(x) ((x)>=0?(x):-(x))
struct node{
    int l,r;
    bool operator < (const node &a) const {
        if(a.r==r) return l<a.l;
        return r<a.r;
}
}num[N];
map<int ,int >ma;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif // ONLINE_JUDGE
    int T;
    scanf("%d",&T);
    while(T--){
        int n;
        scanf("%d",&n);
        rep(i,1,n)
        scanf("%d%d",&num[i].l,&num[i].r);
        sort(num+1,num+1+n);
        int ans=0;

        ma.clear();
        for(int i=1;i<=n;i++){
            for(int j=num[i].l;j<=num[i].r;j++)
            if(!ma[j]) {
                ma[j]=1;
                ans++;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
 }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值