• 题目链接:

    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. Arcgis python输出当前窗口

    import arcpy mxd = arcpy.mapping.MapDocument("CURRENT") mxdfile=arcpy.GetParameterAsText(0 ...

  2. ELMO及前期工作 and Transformer及相关论文

    论文1 https://arxiv.org/pdf/1705.00108.pdf Semi-supervised sequence tagging with bidirectional languag ...

  3. LC 979. Distribute Coins in Binary Tree

    Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and there ar ...

  4. LC 593. Valid Square

    Given the coordinates of four points in 2D space, return whether the four points could construct a s ...

  5. Linux系统调优相关工具

    一.系统调优概述 系统的运行状况: CPU -> MEM -> DISK*-> NETWORK -> 应用程序调优 分析是否有瓶颈(依据当前应用需求) 调优(把错误的调正确) ...

  6. Linux 查看 MySQL的版本信息

    Linux 查看 MySQL的版本信息 如何查看某台 Linux 主机上的 安装的 MySQL版本信息? 使用如下命令,查看 MySQL的版本信息: mysql -V 或者 mysql --versi ...

  7. MATLAB学习(八)神经网络拟合工具箱 Neural Net Fitting使用示例

    >> x=-3:0.2:5;y=x.^2-1;xn=-2:0.1:7; >>     >> %多元函数(z=sin(x2+y2)/(x2+y2))拟合 >&g ...

  8. jquery中对地址中的中文进行encodeURI编码

    传递参数:<script type="text/javascript">     var id= 'abc';  //字符串英文     var num = 998;  ...

  9. Centos7.2 搭建emqttd集群,添加自启动服务

    关闭防火墙(可选):systemctl stop firewalld.service 1.安装依赖库> sudo yum -y install make gcc gcc-c++ kernel-d ...

  10. PTA --- L2-003 月饼

    这道题挺简单的,测试点2没过的话,注意题目中是两个正整数,而其余是正数 [没注意到,,,踩坑了,,,] 题目地址: https://pintia.cn/problem-sets/99480504638 ...