21212

package farm;

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

public class Farmland {
 
 public static List<Vertice> vertices = new ArrayList<Vertice>();
 
 public static int[] degree = new int[300];
 
 public static Map<Integer, List<Integer>> adjsMap = new HashMap<Integer, List<Integer> >();
 
 public static boolean[] visited = new boolean[300];
 
 public static int begin;
 
 public static int length;
 
 public static int findProper(int size) {
  int result = 0;
  for(int i = 0; i < vertices.size(); i++) {
   begin = vertices.get(i).getNum();
   length = size - 1;
   DFS(begin, size-1);
  }
  return result;
 }
 
 public static void DFS(int v, int len) {
  visited[v] = true;
  if(len == length)
  int w;
  List<Integer> adjs = adjsMap.get(v);
  for(int i = 0; i < degree[v]; i++) {
   w = adjs.get(i);
   if(visited[w]) {
    DFS(w);
   }
  }
 }

 public List<Integer> calc(List<String> input) {
  List<Integer> resultList = new ArrayList<Integer>();
  int caseNum = Integer.parseInt(input.get(0));
  int index = 1;
  int size = 0;
  while(caseNum > 0) {
   caseNum--;
   vertices.clear();
   int verticeNum = Integer.parseInt(input.get(index++));
   for(int i = 0; i < verticeNum; i++) {
    String verticeStr = input.get(index++);
    String[] verticedes = verticeStr.split("\\s");
    
    visited[Integer.parseInt(verticedes[0])] = false;
    Vertice vertice = new Vertice(Integer.parseInt(verticedes[0]),
      Integer.parseInt(verticedes[1]), Integer.parseInt(verticedes[2]),
      Integer.parseInt(verticedes[3]));
    degree[vertice.getNum()] = Integer.parseInt(verticedes[3]);
    List<Integer> adjList = new ArrayList<Integer>();
    for(int j = 4; j < verticedes.length; j++) {
     adjList.add(Integer.parseInt(verticedes[j]));
     adjsMap.put(vertice.getNum(), adjList);
    }
    vertices.add(vertice); 
   }
   
   size =  Integer.parseInt(input.get(index++));
   
   resultList.add(findProper(size));
  }
  return resultList;
 }
 
 public static void main(String[] args) {
  Scanner scanner = new Scanner(System.in);
  List<String> inputstrList = new ArrayList<String>();
  while(scanner.hasNextLine()) {
   String tmp = scanner.nextLine();
   inputstrList.add(tmp);
  }
  List<Integer> resultList = new Farmland().calc(inputstrList);
  for(Integer result : resultList) {
   System.out.println(result);
  }
 }

}

 

Farmland

 

Description

We have a map for farming land in a country. The whole farming land of the country is divided into a set of disjoint farming regions. Each farmer owns only one farming region in this country. There is a boundary fence between two neighboring farming regions. The farmland map for this country can be represented in a plane graph. The following Figure-1 shows one example.


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值