ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

H - Horror Film Night

2020-01-13 09:37:14  阅读:406  来源: 互联网

标签:Horror watch Sample film they Night films Output Film


/problems/horrorfilmnight/file/statement/en/img-0001.jpg

 

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 11 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≤10000000≤k≤1000000 for the number of films this person likes;

  • followed by kk integers indicating all days (numbered by 0,…,9999990,…,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

 

题意:有两个朋友 一起去看电影,每个人都有自己喜欢的电影;

规则:(1)两个人不能看都不喜欢的电影;

           (2)看的两场电影中不能出现同时为同一个人喜欢看,而另一个人不喜欢看;

思路:其实很简单就是将所有数压到一个数组中去重,然后对这个数组排序,让num=总数,只要出现两个相邻的电影同为一个人喜欢且另一个人不喜欢就tot

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn =1e6+10;
const  ll mod =1e9+7;
int a[maxn];
int b[maxn];
struct node
{
    int x,y;
}st[maxn*2];
vector<int>p;
vector<int>q;
map<int,int>mp1;
map<int,int>mp2;
bool cmp(node n,node m)
{
    return n.x<m.x;
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        mp1[a[i]]=1;
    }
    int m;
    int num=0;
    scanf("%d",&m);
    int tot=0;
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&b[i]);
        if(mp1[b[i]])
        {
            mp1[b[i]]=0;
            st[++tot].x=b[i];
            st[tot].y=3;
        }
        else
        {
            st[++tot].x=b[i];
            st[tot].y=1;
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(mp1[a[i]])
        {
           st[++tot].x=a[i];
           st[tot].y=2;
        }
    }
    sort(st+1,st+tot+1,cmp);
    num=tot;
    for(int i=1;i<tot;i++)
    {
        if(st[i].y==st[i+1].y&&st[i].y!=3)
        {
            num--;
        }
    }
    cout<<num<<endl;
    return 0;
}

减一,最后输出tot就可以。。。。比赛的时候,想复杂了,比完赛补题,ac的时候发现自己太菜了

 

Ramzes_666_fan 发布了4 篇原创文章 · 获赞 0 · 访问量 12 私信 关注

标签:Horror,watch,Sample,film,they,Night,films,Output,Film
来源: https://blog.csdn.net/Ramzes_666_fan/article/details/103952152

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有