HDU 6129 Just do it【杨辉三角】【思维题】【好题】
来源:互联网 发布:网络电影排行榜前十名 编辑:程序博客网 时间:2024/05/05 02:40
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 integersn,m(1≤n≤2×105,1≤m≤109) .
The second line containsn nonnegative integers a1...n(0≤ai≤230−1) .
For each test case:
The first line contains two positive integers
The second line contains
Output
For each test case:
A single line containsn nonnegative integers, denoting the final sequence.
A single line contains
Sample Input
21 113 31 2 3
Sample Output
11 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取yint 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;}
阅读全文
1 0
- HDU 6129 Just do it【杨辉三角】【思维题】【好题】
- HDU 6129 Just do it【杨辉三角+思维+Lucas定理】
- 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(杨辉三角+lucas \ 记忆化dp)
- 2017杭电多校第七场1010 Just do it(数论,杨辉三角)HDU 6129
- 2017多校联合第七场1010/hdu 6129 Just do it(递推/杨辉三角)
- HDU 6129 Just do it
- HDU 6129 Just do it
- HDU 6129 Just do it
- HDU 6129Just do it
- HDU-6129 Just do it
- hdu 6129 Just do it
- hdu 6129 Just do it
- Hard challenge(HDU6127)
- hdu6130Kolakoski(第七场打表)
- laravel上传图片
- SNMP详解
- 笨办法学 Python · 续 练习 47:`bc`
- HDU 6129 Just do it【杨辉三角】【思维题】【好题】
- SQL SERVER 查自动本月,本年,本日的数据条件
- golang中发送http请求的几种常见情况
- apache ab开源的压力测试工具参数介绍
- Maven 依赖管理
- PAT_1068. Find More Coins
- jQuery $.ajax()方法参数详解
- java中的生命周期详解
- Kafka vs RocketMQ—— Topic数量对单机性能的影响-转自阿里中间件