CF div2
这是一道二进制思维题;
将所有数字列成二进制形式,然后找出最大的一位“1”出现一次的位数;
然后把这个数提到前面,其他照常输出即可
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+;
int a[maxn];
int cot[];
int main()
{
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%d",&a[i]);
for(int i=;i<=n;i++){
int tmp=a[i];
int num=;
while(tmp){
++num;
if(tmp%){
cot[num]++;
}
tmp/=;
}
}
int tt=;
int biao=;
while(tt){
if(cot[tt]==){
biao=tt;
break;
}
tt--;
}
if(!biao){
for(int i=;i<=n;i++)
printf("%d ",a[i]);
printf("\n");
return ;
}
int flag;
for(int i=;i<=n;i++){
if((a[i]&(<<(biao-)))==(<<(biao-))){
printf("%d ",a[i]);
flag=i;
break;
}
}
for(int i=;i<=n;i++){
if(i==flag) continue;
printf("%d ",a[i]);
}
printf("\n");
return ;
}
CF div2的更多相关文章
- cf div2 234 D
D. Dima and Bacteria time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- 离线dfs CF div2 707 D
http://codeforces.com/contest/707/problem/D 先说一下离线和在线:在线的意思就是每一个询问单独处理复杂度O(多少多少),离线是指将所有的可能的询问先一次都处理 ...
- cf div2 239 D
D. Long Path time limit per test 1 second memory limit per test 256 megabytes input standard input o ...
- cf div2 236 D
D. Upgrading Array time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 237 D
D. Minesweeper 1D time limit per test 2 seconds memory limit per test 512 megabytes input standard i ...
- cf div2 238 D
D. Toy Sum time limit per test 1 second memory limit per test 256 megabytes input standard input out ...
- cf div2 238 c
C. Unusual Product time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- cf div2 235 D
D. Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standar ...
- cf div2 234 E
E. Inna and Binary Logic time limit per test 3 seconds memory limit per test 256 megabytes input sta ...
- CF div2 D BFS
http://codeforces.com/contest/676/problem/D 题目大意: 勇者去迷宫杀恶龙.迷宫是有n*m的方格子组成的.迷宫上有各种记号,这些记号表达着能走的方向.当且仅当 ...
随机推荐
- iptables (二) nat & tcp_wrapper
一.nat 之前网络防火墙的示例中,如果内网是私网地址,那么内网主机如何与外网通信呢? 这时候,iptables要实现内网和外网通信,有两种方式: nat: Network Address Trans ...
- 阿里支付:User Notice: invalid [default store dir]: /tmp/
主要是因为windows和linux文件系统不一致才导致此错误的.在linux系统上阿里提供的SDK没问题,但在windows上我们做测试或者开发的时候就会遇到这样的错误. 解决方法就是在alipay ...
- 今天才知道a标签的href="#"是回到页面顶部
如题,真的是,做了一年多的开发,今天才知道a标签的href="#"是回到顶部.以前一直以为这是个多么了不起的功能. 顺便扩展一下滑动隐藏和显示按钮(从别处拷贝来的代码) $( do ...
- 1级搭建类106-Oracle 19c 单实例 FS(华为云)公开
项目文档引子系列是根据项目原型,制作的测试实验文档,目的是为了提升项目过程中的实际动手能力,打造精品文档AskScuti. 项目文档引子系列除特定项目目前不对外发布,仅作为博客记录,其他公开.如学员在 ...
- springboot~gradle4.7之后的lombok引用方法
在gradle4.7以后对于加入依赖lombok方式发生变化,gradle4.7版本以前,可以直接如下引用: compile("org.projectlombok:lombok:1.18.2 ...
- 书写makefile的注意点
1.空格 定义一个变量时用“foo = 1”这种形式,1后面千万不可以有空格,否则,foo的值为“1 ”.等于号和1之间的空格有无,并没有关系. 2.ifeq ifeq的形式是“ifeq ($(foo ...
- jupyter CSS
.caret, .dropup > .btn > .caret { border-top-color: #000 !important; } .label { border: 1px so ...
- 利用MongoDB进行地理坐标查询
BS的应用在生活中已经非常常见,我们打车,叫外卖,查个地图之类的都会查询附近的相关坐标位置,mongodb提供了原生的二维地图查询,极大地方便了大家的开发. 假定我们有一个定义了位置信息的集合loca ...
- navicat连接mysql8.0+版本报错2059
ERROR 2059 : Authentication plugin 'caching_sha2_password' cannot be loaded 问题: 连接Docker启动的mysql出现:E ...
- C++构造函数和重载函数运算符如何区分
构造函数和重载函数运算符如何区分: class Distance { private: int feet; int inches; public: Distance(){ feet = ; inche ...