1. 程式人生 > >CF814B An express train to reveries

CF814B An express train to reveries

out == else using for ons 思路 names con

思路:

模擬,枚舉。

實現:

 1 #include <iostream>
 2 using namespace std;
 3 
 4 const int N = 1005;
 5 
 6 int a[N], b[N], cnt[N], n, x, y;
 7 
 8 int main()
 9 {
10     cin >> n;
11     for (int i = 0; i < n; i++) cin >> a[i], cnt[a[i]]++;
12     for (int i = 0; i < n; i++) cin >> b[i];
13 for (int i = 1; i <= n; i++) 14 { 15 if (cnt[i] == 2) x = i; 16 else if (cnt[i] == 0) y = i; 17 } 18 for (int i = 0; i < n; i++) 19 { 20 if (a[i] == x) 21 { 22 a[i] = y; 23 int bad = 0; 24 for (int j = 0; j < n; j++)
25 if (b[j] != a[j]) bad++; 26 if (bad == 1) 27 { 28 for (int j = 0; j < n; j++) cout << a[j] << " "; 29 return 0; 30 } 31 a[i] = x; 32 } 33 } 34 return 0; 35 }

CF814B An express train to reveries