题解 | #特征提取#

特征提取

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用_来连接貌似不是最佳,有更好的建议么?

全部评论

相关推荐

01-30 22:03
门头沟学院 Java
用微笑面对困难:我滴妈,【俩月】【实习】【主管】仨debuff吃满了,独立设计开发的项目写了绝大占比的运营板块,你独立开发,那维护、问题复盘、日志更新、bug、策划书全是自己整的? 不建议写那么大,可以从小出发更容易
点赞 评论 收藏
分享
03-26 12:00
已编辑
门头沟学院 Java
offer魅魔_oc...:100-200每天,你还要倒贴100
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务