• 题目链接:

    https://www.luogu.org/problemnew/show/CF670C

  • 思路:

    • step-1:

      语言的数据范围是10^9,所以我们采取用map离散化,这样就能方便且不MLE地记录每个语言会的人数。

    • step-2:

      然后我们再遍历一遍所有场次的电影,记录下最多人能听懂声音的那一场,放在一个ok数组里。

      接着再遍历ok数组,记录最多人能看懂字幕的那一场就是答案。

  • Tips:

    • step-2能用sort代替,但实测这样会过不了第125个点,因为那个点数据比较毒瘤。下面的代码也给出了sort的cmp函数。
    • mx(最大值)要设成小于0的数,多亏了样例2,因为样例2中第一场电影的字幕没有一个人懂。
  • 代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
const int maxn=200005;
map <int,int> lan;
struct Film{
int voi,tit,index;
}film[maxn];
int n,m;
template <class T>inline void read(T &x)
{
x=0;char c;int ne=0;
while(!isdigit(c=getchar()))ne=c=='-';
x=c-48;
while(isdigit(c=getchar()))x=(x<<3)+(x<<1)+c-48;
x=ne?-x:x;
}
inline bool cmp(const Film &x,const Film &y)
{
if(lan[x.voi]==lan[y.voi])
{
return lan[x.tit]>lan[y.tit];
}
return lan[x.voi]>lan[y.voi];
}
int main()
{
int x,mx=-1;
scanf("%d",&n);
for(register int i=1;i<=n;i++){
read(x);
lan[x]++;
}
scanf("%d",&m);
for(register int i=1;i<=m;i++){
read(film[i].voi);
film[i].index=i;
}
for(register int i=1;i<=m;i++){
read(film[i].tit);
}
//sort(film+1,film+1+m,cmp);
int ok[maxn],cnt=0,ans; //step-2
for(register int i=1;i<=m;i++){
if(lan[film[i].voi]>mx){
cnt=0,mx=lan[film[i].voi];
ok[++cnt]=i;
}
else if(lan[film[i].voi]==mx){
ok[++cnt]=i;
}
}mx=-1;
for(register int i=1;i<=cnt;i++){
if(lan[film[ok[i]].tit]>mx){
mx=lan[film[ok[i]].tit];ans=ok[i];
}
}
cout<<ans<<endl;
return 0;
}

题解 CF670C 【Cinema】的更多相关文章

  1. CF670C Cinema 【离散化+map】

    题意翻译 莫斯科在举办一场重要的有 nn 个不同国家的珂学家参与的国际会议,每个珂学家都只会一种语言.为了方便起见,我们规定一种语言用 11 到 10^9109 的数来描述. 在会议之后的晚上,珂学家 ...

  2. CF670C cinema

    想必是个半水题,div2的C嘛 仔细观察,发现排序可做. 怎么排序呢?排啥呢?拿啥离散化,拿啥结构体呢? 仔细思考热静分析,便可得出结论: 以每个人会的语言离散化,把每个电影建结构体后不排序,而是枚举 ...

  3. Codeforces 380D Sereja and Cinema (看题解)

    Sereja and Cinema 首先我们可以发现除了第一个人, 其他人都会坐在已入坐人的旁边. 难点在于计算方案数.. 我们可以从外往里把确定的人用组合数算上去,然后缩小范围. #include& ...

  4. 校省选赛第一场A题Cinema题解

    今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...

  5. 【题解】CF#896 D-Nephren Runs a Cinema

    容易发现这些 vip 用户并没什么用,所以考虑枚举手持50元与100元的人共有多少个.设手持50元的人 \(a\) 个,手持100元的人 \(a - k\) 个,那么一共是 \(2*a - k\) 个 ...

  6. 「CF670C」Cinema 解题报告

    题面 传送门 思路: 离散化.hash 对于这样一个明显的统计排序的题目,当然轻而易举啦~ 但是!看!语言的编号 a数组和 b数组的值最大在\(10^9\)的级别,所以开个数组来存---That's ...

  7. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  8. 【CF896D】Nephren Runs a Cinema 卡特兰数+组合数+CRT

    [CF896D]Nephren Runs a Cinema 题意:一个序列中有n格数,每个数可能是0,1,-1,如果一个序列的所有前缀和都>=0且总和$\in [L,R]$,那么我们称这个序列是 ...

  9. Codeforces Round #350 (Div. 2) C. Cinema 水题

    C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...

随机推荐

  1. 解决WAMP Server与IIS端口冲突问题

    版本前提: 腾讯云服务器 windows server 2012 R2 WampServer3.10  64bit 有两种思路 一.修改wamp端口 文件位置   C:\wamp64\bin\apac ...

  2. CNN基础框架简介

    卷积神经网络简介 卷积神经网络是多层感知机的变种,由生物学家休博尔和维瑟尔在早期关于猫视觉皮层的研究发展而来.视觉皮层的细胞存在一个复杂的构造,这些细胞对视觉输入空间的子区域非常敏感,我们称之为感受野 ...

  3. 使用预设半透明鼠标Cursor

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  4. LC 869. Reordered Power of 2

    Starting with a positive integer N, we reorder the digits in any order (including the original order ...

  5. python设计模式-命令模式

    命令模式就是对命令的封装.所谓封装命令,就是将一系列操作封装到命令类中,并且命令类只需要对外公开一个执行方法execute,调用此命令的对象只需要执行命令的execute方法就可以完成所有的操作.这样 ...

  6. Java线程池(Callable+Future模式)

    转: Java线程池(Callable+Future模式) Java线程池(Callable+Future模式) Java通过Executors提供四种线程池 1)newCachedThreadPoo ...

  7. 小D课堂 - 新版本微服务springcloud+Docker教程_6-01 微服务网关介绍和使用场景

    笔记 第六章 微服务网关zuul开发实战 1.微服务网关介绍和使用场景     简介:讲解网关的作用和使用场景 (画图)          1)什么是网关         API Gateway,是系 ...

  8. Python 的内置函数__import__

    我们知道import语句是用来导入外部模块的,当然还有from...import...也可以,但是其实import实际上是使用builtin函数__import__来工作的.     在一些程序中,我 ...

  9. 8-1 文本三级剑客之sed

    文本三级剑客之sed Stream EDitor, 行编辑器 sed是一种流编辑器,它一次处理一行内容.处理时,把当前处理的行存储在临时缓冲区中,称为"模式空间"(pattern ...

  10. C语言递归之二叉树的最大深度

    题目描述 给定一个二叉树,找出其最大深度. 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数. 说明: 叶子节点是指没有子节点的节点. 示例 给定二叉树 [3,9,20,null,null,15 ...