第一行包含一个正整数N,代表测试用例的个数。
每个测试用例的第一行包含一个正整数M,代表视频的帧数。
接下来的M行,每行代表一帧。其中,第一个数字是该帧的特征个数,接下来的数字是在特征的取值;比如样例输入第三行里,2代表该帧有两个猫咪特征,<1,1>和<2,2>
所有用例的输入特征总数和<100000
N满足1≤N≤100000,M满足1≤M≤10000,一帧的特征个数满足 ≤ 10000。
特征取值均为非负整数。
对每一个测试用例,输出特征运动的长度作为一行
1 8 2 1 1 2 2 2 1 1 1 4 2 1 1 2 2 2 2 2 1 4 0 0 1 1 1 1 1 1
3
特征<1,1>在连续的帧中连续出现3次,相比其他特征连续出现的次数大,所以输出3
业务逻辑题- -难度不大
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int totalnum = sc.nextInt(); for(int x = 0; x < totalnum; x++){ int zhen = sc.nextInt(); HashMap<String, Integer> max = new HashMap(); //存放最大帧形态连续次数 HashMap<String, Integer> current = new HashMap(); //存放当前形态连续次数 ArrayList<String> lastAl = new ArrayList(); //存放上一帧 ArrayList<String> currentAl = new ArrayList(); //存当前帧 for(int y = 0; y < zhen; y++){ int zhenNum = sc.nextInt(); for(int z = 0; z < zhenNum; z++) { int move1 = sc.nextInt(); int move2 = sc.nextInt(); String move = move1 + "_" + move2; //存入当前帧 currentAl.add(move); //判断这一形态是否第一次出现 if(max.get(move) == null){ max.put(move, 1); current.put(move, 1); continue; } //判断上一帧是否出现了这一形态 if (lastAl.indexOf(move) >= 0) { int currentNum = current.get(move) + 1; current.put(move, currentNum); int maxNum = max.get(move); if (maxNum < currentNum) { max.put(move, currentNum); } } else { //max.put(move, 1); current.put(move, 1); } } //当前帧变为上一帧然后处理下一帧。 lastAl.clear(); for(int i = 0; i < currentAl.size(); i++){ lastAl.add(currentAl.get(i)); } currentAl.clear(); } ArrayList<Integer> maxAl = new ArrayList(max.values()); int result = 0; for(int i = 0; i < maxAl.size(); i++){ int m = maxAl.get(i); if(result < m){ result = m; } } System.out.println(result); } } }
原文:https://www.cnblogs.com/clamp7724/p/12334804.html