• 牛客练习赛22 C 简单瞎搞题


     1 //位运算 
     2 //  & 都是1 才是 1
     3 // | 都是0 才是0
     4 // ^  不一样才是1
     5 #include <iostream>
     6 #include <cstdio>
     7 #include <bitset>
     8 using namespace std;
     9 const int N=1e6+9;
    10 bitset<N>dp[105];
    11 int main()
    12 {
    13     dp[0][0]=1;
    14     int n,l,r;
    15     scanf("%d",&n);
    16     for(int i=1;i<=n;i++){
    17         scanf("%d%d",&l,&r);
    18         dp[i].reset();//清0
    19         for(int j=l;j<=r;j++){
    20             dp[i]|=dp[i-1]<<j*j;//用1的个数来代表种类数
    21             //加上某个数就要左移几位,
    22             //eg 第3位是1,那么就表示此时2是当下和的一个数
    23         }
    24     }
    25     printf("%d
    ",dp[n].count());//有几个1
    26     return  0;
    27 }


    // 这是一个讲解bitset 的博客 https://www.cnblogs.com/magisk/p/8809922.html
    ll x=(ll)(1ll<<31)-1;
    cout<<x<<endl;
     2^31-1
    int : 2.14*10^9 2147483647==2^31-1(可以用int)
    ll : 9.2*10^18
    2^60 10^18
    2^30 10^9
    2^64 1.8*10^19
     1 牛课练习赛23 C      托米的位运算
     2 
     3 托米完成了1317的上一个任务,十分高兴,可是考验还没有结束
     4 说话间1317给了托米 n 个自然数 a1... an, 托米可以选出一些带回家,但是他选出的数需要满足一些条件
     5 设托米选出来了k 个数 b1,b2... bk, 设这个数列 b 的给值为 b 中所有数按位与的结果,如果你能找到一个整除 b 的最大的 2v,(v≥ 0), 则设定 v 为这个数列的给价,如果不存在这样的 v,则给价值为 -1, 1317 希望托米在最大化给价的情况下,最大化 k
     6 输入描述:
     7 第一行输入一个整数 n, 第二行输入 a1...an
     8 输出描述:
     9 第一行输出最大的整数 k, 第二行输出 k 个整数 b1... bk, 按原数列的相对顺序输出 (如果行末有额外空格可能会格式错误)
    10 示例1
    11 输入
    12 复制
    13 5
    14 1 2 3 4 5
    15 输出
    16 复制
    17 2
    18 4 5
    19 备注:
    20 n≤ 105, a1... an < 231
    21 
    22 #include <iostream>
    23 #include <cstdio>
    24 #include <cstring>
    25 #include <vector>
    26 #include <string>
    27 #include <string>
    28 #include <map>
    29 #include <cmath>
    30 #include <set>
    31 #include <algorithm>
    32 using namespace std;
    33 typedef long long ll;
    34 const int N=1e5+7;
    35 const ll  M=(ll)(1ll<<31)-1;
    36 vector<int>ve;
    37 int n,a[N];
    38 int main()
    39 {   
    40     scanf("%d",&n);
    41     ll sum=0;
    42     for(int i=1;i<=n;i++) 
    43     {
    44         scanf("%d",&a[i]);
    45         sum+=a[i];
    46     }
    47     if(!sum){
    48         printf("%d
    ",n);
    49         for(int i=1;i<=n;i++){
    50             printf("0%c",i==n?'
    ':' ');
    51         }
    52         return 0;
    53     }
    54     
    55     //从大到小枚举2^v
    56     for(int i=1<<30;i>=1;i>>=1){//只要不全为0,就至少i==1
    57          ll  ans=M;//111……(31个1)按位与结果还是别的本身
    58         for(int j=1;j<=n;j++){
    59             if(a[j]&i) ans&=a[j];
    60             /*举个例子:
    61             2^v==8  ,那么b%8===0,可以为8,16,24,32,40……
    62             首先这些数的末尾至少有3个0.
    63             16,32这样的一定不行,因为v就变大了。
    64             而24,40这样的一定会是8*奇数,也就是二进制的8
    65             对应位一定为1,因此a[j]对应位(8)也一定为1才能让最后
    66             按位与的结果为(对应位为1).
    67             当然这些数一定要>=i,因为小于i的按位与结果为0.
    68             而且要让所有的满足当下条件的a[j]都参与到按位与
    69             因为此时的结果不成立的话,那么所有的a[j]至少某一位全为1(最后
    70             3位中的一个,v==3时)。因此用更少的a[j]就更不可能了。
    71             */
    72         }
    73         if(ans%i==0){
    74             for(int k=1;k<=n;k++){
    75                 if(a[k]&i) ve.push_back(a[k]);//因为v时由大到小遍历的
    76             }
    77             printf("%d
    ",ve.size());
    78             for(int z=0;z<ve.size();z++){
    79                 printf("%d%c",ve[z],z==ve.size()-1?'
    ':' ');
    80             }
    81             return 0;
    82         }
    83     }
    84 }
    •  128536K
      E. AC Challenge

    Dlsj is competing in a contest with n (0 < n le 20)n(0<n20) problems. And he knows the answer of all of these problems.

    However, he can submit ii-th problem if and only if he has submitted (and passed, of course) s_isi problems, the p_{i, 1}pi,1-th, p_{i, 2}pi,2-th, ......, p_{i, s_i}pi,si-th problem before.(0 < p_{i, j} le n,0 < j le s_i,0 < i le n)(0<pi,jn,0<jsi,0<in) After the submit of a problem, he has to wait for one minute, or cooling down time to submit another problem. As soon as the cooling down phase ended, he will submit his solution (and get "Accepted" of course) for the next problem he selected to solve or he will say that the contest is too easy and leave the arena.

    "I wonder if I can leave the contest arena when the problems are too easy for me."
    "No problem."
    —— CCF NOI Problem set

    If he submits and passes the ii-th problem on tt-th minute(or the tt-th problem he solve is problem ii), he can get t imes a_i + b_it×ai+bi points. (|a_i|, |b_i| le 10^9)(ai,bi109).

    Your task is to calculate the maximum number of points he can get in the contest.

    Input

    The first line of input contains an integer, nn, which is the number of problems.

    Then follows nn lines, the ii-th line contains s_i + 3si+3 integers, a_i,b_i,s_i,p_1,p_2,...,p_{s_i}ai,bi,si,p1,p2,...,psias described in the description above.

    Output

    Output one line with one integer, the maximum number of points he can get in the contest.

    Hint

    In the first sample.

    On the first minute, Dlsj submitted the first problem, and get 1 imes 5 + 6 = 111×5+6=11 points.

    On the second minute, Dlsj submitted the second problem, and get 2 imes 4 + 5 = 132×4+5=13 points.

    On the third minute, Dlsj submitted the third problem, and get 3 imes 3 + 4 = 133×3+4=13 points.

    On the forth minute, Dlsj submitted the forth problem, and get 4 imes 2 + 3 = 114×2+3=11 points.

    On the fifth minute, Dlsj submitted the fifth problem, and get 5 imes 1 + 2 = 75×1+2=7 points.

    So he can get 11+13+13+11+7=5511+13+13+11+7=55 points in total.

    In the second sample, you should note that he doesn't have to solve all the problems.

    样例输入1

    5
    5 6 0
    4 5 1 1
    3 4 1 2
    2 3 1 3
    1 2 1 4

    样例输出1

    55

    样例输入2

    1
    -100 0 0

    样例输出2

    0

    题目来源

    ACM-ICPC 2018 南京赛区网络预赛

     

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <string>
    #include <utility>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <stack>
    using namespace std;
    #define max(x,y) x>=y?x:y
    #define lowbit(x) x&(-x)
    #define ll long long 
    const  ll inf=9e18;
    #define   N  50
    #define   M 1<<21
    int n,k,pre[N];
    ll a[N],b[N],dp[M];//dp的大小
    int  main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%lld%lld%d",&a[i],&b[i],&k);
            int x;
            for(int j=0;j<k;j++)
            {
                scanf("%d",&x);
                pre[i]+=(1<<(x-1));
                //在提交第i个之前要完成的
                //如 提交第1个之前要完成的 2 3
                //那么 pre[1]=110
            }
        }
        int cnt=(1<<n);
        for(int i=1;i<cnt;i++ ) dp[i]=-inf;
        dp[0]=0ll;
        ll ans=0;//题意最小0
        //dp[i] :按照i的方法进行可以获得的最大价值
        for(int i=1;i<cnt;i++)//枚举所有情况
            //0 1 1 就包含了1 2|2 1
        {
            for(int j=0;j<n;j++)
                
                {
                    if(i>>j&1){
                    
                        int u=i-(1<<j);//提交第j+1个之前已经做的
                        if((u&pre[j+1])==pre[j+1]){//把提交第j+1个之前要做的都做了。要加(),==高于&
                            
                            ll val=dp[u]+__builtin_popcount(i)*a[j+1]+b[j+1];
                            dp[i]=max(dp[i],val);
                            ans=max(ans,dp[i]);
                        }
                    }
                }
        }
        printf("%lld
    ",ans);
        return 0;
    }
  • 相关阅读:
    ThinkPhp学习11
    ThinkPhp学习10
    1.自我介绍
    Axure高级教程--在原型中插入视频
    Axure制作iphone手机交互模型—覆盖切换
    对产品的一些总结
    详解Axure的Masters功能
    详解使用Axure 制作Tab切换功能
    产品经理的初识
    作为产品经理--如何写好PRD文档
  • 原文地址:https://www.cnblogs.com/tingtin/p/9316069.html
Copyright © 2020-2023  润新知