zoukankan      html  css  js  c++  java
  • Codeforces Round #242 (Div. 2)C(找规律,异或运算)

    一看就是找规律的题。只要熟悉异或的性质,可以秒杀。

    为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法。

    一些性质如下:

    交换律A oplus B = B oplus A

    结合律A oplus (B oplus C)=(A oplus B) oplus C

    恒等律Xoplus 0=X

    归零律Xoplus X=0

    典型应用:交换a和b的值:a=a^b^(b=a);

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<cmath>
    #include<map>
    #include<set>
    #include<vector>
    #include<algorithm>
    #include<stack>
    #include<queue>
    using namespace std;
    #define INF 1000000000
    #define eps 1e-8
    #define pii pair<int,int>
    #define LL long long int
    int n,p;
    int ans=0;
    int x[1000009];
    int main()
    {
        //freopen("in7.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        scanf("%d",&n);
        x[0]=0;
        for(int i=1; i<=n; i++)
        {
            x[i]=x[i-1]^(i-1);
            int t=n/i;
            if(t%2==1)      ans^=x[i];
            ans^=x[n%i+1];
        }
        for(int i=0; i<n; i++)
        {
            scanf("%d",&p);
            ans^=p;
        }
        printf("%d
    ",ans);
        //fclose(stdin);
        //fclose(stdout);
        return 0;
    }
  • 相关阅读:
    Maven 基础
    Apache 免重启 刷新jsp
    【FeignClient证书】 忽略证书验证
    【转】MAC 配置ssh免密登录
    一次神奇的JVM调优
    Js 监听器
    Js 使用Map
    [leetcode]两数之和
    nginx在普通用户下的部署和安装
    oracle11G的linux下的离线安装教程
  • 原文地址:https://www.cnblogs.com/zywscq/p/3963460.html
Copyright © 2011-2022 走看看