#include <iostream> #include <algorithm> #include <map> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,buffor0,buffor1; cin>>n; cin>>m; map<int,int>mapa; int *powpis = new int[m]; int **oceny = new int*[m]; for(int i = 0; i < m; i++) oceny[i] = new int[n+1]; for(int i=0;i<n;i++) { cin>>oceny[0][i]; } oceny[0][n]=1; for(int i=0;i<m-1;i++) { copy(oceny[i],oceny[i]+n,oceny[i+1]); cin>>buffor0; cin>>buffor1; swap(oceny[i+1][buffor0-1],buffor1); oceny[i+1][n]=i+2; } for(int i=0;i<m;i++) { powpis[i]=0; for(int j=0;j<(n+1);j++) { powpis[i]*=10; powpis[i]+=oceny[i][j]; } } for(int i=0; i<m; i++) { mapa[powpis[i]]++; } for(pair<int, int>p : mapa) cout<<p.first-((int)p.first/10)*10<<" "; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | #include <iostream> #include <algorithm> #include <map> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n,m,buffor0,buffor1; cin>>n; cin>>m; map<int,int>mapa; int *powpis = new int[m]; int **oceny = new int*[m]; for(int i = 0; i < m; i++) oceny[i] = new int[n+1]; for(int i=0;i<n;i++) { cin>>oceny[0][i]; } oceny[0][n]=1; for(int i=0;i<m-1;i++) { copy(oceny[i],oceny[i]+n,oceny[i+1]); cin>>buffor0; cin>>buffor1; swap(oceny[i+1][buffor0-1],buffor1); oceny[i+1][n]=i+2; } for(int i=0;i<m;i++) { powpis[i]=0; for(int j=0;j<(n+1);j++) { powpis[i]*=10; powpis[i]+=oceny[i][j]; } } for(int i=0; i<m; i++) { mapa[powpis[i]]++; } for(pair<int, int>p : mapa) cout<<p.first-((int)p.first/10)*10<<" "; return 0; } |