Codeforces Round #685 (Div. 2) E2 - Bitwise Queries (Hard Version)题解

Codeforces Round #685 (Div. 2) E Bitwise Queries 位运算 妙啊 E Bitwise Queries 题目链接 easy和hard 交互题 题意: 给一个长度为nnn的数组,元素为从[0,n−1][0,n - 1][0,n−1]。刚开始给你长度nnn,n是2的次幂,让猜这个数组,每次询问有可以是三种中的一种: XOR i j //返回a[i] ^ a[j] AND i j // 返回a[i] & a[j] OR i j // 返回a[i] | a[j] easy让询问不超过n+2n + 2n+2次、hard让询问不超过n+1n + 1n+1次。让猜出这 阅读详情

E Bitwise Queries

题意

交互题,有一个nnn个数(nnn为222的幂次)的序列,每个数范围[0,n−1][0,n-1][0,n−1]。最多给出n+1n+1n+1次询问,能得到任意两个数的AND或OR或XOR。根据询问还原序列。

想法

easy version的比较简单,直接n−1n-1n−1次的XOR来链接这些数然后用3次的两两OR来确定前三个数(能根据XOR结果知道前三个数哪些位两两相同并且用OR来确定这些相同的位的值,XOR为000的位OR为000则全000,OR为111则全111)。

hard version需要用到每个数的范围和power of two这个条件,同样不可缺少的是n−1n-1n−1次的XOR(都与第一个数XOR)链接每个数。然后可以发现最多n−1n-1n−1个数,分两种情况

  • 有重复的数
    • 和第一个数相同,a1XORaj=0,2≤j≤na_1 XOR a_j=0,2 \leq j\leq na1​XORaj​=0,2≤j≤n。直接用AND来给第一个数赋值,a1=a1ANDaja_1=a_1 AND a_ja1​=a1​ANDaj​。
    • 除了第一个数的两个数相同aiXORaj=0(aiXORa1=ajXORa1),2≤i,j≤na_i XOR a_j=0(a_i XOR a_1 = a_j XOR a_1),2 \leq i,j\leq nai​XORaj​=0(ai​XORa1​=aj​XORa1​),2≤i,j≤n。那么找到这些位置,用aiANDaja_i AND a_jai​ANDaj​来赋值。同样得到全部数。
  • 没有重复的数,那么这n个数分布在[0,n−1][0,n-1][0,n−1]。根据异或的性质,第一个数与后面n−1n-1n−1个数的异或结果范围为[1,n−1][1,n-1][1,n−1]。那么找到异或结果为1和2的两个位置,a1XORai=1,a1XORaj=2a_1 XOR a_i = 1,a_1 XOR a_j = 2a1​XORai​=1,a1​XORaj​=2。分别来确定a1a_1a1​的除了202^020和212^121位的全部值,从而确定a1a_1a1​。
代码
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
const int maxn = 1e5 + 5;
typedef long long ll;
int a[1 << 17];
int q1(int i, int j) {
    printf("OR %d %d\n", i, j);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}
int q2(int i, int j) {
    printf("AND %d %d\n", i, j);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}
int q3(int i, int j) {
    printf("XOR %d %d\n", i, j);
    fflush(stdout);
    int x;
    scanf("%d", &x);
    return x;
}
int res[1 << 17];
int n;
inline void cal() {
    for (int i = 2; i <= n; ++i) {
        a[i] = a[1] ^ res[i];
    }
}
map<int, int> mp;
int main() {
    scanf("%d", &n);
    int flag1 = 0, flag2 = 0;
    int p1, p2;
    for (int i = 2; i <= n; ++i) {
        res[i] = q3(1, i);
    }
    for (int i = 2; i <= n; ++i) {
        if (res[i] == 0) {
            flag1 = i;
            break;
        }
        if (res[i] == 1) p1 = i;
        if (res[i] == 2) p2 = i;
        if (mp.find(res[i]) != mp.end()) {
            flag2 = 1;
            p1 = i, p2 = mp[res[i]];
            break;
        }
        mp[res[i]] = i;
    }
    if (flag1) {
        a[1] = q2(1, flag1);
    } else if (flag2) {
        a[p1] = q2(p1, p2);
        a[1] = a[p1] ^ res[p1];
    } else {
        a[1] = q2(1, p1);
        int tp = q2(1, p2);
        if (a[1] & 1) a[1] ^= 1;
        a[1] ^= (tp & 1);
    }
    cal();
    printf("!");
    for (int i = 1; i <= n; ++i) printf(" %d", a[i]);
    puts("");
    return 0;
}
到底是什么决定了二极管的最高工作频率? 硬件工程师,应该都用过二极管的吧,不过也许有一个误区,大多数人可能并不知道,或者说是理解有问题,下面就来细细说下。 一个问题 先提一个问题:到底是什么决定了二极管的最高工作频率? 估计有不少人会回答是二极管反向恢复时间Trr,也有人会说是二极管结电容,那到底谁是对的呢?或者说都一样,反向恢复时间由结电容决定? 到底什么决定了二极管的最高工作频率,我们暂且不论,不过需要知道的是,二极管的反向恢复时间和结电容根本就是两回事,反向恢复时间绝不能等同于结电容的充放电时间。 为什么我这么说呢?. 阅读详情

