H - Horror Film Night Kattis - horrorfilmnight

H - Horror Film Night

题意:有两个人想去一起看电影,然后分别给出两个人 分别喜欢看的电影都在哪些天,然后, 同一个人 不能连续看两天他不喜欢的电影。
求他们最多可以看多少次电影。

思路:把这两个人喜欢的电影分别标记一下,遍历1e7,
1.如果他们都喜欢,加一;2. 有一个喜欢而且上一场电影自己不喜欢的,加一。

Emma and Marcos are two friends who love horror films. This year, and possibly the years hereafter, they want to watch as many films together as possible. Unfortunately, they do not exactly have the same taste in films. So, inevitably, every now and then either Emma or Marcos has to watch a film she or he dislikes. When neither of them likes a film, they will not watch it. To make things fair they thought of the following rule: They can not watch two films in a row which are disliked by the same person. In other words, if one of them does not like the current film, then they are reassured they will like the next one. They open the TV guide and mark their preferred films. They only receive one channel which shows one film per day. Luckily, the TV guide has already been determined for the next 1 million days.

Can you determine the maximal number of films they can watch in a fair way?

Input
The input consists of two lines, one for each person. Each of these lines is of the following form:

One integer 0≤k≤1000000 for the number of films this person likes;

followed by k integers indicating all days (numbered by 0,…,999999) with a film this person likes.

Output
Output a single line containing a single integer, the maximal number of films they can watch together in a fair way.

Sample Input 1 Sample Output 1
1 40
2 37 42
3
Sample Input 2 Sample Output 2
1 1
3 1 3 2
2
Sample Input 3 Sample Output 3
1 2
1 2
1

#include<bits/stdc++.h>
using namespace std;
#define mm 10000010
int a[mm], b[mm];

int main()
{
    ios::sync_with_stdio(0);
    int n, m;
    cin >> n;
    memset(a, 0, sizeof(a));
    for(int i = 0; i <n; i ++)
    {
        int x;
        cin >>x;
        a[x] = 1;
    }
    cin >> m;
    memset(b, 0, sizeof(b));
    for(int i = 0; i < m; i ++)
    {
        int x;
        cin >> x;
        b[x] = 1;
    }
    int pre1 = 0;
    int pre2 = 0;
    int ans = 0;
    for(int i = 0; i < mm; i ++)
    {
        if(a[i]&&b[i])
        {
            pre1 = 0;
            pre2 = 0;
            ans++;
        }
        else if(a[i]&&!pre1)
        {
            pre2 = 0;
            pre1 = 1;
            ans++;
        }
        else if(b[i]&&!pre2)
        {
            pre2 = 1;
            pre1 = 0;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值