欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

202006-2 csp稀疏向量java

程序员文章站 2024-03-17 21:34:04
...

202006-2 csp稀疏向量java

 

202006-2 csp稀疏向量java

202006-2 csp稀疏向量java

202006-2 csp稀疏向量java

思路:1.一维数组60 2 二维数组 60 3 hashmap 60 4最后参考网上 发现是因为结果是long的原因

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.StringTokenizer;

class Reader {
    static StringTokenizer token =new StringTokenizer("");
    static BufferedReader reader   =new BufferedReader (new InputStreamReader(System.in)) ;
    static String nextLine() throws IOException {
        return reader.readLine() ;
    }
    static  String next() throws IOException {
        while(!token.hasMoreTokens()) {
            token =new StringTokenizer(reader.readLine()) ;
        }
        return token.nextToken() ;
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next()) ;
    }
    static double nextDouble() throws IOException {
        return Double.parseDouble(next()) ;
    }

}
public class XiShu {



    public static void main(String[] args) throws IOException {
        int n = Reader.nextInt();
        int a = Reader.nextInt();
        int b = Reader.nextInt();
        HashMap<Integer,Integer> map = new HashMap<>();



        for (int i = 0; i < a;i++){

               int key = Reader.nextInt();
               int value = Reader.nextInt();
               map.put(key,value);

        }
        long sum = 0L;

        for (int i = 0; i < b;i++){

            int key = Reader.nextInt();
            int value = Reader.nextInt();
            if(key!=0 && map.containsKey(key)) sum += map.get(key) * value;

        }

       System.out.println(sum);
    }
}

样例输入 

10 3 4
4 5
7 -3
10 1
1 10
4 20
5 30
7 40

 

 

上一篇: PAT A1022. Digital Library (30)

下一篇: