题解 CF670C 【Cinema】
题目链接:
思路:
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】的更多相关文章
- CF670C Cinema 【离散化+map】
题意翻译 莫斯科在举办一场重要的有 nn 个不同国家的珂学家参与的国际会议,每个珂学家都只会一种语言.为了方便起见,我们规定一种语言用 11 到 10^9109 的数来描述. 在会议之后的晚上,珂学家 ...
- CF670C cinema
想必是个半水题,div2的C嘛 仔细观察,发现排序可做. 怎么排序呢?排啥呢?拿啥离散化,拿啥结构体呢? 仔细思考热静分析,便可得出结论: 以每个人会的语言离散化,把每个电影建结构体后不排序,而是枚举 ...
- Codeforces 380D Sereja and Cinema (看题解)
Sereja and Cinema 首先我们可以发现除了第一个人, 其他人都会坐在已入坐人的旁边. 难点在于计算方案数.. 我们可以从外往里把确定的人用组合数算上去,然后缩小范围. #include& ...
- 校省选赛第一场A题Cinema题解
今天是学校省选的第一场比赛,0战绩收工,死死啃着A题来做,偏偏一直WA在TES1. 赛后,才发现,原来要freopen("input.txt","r",stdi ...
- 【题解】CF#896 D-Nephren Runs a Cinema
容易发现这些 vip 用户并没什么用,所以考虑枚举手持50元与100元的人共有多少个.设手持50元的人 \(a\) 个,手持100元的人 \(a - k\) 个,那么一共是 \(2*a - k\) 个 ...
- 「CF670C」Cinema 解题报告
题面 传送门 思路: 离散化.hash 对于这样一个明显的统计排序的题目,当然轻而易举啦~ 但是!看!语言的编号 a数组和 b数组的值最大在\(10^9\)的级别,所以开个数组来存---That's ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【CF896D】Nephren Runs a Cinema 卡特兰数+组合数+CRT
[CF896D]Nephren Runs a Cinema 题意:一个序列中有n格数,每个数可能是0,1,-1,如果一个序列的所有前缀和都>=0且总和$\in [L,R]$,那么我们称这个序列是 ...
- Codeforces Round #350 (Div. 2) C. Cinema 水题
C. Cinema 题目连接: http://www.codeforces.com/contest/670/problem/C Description Moscow is hosting a majo ...
随机推荐
- 码支付(php版本)应用
1.下载软件 2.安装php 版本 2.打开软件,登陆支付宝 3.codepay_config.php 中填写逻辑代码 4.充值路径: 说明:$username = trim($_GET['user ...
- mysql if--else
SQL之case when then用法 case具有两种格式.简单case函数和case搜索函数. --简单case函数 case sex when '1' then '男' when '2' th ...
- PHP遍历目录下的文件夹和文件 以及遍历文件下内容
1.遍历目录下的文件夹和文件: public function bianli1($dir) { $files = array(); if($head = opendir($dir)) { while( ...
- 理解MyCat分库分表
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18.
- smarty section 循环不同的四个样式
<div class="moban_spzs"> <{section name=goodslist loop=$strdata6}> <{if $sm ...
- 怎么用php实现短信验证码发送
我在在众多的第三方短信服务商里选择了云片网这个短信服务商,我也会尽可能利用最简单的方式去帮助广大开发者解决短信验证码功能模块的实现. 再次之前我也参考了大部分网上的博客等,大多数都是把云片网的demo ...
- c语言求素数以及改进算法
代码需要使用c99编译 #include <stdio.h> #include <stdlib.h> #include <math.h> //是否为素数 //从2到 ...
- 1. Linux基本操作和基本命令
常用快捷键: Ctrl + d : 结束符 Ctrl + c : 中断前台进程 Ctrl + z : 将前台进程停止掉 创建终端: 创建终端标签:Ctrl + Shift + t; 切换标签: A ...
- Kubernetes架构
一.Kubernetes 架构: Kubernetes Cluster 由 Master 和 Node 组成,节点上运行着若干 Kubernetes 服务. 1. Master 节点 Master 是 ...
- HTML5 DOM 新增数据类型
HTML5 DOM 新增数据类型 前言 相对于HTML4当中的DOM,在HTML5中的DOM,新增了很多复杂数据类型,为实际的应用提供了便捷的操作. 在HTML5 DOM中,新增了如下的内容: HTM ...