题解 CF387B 【George and Round】

本文介绍了一种使用贪心算法解决编程竞赛题目的方法,通过将题目按复杂度排序并遍历,实现资源的最大化利用。文章提供了完整的C++代码示例,包括快速读取输入、排序和枚举等步骤。

题目大家都理解清楚了吧

其实就是尽量多用已有的题,就要求对自己的题按复杂度由低到高排序,从头到尾遍历,用贪心。排序为了便于比较。然后就是只要普通的遍历枚举就可以辣~

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cctype>
#include <vector>
#include <queue>
#include <stack>//头文件(管理都不用万能我为神马要用万能)
using namespace std;
int n,m,a[1000005],b[1000005],l,r;//不要被这个空间吓着了,放心,不会炸
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
    while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
    return x*f;
}//快读(cz专用模板)
int main(){
    n=read(),m=read();
    for(int i=0;i<n;i++)
        a[i]=read();
    for(int i=0;i<m;i++)
        b[i]=read();//输入部分就不详细讲了
    sort(a,a+n);
    sort(b,b+m);//排序,以便后头进行比较分析
    while(l<n&&r<m){//遍历枚举
        if(a[l]<=b[r])
            l++; 
        r++;
    }
    cout<<n-l<<endl;//最后输出掉
    return 0;
}

 

 

转载于:https://www.cnblogs.com/Sworddust/p/11615280.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值