首页 > 其他 > 详细

CF814B An express train to reveries

时间:2017-06-18 14:52:17      阅读:282      评论:0      收藏:0      [点我收藏+]

思路:

模拟,枚举。

实现:

 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

原文:http://www.cnblogs.com/wangyiming/p/7044282.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!