HDU 6129 Just do it【杨辉三角】【思维题】【好题】
2017-08-16 11:18
423 查看
Just do it
Time Limit: 5000/2500 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)Total Submission(s): 635 Accepted Submission(s): 356
Problem Description
There is a nonnegative integer sequence a1...n of
length n.
HazelFan wants to do a type of transformation called prefix-XOR, which means a1...n changes
into b1...n,
where bi equals
to the XOR value of a1,...,ai.
He will repeat it for m times,
please tell him the final sequence.
Input
The first line contains a positive integer T(1≤T≤5),
denoting the number of test cases.
For each test case:
The first line contains two positive integers n,m(1≤n≤2×105,1≤m≤109).
The second line contains n nonnegative
integers a1...n(0≤ai≤230−1).
Output
For each test case:
A single line contains n nonnegative
integers, denoting the final sequence.
Sample Input
2
1 1
1
3 3
1 2 3
Sample Output
1
1 3 1
Source
2017 Multi-University Training Contest - Team 7
判断每位数对后面的影响即可,
打表发现其每位对后面的值为:
对比杨辉三角,则:
则可直接根据杨辉三角的公式退出每位对后面的影响,则问题解决。
#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define ms(x,y) memset(x,y,sizeof(x))
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 100;
int a[maxn], b[maxn];
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
int t;
scanf("%d", &t);
while (t--)
{
int n, m;
ms(b, 0);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%d", &a[i]);
for (int i = 1; i <= n; i++) //第i位
{
int x = m + i - 2; //组合数x取y
int y = i - 1;
if ((x & y) == y) //x取y奇偶判断,如果为奇则对后面有影响
{
for (int j = 1; j <= n; j++) //计算对后面影响
{
if (j - i + 1 >= 1)
b[j] ^= a[j - i + 1];
}
}
}
for (int i = 1; i <= n; i++)
{
printf("%d", b[i]);
if (i != n) printf(" ");
}
puts("");
}
return 0;
}
相关文章推荐
- HDU 6129 Just do it【杨辉三角+思维+Lucas定理】
- HDU-6129 Just do it - 2017 Multi-University Training Contest - Team 7(规律、杨辉三角、组合数奇偶性)
- hdu6129Just do it(杨辉三角、组合数)
- Hdu 6129 Just do it【杨辉三角、规律】
- 2017杭电多校第七场1010 Just do it(数论,杨辉三角)HDU 6129
- HDU 2017 多校联合训练赛7 1010 6129 Just do it 杨辉三角 组合数的奇偶判断
- HDU 6129 Just do it(杨辉三角)
- hdu 6129 Just do it(杨辉三角)
- 2017多校联合第七场1010/hdu 6129 Just do it(递推/杨辉三角)
- HDU 6129 Just do it【杨辉三角】
- hdu 6129 Just do it (杨辉三角)
- HDU 6129 Just do it(找规律+杨辉三角)
- HDU - 6129 Just do it(找规律)
- 【多校训练】hdu 6129 Just do it
- HDU 6129 Just do it
- HDU 6129 Just do it(规律)
- (2017多校训练第七场)HDU - 6129 Just do it 找规律
- hdu 6129 Just do it(递推)
- 【HDU 6129 Just do it】& 数学推导
- hdu 6129 Just do it(递推)