2017多校 Just do it (Hdu 6129)

1 篇文章 0 订阅
1 篇文章 0 订阅

题目来源

多校2017 Hdu 6129

题意

给一个数组arr(最大为2e5),给出一种操作,求出arr的每个前缀异或和,作为新的arr.
操作最大次数为1e9,问最后的arr数组是啥

想法

  • 1.M这么大,本能就想找规律(赛上还找错了…)

  • 2.赛下重新打了一次表,发现了1 - 2 - 4 - 8的规律(打表到8就知道了

  • 3.规律有了1e9进行二进制枚举就行(这里和快速幂很像)

  • 写的时候注意细节,容易越界(代码如下)

AC代码

#include <set>
#include <map>
#include <queue>
#include <vector>
#include <cstdio>
#include <math.h>
#include <cstring>
#include <iostream>
#include <algorithm>

#define sc(x) scanf("%d",&x);
#define pr(x)  cout << x << endl;
#define bug(x)  cout << #x << " = " << x << endl;
#define ppr(x,y) cout << "(" << x << "," << y << ")" << endl;
#define mem(arr,x) memset(arr,x,sizeof arr);
#define clr(arr)   mem(arr,0);

using namespace std;
typedef long long LL;
typedef pair<int,int> P;
const int maxn = 2e5 + 5;
const int inf  = 0x3f3f3f3f;
const int mod  = 1e9 + 7;
int a[maxn];
int n,m;

void F(int x){      //m = x 时的变换 
    for(int i = x + 1; i <= n ; ++i)
        a[i] ^= a[i - x];
}

void _Bit(){        //用二进制枚举把m 分解成二进制乘积的变换 
    int x = 1;
    while(m){
        if(m & 1){
            F(x);
        }
        x *= 2;
        m >>= 1; 
    }   
}

int main(){
    ios::sync_with_stdio(false);
    int T;
    sc(T)
    while(T--){
        scanf("%d%d",&n,&m);
        for(int i = 1 ; i <= n ; i++) scanf("%d",a + i);
        _Bit(); 
        for(int i = 1;  i <= n ; i++) printf("%d%c",a[i],i == n ? '\n' : ' ');
    }
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值