• baro1n
    了解作者
  • WINDOWS
    开发工具
  • 8KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 1
    下载次数
  • 2017-12-04 18:19
    上传日期
头条笔试真题和代码。质量和效果很好,全国的
lianxi.rar
  • lianxi
  • out
  • production
  • lianxi
  • .idea
  • copyright
  • profiles_settings.xml
    76B
  • workspace.xml
    31KB
  • misc.xml
    1.5KB
  • compiler.xml
    686B
  • modules.xml
    252B
  • src
  • lianxia
  • toutiao
  • Main.java
    782B
  • tt
  • Main.java
    2.7KB
  • lianxi.java
    972B
  • Main.java
    669B
  • lianxi.iml
    423B
内容介绍
import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Map.Entry; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in ); while (sc.hasNext()) { String s = sc.nextLine(); String[] str = s.split(" "); int n = Integer.valueOf(str[0]); int m = Integer.valueOf(str[1]); int c = Integer.valueOf(str[2]); Map<Integer ,HashSet<Integer>> mp = new LinkedHashMap<Integer ,HashSet<Integer>>(); HashSet<Integer> color = new HashSet<Integer>(); for (int i = 1; i <= n; i++) { String line = sc.nextLine(); String[] str_line = line.split(" "); HashSet<Integer> st = new HashSet<Integer>(); int sum = Integer.valueOf(str_line[0]); for (int j = 1; j <= sum; j++) { int k = Integer.valueOf(str_line[j]); st.add(k); color.add(k); } mp.put(i, st); } int num = jisun(mp,n,m); if (c>color.size()) { num+=c-color.size(); } System.out.println(num); } } private static int jisun(Map<Integer, HashSet<Integer>> mp,int n,int m) { // TODO Auto-generated method stub if (m>n) { return 0; } int num=0; int start = 0; for (Entry<Integer, HashSet<Integer>> entry : mp.entrySet()) { start =entry.getKey() ; HashSet<Integer> Value = entry.getValue(); if (Value.size()!=0) { break; } } int end = start+m; if (end >n) { end = start%n; } while(end<n){ HashSet<Integer> st_first = mp.get(start); HashSet<Integer> st_next = mp.get(end); int notequalnum=notequalnum(st_first,st_next); if (notequalnum!=0) { num += notequalnum; } end = end+m; if (end==start) { break; } } return num; } private static int notequalnum(HashSet<Integer> st_first, HashSet<Integer> st_next) { // TODO Auto-generated method stub int num=0; for(int i : st_first){ if (st_next.contains(i)) { num++; } } return num; } }
评论
    相关推荐