Posts: 94
Threads: 8
Joined: Jan 2020
ok,but where to add those extra print statements and which are the right branches which could satisfy below conditions in this program:-
nput:-
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.
Posts: 1,823
Threads: 2
Joined: Apr 2017
You really want us to do all the thinking for you, don't you? That's disappointing.
Posts: 94
Threads: 8
Joined: Jan 2020
no i don't want that but where exactly should i ake changes and what changes should i make to get this input/output results?
Thanks
Posts: 1,823
Threads: 2
Joined: Apr 2017
You're literally trying nothing to work it out. Put some effort into debugging your program if you want help.
Posts: 94
Threads: 8
Joined: Jan 2020
any idea how could i debug it in pycharm IDE to fix to get desired results?
Thanks
Posts: 1,823
Threads: 2
Joined: Apr 2017
What's wrong with printing, as I suggested?
Posts: 94
Threads: 8
Joined: Jan 2020
it's not printing as expected:-nput:-
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.
Posts: 1,823
Threads: 2
Joined: Apr 2017
Sigh. We're just going around in circles here. You need to add more print statements to help you work out why that is.
Why are you not willing to do any of your own work? Repeating over and over that your program doesn't work, without showing any effort in trying the suggestions is not a good use of anyone's time.
Posts: 1,350
Threads: 2
Joined: May 2019
Think about it. You are using a 1D array (list) to store your numbers and define your pairs as x[n] and x[n+1]. Is this the best way, or should you use actual pairs?
What are you doing to prevent accidentally stranding numbers making the task impossible? For example, if your list has the numbers 0,1,2,3,4,5 and you have one of your pairs as 1,2, that is a "good looking pair" but 0 can never be paired to be good looking (hint - all pairs must have the even number as the lower number and the odd as lower+1).
That should get you going. Show your work along with intermediate results.
Posts: 94
Threads: 8
Joined: Jan 2020
(Feb-29-2020, 03:07 PM)jefsummers Wrote: Think about it. You are using a 1D array (list) to store your numbers and define your pairs as x[n] and x[n+1]. Is this the best way, or should you use actual pairs?
What are you doing to prevent accidentally stranding numbers making the task impossible? For example, if your list has the numbers 0,1,2,3,4,5 and you have one of your pairs as 1,2, that is a "good looking pair" but 0 can never be paired to be good looking (hint - all pairs must have the even number as the lower number and the odd as lower+1).
That should get you going. Show your work along with intermediate results.
I am not sure which way is best here only thing i am concerned to solve it as soon as possible,as i have been struggling with this complex problem for a long time now.if any one could please tell me exactly what corrections i should make in my existing code to get desired input/output then it would be much aprrecited.
Thanks
|