题目链接:
Anu Has a Function

题目解析:
观察函数f(x,y)定义:(x|y)-y
取出来x里是1但是y里不是1的地方 也就是 x&(~y)
(也可以列真值表)
因此题目就变为求 a1&(∼a2)&…(∼an) 最大值
先预处理出 前缀按位和 以及 后缀按位和,再求出最大值即可

AC代码:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
#define ll long long
int a[100010],prefix[100010],suffix[100010],n;
int main()
{scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&a[i]);if(i==1) prefix[i]=(~a[i]);else prefix[i]=(~a[i])&prefix[i-1];}suffix[n]=~a[n];for(int i=n-1;i>=1;i--) suffix[i]=(~a[i])&suffix[i+1];//for(int i=1;i<=n;i++) printf("%d\n",prefix[i]);int maxx=-1,id;for(int i=1;i<=n;i++){int temp=(prefix[i-1]&suffix[i+1]&a[i]);if(i==1) temp=(a[1]&suffix[2]);if(i==n) temp=(a[n]&prefix[n-1]);if(temp>=maxx) {maxx=max(maxx,temp);id=i;}}printf("%d ",a[id]);for(int i=1;i<=n;i++)if(i!=id) printf("%d ",a[i]);
}

寒假刷题13: Anu Has a Function Codeforces Round #618 (Div. 2) C相关推荐

  1. Codeforces Round #618 (Div. 1)-----A. Anu Has a Function

    提示: Codeforces Round #618 (Div. 1)-----A. Anu Has a Function 题意: 定义一个函数f(x , y) = f(x | y) - y 给定一个长 ...

  2. Codeforces Round #618 (Div. 2)C、Anu Has a Function

    C. Anu Has a Function time limit per test1 second memory limit per test256 megabytes inputstandard i ...

  3. 【Codeforces Round#618 (Div. 2)】C. Anu Has a Function 题解

    题目链接:C. Anu Has a Function 题目 Anu has created her own function f: f(x,y)=(x|y)−y where | denotes the ...

  4. Codeforces Round #618 (Div. 2)-C. Anu Has a Function

    Anu has created her own function f: f(x,y)=(x|y)−y where | denotes the bitwise OR operation. For exa ...

  5. E. Mahmoud and Ehab and the function Codeforces Round #435 (Div. 2)

    http://codeforces.com/contest/862/problem/E 二分答案 一个数与数组中的哪个数最接近: 先对数组中的数排序,然后lower_bound 1 #include ...

  6. BUUCTF-2020寒假刷题记录

    BUUCTF-2020寒假刷题记录 Web [RoarCTF 2019]Easy Calc 打开源码,看到calc.php,打开看到源码. 在 num 前面加个空格即可绕过 ? num=phpinfo ...

  7. Codeforces Round #701 (Div. 2) A ~ F ,6题全,超高质量良心题解【每日亿题】2021/2/13

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 A - Add and Divide B - Replace and Keep Sorted C ...

  8. Codeforces Round #694 (Div. 1 + Div2)(A ~ H,8题全,超高质量题解)【每日亿题】2021/2/1、2/2

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 目录 [每日亿题]Codeforces Round #694 (Div. 1 + Div2)(A ~ ...

  9. 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas

    题目传送门 1 /* 2 水题:ans = (1+2+3+...+n) * k - n,开long long 3 */ 4 #include <cstdio> 5 #include < ...

最新文章

  1. DRV8711的使用,堵转stall检测的使用及衰减模式
  2. Codeforces 809A - Do you want a date?(数学+排序)
  3. c语言尹宝林答案,c程序设计导引 尹宝林
  4. 每日一题(4)—— (a ^ b 2)
  5. matlab多元函数_函数的计算机处理8(1)_1MATLAB
  6. 抱怨一下有些邮件列表的气氛
  7. 深圳市工信局、发改委与商务局项目
  8. JRebel激活教程
  9. Yaml:基本语法使用
  10. 图书信息管理系统(MVC设计模式)
  11. 《东周列国志》第四十七回 弄玉吹箫双跨凤 赵盾背秦立灵公
  12. PHP实现队列(二)Redis 实现队列
  13. 基于linux服务器的hashcat握手包破解
  14. 全屏滚动插件之 fullpage.js
  15. php file_get_contents 失效,phpfile_get_contents返回空无效解决办法_PHP教程
  16. 电气潮流运算Matlab怎么编程,基于Matlab的电力系统潮流编程计算
  17. 核心业务8:提现+展示还款信息和回款信息
  18. Redis缓存及缓存粒度
  19. 飞猪登录器推荐《怪物猎人世界》萌新入坑武器装备推荐
  20. 电气工程系毕业设计大全单片机精品设计合集参考案例地址

热门文章

  1. 什么是GIS(地理信息系统)
  2. android实现电话通信原理,电话通信原理.pdf
  3. MT6735调试s5k3m2摄像头isp timout
  4. 将多个列重新排版成交叉表
  5. 人工神经网络设计选择题,人工神经网络设计原则
  6. python实现主成分估计
  7. bootstrap:导航栏【基础、简单、实用】
  8. linux魔兽世界黑屏,在UBUNTU下玩魔兽世界并不轻松。许多问题无法自己解决,请有兴趣的...
  9. python数据清洗+数据可视化
  10. mysql 1025_ERROR 1025 (HY000): Error on rename of to