1 #include "iostream" 2 #include "cstdio" 3 #include "cstring" 4 #include "algorithm" 5 #include "vector" 6 using namespace std; 7 int cmd[110][110]; 8 bool used[110], locked[110]; 9 int n, m, k; 10 int core[110], pre[110]; 11 12 int main() 13 { 14 int i, j; 15 scanf("%d%d%d", &n, &m, &k); 16 for(i = 1; i <= n; ++i) 17 for(j = 1; j <= m; ++j) 18 scanf("%d", &cmd[i][j]); 19 for(j = 1; j <= m; ++j) { 20 memset(used, 0, sizeof(used)); 21 memset(pre, 0, sizeof(pre)); 22 for(i = 1; i <= n; ++i) { 23 if(core[i] || (!cmd[i][j])) 24 continue; 25 if(locked[cmd[i][j]]) { 26 core[i] = j; 27 } 28 else if(used[cmd[i][j]]){ 29 locked[cmd[i][j]] = 1; 30 core[i] = j; 31 core[pre[cmd[i][j]]] = j; 32 } 33 else { 34 pre[cmd[i][j]] = i; 35 used[cmd[i][j]] = 1; 36 } 37 } 38 } 39 for(i = 1; i <= n; ++i) { 40 printf("%d\n", core[i]); 41 } 42 }
时间: 2024-10-24 05:16:09