zoukankan      html  css  js  c++  java
  • A. 2048 Game (模拟) Educational Codeforces Round 73 (Rated for Div. 2)

    You are playing a variation of game 2048. Initially you have a multiset ss of nn integers. Every integer in this multiset is a power of two.

    You may perform any number (possibly, zero) operations with this multiset.

    During each operation you choose two equal integers from ss, remove them from ss and insert the number equal to their sum into ss.

    For example, if s={1,2,1,1,4,2,2}s={1,2,1,1,4,2,2} and you choose integers 22 and 22, then the multiset becomes {1,1,1,4,4,2}{1,1,1,4,4,2}.

    You win if the number 20482048 belongs to your multiset. For example, if s={1024,512,512,4}s={1024,512,512,4} you can win as follows: choose 512512 and 512512, your multiset turns into {1024,1024,4}{1024,1024,4}. Then choose 10241024 and 10241024, your multiset turns into {2048,4}{2048,4} and you win.

    You have to determine if you can win this game.

    You have to answer qq independent queries.

    Input

    The first line contains one integer qq (1q1001≤q≤100) – the number of queries.

    The first line of each query contains one integer nn (1n1001≤n≤100) — the number of elements in multiset.

    The second line of each query contains nn integers s1,s2,,sns1,s2,…,sn (1si2291≤si≤229) — the description of the multiset. It is guaranteed that all elements of the multiset are powers of two.

    Output

    For each query print YES if it is possible to obtain the number 20482048 in your multiset, and NO otherwise.

    You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

    Example
    input
    Copy
    6
    4
    1024 512 64 512
    1
    2048
    3
    64 512 2
    2
    4096 4
    7
    2048 2 2048 2048 2048 2048 2048
    2
    2048 4096
    
    output
    Copy
    YES
    YES
    NO
    NO
    YES
    YES
    
    Note

    In the first query you can win as follows: choose 512512 and 512512, and ss turns into {1024,64,1024}{1024,64,1024}. Then choose 10241024 and 10241024, and ssturns into {2048,64}{2048,64} and you win.

    In the second query ss contains 20482048 initially.

     

     

    #include <iostream>
    #include <algorithm>
    #include <cstdio>
    #include <string>
    #include <cstring>
    #include <cstdlib>
    #include <map>
    #include <vector>
    #include <set>
    #include <queue>
    #include <stack>
    #include <cmath>
    
    typedef long long lli;
    #define pql priority_queue<ll>
    #define pq priority_queue<int>
    #define v vector<int>
    #define vl vector<ll>
    //线段树
    #define lson rt<<1, l, m
    #define rson rt<<1|1, m+1, r
    #define gcd __gcd
    
    #define mem(s,t) memset(s,t,sizeof(s))
    #define debug(a,n) for(int i=0;i<n;i++) cout<<" "<<a[i];
    #define Debug(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cout<<a[i][j]<<" ";   cout<<endl; }
    #define rep(j,k) for (int i = j; i <= k; i++)
    #define per(i,k) for (int i = i; i >= k; i--)
    #define test cout<<"+++"<<endl;
    #define input(a,k) for (int i = 1; i <= (int)(k); i++)  {scanf("%d",&a[i]) ; }
    #define INPUT(a,n,m) for(int i=0;i<n;i++) {for(int j=0;j<m;j++) cin>>a[i][j] ; }
    #define TLE std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define ok return 0;
    #define oi(x) cout<<x<<endl;
    #define os(str) cout<<string(str)<<endl;
    #define YES cout<<"YES"<<endl;
    #define NO cout<<"NO"<<endl;
    lli Fibonacci(lli n) {  return (1/sqrt(5))*( pow( (1+sqrt(5))/2,n )-pow( (1-sqrt(5))/2 ,n) );   }
    lli FibonacciSum(lli n) { return 2*Fibonacci(n)+Fibonacci(n-1)-1; }
    using namespace std;
    const int mxn = 2e5+5;
    int t,n,m,flag,a[mxn],k;
    map<lli,int>mp;
    int main()
    {
        TLE;
        cin>>t;
        lli sum;
        while(t--)
        {
            mem(a,0);
            sum=0; flag = 0;
            cin>>n;
            rep(1,n)
            {
                cin>>k;
                if(k==2048) flag=true;
                k %= 2048;
                a[k]++;
                sum+=a[k]*k;
            }
            if(flag) {YES;}
            else if(sum<2048) {NO;}
            else
            {
                k=1;
                for(int i=1;i<=11;i++)
                {
                    a[k<<1] += a[k]/2;
                    k<<=1;
                }
                if(a[2048]) {YES;}
                else {NO;}
            }
        }
        ok;
    }

     

    所遇皆星河
  • 相关阅读:
    UML类图图示样例
    在WSSv3中通过Javascript和创建Feature扩展站点的动作菜单
    LINQ之Select各种操作
    TroubleShoot: SharePoint工作流不能自动启动
    TroubleShoot:页面上WebPart显示错误
    ECMAScript对列表项的增删改查
    隐藏SharePoint查看所有内容及回收站
    Windows2000计划任务对机器进行重新启动
    CF576E Painting Edges
    CF1491H Yuezheng Ling and Dynamic Tree
  • 原文地址:https://www.cnblogs.com/Shallow-dream/p/11591869.html
Copyright © 2011-2022 走看看