Monday, 17 August 2015

USA Tour

Standard
In the state of USA Mr. Adam is a renowned architect. The way in which he has connected the cities is quite interesting.

There are N cities in USA and between any two cities there is a direct one way road connecting them.
Mr Adam has planned a tour so that he can visit all the cities in the state and greet his people. He asks for your help.

The task is to visit all the cities using existing road network but Mr Adam does not want to visit any city more than once on his tour. There may be many possible routes to do this task so suggest him the one which has smallest possible distance.

Input Format:
The first line of input contains an integer N, the number of cities.
Then follow, N lines each containing N integers. These NxN numbers represent the connectivity matrix of cities. The number at position (i, j) indicates the length of direct road from city i to city j. Cities are numbered 0 to N-1.

Output Format:
Print a list of N, space separated integers which denote the order in which the cities should be visited.

Constraints:
N <= 1000

Scoring:
The score for a correct sequence of cities depends on the total path length of the tour.
Score = [[10(N-1)-tourLength]/10(N-1)]*20.

Explanation for Sample Input/Output:
The path 2->1->0 is of length 10+5 =15. So the score is calculated as:
A = 10*2-15 = 5;
B = (5/20)*20 = 5;
Score = 5.00;

Sample Input
3
0 0 0
5 0 0
6 10 0
Sample Output
2 1 0

Time Limit: 10 sec(s) for all input files combined.
Memory Limit: 256 MB
Source Limit: 1024 KB 
 
Code:
 
/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.
import java.io.BufferedReader;
import java.io.InputStreamReader;
*/
import java.util.Scanner;

class TestClass
{
    public static void main(String args[] ) throws Exception
    {
        Scanner scanner = new Scanner(System.in);
        int noOfCitys = 1;
        noOfCitys = Integer.parseInt(scanner.next());
       
        int[][] matrix = new int[noOfCitys][noOfCitys];
       
        for (int i=0; i<noOfCitys; i++)
        {
            for (int j=0; j<noOfCitys; j++)
            {
                matrix[i][j] = Integer.parseInt(scanner.next());
                System.out.println(    matrix[i][j]);
            }
        }
       
       
       
       
//        System.out.println(noOfCitys);
    }

Related Posts:

  • Teaching how to draw A man has brought a new drawing book for his child, which consists only of geometric shapes. Its consists of lessons where the child has to make dr… Read More
  • Radiator Springs We all know the town Radiator Springs, connected to California by direct road (Route no. 66). After a commendable performance by Lighting McQueen … Read More
  • Tom & Jerry Tom and Jerry are wonderful characters. They are always running and make us laugh. Right now, they are in a grid of houses and Jerry is running away… Read More
  • The colorful street There is a street by the name of colorful street in the Pretty Town. The residents of the house have decided that they will paint their houses in e… Read More
  • The cheapest palindrome Palindrome is a string that reads the same backward as forward, e.g., madam. You are given a string whose length is even, and each character of t… Read More

0 comments:

Post a Comment