CodeForces - 670C Cinema(离散化+排序/map,水题)
题目链接:点击查看
题目大意:有m部正在上映的电影,每部电影的语音和字幕都采用不同的语言,用一个int范围内的整数来表示语言。有n个人相约在一起去看其中一部电影,每个人只会一种语言,如果一个人能听懂电影的语音,他会很高兴,如果他能看懂字幕,他会比较高兴,如果语音和字母都看不懂,他会不开心,现在要求我们选择一部电影让这n个人一起看,使很高兴的人数最多,若答案不唯一,则在此条件下再让比较高兴的人最多,若此时答案仍然不唯一,输出任意一个答案即可
题目分析:这个题目的关键就是离散化,因为每种语言的编号都在int范围内,我们不方便开数组统计数字,所以需要先离散化一下,然后就可以统计每种数字出现的次数了,最后按照规则排一下序就能得到答案了,比较经典的离散化题目,做一下练练手,需要注意的是不同的语言最多有2*m+n种,也就3*2e5种,cnt数组记得开大点就好啦
说实话其实没必要这么麻烦。。直接上map乱搞就好了
代码:
离散化:
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=2e5+100;struct Node
{int a,b,id;//id保存每部电影的下标bool operator<(const Node& t)const{if(a!=t.a)//先按照很高兴的人数降序排序return a>t.a;return b>t.b;//其次按照比较高兴的人数降序排序}
}node[N];int a[N],b[N],c[N];int cnt[3*N];//cnt数组记得开三倍大小vector<int>v;int get_id(int x)//查找离散化后的下标
{return lower_bound(v.begin(),v.end(),x)-v.begin();
}int main()
{
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(false);int n,m;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",a+i);v.push_back(a[i]);}scanf("%d",&m);for(int i=1;i<=m;i++){scanf("%d",b+i);v.push_back(b[i]);}for(int i=1;i<=m;i++){scanf("%d",c+i);v.push_back(c[i]);}sort(v.begin(),v.end());//离散化 v.erase(unique(v.begin(),v.end()),v.end());for(int i=1;i<=n;i++)//统计cnt[get_id(a[i])]++;for(int i=1;i<=m;i++){node[i].a=cnt[get_id(b[i])];node[i].b=cnt[get_id(c[i])];node[i].id=i;}sort(node+1,node+1+m);cout<<node[1].id<<endl;//排序后node[1]就是答案了return 0;
}
map:
#include<iostream>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cctype>
#include<stack>
#include<queue>
#include<list>
#include<vector>
#include<set>
#include<map>
#include<sstream>
#include<unordered_map>
using namespace std;typedef long long LL;const int inf=0x3f3f3f3f;const int N=2e5+100;struct Node
{int a,b,id;bool operator<(const Node& t)const{if(a!=t.a)return a>t.a;return b>t.b;}
}node[N];unordered_map<int,int>cnt;int main()
{
// freopen("input.txt","r",stdin);
// ios::sync_with_stdio(false);int n,m,num;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&num);cnt[num]++;}scanf("%d",&m);for(int i=1;i<=m;i++){scanf("%d",&num);node[i].a=cnt[num];node[i].id=i;}for(int i=1;i<=m;i++){scanf("%d",&num);node[i].b=cnt[num];}sort(node+1,node+1+m);cout<<node[1].id<<endl;return 0;
}
CodeForces - 670C Cinema(离散化+排序/map,水题)相关推荐
- 【CodeForces - 1A】Theatre Square(水题,几何)(CODEFORCES,梦的开始)
题干: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters ...
- Educational Codeforces Round 7 B. The Time 水题
B. The Time 题目连接: http://www.codeforces.com/contest/622/problem/B Description You are given the curr ...
- poj 2388 排序的水题
纯纯的水题. #include <iostream> #include <fstream> #include <cstdlib>using namespace st ...
- CodeForces - 1263A Sweet Problem(思维,水题)
题目链接:点击查看 题目大意:给出三种颜色的糖果,分别表示为r,g,b,现在Tanya每天可以吃两个不同颜色的糖果,问最多可以吃多少天 题目分析:大水题一个,但自己真的蠢,一开始思路混乱,写了一大堆乱 ...
- Codeforces Round #300 A. Cutting Banner 水题
A. Cutting Banner Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/538/pro ...
- 【CodeForces - 707B】Bakery(思维水题)
Bakery Descriptions 玛莎想在从1到n的n个城市中开一家自己的面包店,在其中一个城市烘焙松饼. 为了在她的面包房烘焙松饼,玛莎需要从一些储存的地方建立面粉供应.只有k个仓库,位于不同 ...
- HDOJ2020 ( 绝对值排序 ) 【水题】
Problem : 2020 ( 绝对值排序 ) Judge Status : Accepted RunId : 6000618 Language : C++ Author : q ...
- C - Internet Address CodeForces - 245B(有些思维的水题)
Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote ...
- HDOJ 1228 A+B(map水题)
A + B Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
最新文章
- redistemplate文档用法_Jedis 使用及 StringRedisTemplate 常用方法
- 苹果手机换了屏显示无服务器,苹果将​​为存在显示问题的iPhone 11提供免费更换...
- CloudStack无法添加模板和iso
- NgModule imports定义的运行时数据结构
- 高斯曲率求表面极值点
- Ubuntu 无法应用原保存的显示器配置
- linux java xmx_linux应用实际内存大于 jvm xmx
- 快速搭建开发环境(Vs Code)
- flex java blazeds_flex+java+blazeds 多通道好文
- 洛神云网络 SLB 负载均衡新姿势
- Windows映射网络驱动器
- 六西格玛dfss_六西格玛设计DFSS.pdf
- Android音视频开发(一)——音视频开发流程
- 化工厂人员定位如何实现,可以解决哪些问题?
- 用Excel曲面图做等高线图(仿罗兰贝格消费者价值体系图)
- 饥荒联机云服务器_饥荒联机云服务器开档
- (JavaSE 学习记录) 多线程之两种常用实现方式
- Electron是什么以及可以做什么
- Ubuntu16.04配置orb_slam2环境,orb_slam的单目数据集,单目实时运行,RGB-D数据集的运行
- kali2020设置默认root用户登录——全网最简单教程