HDU 6129 Just do it【杨辉三角】【思维题】【好题】

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(1T5), denoting the number of test cases.
For each test case:
The first line contains two positive integers n,m(1n2×105,1m109).
The second line contains n nonnegative integers a1...n(0ai2301).
 

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

判断每位数对后面的影响即可,

打表发现其每位对后面的值为:


对比杨辉三角,则:


则可直接根据杨辉三角的公式退出每位对后面的影响,则问题解决。

#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;
}






posted @ 2017-08-16 11:19  Archger  阅读(99)  评论(0编辑  收藏  举报