相关推荐

脑机接口(BCI)从原理到开发实战 10|脑控外设:用脑电波控制机械臂/游戏

摘要: 脑机接口(BCI)的“最后一公里”是将分类结果转化为实际动作的关键环节。本文介绍如何通过指令映射、硬件通信和执行反馈实现脑控外设,包括离散/连续控制策略、防抖处理及串口/蓝牙通信方法。通过两个实战案例(运动想象控制机械臂抓取、P300/SSVEP控制游戏)和完整项目(OpenBCI控制小车),演示了从分类标签到设备动作的完整流程,重点涵盖指令生成算法(多数投票)、Python与Arduino的串口通信集成,为BCI系统落地提供实用解决方案。(149字)

小明的博客 780

CS:APP Data Lab实验详解

CS:APP Data Lab实验15题详解,多种方法

gravity_w的博客 3130

微带线,带状线和接地共面波导的区别

微带线,带状线和接地共面波导的区别

sky_ying的博客 3万+

data lab 1(暂时只放题目)

2019独角兽企业重金招聘Python工程师标准>>> ...

weixin_34130269的博客 1265

保姆级教程:用STM32单片机实现国标交流充电桩的CP信号检测(附完整代码)

本文详细介绍了基于STM32单片机实现国标交流充电桩CP信号检测的全流程,包括硬件设计、软件架构和充电控制实现。通过分压电路设计、ADC配置和状态机逻辑,确保充电过程的安全与可靠性,适用于新能源汽车充电桩开发。附完整代码和调试技巧,助力开发者快速掌握关键技术。

weixin_42641998的博客 258

从零开始使用CubeMX配置STM32使用lwip实现httpd服务器以及使用vscode编辑阅读keil代码(三)

使用stm32搭载lwip实现HTTPd服务器

qq_30623327的博客 5939

计算机系统基础 实验一 csapp date lab1

1.题目与解答: /* * lsbZero - set 0 to the least significant bit of x * Example: lsbZero(0x87654321) = 0x87654320 * Legal ops: ! ~ & ^ | + << >> * Max ops: 5 * Rating: 1 */...

qq_43544682的博客 1万+

R分析|怎么样使用piecewiseSEM构建结构方程模型?保姆级教程

计算科学的发展让我们有了更先进的工具揭示自然规律。结构方程模型(SEM)已被广泛应用于多学科进行数据挖掘。其中在R中实现的结构方程模型是方便快捷的。今天要介绍的piecewiseSEM包就是R中实现SEM的一种方式。piecewiseSEM被开发出来主要目的是为了解决复杂模型简化后进行分段分析。个人认为最大的特点是更灵活,且采用的是原始数据,并不是传统的协方差矩阵。其次,将SEM破碎化为多个独立的方程,对样本量要求较少。

weixin_46814750的博客 6976

CodeForces - 1451E2-Bitwise Queries(Hard Version) ( 交互 + 位运算 )

