【Codeforces】-629B-.Far Relative’s Problem(贪心.时间区间)
来源:互联网 发布:二叉树的前序遍历java 编辑:程序博客网 时间:2024/04/27 11:38
点击打开链接
这道题和饭店那道题差不多都是时间区间的问题。
题意:去XX人家,每个人都有一个可以去的开始时间和结束时间,车子只可以带男女数目相等的人,求最多去多少人。
题解:把从第一天到第366天每天可以去的人的数目算出来。
找到一个时间使得min(男生人数,女生人数)最大,最大值乘以2即可。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){int n;int F[5050];int M[5050]; int st,ed;while(~scanf("%d",&n)){memset(F,0,sizeof(F));memset(M,0,sizeof(M));for(int i=1;i<=n;i++){getchar();char c;scanf("%c",&c);if(c=='F'){scanf("%d %d",&st,&ed);for(int i=st;i<=ed;i++)F[i]++;//计算女生每天可以去的人数 }else{scanf("%d %d",&st,&ed);for(int i=st;i<=ed;i++)M[i]++;//计算男生每天可以去的人数 }}int ans=0;for(int i=1;i<=366;i++){if(F[i]<M[i])//取男女人数的较小值,因为去的男女数必须相等 ans=max(ans,F[i]);//但又是取ans的较大值 elseans=max(ans,M[i]);}printf("%d\n",ans*2);}return 0;}
0 0
- 【Codeforces】-629B-.Far Relative’s Problem(贪心.时间区间)
- Codeforces 629B Far Relative’s Problem(简单区间贪心)
- Codeforces 629B Far Relative’s Problem(简单区间贪心)
- Codeforces 629B Far Relative’s Problem 区间贪心
- Codeforces Far Relative’s Problem(区间贪心)
- Codeforces 629B(贪心Far Relative’s Problem
- CodeForces - 629B Far Relative’s Problem (贪心
- CodeForces Far Relative’s Problem (贪心)
- CodeForces 629B Far Relative’s Problem
- 【CodeForces】[629B]Far Relative’s Problem
- CodeForces-629B-Far Relative’s Problem
- 【Codeforces 629 B Far Relative’s Problem】
- CodeForces 629 B. Far Relative’s Problem(水~)
- Codeforces--629B--Far Relative’s Problem(模拟)
- CodeForces 629B Far Relative’s Problem(暴力)
- codeforces 629-B. Far Relative’s Problem(思想)
- 【Codeforces 贪心】Far Relative’s Problem
- CodeForces NO.629B Far Relative’s Problem
- Python入门&进阶资料整合
- 接口
- Apache Parquet 与Apache ORC简介
- 与轮播图结合的ViewPagerIndicatorView
- 继承
- 【Codeforces】-629B-.Far Relative’s Problem(贪心.时间区间)
- Cow Contest(Floyd)
- codeforces #300 E. Demiurges Play Again(tree DP)
- 【源码】LinkedHashMap源码剖析
- (一)Spring框架——概览
- 安装,卸载WPS-office报错,如何解决?
- java根据后台查询结果合并list
- UIWebView的简单使用
- 经验分享之搭建SVN服务器问题集锦