zoukankan      html  css  js  c++  java
  • 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;
    }






    Fighting~
  • 相关阅读:
    无锁队列的实现 | 酷壳 CoolShell.cn
    简明 Vim 练级攻略 | 酷壳 CoolShell.cn
    分享:lucene 的评分机制
    JS实现面向对象的设计
    EF架构~性能高效的批量操作(Update篇)
    将不确定变为确定~transactionscope何时提升为分布式事务?
    将不确定变为确定~Linq to SQL不能随机排序吗?
    vs2012~ 开发人员的福音
    白领职场必懂的22条潜规则(转载)
    经典面试题(转载)
  • 原文地址:https://www.cnblogs.com/Archger/p/12774700.html
Copyright © 2011-2022 走看看