ZOJ 1589 dead sor John ~ Floyd algorithm

Source: Internet
Author: User

Both Floyd and Dij can be used for this question, but it is very convenient to use Floyd. It is also the first time to use the Floyd algorithm. I didn't have this idea at first, so I could refer to other people's ideas ..~~~~ (>_< )~~~~

 

# Include <stdio. h> # include <iostream> # include <string. h> using namespace std; int main (void) {int ncases, n, I, j, k; int map [30] [30], mark [30] [30]; cin> ncases; for (int f = 1; f <= ncases; f ++) {memset (map, 0, sizeof (map); memset (mark, 0, sizeof (mark); int flag = 1; cin> n; char s [4]; while (n --) {scanf ("% s", s ); int a, B; char o; a = s [0]-'A' + 1; o = s [1]; B = s [2]-'A' + 1; if (o = '<') map [A] [B] = 1; else Map [B] [a] = 1;} memcpy (mark, map, sizeof (map); for (k = 1; k <= 28; k ++) for (I = 1; I <= 28; I ++) for (j = 1; j <= 28; j ++) map [I] [j] = map [I] [j] | (map [I] [k] & map [k] [j]); // here the Floyd is cleverly deformed .. At least I think this is a weak dish. Aha printf ("Case % d: \ n", f); for (I = 1; I <= 28; I ++) for (j = 1; j <= 28; j ++) if (map [I] [j]) &! Mark [I] [j]) {printf ("% c <% c \ n", I + 'a'-1, j + 'a'-1 ); flag = 0;} if (flag) printf ("NONE \ n") ;}return 0 ;}

 

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.