zoukankan      html  css  js  c++  java
  • 「AGC043B」123 Triangle「思维」

    题意:https://www.luogu.com.cn/problem/AT5799

    题解:先把所有数减一。可以发现,把距离运算改成xor,就可以求出答案的奇偶性。

    答案的奇偶性为(left(sum { {n-1}choose {i-1}} ight) mod 2)

    如果是奇数,直接输出(1),否则考虑是(0)还是(2)

    如果序列存在(1),可以发现答案一定是(0)。证明可以使用数学归纳法,从最终状态往起始状态归纳,就能发现答案是(2)时原序列不存在(1)

    那么剩下的情况就是求一个(02)序列的答案。直接变成(01)序列求奇偶性就行了。

    #include <algorithm>
    #include <cstdio>
    using namespace std;
    const int N = 1e6 + 10;
    int a[N], n;
    char s[N];
    int main() {
    	scanf("%d%s", &n, s); n --;
    	for(int i = 0; i <= n; i ++) {
    		a[i] = s[i] - '0' - 1;
    	}
    	int ans = 0;
    	for(int i = 0; i <= n; i ++) {
    		if((n & i) == i) ans ^= a[i] & 1;
    	}
    	if(ans == 1) puts("1");
    	else {
    		for(int i = 0; i <= n; i ++) {
    			if(a[i] == 1) { puts("0"); return 0; }
    			a[i] >>= 1;
    		}
    		ans = 0;
    		for(int i = 0; i <= n; i ++) {
    			if((n & i) == i) ans ^= a[i] & 1;
    		}
    		printf("%d
    ", ans ? 2 : 0);
    	}
    	return 0;
    }
    
  • 相关阅读:
    jQuery-03
    正则表达式
    文件下载
    Shiro笔记
    MyBatis笔记
    Spring5笔记
    JavaScript笔记
    smartsvn安装和使用 —— svn工具linux版
    网易云歌单导入qq音乐
    svn版本回滚 —— svn使用笔记之三
  • 原文地址:https://www.cnblogs.com/hongzy/p/12551494.html
Copyright © 2011-2022 走看看