hdu 6129 Just do it 找规律

题意很好理解

问你一个数组 按照他的规则处理m次之后是什么样的

看到这道题我一开始也没什么思路

但是我列了五个数

把它们m≤4的都算出来之后发现

如果m把化成二进制的这一位是1

那么所有相隔是这一位数大小的数都要异或起来

然后模拟就好了

(题解中给出了相应的推导证明)

 1 #include<bits/stdc++.h>
 2 #define cl(a,b) memset(a,b,sizeof(a))
 3 #define debug(a) cerr<<#a<<"=="<<a<<endl
 4 using namespace std;
 5 typedef long long ll;
 6 typedef pair<int,int> pii;
 7
 8 const int maxn=2e5+10;
 9
10 int n,m;
11 int a[maxn];
12
13 void solve()
14 {
15     int bits=1;
16     while(bits*2<=m) bits*=2;
17     while(m)
18     {
19         while(m>=bits)
20         {
21             for(int i=bits; i<n; i++) a[i]^=a[i-bits];
22             m-=bits;
23         }
24         bits/=2;
25     }
26 }
27
28 int main()
29 {
30     int T;
31     scanf("%d",&T);
32     while(T--)
33     {
34         scanf("%d%d",&n,&m);
35         for(int i=0; i<n; i++)
36         {
37             scanf("%d",&a[i]);
38         }
39         solve();
40         for(int i=0; i<n; i++)
41         {
42             printf("%d%c",a[i],i==n-1?‘\n‘:‘ ‘);
43         }
44     }
45     return 0;
46 }/*
47
48 2
49 1 1
50 1
51 3 3
52 1 2 3
53
54 */
时间: 2024-08-29 16:18:36

hdu 6129 Just do it 找规律的相关文章

2017多校第7场 HDU 6129 Just do it 找规律

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6129 题意:求a序列后m次xor前缀和 解法: 手动对1位置对每个位置的贡献打表发现 第一次 贡献为 1 1 1 1 1 1 1 1 1 1 1 第二次 贡献为 1 0 1 0 1 0 1 0 1 0 1 0 第四次 贡献为 1 3个0 1 3个0 1 3个0 1 3个0 第八次 贡献为 1 7个0 1 7个0 1 7个0 1 7个0 ... 这是比赛之后才知道的,看着比赛的时候通过了200+人,被

HDU 4572 Bottles Arrangement(找规律,仔细读题)

题目 //找规律,123321123321123321…发现这样排列恰好可以错开 // 其中注意题中数据范围: M是行,N是列,3 <= N < 2×M //则猜测:m,m,m-1,m-1,m-2,m-2,……,2,2,1,1求出前m个数字的和就是答案. //发现案例符合(之前的代码第二天发现案例都跑不对,真不知道我当时眼睛怎么了) #include <iostream> #include<stdio.h> #include<string.h> #inclu

HDU 2147-kiki&#39;s game(博弈/找规律)

kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/10000 K (Java/Others) Total Submission(s): 9174    Accepted Submission(s): 5485 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his

HDU 5703 Desert 水题 找规律

已知有n个单位的水,问有几种方式把这些水喝完,每天至少喝1个单位的水,而且每天喝的水的单位为整数.看上去挺复杂要跑循环,但其实上,列举几种情况之后就会发现是找规律的题了= =都是2的n-1次方,而且这题输出二进制数就行了......那就更简单了,直接输出1,然后后面跟n-1个0就行了╮(╯_╰)╭ 下面AC代码 #include<iostream> #include<cstdio> #include<cstring> #include<algorithm>

HDU 5793 A Boring Question (找规律 : 快速幂+乘法逆元)

A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 865    Accepted Submission(s): 534 Problem Description There are an equation.∑0≤k1,k2,?km≤n∏1?j<m(kj+1kj)%1000000007=?We define

HDU - 4722 Good Numbers 【找规律 or 数位dp模板】

If we sum up every digit of a number and the result can be exactly divided by 10, we say this number is a good number. You are required to count the number of good numbers in the range from A to B, inclusive. InputThe first line has a number T (T <=

HDU 1041 Computer Transformation(找规律加大数乘)

主要还是找规律,然后大数相乘 #include<stdio.h> #include<string.h> #include<math.h> #include<time.h> #include<map> #include<iostream> #include<ctype.h> #include<string> #include<algorithm> #include<stdlib.h> #i

HDU 4990 Reading comprehension(找规律+矩阵快速幂)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4990 Problem Description Read the program below carefully then answer the question. #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include<iostream> #include

HDU 4203 博弈 打表找规律

http://acm.hdu.edu.cn/showproblem.php?pid=4203 一堆数量为s的硬币,两个人轮流从中取硬币,最后取完的人获胜,其中每次只能取k的n次方个硬币(n = 0, 1, 2, 3-),求想要取胜,当前要取走的最少硬币数. s的范围是1e9,直接储存sg函数是不现实的,所以考虑打表找找规律看. 通过打表可以得出规律: 当k为偶数时,sg函数值依次为 0 1 0 1 0 1 0 1- 当k为奇数时,sg函数值依次为 0 1 0 1 0 1-k(总长度为k + 1)