ZOJ 3780 E-paint the Grid Again topology ordering

Source: Internet
Author: User

Https://vjudge.net/problem/49919/origin

Test Instructions: give you n*n only the character array of O and X appears. There are two operations, an operation RI turns the I row into X, an operation CI turns the I column into O, and each operation is performed at most once. Now the target state is given, so what is the minimum order of the dictionary order under the empty disk?

Ideas: It seems complicated to get the title, but the careful reading will find that X and O are only performed by a specific action, and the operation is done only once, so that each row is considered separately, such as an O in row I, and X (if there is no x so the RI operation can be omitted), the operation of CJ after the RI operation The same method to consider the column, you can get all the need to do the relative sequence of rows and columns. This is clearly a topological structure. Then the row or column operations are considered points, and the map topology is sorted.

The key is still modelling, vijos on a very similar topic (1030), but more complex than this one needs DFS. However, because of the complexity of the requirements of this province is not very strict, but also can be simulated.

But I didn't even think about it. Sort by topology Orz

weak-dish?

/** @Date: 2017-03-27-21.44 * @Author: Lweleth ([email protected]) * @Link: https://github.com/* @Versi On: */#include <bits/stdc++.h> #define LL long long#define PII pair#define MP (x, y) Make_pair ((x), (y)) #define FI fir St#define se second#define PB (x) push_back ((x)) #define MMG (x) memset ((x), -1,sizeof (x)) #define MMF (x) memset ((x), 0, sizeof (x)) #define MMI (x) memset ((x), INF, sizeof (x)) using namespace Std;const int INF = 0x3f3f3f3f;const int N = 1e5+20;co NST double EPS = 1e-8;const int ost = 510;char mp[510][510];vectorvt[1100];int fr[510], fc[510];int cnt[1100];int n;void i    NIT () {MMF (FR);    MMF (FC);    MMF (CNT);    for (int i = 0; I < n + ost; i++) vt[i].clear ();                for (int i = 0, i < n; i++) {for (int j = 0; J < N; j + +) {if (mp[i][j] = = ' O ')            FC[J] = 1;        else fr[i] = 1;        }} for (int i = 0; i < n; i++) {if (!fr[i]) continue;        for (int j = 0; J < N; j + +){if (mp[i][j] = = ' O ') vt[i].        PB (j + ost), Cnt[j + ost]++;        }} for (int j = 0; J < N; j + +) {if (!fc[j]) continue; for (int i = 0; i < n; i++) {if (mp[i][j] = = ' X ') Vt[j + OST].        PB (i), cnt[i]++;    }}}void Top () {int ct = 0;    Priority_queue<int, vector, greater >q;    for (int i = 0; I < n + ost; i++) {if (cnt[i] = = 0 && vt[i].size ()! = 0) Q.push (i);        } while (!q.empty ()) {int NW = Q.top ();        Q.pop ();            for (int i = 0; i < vt[nw].size (); i++) {int nt = vt[nw][i];            cnt[nt]--;        if (!cnt[nt]) Q.push (NT);        } if (NW < OST) printf ("%sr%d", ct==0? "": "", NW + 1), CT = 1;    else printf ("%sc%d", ct==0? "": "", Nw-ost + 1), CT = 1;    } if (ct = = 0) printf ("No solution"); printf ("\ n");}    int main () {int T;    Cin >> T; while (t-) {cin >> n;        for (int i = 0; i < n; i++) {scanf ("%s", Mp[i]);        } init ();    Top (); } return 0;}

ZOJ 3780 E-paint the Grid Again topology sort

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.