C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 09-28-2005, 09:22 AM   #1
Registered User
 
Join Date: Sep 2005
Posts: 14
anyone know the solution?

Emily is a teacher. She likes to give candies to her students on days near festivals. She would like to give the candies to the students in order.

She decides to distribute the candies to them one by one, with a rule that if student A is teased by B, A can receive candy before B. But this is a troublesome and time consuming task as she is very busy.

You are asked to help Emily by writing a program to find the order of students that satisfies the rule.

Input

The first line of the input file contains an integer N (2 £ N £ 100), the number of students. The students are numbered as 1 to N. The following N lines describe each student being teased by whom. In the Kth line of those N lines, the first integer M (0 £ M < N) contains the number of students who tease student K, and the next M integers are the student numbers who tease student K.

Output

The output file should contain the sequence of student numbers separated by a space that Emily can distribute the candies with the rule satisfied. If there is more than one solution, you are only required to output anyone of them. If there is no solution, output "No Solution".

Sample Input 1


5
2 2 3
1 3
1 5
1 2
0

Sample Output 1

1 4 2 3 5



Sample Input 2

5
2 2 3
1 3
1 4
1 2
0

Sample Output 2

No Solution




do anyone know how to solve this problem?
heeroyung is offline   Reply With Quote
Old 09-28-2005, 09:34 AM   #2
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
I assume you can figure out input and output okay.

Here's a hint for you. This problem uses a datastructure that represents a graph.
Rashakil Fol is offline   Reply With Quote
Old 09-28-2005, 09:54 AM   #3
cwr
Registered Luser
 
cwr's Avatar
 
Join Date: Jul 2005
Location: Singapore
Posts: 867
Here's another hint for you: Read This
cwr is offline   Reply With Quote
Old 09-28-2005, 10:52 AM   #4
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
> do anyone know how to solve this problem?

This is a little story about four people named Everyone, Someone, Anyone, and Noone.

There was an important job to be done and Everyone was sure that Someone would do it.

Anyone could have done it, but Noone did it.

Someone got angry about that because it was Everyone's job.

Everyone thought that Anyone could do it, but Noone realized that Everyone wouldn't do it.

It ended up that Everyone blamed Someone when Noone did what Anyone could have done
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 09-28-2005, 04:30 PM   #5
Registered User
 
Join Date: Aug 2005
Posts: 1,265
Quote:
Originally Posted by Salem
> do anyone know how to solve this problem?

This is a little story about four people named Everyone, Someone, Anyone, and Noone.

There was an important job to be done and Everyone was sure that Someone would do it.

Anyone could have done it, but Noone did it.

Someone got angry about that because it was Everyone's job.

Everyone thought that Anyone could do it, but Noone realized that Everyone wouldn't do it.

It ended up that Everyone blamed Someone when Noone did what Anyone could have done
I haven't heard that one before.
Ancient Dragon is offline   Reply With Quote
Old 09-28-2005, 05:24 PM   #6
Registered User
 
Join Date: Sep 2005
Posts: 14
Quote:
Originally Posted by cwr
Here's another hint for you: Read This
this is not my homework!this is a question from Hong Kong Computer Olympiad. i study this question just for my own interest.
heeroyung is offline   Reply With Quote
Old 09-28-2005, 05:25 PM   #7
Registered User
 
Join Date: Sep 2005
Posts: 14
Quote:
Originally Posted by Rashakil Fol
I assume you can figure out input and output okay.

Here's a hint for you. This problem uses a datastructure that represents a graph.
do you mean using array?let me try first
heeroyung is offline   Reply With Quote
Old 09-28-2005, 05:52 PM   #8
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,730
Quote:
Originally Posted by heeroyung
this is not my homework!this is a question from Hong Kong Computer Olympiad. i study this question just for my own interest.
Then actually study it. Asking if any of us know how to solve it doesn't help you at all.
Thantos is offline   Reply With Quote
Old 09-28-2005, 11:53 PM   #9
Registered User
 
Join Date: Sep 2005
Posts: 14
Quote:
Originally Posted by Thantos
Then actually study it. Asking if any of us know how to solve it doesn't help you at all.
i have already think this problem for two days. i don't think it's wrong to ask for some hints.
heeroyung is offline   Reply With Quote
Old 09-29-2005, 12:08 AM   #10
aoeuhtns
 
Join Date: Jul 2005
Posts: 581
Are you familiar with graphs?

Topological sort.
Rashakil Fol is offline   Reply With Quote
Old 09-29-2005, 12:19 AM   #11
Registered User
 
Join Date: Sep 2005
Posts: 14
Topological sort
what's the meaning of this word?
heeroyung is offline   Reply With Quote
Old 09-29-2005, 01:06 AM   #12
and the hat of vanishing
 
Salem's Avatar
 
Join Date: Aug 2001
Location: The edge of the known universe
Posts: 21,214
> what's the meaning of this word?
Oh please tell me you've heard of google....
__________________
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Up to 8Mb PlusNet broadband from only £5.99 a month!
Salem is offline   Reply With Quote
Old 09-29-2005, 07:36 AM   #13
& the hat of GPL slaying
 
Thantos's Avatar
 
Join Date: Sep 2001
Posts: 5,730
Quote:
Originally Posted by heeroyung
i have already think this problem for two days. i don't think it's wrong to ask for some hints.
Then how about sharing some of the ideas that didn't work. Sorry but I don't believe you. If you show at least some attempt then we can actually aid you.
Thantos is offline   Reply With Quote
Old 09-29-2005, 08:33 AM   #14
Registered User
 
Join Date: Sep 2005
Posts: 14
Quote:
Originally Posted by Thantos
Then how about sharing some of the ideas that didn't work. Sorry but I don't believe you. If you show at least some attempt then we can actually aid you.
No need to say sorry. That's normal.

This question require us to find a correct order of students. This can be done by making an array, e.g.
Code:
student[5]={1,2,3,4,5}
, and then do swapping.if student 4 is teased by 1.the final array should be like that:{4,2,3,1,5}. The hardest problem is there may have some contradiction. e.g. student 4 is teased by 1 but student 1 is also teased by student 4! this come to another output--no solution. yesterday i thought one method---use array to store each student, and the following space store the number of students who tease this student. but i don't think this is a good method because the file size may be very large and the running time may be very long. so i hope to hear some opinions from you.

(if you still don't trust me, you can ask me to explain. since my english standard is very low, i hope you can understand what i am saying above.)
heeroyung is offline   Reply With Quote
Old 09-30-2005, 06:05 AM   #15
Registered User
 
Join Date: Sep 2005
Posts: 14
no one help me..................
heeroyung is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
K&R solution? deadhippo C Programming 12 05-09-2008 06:36 AM
'Solution' and 'Project' usage in VC++ C+/- C++ Programming 2 01-13-2007 09:50 AM
My Unix/Linux SECURITY SOLUTION - pls read bjdea1 Linux Programming 3 04-11-2004 09:28 PM
Solution - Israel and Palestine? Vber A Brief History of Cprogramming.com 1 03-19-2003 08:27 AM
Speed Challenge, my solution: RoD C++ Programming 11 03-17-2003 09:12 PM


All times are GMT -6. The time now is 01:36 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22