zoukankan      html  css  js  c++  java
  • Codeforces 862 C. Mahmoud and Ehab and the xor 位运算

      题目链接: http://codeforces.com/problemset/problem/862/C

      题目描述: 给你n, k 找到一个大小为n的集合, 使得集合异或等于k

      解题思路: 自己一开始想的思路是有一个数必须是x, 剩下的异或为0, 想了好久没有什么思路.......看代码吧, 不复杂的, 主要是利用了异或的性质

      代码: 

    #include <iostream>
    #include <cstdio>
    #include <map>
    #include <iterator>
    #include <string>
    #include <algorithm>
    #include <vector>
    using namespace std;
    
    typedef long long ll;
    const int maxn = 1e5+10;
    
    ll base = 1e6;
    int n, x;
    
    int main() {
        scanf("%d%d", &n, &x);
        if( n == 2 && x == 0 ) { printf( "NO
    " ); return 0; }
        printf( "YES
    " );
        ll ans = 0;
        if( n % 2 == 0 ) {
            printf( "0 " );
            n--;
        }
        for( int i = 0; i < n-1; i++ ) {
            ll temp = base - i;
            if( i == n-2 && ans ^ x ^ temp == 0 ) temp--;
            ans = ans ^ temp;
            printf( "%lld ", temp );
        }
        printf( "%lld
    ", ans ^ x );
        return 0;
    }
    View Code

      思考: 自己的位运算也不好, 哎, 真的是弱项实在是太多了, 自己还是需要多加大比赛, 训练自己将问题抽象出来的能力和代码能力, 同时慢慢的扩充自己的知识点, 两天一场CF

  • 相关阅读:
    ansible
    celery 计划任务使用
    11 session 使用
    10 模版继承和页面之间的调用
    9 模版语言 jinja2
    8 公共函数
    7 文件上传
    6 获取请求头和URL信息
    5 获取Form表单取值
    4 文件操作 支持图片 视频 mp3 文本等
  • 原文地址:https://www.cnblogs.com/FriskyPuppy/p/7608593.html
Copyright © 2011-2022 走看看