题解 | #特征提取#

特征提取

http://www.nowcoder.com/practice/5afcf93c419a4aa793e9b325d01957e2

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); // test cases
        for (int t = 0; t < n; t++) {
            int m = sc.nextInt(); // frames
            int max = 1;
            Map<String, Integer> motions = new HashMap<>();
            motions.put("max", 0);
            for (int i = 0; i < m; i++) {
                int f = sc.nextInt(); // features
                Set<String> hashes = new HashSet<String>();
                for (int j = 0;j < f; j++) {
                    String hash = String.valueOf(sc.nextInt()) + '_' + String.valueOf(sc.nextInt());
                    if (motions.containsKey(hash)) {
                        int times = motions.get(hash)+1;
                        motions.put(hash, times);
                        max = Math.max(max, times);
                    } else {
                        motions.put(hash, 1);
                    }
                    hashes.add(hash);
                }
                for (Map.Entry<String, Integer> entry : motions.entrySet()) {
                    if (!hashes.contains(entry.getKey())) {
                        motions.put(entry.getKey(), 0); //reset number if it stops repeating.
                    }
                }
            }
              
            System.out.println(max);
        }
    }
}

用了一个Set来清除中断的特征,hash用_来连接貌似不是最佳,有更好的建议么?

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务