当前位置:网站首页>C. Fishingprince Plays With Array

C. Fishingprince Plays With Array

2022-06-30 07:42:00 I would like to have egg yolk and meat dumplings

I didn't make a big score in the game . The idea is right , No function written , Writing is ugly and long , I don't know what's wrong . I learned the short writing of others .

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int maxn=1e6+5;
int a[maxn],b[maxn];
int n,m;

vector<pair<int,int>> zip(int *a,int n)
{
    vector<pair<int,int>>v;
    int last=0,num=0;
    for(int i=1;i<=n;i++)
    {
        int cnt=1;
        while(a[i]%m==0)
        {
            cnt*=m;
            a[i]/=m;
        }
        if(a[i]==last) num+=cnt;
        else
        {
            v.push_back({num,last});
            num=cnt;
            last=a[i];
        }
    }
    v.push_back({num,last});
    return v;
}

void solve()
{
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    int k;
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        cin>>b[i];
    }
    if(zip(a,n)==zip(b,k)) puts("YES");
    else puts("NO");
}
 
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--) solve();
}

原网站

版权声明
本文为[I would like to have egg yolk and meat dumplings]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/181/202206300724544671.html