cf题 C - Division by Two and Permutation 思维题

cf题 C - Division by Two and Permutation 思维题,第1张

cf题 C - Division by Two and Permutation 思维题

只要有n个数,它能一直除2且没有再出现过(找到后被标记)则满足整个序列要求。

一种搜索的做法

#include
using namespace std;
 
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n;
        cin>>n;
        int flag = 1;
        vector a(n);
        for(int i=0; i>a[i];
        sort(a.begin(), a.end());
        bool f[n+1];
        for(int i=0; i1 && (a[i]>n || f[a[i]]))
                a[i] = a[i]/2;
            if(a[i]>n || f[a[i]])
            {
                cout<<"NOn";
                flag = 0;
                break;
            }
            f[a[i]] = true;
        }
        if(flag == 1)
            cout<<"YESn";
       
    }
    return 0;
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5702811.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-17
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存