4 条题解
-
5huhes (liangjiaQ) LV 10 @ 2021-12-4 20:00:52
#pragma GCC optimize ("O2") #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<fstream> #include<iomanip> #include<iostream> #include<string> #include<map> using namespace std; const int INF=0x3f3f3f3f; const int N=2e5+10; const int eps=1e-5; int n,m,lan[N],sub[N],lanp[N],subp[N],maxi,maxlan,maxsub; map<int,int> mp; int read() { char ch=getchar(); int x=0,f=1; while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+ch-48; ch=getchar(); } return x*f; } int main() { n=read(); for(int i=1,x;i<=n;i++) { x=read(); mp[x]++; } m=read(); for(int i=1;i<=m;i++) lan[i]=read(); for(int i=1;i<=m;i++) { sub[i]=read(); lanp[i]=mp[lan[i]]; subp[i]=mp[sub[i]]; } for(int i=1;i<=m;i++) { if(lanp[i]>maxlan||lanp[i]==maxlan&&subp[i]>=maxsub) { maxi=i; maxlan=lanp[i]; maxsub=subp[i]; } } printf("%d",maxi); return 0; }
-
32021-8-7 18:35:25@
C++ :
#pragma GCC optimize ("O2") #include <iostream> #include <map> using namespace std; struct movie{ int lan; int title; }mov[200000]; map <int,int> a; inline int read() { char ch = getchar(); int ans = 0,f = 1; while(ch<'0'||ch>'9') { if(ch == '-') f = -1; ch = getchar(); } while(ch>='0'&&ch<='9') { ans = ans*10 + ch - '0'; ch = getchar(); } return ans*f; } int main() { int n; n=read(); for(int i=0;i<n;i++) { int t; t=read(); a[t] ++; } int m; cin>>m; for(int i=0;i<m;i++) mov[i].lan = read(); for(int i=0;i<m;i++) mov[i].title = read(); int maxlan,maxtitle,maxpos; maxlan = maxtitle = -1; for(int i=0;i<m;i++) { int x,y; x = a[mov[i].lan]; y = a[mov[i].title]; if(x>maxlan) { maxlan = x; maxtitle = y; maxpos = i+1; } else if(x==maxlan) { if(y>=maxtitle) { maxtitle = y; maxpos = i+1; } } } cout<<maxpos<<endl; return 0; }
-
12023-9-27 18:27:40@
#pragma GCC optimize ("O2") #include<algorithm> #include<cmath> #include<cstdio> #include<cstring> #include<fstream> #include<iomanip> #include<iostream> #include<string> #include<map> using namespace std; const int INF=0x3f3f3f3f; const int N=2e5+10; const int eps=1e-5; int n,m,lan[N],sub[N],lanp[N],subp[N],maxi,maxlan,maxsub; map<int,int> mp; int read() { char ch=getchar(); int x=0,f=1; while(ch<'0'||ch>'9') { if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&ch<='9') { x=(x<<3)+(x<<1)+ch-48; ch=getchar(); } return x*f; } int main() { n=read(); for(int i=1,x;i<=n;i++) { x=read(); mp[x]++; } m=read(); for(int i=1;i<=m;i++) lan[i]=read(); for(int i=1;i<=m;i++) { sub[i]=read(); lanp[i]=mp[lan[i]]; subp[i]=mp[sub[i]]; } for(int i=1;i<=m;i++) { if(lanp[i]>maxlan||lanp[i]==maxlan&&subp[i]>=maxsub) { maxi=i; maxlan=lanp[i]; maxsub=subp[i]; } } printf("%d",maxi); return 0; }
-
02023-12-9 22:29:13@
#pragma GCC optimize ("O2") #include <iostream> #include <map>
using namespace std; struct movie{ int lan; int title; }mov[200000]; map <int,int> a; inline int read() { char ch = getchar(); int ans = 0,f = 1; while(ch<'0'||ch>'9') { if(ch == '-') f = -1; ch = getchar(); } while(ch>='0'&&ch<='9') { ans = ans10 + ch - '0'; ch = getchar(); } return ansf; } int main() { int n; n=read(); for(int i=0;i<n;i++) { int t; t=read(); a[t] ++;
} int m; cin>>m; for(int i=0;i<m;i++) mov[i].lan = read(); for(int i=0;i<m;i++) mov[i].title = read(); int maxlan,maxtitle,maxpos; maxlan = maxtitle = -1; for(int i=0;i<m;i++) { int x,y; x = a[mov[i].lan]; y = a[mov[i].title]; if(x>maxlan) { maxlan = x; maxtitle = y; maxpos = i+1; } else if(x==maxlan) { if(y>=maxtitle) { maxtitle = y; maxpos = i+1; } } } cout<<maxpos<<endl; return 0;
}
- 1
信息
- ID
- 15
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 1
- 标签
- 递交数
- 157
- 已通过
- 114
- 上传者