Problem Statement

Suppose that A is a list of n numbers {A1,A2,A3,…,An} and B={B1,B2,B3,..,Bn} is a permutation of these numbers, we say B is K-Manipulative if and only if:

M(B)=minimum(B1⊕B2,B2⊕B3,B3⊕B4,…,Bn−1⊕Bn,Bn⊕B1) is not less than 2K , where ⊕ represents the XOR operator.

You are given A . Find the largest K such that there exists a K-manipulative permutation B .

Input:

The first line is an integer N . The second line contains N space separated integers - A1 A2 … An .

Output:
The largest possible K , or −1 if there is no solution.

Constraints:

  • 1<n<=100
  • 0≤Ai≤109,where i∈[1,n]

Sample Input #00

3
13 3 10

Sample Output #00

2

解题思路:Bi^Bi+1 >= 2^K当且仅当(Bi>>K) != (Bi+1>>K),对于上述的排列如果M(B)=K,则Bi>>K相同的数最多不能超过的n/2,这个分为奇数和偶数两种情况,画画图就很明显了。

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
map<int, int> myMap;
int arr[110];int main() {int n;int ans = -1;scanf("%d", &n);for(int i = 1; i <= n; ++i) {scanf("%d", &arr[i]);}for(int k = 30; k >= 0; --k) {myMap.clear();for(int i = 1; i <= n; ++i) {myMap[arr[i]>>k]++;}bool ok = true;for(map<int,int>::iterator iter = myMap.begin(); iter != myMap.end(); ++iter) {if(iter->second > n/2) {ok = false;break;}}if(ok) {ans = k;break;}}printf("%d\n", ans);return 0;
}

Manipulative Numbers相关推荐

  1. usaco ★Humble Numbers 丑数

    ★Humble Numbers 丑数 对于一给定的素数集合 S = {p1, p2, ..., pK}, 来考虑那些质因数全部属于 S 的数的集合.这个集合包括,p1, p1p2, p1p1, 和 p ...

  2. Codeforces Round #FF 446 C. DZY Loves Fibonacci Numbers

    參考:http://www.cnblogs.com/chanme/p/3843859.html 然后我看到在别人的AC的方法里还有这么一种神方法,他预先设定了一个阈值K,当当前的更新操作数j<K ...

  3. iwork11旗舰版 linux,苹果 iWork 11 套件来了,Pages/Numbers/Keynote iOS/macOS 版大升级

    IT之家3月24日消息 苹果今天专为 iOS 和 macOS 设备设计的 iWork 应用套件更新到了版本 11,引入了许多新功能和调整,以改善其功能. IT之家获悉,在 iOS 系统上,Pages. ...

  4. pandas使用extract函数根据正则表达式从dataframe指定数据列的字符串中抽取出数字并生成新的数据列(extract numbers from column)

    pandas使用extract函数根据正则表达式从dataframe指定数据列的字符串中抽取出数字并生成新的数据列(extract numbers from column and generate n ...

  5. pandas创建内容全是0的dataframe、pandas基于随机整数、随机浮点数创建dataframe(random numbers)

    pandas创建内容全是0的dataframe.pandas基于随机整数.随机浮点数创建dataframe(random numbers) 目录 pandas创建内容全是0的dataframe.pan ...

  6. LeetCode 421. Maximum XOR of Two Numbers in an Array--Python解法

    LeetCode 421. Maximum XOR of Two Numbers in an Array–C++,Python解法 LeetCode题解专栏:LeetCode题解 我做的所有的Leet ...

  7. LeetCode 445. Add Two Numbers II--面试算法题--C++,Python解法

    题目地址:Add Two Numbers II - LeetCode You are given two non-empty linked lists representing two non-neg ...

  8. LeetCode 829. Consecutive Numbers Sum--笔试题--C++解法

    LeetCode 829. Consecutive Numbers Sum–笔试题–C++解法 LeetCode题解专栏:LeetCode题解 LeetCode 所有题目总结:LeetCode 所有题 ...

  9. Codeforces Round #181 (Div. 2) C. Beautiful Numbers 排列组合 暴力

    C. Beautiful Numbers 题目连接: http://www.codeforces.com/contest/300/problem/C Description Vitaly is a v ...

最新文章

  1. 如何从文件内容创建Java字符串?
  2. [转载]MATLAB movie 函数动态绘图
  3. Windows跟Linux的不同处理
  4. vscode编写go没有代码提示
  5. mysql 两行的差异_MySQL两行之间的日期差异
  6. jQuery实现字体变大和缩小
  7. shell编写监控httpd服务80端口脚本.间隔3秒监控端口如果服务关闭自动重启
  8. Sturts2 三种开发模式 (转)
  9. linux vi字体大小,设置VIM字体大小
  10. 2022-2027年中国衬衫行业市场调研及未来发展趋势预测报告
  11. 【HTTP】401未经授权的错误及其通常解决方案
  12. CentOS 7中利用Snapper快照进行系统备份与恢复
  13. C++中endl的本质是什么
  14. 用tagcloud插件制作的超炫酷“云标签”(3D旋转和平铺),附前后台代码及标签配置页面
  15. 仅需简单的文字描述,即可把文字转图片
  16. 成为一名优秀的Python工程师需要怎么做?
  17. myeclispe 启动报错Location Type Faceted project metadata file /farming/.settings/org.eclips
  18. ARP局域网断网攻击原理分析及演示
  19. 【转】上海居住证和户口的区别
  20. Mybatis自定义Handler实现Json数组转List对象

热门文章

  1. Linux自学笔记------Day02 文件I/O
  2. 家庭资产配置:相关性原则(1)
  3. 4.1.4 Bond Yields and Return Calculations
  4. 用git连接远程仓库步骤
  5. 泄密事件不断 内网安全该如何保障?
  6. matlab控制参考文献,SPWM的控制的系统文献综述
  7. Layui表格全部数据!导出!
  8. 第一篇:更多腰间盘突出的几大点!
  9. 最新kali之dmitry
  10. 阮开心自学JAVA 第一天++