AcWing 103. ACW 103
原题链接
简单
作者:
66brother
,
2021-07-17 01:03:44
,
所有人可见
,
阅读 283
ACW103
思路:
- 用map 储存各种语言的个数
- 对于每个电影,根据开心值和挺开心值排序
Java++ 代码
// Don't place your source in a package
import javax.swing.*;
import java.lang.reflect.Array;
import java.text.DecimalFormat;
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
import java.util.stream.Stream;
// Please name your class Main
public class Main {
static FastScanner fs=new FastScanner();
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
public String next() {
while (!st.hasMoreElements())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int Int() {
return Integer.parseInt(next());
}
long Long() {
return Long.parseLong(next());
}
String Str(){
return next();
}
}
public static void main (String[] args) throws java.lang.Exception {
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
//reading /writing file
//Scanner sc=new Scanner(new File("input.txt"));
//PrintWriter pr=new PrintWriter("output.txt");
int T=1;
for(int t=0;t<T;t++){
int n=Int();
int A[]=Arr(n);
int m =Int();
int B[]=Arr(m);
int C[]=Arr(m);
Solution sol=new Solution(out);
sol.solution(A,B,C);
}
out.close();
}
public static int[] Arr(int n){
int A[]=new int[n];
for(int i=0;i<n;i++)A[i]=Int();
return A;
}
public static int Int(){
return fs.Int();
}
public static long Long(){
return fs.Long();
}
public static String Str(){
return fs.Str();
}
}
class Solution {
PrintWriter out;
int INF = Integer.MAX_VALUE;
int MOD = 1000000007;
public Solution(PrintWriter out) {
this.out = out;
}
public void solution(int A[],int B[],int C[]) {
Map<Integer,Integer>f=new HashMap<>();
for(int i:A){
if(!f.containsKey(i)){
f.put(i,1);
}
else{
f.put(i,f.get(i)+1);
}
}
int D[][]=new int[B.length][3];
for(int i=0;i<B.length;i++){
D[i][2]=i+1;
if(f.containsKey(B[i])){
D[i][0]=f.get(B[i]);
}
if(f.containsKey(C[i])){
D[i][1]=f.get(C[i]);
}
}
Arrays.sort(D,(a,b)->{
if(a[0]==b[0]){
return b[1]-a[1];
}
return b[0]-a[0];
});
out.println(D[0][2]);
}
}