日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CodeForces - 670C Cinema(离散化+排序/map,水题)

發布時間:2024/4/11 编程问答 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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,水题)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。