• 位运算实现x+1


     1 #include <iostream>
     2 #include <cstdio>
     3 #include <cstring>
     4 using namespace std;
     5 
     6 int main() {
     7     int x;
     8     while(cin >> x) {
     9         x = (x & 1) ? ( ( x & ((-1) << (((( ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) | ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) | (((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) > 0xF) << 2)) | ((((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) >> (((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) > 0xF) << 2)) > 0x3) << 1)) | ((((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) >> (((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) > 0xF) << 2)) >> ((((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) >> (((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) >> ((( ((x ^ -1) & ( - (x ^ -1) ) ) >> ( ( ((x ^ -1) & ( - (x ^ -1) ) ) > 0xFFFF) << 4) ) > 0xFF) << 3)) > 0xF) << 2)) > 0x3) << 1)) >> 1)))) | ((x ^ -1) & ( - (x ^ -1) ) )) : x | 1;
    10         cout << x << endl;
    11     }
    12 }
  • 相关阅读:
    课堂作业之公文流转
    统计字符出现频率(java)
    课堂测试第八周
    HTML学习笔记——语法+骨架
    HTTP协议
    MVC架构模式概述
    CodeIgniter框架——CI中视图路径问题
    CodeIgniter框架——CI组件间信息流走向
    CodeIgniter框架——数据库类(配置+快速入门)
    chm文件无法阅读
  • 原文地址:https://www.cnblogs.com/zhanzhao/p/4849575.html
Copyright © 2020-2023  润新知