原题目

  给你一个长度为n的序列A,请求出最大的一对数(A,Aj),使Ai&Aj最大。

  第一行为n,接下来n行,每一个数表示Ai.

  输出最大的“and”。

S1:

  Input:


  Output:



  Describe:暴枚当然会T成狗,所以我们考虑剪枝

  code:

#include<bits/stdc++.h>
#define INF 214748364
#define eps 1e-9
#define rep1(a,b) for(register long long i=(a);i<=(b);i++)
#define rep2(a,b) for(register long long j=(a);j<=(b);j++)
using namespace std;
long long a[500101],n,ans;
inline long long read(){
long long ret=0,f=1;char ch=getchar();
while (ch<'0'||ch>'9') {if (ch=='-') f=-f;ch=getchar();}
while (ch>='0'&&ch<='9') ret=ret*10+ch-'0',ch=getchar();
return ret*f;
}
inline double read2(){
double X=0,Y=1.0;long long w=0;char ch=0;
while(!isdigit(ch)){w|=ch=='-';ch=getchar();}
while(isdigit(ch))X=X*10+(ch^48),ch=getchar();
ch=getchar();
while(isdigit(ch)) X+=(Y/=10)*(ch^48),ch=getchar();
return w?-X:X;
}
inline void write(long long x){
if(x<0){putchar('-');write(-x);return;}
if(x/10) write(x/10);putchar(x%10+'0');
}
int main(){
//freopen("carpet.in","r",stdin);
//freopen("carpet.out","w",stdout);
n=read();
for(int i=1;i<=n;i++)a[i]=read();
sort(a+1,a+n+1);for(int i=1;i<n;i++)if(a[i]==a[i+1])ans=a[i]; //如果两个数相等,至少是这两个数的值。[从小到大--SORT]
for(int i=n;i>=1;i--){ //从大到小枚以便剪枝
for(int j=n;j>=i+1;j--){ //同上
if(a[j]<=ans)break; //若A<B,则A&C[C∈R]<=A<B
ans=max(ans,a[i]&a[j]); //取最大值
}
if(a[i]<=ans)break; //嗯哼
}
write(ans);
return 0;
}

  

Day6-T2的更多相关文章

  1. XJOI网上同步训练DAY6 T2

    思路:记得FJ省队集训好像有过这题,可是我太弱了,根本不懂T_T #include<cstdio> #include<iostream> #include<cmath&g ...

  2. 雅礼集训 Day6 T2 Equation 解题报告

    Equation 题目描述 有一棵\(n\)个点的以\(1\)为根的树,以及\(n\)个整数变量\(x_i\).树上\(i\)的父亲是\(f_i\),每条边\((i,f_i)\)有一个权值\(w_i\ ...

  3. Python之路,Day6 - Python基础6

    本节大纲: 模块介绍 time &datetime模块 random os sys shutil json & picle shelve xml处理 yaml处理 configpars ...

  4. python笔记 - day6

    python笔记 - day6 参考: http://www.cnblogs.com/wupeiqi/articles/5501365.html 大纲: 利用递归,实现阶乘: Python反射 pyt ...

  5. Day6 - Python基础6 面向对象编程

    Python之路,Day6 - 面向对象学习   本节内容:   面向对象编程介绍 为什么要用面向对象进行开发? 面向对象的特性:封装.继承.多态 类.方法.     引子 你现在是一家游戏公司的开发 ...

  6. Day3:T1数论+高精 T2搜索

    T1:数论+高精(水~) 根据题意可知,从除的数越大越好(在0~9中) 所以我们只要用到高精除然后再模拟一下就可以了 //MARK:但是要注意0-9这个特殊值需要特判,因为题目要求输出的数至少是两位数 ...

  7. 转:Python之路,Day6 - 面向对象学习

    这篇文章写的不错,转来收了 转自:http://www.cnblogs.com/alex3714/articles/5188179.html   本节内容:   面向对象编程介绍 为什么要用面向对象进 ...

  8. Python-模块使用-Day6

    Python 之路 Day6 - 常用模块学习 本节大纲: 模块介绍time &datetime模块randomossysshutiljson & picleshelvexml处理ya ...

  9. 考前停课集训 Day6 垒

    Day 6 今天在家里的 家里蹲 其实是day7的时候想到要写day6了 草率补充一下 NOIP考前棕名退不掉咯 你觉得我还会打洛谷的题目吗? 依然退步 没用心 T1 分火腿 数论题 我感觉挺难的 T ...

  10. Day6 Python常用的模块

    一.logging模块 一.日志级别 critical=50 error=40 waring=30 info=20 debug=10 notset=0 二.默认的日志级别是waring(30),默认的 ...

随机推荐

  1. centos7.4安装gitlab

    1. 安装依赖软件 yum -y install policycoreutils openssh-server openssh-clients postfix 2.下载gitlab安装包,然后安装 c ...

  2. MyBatis 入门Demo

    新建数据库my_db,新建表student_tb id为主键,不自动递增. 不必插入数据. 下载MyBatis https://github.com/mybatis/mybatis-3/release ...

  3. C/C++网络编程9——多进程服务器端实现

    #include <iostream> #include <unistd.h> #include <cstdlib> #include <arpa/inet. ...

  4. 【原】openresty学习

    参考文档: 1.openresty最佳实践:https://moonbingbing.gitbooks.io/openresty-best-practices/content/ 2.openResty ...

  5. c++ 读取、保存单张图片

    转载:https://www.jb51.net/article/147896.htm 实际上就是以二进制形式打开文件,将数据保存到内存,在以二进制形式输出到指定文件.因此对于有图片的文件,也可以用这种 ...

  6. virtual column make sqlserver using function index

    In sqlserver, it is impossible that if we want to create an function index. Doesn`t means we can not ...

  7. python3爬虫

    1.爬虫的基本原理讲解 2.Urllib库的基本使用 3.Requests库的基本使用 4.正则的基本使用 5.BeautifulSoup库的使用 6.PyQuery库的使用   √ 7.Seleni ...

  8. Python语法速查: 20. 线程与并发

    返回目录 本篇索引 (1)线程基本概念 (2)threading模块 (3)线程间同步原语资源 (4)queue (1)线程基本概念 当应用程序需要并发执行多个任务时,可以使用线程.多个线程(thre ...

  9. redis地理位置

    redis 3.2版本中增加的最大功能就是对GEO(地理位置)的支持 当前业务中地图方面是调用高德api(云图),请求多少会有延迟  而redsigeo可以实现查找附近的终端以及测量两点之间的直线距离 ...

  10. leetcode菜鸡斗智斗勇系列(5)--- 寻找拥有偶数数位的数字

    1.原题: https://leetcode.com/problems/find-numbers-with-even-number-of-digits/ Given an array nums of ...