---
# System prepended metadata

title: j354. 積木對接 (Blocks)

---

# j354. 積木對接 (Blocks)
## 題目連結: [j354](https://zerojudge.tw/ShowProblem?problemid=j354)
有兩塊積木，分別有凹槽和卡榫交錯，卡榫和卡榫不能對接。
我用vector建立了兩個陣列，如果是卡榫就寫2，凹槽就寫1，兩個相加小於等於3就可以對接。
``` cpp=
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n = 0;
    cin>>n;
    vector<int>a;
    for (int i = 0; i< (2*n)+1; i++)
    {
        int temp = 0;
        cin>>temp;
        while (temp > 0)
        {
            a.push_back(1+(i%2));
            temp--;
        }
    }

    int m = 0;
    cin>>m;
    vector<int>b;
    for (int i = 1; i<= (2*m)-1; i++)
    {
        int temp = 0;
        cin>>temp;
        while (temp > 0)
        {
            b.push_back(1+(i%2));
            temp--;
        }
    }


    int f2 = 0;
    for (int i = 0; i<a.size()-b.size()+1; i++)
    {
        int f = 1;
        for (int j = 0; j<b.size(); j++)
        {
            if (b[j] + a[j+i] > 3)
            {
                f = 0;
            }
        }
        if (f == 1)
        {
            cout<<"YES";
            f2 = 1;
            break;
        }
    }
    if (f2 == 0)
    {
        cout<<"NO";
    }
}
```