• 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 }
  • 相关阅读:
    Javascript
    CSS3新增特性HTML标签类型
    HTML5新增的标签
    prototype __proto__ Function
    oninput
    extend
    hasOwnProperty()
    this prototype constructor
    Array类型判断
    指针
  • 原文地址:https://www.cnblogs.com/wangyiming/p/7044282.html
Copyright © 2020-2023  润新知