题目链接:点击进入 题目 题意 长度为n的数组(n 是 2 的幂次),数组内每个数的范围在 [ 0 , n - 1 ] ,求在最多n+1次询问下确定整个数组 询问有三种类型: 1、询问 a [ i ] and a [ j ] 的值 2、询问 a [ i ] or a [ j ] 的值 3、询问 a [ i ] xor a [ j ] 的值 思路 数组有两种情况 1、数组内出现相同值 2、数组内没有相同的值( 即 [ 0 - n - 1 ] 各自出现一次 ) 对于情况1,对于出现两次的值求and,即可确

Cosmic_Tree的博客 316

OpenSpec 完全指南 config.yaml文件

不管是项目内还是全局存放,自定义工作流都要遵守以下规则,否则会导致OpenSpec无法识别,新手一定要记牢:一个文件夹 = 一个工作流:工作流文件夹的名称,就是中schema字段要填写的名称;每个工作流文件夹必须包含:这是工作流的核心定义文件,没有它,OpenSpec无法识别这个工作流;模板文件统一放templates/目录:如果需要自定义生成文件的模板(比如统一的提案模板、任务模板),就放在工作流文件夹下的templates/里,OpenSpec会自动识别;

h a 6 6 6 c k 为 你解决复杂难题! 1440

【异常】Milvus向量数据库的常见错误“collection not loaded“(集合未加载)

Milvus数据库报错"collection not loaded"分析及解决方案。该错误发生在对未加载的集合执行查询操作时,核心原因是集合创建后需先加载到内存才能使用。解决方案包括:1)确认集合是否存在;2)查询前调用loadCollection接口加载集合;3)处理加载超时或失败情况,可检查加载状态;4)确保Milvus服务正常运行。建议在长期不使用集合时释放内存资源。文末附Java代码示例说明具体操作方法。

奶爸的编程之路,也就一周冷个三天 384

(1)!+-<<>>|&^

...

weixin_64197656的博客 1226

运放+MOS恒流源电路仿真分析

利用运放设计一个恒流源

HW-BASE的博客 4123

Codeforces Round #685 (Div. 2)E2. Bitwise Queries (Hard Version)题解(数学竞赛/组合构造题)

题目链接: https://codeforces.com/contest/1451/problem/E2 大意:这是一个人机交互题。一共有N个[0, N-1]的整数,其中N是2的幂次。允许每次人指定其中两个数字与AND、OR、XOR其中一种运算,查询其计算后得到的结果。最多查询N + 1次,复现出整个数组每个数字的值。 思路: 记我们的原始的数组为A数组。 定理一: 对于非负整数x与y,有: x + y = (x xor y) + 2 * (x and y) 证明:按照比特位,按位计算。 .

weixin_38839688的博客 229

廖雪峰Python教程[完整版]

廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Codeforces Round #685 (Div. 2) D,E

Codeforces Round #685 (Div. 2) 失踪人口回归… D. Circle Game 思维难度:4 算法难度:0 代码难度:3 题目大意: ttt组数据(t<=100)(t<=100)(t<=100) 给你一个半径ddd和步数kkk,你最开始在原点(0,0)(0,0)(0,0)每次可以让xxx坐标增加kkk,或者yyy坐标增加kkk 两人轮流走,求谁最后不能走了,谁就输了,都是最优博弈 输的条件为下次走的坐标(x,y)(x,y)(x,y)都满足x2+y2>d2x

Slime 389

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Codeforces Round #685 (Div. 2) E2 - Bitwise Queries (Hard Version)

