Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let node_exists map x =
- List.exists (fun (x1, _, _) -> x = x1) map
- let get_map ln gwn =
- let rec f1 cnt acc =
- if cnt <= 0 then acc
- else
- let x, y = Scanf.sscanf (input_line stdin) "%d %d" (fun n1 n2 -> (n1, n2)) in
- let acc = if (node_exists acc x)
- then
- let acc = List.map (fun (x1, links, gw) -> if x = x1 then x1, (y :: links), gw else (x1, links, gw)) acc in
- if (node_exists acc y)
- then List.map (fun (x1, links, gw) -> if y = x1 then x1, (x :: links), gw else (x1, links, gw)) acc
- else ((y, [x], false) :: acc)
- else if (node_exists acc y)
- then List.map (fun (x1, links, gw) -> if y = x1 then x1, (x:: links), gw else (x1, links, gw)) acc
- else ((y, [x], false) :: (x, [y], false) :: acc) in
- f1 (cnt - 1) acc in
- let map = f1 ln [] in
- let rec f2 cnt acc =
- if cnt <= 0 then acc
- else
- let v = int_of_string (input_line stdin) in
- f2 (cnt - 1) (v :: acc) in
- let gateways = f2 gwn [] in
- let into_gateways (x, links, _) =
- let is_gw = List.mem x gateways in
- (x, links, is_gw) in
- List.map into_gateways map
- ;;
- let l, e = Scanf.sscanf (input_line stdin) "%d %d %d" (fun _ l e -> (l, e)) in
- (* l: the number of links *)
- (* e: the number of exit gateways *)
- let map = get_map l e in
- (* game loop *)
- while true do
- let si = int_of_string (input_line stdin) in (* The index of the node on which the Skynet agent is positioned this turn *)
- (* Write an action using print_endline *)
- (* To debug: prerr_endline "Debug message"; *)
- print_endline "1 2"; (* Example: 0 1 are the indices of the nodes you wish to sever the link between *)
- ();
- done;
- (*
- Your virus has caused a backdoor to open on the Skynet network enabling you to send new instructions in real time.
- You decide to take action by stopping Skynet from communicating on its own internal network.
- Skynet's network is divided into several smaller networks, in each sub-network is a Skynet agent tasked with transferring information by moving from node to node along links and accessing gateways leading to other sub-networks.
- Your mission is to reprogram the virus so it will sever links in such a way that the Skynet Agent is unable to access another sub-network thus preventing information concerning the presence of our virus to reach Skynet's central hub.
- Rules
- For each test you are given:
- A map of the network.
- The position of the exit gateways.
- The starting position of the Skynet agent.
- >>> Nodes can only be connected to up to a single gateway. <<<
- Each game turn:
- First off, you sever one of the given links in the network.
- Then the Skynet agent moves from one Node to another accessible Node.
- Skynet agent
- Gateway
- Victory Conditions
- The Skynet agent cannot reach an exit gateway
- Lose Conditions
- The Skynet agent has reached a gateway
- Example
- 4 4 1
- 0 1
- 0 2
- 1 3
- 2 3
- 3
- Initialization input
- Text representation of the network used in this example. There are 4 nodes, 4 links and 1 gateway. The next 4 lines describe the links. The last integer is the index of the exit node.
- Turn 1
- The Skynet agent starts at node 0 (SI = 0). Our virus cut the link between the nodes 1 and 3.
- Turn 2
- The Skynet agent moves to node 2 (SI = 2). Our virus cut the link between the nodes 2 and 3.
- Turn 3
- The Skynet agent has been cut off from the exit, you have won !
- Initialization input
- Line 1: 3 integers N L E
- - N, the total number of nodes in the level, including the gateways.
- - L, the number of links in the level.
- - E, the number of exit gateways in the level.
- Next L lines: 2 integers per line (N1, N2), indicating a link between the nodes indexed N1 and N2 in the network.
- Next E lines: 1 integer EI representing the index of a gateway node.
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement