时间:2016-04-07 14:39:44 星期四
题目编号:[2016-04-07][codeforces][629][B][Far Relative’s Problem]
题目大意:给定n个朋友的性别和位置以及得闲的时间,问最多能同时邀请多少朋友到家里做客,要求男和女的人数一样
分析:
- 直接前缀和数组,处理出366天中某一天都多少个男性和女性,扫一遍366天,求和取最大值即可
遇到的问题:
- 不一定要当天男女人数相同才能够聚会,而是应该取最小那个数目*2来计算
#include <cstdio>#include <algorithm>using namespace std;int cnt[2][366 + 10];int main(){ int n; scanf("%d",&n); char s[10];int a,b; for(int i = 0 ; i < n ; ++i){ scanf("%s%d%d",s,&a,&b); ++cnt[s[0] == 'M'][a]; --cnt[s[0] == 'M'][b + 1]; } int cnt1 = 0,cnt2 = 0,res = 0; for(int i = 1; i <= 366;++i ){ cnt1 += cnt[0][i]; cnt2 += cnt[1][i]; res = max(res, min(cnt1,cnt2) * 2); } printf("%d\n",res); return 0;}