Luo Gu P5594 [XR-4] simulation game

Portal

Thinking

This is a real problem Water, simulates just fine

\(subtask1\):

\ (the n-1 = m = k = \) , it is clear that this part of the sub answer is \ (1 \) , then we successfully got the \ (13 \) points, good results

Behind scores ...... seems to be no need to have, anyway, I was directly written out. Then we look out for ideas

Since everyone after the \ (k \) days have \ (m \) day free to do simulation questions, then we use a free day of deposit structure and several sets of simulation questions, as follows

struct node {
    int x, num;
    //x表示输入的编号,即第几天有空,num表示这一天应该做哪一套模拟题
}a[N][N];

Then \ (n ^ 2 \) after the input we can directly process, we use a \ (VIS \) array, \ (VIS [I] [J] \) represents \ (I \) Day \ (J \) sets simulation that has not been used, two sets of direct circulation, it is determined \ (a [i] [j ] .x \) day \ (a [i] [j ] .num \) this simulation that has not used, if not used, will be \ (vis [a [i] [j] .x] [a [i] [j] .num] \) is set to have visited, let \ (ans [i] ++ \) , if you have this day have used a set of simulation questions directly to continue the cycle, the time complexity \ (O (the n-^ 2) \) , space complexity \ (O (the n-^ 2) \) , then the question we have done

Is not it the water? ? The Code \ (qwq \)

Code

/*
By:Loceaner
*/
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;

inline int read() {
    char c = getchar();
    int x = 0, f = 1;
    for( ; !isdigit(c); c = getchar()) if(c == '-') f = -1;
    for( ; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
    return x * f;
}

const int N = 1e3 + 11;

struct node {
    int x, num;
} a[N][N];

int n, m, k, ans[N], vis[N][N];

int main() {
    n = read(), m = read(), k = read();
    for(int i = 1; i <= n; i++)
        for(int j = 1; j <= m; j++) {
            a[i][j].x = read();
            a[i][j].num = j;
        }
    for(int i = 1; i <= n; i++) 
        for(int j = 1; j <= m; j++) 
            if(!vis[a[i][j].x][a[i][j].num]) {
                vis[a[i][j].x][a[i][j].num] = 1;
                ans[a[i][j].x]++;
            }
    for(int i = 1; i <= k; i++) printf("%d ", ans[i]);
    return 0;
}

Guess you like

Origin www.cnblogs.com/loceaner/p/11711323.html