Horror Film Night【贪心】

Horror Film Night

时间限制: 2 Sec 内存限制: 128 MB

题目描述

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?

输入

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 a single line containing a single integer, the maximal number of films they can watch together in a fair way.

样例输入

1 40

2 37 42

样例输出

3


题意:

就是给你两个同学,有一个叫E,有一个叫M,他们两个喜欢看恐怖片,

然而他们对一部电影的感觉不近相同,

1、可能两个人有一个人喜欢,另一个不喜欢。

2、如果两个人都不喜欢,肯定不会去看。

如果遇到情况一,那么另一个人就会和这个喜欢的同共同协商,调整下一个要看的电影。

这个要看的电影一定是对于正在上映的电影不喜欢的那位。

简单来说就是:

1、【2,4,6,8】

2、【3,5,6,9】

现在怎样执行??才能看得到最多的电影。

就是 【2、3、4、5、6、8、9】

这样就可以了,一句简单的话就是,一个人不能同时看两部不喜欢的电影。

 

『题解』:

贪心即可,因为数据是1e6我直接跑一遍也是挺快的。

所以我决定用vis数组来处理,第一个人喜欢就是1,第二个人喜欢就是2,

两者都喜欢那就是3.

 

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
int k1,k2,a[N],b[N],vis[N]={0};
int main()
{
    scanf("%d",&k1);
    for(int i=0;i<k1;i++){
        scanf("%d",&a[i]);
        vis[a[i]]+=1;
    }
    scanf("%d",&k2);
    for(int i=0;i<k2;i++){
        scanf("%d",&b[i]);
        vis[b[i]]+=2;
    }
    int cur=0,ans=0;
    for(int i=1;i<=N-1;i++){
        if(cur==vis[i]){
            continue;
        }else if(vis[i]==3){
            cur=0;
            ans++;
        }else if(cur==1&&vis[i]==0){
            continue;
        }else if(cur==2&&vis[i]==0){
            continue;
        }else if(cur!=vis[i]&&vis[i]!=0){
            ans++;
            cur=vis[i];
        }
    }
    printf("%d\n",ans);
    return 0;
}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值