F 题意: 给你长度为n的隐藏的数组,你有三种询问:选两个不同的下标i,j,询问(1)a[i]|a[j] (2) a[i]&a[j] (3) a[i]^a[j] 你可以询问至多n+2次(hard verson 为n+1次) 题解: (1)做n-1次操作——每次询问a[i]^a[i-1] (i=2,3,4.....n) (这样把询问结果求个前缀异或和b[i],任意两个下标i,j对应的数的异或和就是b[i]^b[j-1] (假设j<i) (2)然后有两种情况 ...

shejunda的博客 263

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Codeforces 1451E2. Bitwise Queries (Hard Version)(交互,二进制)

The only difference between the easy and hard versions is the constraints on the number of queries. This is an interactive problem. Ridbit has a hidden array ???? of ???? integers which he wants Ashish to guess. Note that ???? is a power of two. Ashish is

tomjobs的博客 689

cf1451 E2. Bitwise Queries (Hard Version)(位运算+思维)

的运算优先级小于+!

qq_60008503的博客 181

计算机系统基础(实验一)

int lsbZero(int x) { return (x>>1)<<1; } int tmax(void) { return ~(1<<31); } int isZero(int x) { return !x; } int sign(int x) { int s = x>>31; int sig = ( s&(~0)) + ((!s) & (!!x)); return sig; } int by

米莱虾 5940

CodeForces - 1451E2 Bitwise Queries (Hard Version)(交互+构造+位运算)

题目链接:点击查看 题目大意:给出一个长度为 n(n 保证了是 2 的幂次),每个数的范围在 [ 0 , n - 1 ] 的一个数组,现在要求通过有限次操作确定下来这个数组: 询问 a[ i ] xor a[ j ] 的答案 询问 a[ i] or a[ j ] 的答案 询问 a[ i ] and a[ j ] 的答案 题目分析:因为可以询问任意两个数异或运算后的答案,根据 ,我们可以先确定出序列中的任意一个数字设为 x,然后对于其他的数字依次询问与 x 的异或,就可以反推出所有的数字了,所以现在.

Falcon的博客 2665

1451E2 Bitwise Queries (交互题,位运算)

Codeforces Round #685 (Div. 2) E2. Bitwise Queries (Hard Version)

月巴虫丰博客 434

codeforces1451 E. Bitwise Queries(位运算妙用)

E1. Bitwise Queries (Easy Version) a+b=(a&b)+(a∣b)a+b=(a\&b)+(a|b)a+b=(a&b)+(a∣b) 根据上述式子用333次$&和333次∣|∣操作求出a1+a2,a2+a3,a1+a3a_1+a_2,a_2+a_3,a_1+a_3a1​+a2​,a2​+a3​,a1​+a3​由此得出a1,a2,a3a_1,a_2,a_3a1​,a2​,a3​ 根据a1⊕ai=xa_1\oplus a_i=xa1​⊕ai​=x于是

Fighting_Peter的博客 379

acm-(异或、与、或、交互、思维)Codeforces Round #685 (Div. 2) E.Bitwise Queries

传送门 本题中数字范围[0,n−1][0,n-1][0,n−1]这个条件以及nnn是2的幂次这个条件是解决问题的关键。 首先有个结论:(x&y)+(x∣y)=x+y(x\&y)+(x|y)=x+y(x&y)+(x∣y)=x+y,然后很容易联想到通过计算a1,a2,a3a_1,a_2,a_3a1​,a2​,a3​这三个数两两之间的与或值,来解个方程从而得到它们三个分别的值,然后再让a1a_1a1​与剩下的数去异或从而得到其他数的值,可惜这样做要花费6+n−3=n+36+n-3=n+3.

qq_30361651的博客 330

Codeforces Round #685 (Div. 2)---2020--11--29

文章目录 可以想到,只需要判断字符串左端(或右端)是否等于其左边(或右边)一个数 代码如下(示例): #include<bits/stdc++.h> using namespace std; char s[1010],s1[1010]; int main() { int t; scanf("%d",&t); while(t--) { int n=0,q=0; scanf("%d%d",&n,&q); scanf("%s",s); wh..

p15008340649的博客 111

E2. Voting (Hard Version)(思维)

有 n 个人,每个人有 mi 和 pi ,mi 代表着如果有 mi 个人投票给他,那么他就免费投票给他,否则你需要花费pi的代价来收买他。请问最少花费多少使得所有人都投他。 看到 m 数组的数据范围,m 数组作为数组下标应该是没得跑了,有贪心策略我们应该选择 pi 尽量少的那些人,但是同时要照顾到 m 数组。 因为要贿赂的总人数我们不知道,但借用优先队列(小根堆),将目前为止的最少需要的贿赂人数贿赂。 向题目中提到的:m :1 2 2 4 5,只需贿赂 m[5] 即可,这样贪心策略就...

C_Dreamy的博客 578

Mac下安装Maven详细教程

https://www.jianshu.com/p/f1bda85a7bf4

qq_38319289的博客 895
上一篇: Codeforces Round #684 (Div. 2) D Graph Subset Problem
下一篇: 计算机组成原理之运算方法和运算器
hzeroto
博客等级 码龄7年 14粉丝 24原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值