牛客网真题-64-特征提取

特征提取

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

参考抄袭大佬思路:双map当作两个相邻帧,开始还想着字符串匹配,kmp,dp之类的。

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        while (n > 0) {
            n--;
            int cnt;
            Map<String, Integer> map1 = new HashMap<>();
            int m = scanner.nextInt();
            if(m>0){
                cnt=1;
            }else{
                cnt=0;
            }
            for(int i = 0; i < m; i++){
                int t = scanner.nextInt();
                int[][] temp = new int[t][2];
                Map<String, Integer> mapNow = new HashMap<>();
                for(int j = 0; j < t; j++){ //对1行处理
                    temp[j][0] = scanner.nextInt();
                    temp[j][1] = scanner.nextInt();
                    if(map1.containsKey(temp[j][0] + "," + temp[j][1])){
                        int cntTemp = map1.get(temp[j][0] + "," + temp[j][1]) + 1;
                        mapNow.put(temp[j][0] + "," + temp[j][1], cntTemp);
                        cnt = Math.max(cntTemp, cnt);
                    }else{
                        mapNow.put((temp[j][0] + "," + temp[j][1]), 1);
                    }
                }
                map1 = mapNow;
            }
            System.out.println(cnt);
        }
    }
}
全部评论
上理校友有点猛啊大佬
点赞 回复 分享
发布于 2020-10-09 01:23

相关推荐

01-26 19:51
门头沟学院 Java
isabener:怎么感觉像群发的呢
点赞 评论 收藏
分享
评论
2
收藏
分享

创作者周榜

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