HDU5386 (more than 2015 schools 8)--cover

Source: Internet
Author: User

Topic Link: Click to open the link

The main idea: given the initial value of a n*n matrix, and the final value, there is now M operation L I J, the value of column I is reset to J,h i J, the value of line I is reset to J. Ask how the M operation should be done and the matrix can be changed.

Looking forward from the final value of the scheme, each time to find the row and the remaining colors in the column are all the same, see if there is no use of the operation can complete it, if there is recorded, then the final output according to the reverse of the record, it is possible to complete the sequence of changes

#include <cstdio> #include <cstring> #include <stack> #include <algorithm>using namespace std;    struct node{char s[5]; int x, y;}    P[510]; int map[110][110]; int vis[510], n, m; stack <int> sta; void solve (int k) {int i;            if (p[k].s[0] = = ' L ') {for (i = 1; I <= n; i++) {if (map[i][p[k].x] = = 0) continue;        if (map[i][p[k].x]! = p[k].y) break;            } if (i > N) {sta.push (k);            Vis[k] = 1;        for (i = 1; I <= n; i++) map[i][p[k].x] = 0;            }} else {for (i = 1; I <= n; i++) {if (map[p[k].x][i] = = 0) continue;        if (map[p[k].x][i]! = p[k].y) break;            } if (i > N) {sta.push (k);            Vis[k] = 1;        for (i = 1; I <= n; i++) map[p[k].x][i] = 0;    }}}int Main () {int T, I, J;    scanf ("%d", &t); while (t--{scanf ("%d%d", &n, &m);        for (i = 1; l <= N; i++) for (j = 1; J <= N; j + +) scanf ("%d", &map[i][j]);        for (i = 1; l <= N; i++) for (j = 1; J <= N; j + +) scanf ("%d", &map[i][j]);        for (i = 0; i < m; i++) scanf ("%s%d%d", P[i].s, &p[i].x, &AMP;P[I].Y);        memset (vis,0,sizeof (VIS));        while (!sta.empty ()) Sta.pop ();                for (i = 0; i < m; i++) {for (j = 0; J < m; J + +) {if (vis[j]) continue;            Solve (j);            }} for (i = 1; i < m; i++) {printf ("%d", Sta.top () +1);        Sta.pop ();        } printf ("%d\n", Sta.top () +1);    Sta.pop (); } return 0;}


Copyright NOTICE: Reprint Please specify source: Http://blog.csdn.net/winddreams

HDU5386 (more than 2015 schools 8)--cover

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.