当前位置:网站首页>重排数列练习题
重排数列练习题
2022-06-12 21:01:00 【又秃又弱】
题目:
数列异或操作[异或,循环],给你两个整数,n和start,其中n为数据的数量,start为第一个数据。当前数据定义为:num = start + 2*i(i表示从第几个数据,从0开始)。请返回数列中所有数据按位异或(XOR)得到的结果
eg:[2,5,1,3,4,7]
i j
输出:[2,3,5,4,1,7]
(输出一个i,i++,输出一个j,j++)
n=5,start=0; 输出8;原因:(0^2^4^6^8)= 8
解析:
^异或符号的求解:
写出两个数的二进制,相同为0,不同为1
(5^3=0000 0101^0000 0011=0000 0110=6)
代码实现:
#include<stdio.h>
int Xor(int n,int start)
{
int temp=0;
for(int i=0;i<n;i++)
{
temp^=start+2*i;
}
return temp;
}
int main()
{
printf("%d\n",Xor(5,0));
}
如有错误,欢迎评论区告诉我,谢谢
边栏推荐
- Solution of multi machine room dynamic loop status network touch screen monitoring
- 解决cvxpy报错The solver GLPK_MI is not installed
- UVa11991 Easy Problem from Rujia Liu
- 做自媒体视频,友好的新媒体运营必备app分享
- Research Report on hydraulic solenoid valve industry - market status analysis and development prospect forecast
- 入行5年从10k的功能测试到年薪40w的测试开发,花7天时间整理的超全学习路线
- pytorch transforms. Use of lambda
- Shell language
- How do testers plan for their future? To achieve 25K in 2 years?
- Listener in JSP
猜你喜欢

Design and practice of Hudi bucket index in byte skipping

Library cache lock brought by add trandata

Introduction to the characteristics of building a balancer decentralized exchange market capitalization robot

金融信创爆发年!袋鼠云数栈DTinsight全线产品通过信通院信创专项测试

The salted fish has been transmitted for 5W times, and the latest spring recruit face-to-face test questions of bytes have been leaked

shell语言

Leetcode: 210. Programme II

Lintcode:127. Topology sorting

Product Manager: "click here to jump to any page I want to jump" -- decoupling efficiency improving artifact "unified hop routing"

Data visualization diagram microblog forwarding diagram
随机推荐
多机房动环状态网络触摸屏监控解决方案
[tutorial] Firefox send: deployment method of Firefox open source temporary file sharing service platform
Introduction to the characteristics of building a balancer decentralized exchange market capitalization robot
torch. Finfo function
JS深浅拷贝
#981 Time Based Key-Value Store
Mxnet record IO details
The required books for software testers (with e-books) recommended by senior Ali have benefited me a lot
At the same time, do the test. Others have been paid 20W a year. Why are you still working hard to reach 10K a month?
Data visualization diagram microblog forwarding diagram
Compréhension préliminaire des expressions régulières cognitives (regex)
JSP中的监听器
Access control system based on RFID
shell语言
How to determine the sample size of an inspection lot in SAP QM's initial sampling strategy?
对闭包的理解
新品发布丨竣达智能综合环境监测终端
Research Report on market supply and demand and strategy of China's hydraulic hammer industry
Understanding of functions
Data visualization - Calendar chart