Feb-28-2020, 07:03 AM
Hi,
How can we write program for below probelm to accept input and output accordingly:-
We have a list of pair{i,j} of teams where i and j are the
teams who will play their first match together in the tournament.There are 2*N teams numbered 0 to 2*N-1.management wants to make this list
good looking before world cup starts .A good looking list has team pairs like {0,1},{2,3},{4,5},{6,7}...{2*N-2,2*N-1) only.
Note that order doesn't matter ,{0,1} nd {1,0} are both valid good looking pair.
Given a list of team pairs,what is the minimum number of team swaps needed to make it a good looking list.
Input:-
First line contains one integer 1<=N<=1000,number of pairs.
Next N line contains 2 space separated integers representing a pair {i,j} in current list.
Output Format:-
Print one integer,that is minimum number of swaps needed to make the list good looking
Sample Input 1:
3
1 3
0 2
4 5
Sample Output 1:
1
Explanation:
If we swap 0 and 3 list becomes (1,0),(3,2) and (4,5),which is a good looking list.
Sample Input 2:
2
3 2
0 1
Sample Output 2:
0
Explanation:
List is already good looking.
How can we write program for below probelm to accept input and output accordingly:-
We have a list of pair{i,j} of teams where i and j are the
teams who will play their first match together in the tournament.There are 2*N teams numbered 0 to 2*N-1.management wants to make this list
good looking before world cup starts .A good looking list has team pairs like {0,1},{2,3},{4,5},{6,7}...{2*N-2,2*N-1) only.
Note that order doesn't matter ,{0,1} nd {1,0} are both valid good looking pair.
Given a list of team pairs,what is the minimum number of team swaps needed to make it a good looking list.
Input:-
First line contains one integer 1<=N<=1000,number of pairs.
Next N line contains 2 space separated integers representing a pair {i,j} in current list.
Output Format:-
Print one integer,that is minimum number of swaps needed to make the list good looking
Sample Input 1:
3
1 3
0 2
4 5
Sample Output 1:
1
Explanation:
If we swap 0 and 3 list becomes (1,0),(3,2) and (4,5),which is a good looking list.
Sample Input 2:
2
3 2
0 1
Sample Output 2:
0
Explanation:
List is already good looking.