JZOJ5185 tty's sequence

Description
    
Input
Output
Sample Input
input 1:
  6 3
  1 1 1 0 0 0
input 2:
  6 3
  1 1 0 1 0 0
input 3:
  6 3
  11 8 2 1 3 9
Sample Output
output 1
  1 1
output 2
  1 0
output 3
  11 1
Data Constraint
    

Solution

  不难发现一个数字and越多的数会不变或者变小,or越多的数会不变或者变大,所以全部的数or就是答案,对于and就取刚好k位,把数列全部转成二进制,逐位处理是否形成连续k个1。
 1 #include<cstdio>
 2 using namespace std;
 3 int n,m,h,a[1100000],f[1100000][40],l,s[40],ma;
 4 int main()
 5 {
 6     scanf("%d%d",&n,&m);
 7     for (int i=1;i<=n;i++)
 8     {
 9         scanf("%d",&a[i]);
10          int x=a[i],ll=0,p=1;
11          while (x!=0)
12          {
13              f[i][++ll]=x%2;
14              x=x/2;
15              s[ll]=p;
16              p=p*2;
17         }
18         h=h|a[i];
19         if (ll>l) l=ll;
20     }
21     for (int i=1;i<=n;i++)
22         for (int j=1;j<=l;j++)
23             if (f[i][j]!=0)
24                 f[i][j]=f[i-1][j]+1;
25     int ans=0;
26     for (int i=m;i<=n;i++)
27     {
28         int ans=0;
29         for (int j=1;j<=l;j++)
30             if (f[i][j]>=m)
31                 ans=ans+s[j];
32         if (ans>ma) ma=ans;
33     }
34     printf("%d %d\n",h,ma);
35 }
View Code

 

 

转载于:https://www.cnblogs.com/Tokisaki-Kurumi/p/9485097.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值