31.07.2015 Views

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

LITHUANIAN OLYMPIADS INFORMATICS

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

54marks (?). Asterisk stands for any sequence of letters and/or digits (the empty sequenceis possible too), question-mark stands for any one letter or digit.Obviously, one can get a lot of various strings from one pattern, for example,strings 00c001BRABA, BRACA, vBRA1A and etc. applies to the pattern *BRA?A,but strings BRaCA, xBRATKA and etc. do not apply to this pattern.We have two patterns. If any string which applies to the first pattern, applies to thesecond one too, and if any string which applies to the second pattern, applies to thefirst one, these patterns are considered to be equivalent.Task. Given two patterns. Write a program to test if these two patterns are equivalent.Input. Input file consists of three lines. The first line contains two integers: lengthsof the first and of the second patterns L 1and L 2. Each pattern can contain from 1 to500 symbols: 1≤L 1,L 2≤500.The second line contains the first pattern(sequence of L 1symbols without spaces); thethird line contains the second pattern (sequenceof L 2symbols without spaces).Output YES to the output file if the patternsare equivalent, and NO otherwise.243. Housepainter. Housepainter who redecorates flats, signed a big contract forthe following month. He divided everything into N separate jobs. However some jobsare interdependent, that is, particular job can be started only if some other one or severaljobs are done. For example, walls can be painted only after they are daubed and primed.If job a should be done before starting job b, then we will say that jobs a and bmake an interdependent pair.The set of jobs is correct, i.e. there is no such chain of interdependent pairs of jobsthat would make a cycle.Task. It is known the number of jobs and the pairs of interdependent jobs. Write a program,to determine the order of performing jobs. The succession of jobs should be such thatthe job a must be done before job b, if only jobs a and b make an interdependent pair.If several solutions are possible, find any one of them.Input. The first line of the input file contains two integers N and P. Where N is thenumber of jobs (1≤N≤250), P is the number of interdependent pairs. It is assumed thatjobs are numerated from 1 to N.In each of the remaining P lines there are written two integer a and b (1≤a,b≤N). Thesenumbers mean that jobs aand b compose an interdependentpair, i.e. that jobb can be started only afterthe job a is finished.The same interdependentpair can only be metonce in the input.ExampleInputOutput5 7 YESbra*abra***aExampleInput Output Other possible solutions4 4 4 4 44 2 3 2 33 1 2 3 14 3 1 1 24 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!