首页 > 代码库 > CF814B An express train to reveries
CF814B An express train to reveries
思路:
模拟,枚举。
实现:
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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。