Day8 lexicographic orders of prosperous simulation games

Source: Internet
Author: User

/* This question requires us to find a Lexicographic Order. The order given by the string will limit the relative order before and after the Lexicographic Order of the letters. How can we express this limitation? We notice that this one is followed by another, only the previous one can be output. It is obviously the topological sorting, the minimum solution is to give priority to the queue. */# include <iostream> # include <cstdio> # include <string> # include <cstring> # include <algorithm> # include <vector> # include <queue> using namespace STD; const int maxn = 115; struct edge {int V; int NXT;} e [maxn * 50]; int n, l [maxn], ANS [maxn], orz; int head [maxn], CNT, Du [maxn]; char Sb [maxn] [maxn]; priority_que UE <int, vector <int>, greater <int> q; int read () {char CH = getchar (); int x = 0, F = 1; while (! (CH> = '0' & Ch <= '9') {If (CH = '-') F =-1; CH = getchar ();}; while (CH> = '0' & Ch <= '9') {x = x * 10 + (CH-'0'); CH = getchar ();}; return x * F;} void ins (int u, int v) {CNT ++; E [CNT]. V = V; E [CNT]. NXT = head [u]; head [u] = CNT;} void build () {Int J; For (INT I = 2; I <= N; I ++) {j = 1; while (j <= L [I-1] & J <= L [I] & SB [I] [J] = Sb [I-1] [J]) J + +; If (j> L [I-1] | j> L [I] | Sb [I] [J] = Sb [I-1] [J]) continue; ins (SB [I-1] [J]-'A ', SB [I] [J]-'A'); Du [SB [I] [J]-'a'] ++ ;}} bool TOPO () {int U, to; For (INT I = 0; I <26; I ++) {If (! Du [I]) Q. Push (I);} while (! Q. empty () {ans [++ orz] = Q. top (); q. pop (); U = ans [orz]; for (INT I = head [u]; I; I = E [I]. NXT) {to = E [I]. v; Du [to] --; If (! Du [to]) {q. push (to) ;}}return orz = 26;} int main () {freopen ("lexicographical. in "," r ", stdin); freopen (" lexicographical. out "," W ", stdout); n = read (); For (INT I = 1; I <= N; I ++) {scanf (" % s ", SB [I] + 1); L [I] = strlen (SB [I] + 1);} build (); If (! Topo () cout <"impossible"; else {for (INT I = 1; I <= 26; I ++) {char TMP = ans [I] + 'a'; cout <TMP ;}} return 0 ;}

 

Day8 lexicographic orders of prosperous simulation games

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.