[sicily]【1001】 会议安排(田忌赛马类贪心)

题干:

N个会议要同时举行,参会人数分别为A[0], A[1], ...,A[N-1]. 现有M个会议室,会议室可容纳人数分别为B[0], B[1], ...,B[M-1]. A[i]<=B[j]时,可以把会议i安排在会议室j,每间会议室最多安排一个会议,每个会议最多只能安排一个会议室. 求最多安排多少个会议.

1<= N, M <= 100000, 每个会议的参会人数和每间会议室的容纳人数均在11000之间.

请为下面的Solution类实现解决上述问题的函数assignConferenceRoom. 函数参数AB的意义如上,返回值为最多可安排的会议数.

class Solution {

public:

    intassignConferenceRoom(vector<int>& A, vector<int>& B) {

        

    }

};

1A={2, 3}, B={1, 2},答案为1.

2A={3, 4, 5}B={10, 3, 2},答案为2.

注意:你只需要提交Solution类的代码,你在本地可以编写main函数测试程序,但不需要提交main函数的代码. 注意不要修改类和函数的名称.


解题报告:

    田忌赛马类贪心。需要将两个数组均同序排序,然后进行求解。

ac代码:

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;int A[100],B[100];
int main()
{int n;cin>>n;for(int i = 0; i<n; i++) {scanf("%d",&A[i]); }for(int i = 0; i<n; i++) {scanf("%d",&B[i]); }sort(A,A+n,greater<int>() );sort(B,B+n,greater<int>() );int i = 0 , j = 0;int ans = 0 ;while(i<n && j<n) {if(B[j]>= A[i]) {ans++;j++;i++;}else {i++;}}printf("%d\n",ans);return 0 ;      } 

有一个题是类似的,链接如下:


本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/442162.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

设备怎样开启位置服务器,开启设备服务器

开启设备服务器 内容精选换一换购买Windows弹性云服务器后&#xff0c;通过MSTSC远程连接&#xff0c;发现没有声音。通过MSTSC远程连接的Windows弹性云服务器如何播放音频&#xff1f;本节内容适用于Windows Server 2008 R2、Windows Server 2016系统的弹性云服务器。Windows弹…

高端又易学的vbs表白程序了解一下

第一个、 打开txt文件&#xff0c;复制以下代码粘贴进去&#xff08;可以修改中文部分&#xff0c;其它代码不要动&#xff01;&#xff09;。保存并关闭txt文件。 msgbox("做我女朋友好吗&#xff1f;") msgbox("房产证上写你名字") msgbox("保大&qu…

离散化处理 模板

离散化模板&#xff1a; #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int maxn100000; int a[maxn]; int b[maxn]; int n,m; void lisan(); int main() {cin>>n;//元素个数for(int i1;i<n;i) {scanf(&qu…

cf#401(Div. 2)B. Game of Credit Card(田忌赛马类贪心)

题干&#xff1a;After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his fa…

NYOJ-14 会场安排问题(经典贪心,区间完全不覆盖模板)

附另一&#xff1a;此类问题选题总结&#xff1a;https://blog.csdn.net/qq_41289920/article/details/81001357 题干&#xff1a; 会场安排问题时间限制&#xff1a;3000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;4描述学校的小礼堂每天都会有许多活动&#xff0c;有…

可以使用田忌赛马类贪心问题的前提(或说 如何判断题目符合田忌赛马类贪心问题)

前提就是&#xff0c;首先&#xff0c;需要两个数组&#xff01;&#xff01;两个数组&#xff01;&#xff01;两个数组&#xff01;&#xff01;才可以考虑这个&#xff01; 其次&#xff0c;A和B这两个数组的个数是相同的。也正因为如此&#xff0c;所以从大到小排序或者从小…

【nyoj 270】数的分解(统计因子模板)

题干&#xff1a; 数的分解时间限制&#xff1a;1000 ms | 内存限制&#xff1a;65535 KB难度&#xff1a;1描述你的任务是找到一个最小的正整数Q&#xff0c;使Q的各位数的乘积等于N。输入最多450组测试数据。数据以EOF结尾。输入一个整数N&#xff08;0 ≤ N ≤ 400)。输出…

asp.net mvc 地址栏传输信息报错:window.location.pathname

asp.net mvc 地址栏传输信息报错&#xff1a;window.location.pathname 前端cshtml代码内容 代码片. // 页面跳转 window.location.pathname /Home/Index?cc123;“/”应用程序中的服务器错误 从客户端(?)中检测到有潜在危险的 Request.Path 值。 如何解决 web.config中添…

区间覆盖全部类型及部分精选习题汇总详解(贪心策略)

内容如下&#xff1a; 1&#xff09;区间完全覆盖问题 问题描述&#xff1a;给定一个长度为m的区间&#xff0c;再给出n条线段的起点和终点&#xff08;注意这里是闭区间&#xff09;&#xff0c;求最少使用多少条线段可以将整个区间完全覆盖 样例&#xff1a; 区间长度8&#…

数据库提示:正在还原中,无法访问 应该怎么办?

Sql语句 restore database 数据库名 with recovery

数据库工具一段时间后打开报错:远程过程调用失败0x800706be

1.原因可能是安装vs时自带更高版本的sql server服务造成的&#xff0c;只需要卸载Microsoft SQL Server 2012 Express LocalDB或 Microsoft SQL Server 2012 LocalDB就行了 2.先安装vs工具&#xff0c;然后安装数据库工具

【POJ - 1328】Radar Installation(贪心+计算几何)安装雷达辐射岛屿

题干&#xff1a;Assume the coasting is an infinite straight line. Land is in one side of coasting, sea in the other. Each small island is a point locating in the sea side. And any radar installation, locating on the coasting, can only cover d distance, so …

sql语句实现分页查询

2005及以上版本 -- 分页查询&#xff08;通用型&#xff09; select top pageSize * from (select row_number() over(order by sno asc) as rownumber,* from student) temp_row where rownumber>((pageIndex-1)*pageSize);2012及以上版本 select * from student orde…

【51nod-1289】大鱼吃小鱼

题干&#xff1a; 有N条鱼每条鱼的位置及大小均不同&#xff0c;他们沿着X轴游动&#xff0c;有的向左&#xff0c;有的向右。游动的速度是一样的&#xff0c;两条鱼相遇大鱼会吃掉小鱼。从左到右给出每条鱼的大小和游动的方向&#xff08;0表示向左&#xff0c;1表示向右&…

如何通过属性给实体赋值

获取实体属性 Type type family.GetType(); //family为实体对象 PropertyInfo[] infos type.GetProperties(); foreach (PropertyInfo info in infos){info.GetValue(family); //取值info.SetValue(bFamily, info.GetValue(family)); //赋值 }

【CF#801 A.】 Vicious Keyboard(字符串查找,水题)

题干&#xff1a;Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one let…

关于ajax请求400问题解决

ajax请求&#xff1a;400 bad request 原因有两种&#xff1a; 参数不匹配&#xff0c;请求太长 如何解决 针对参数不匹配&#xff0c;只能一一对照 请求太长的话&#xff0c;api最好使用post方式请求&#xff0c;我遇到的问题就是post请求太长&#xff0c;这时候需要给参数…

【uva-673】 Parentheses Balance(括号匹配问题)

题干&#xff1a; You are given a string consisting of parentheses () and []. A string of this type is said to be correct:(a)if it is the empty string(b)if A and B are correct, AB is correct,(c)if A is correct, (A) and [A] is correct.Write a program that ta…

layui前端框架弹出框图标整理

1绿色对勾 2红色 3黄色问号 4黑色小锁 5红色哭脸 6绿色笑脸

【CF#757A】Gotta Catch Em' All!

题干&#xff1a;Bash wants to become a Pokemon master one day. Although he liked a lot of Pokemon, he has always been fascinated by Bulbasaur the most. Soon, things started getting serious and his fascination turned into an obsession. Since he is too young…