Codeforces Round #618 (Div. 1)A(观察规律)
实际上函数值为x&(-y)
答案仅和第一个数字放谁有关
#define HAVE_STRUCT_TIMESPEC
#include <bits/stdc++.h>
using namespace std;
int a[];
int b[][];
int flag[];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin>>n;
int start=;
int mx=;
for(int i=;i<=n;++i){
cin>>a[i];
int temp=a[i];
while(temp){
b[i][++b[i][]]=temp%;//转化为二进制
temp>>=;
}
for(int j=;j<=b[i][];++j)
if(b[i][j]!=)
++flag[j];//记录有多少数字这一位上是1
a[n+i]=a[i];
}
for(int i=;i<=n;++i){
int he=;
for(int j=;j<=b[i][];++j)
if(b[i][j]&&flag[j]==)//如果仅有a[i]这一位上为1,那么它放在顺序的第一个时可以为总和做出1<<(j-1)的贡献
he|=(1ll<<(j-));
if(he>mx){//更新最大值
mx=he;
start=i;
}
}
for(int i=start;i<=n-+start;++i)
cout<<a[i]<<" ";
return ;
}
Codeforces Round #618 (Div. 1)A(观察规律)的更多相关文章
- Codeforces Round #618 (Div. 1)B(几何,观察规律)
观察猜测这个图形是中心对称图形是则YES,否则NO #define HAVE_STRUCT_TIMESPEC #include<bits/stdc++.h> using namespace ...
- Codeforces Round #242 (Div. 2)C(找规律,异或运算)
一看就是找规律的题.只要熟悉异或的性质,可以秒杀. 为了防止忘记异或的规则,可以把异或理解为半加运算:其运算法则相当于不带进位的二进制加法. 一些性质如下: 交换律: 结合律: 恒等律: 归零律: 典 ...
- Codeforces Round #618 (Div. 2)
题库链接 https://codeforces.ml/contest/1300 A. Non-zero 一个数组,每次操作可以给某个数加1,让这个数组的积和和不为0的最小操作数 显然如果有0的话,必须 ...
- [CF百场计划]#2 Codeforces Round #618 (Div. 2)
A. Non-zero Description: Guy-Manuel and Thomas have an array \(a\) of \(n\) integers [\(a_1, a_2, \d ...
- Codeforces Round #618 (Div. 1)C(贪心)
把所有数看作N块,后面的块比前面的块小的话就合并,这个过程可能会有很多次,因为后面合并后会把前面的块均摊地更小,可能会影响更前面地块,像是多米诺骨牌效应,从后向前推 #define HAVE_STRU ...
- Codeforces Round #618 (Div. 2)A. Non-zero
Guy-Manuel and Thomas have an array aa of nn integers [a1,a2,…,an ]. In one step they can add 11 to ...
- Codeforces Round #618 (Div. 2)C. Anu Has a Function
Anu has created her own function ff : f(x,y)=(x|y)−y where || denotes the bitwise OR operation. For ...
- Codeforces Round #618 (Div. 2) 小号上紫之路
这一场涨了不少,题也比较偏思维,正好适合我 A. Non-zero 我们记录这些数字的总和sum,并且记录0的个数zero,显然答案应该是这些0的个数,注意如果sum+zero==0的话答案要额外加一 ...
- Codeforces Round #618 (Div. 2)-B. Assigning to Classes
Reminder: the median of the array [a1,a2,-,a2k+1] of odd number of elements is defined as follows: l ...
随机推荐
- PP: Learning representations for time series clustering
Problem: time series clustering TSC - unsupervised learning/ category information is not available. ...
- MongoDB的安装问题
Mongo的安装与启动: npm install mongodb -g MongoDB高性能.开源.无模式的文档型数据库,它基于分布式文件存储.介于关系数据库和非关系数据库之间的一种产品.其最大特点: ...
- java替换文件中某一行文本的内容
个人博客 地址:http://www.wenhaofan.com/article/20180913160442 代码如下 package com.wenhaofan.common.kit; impor ...
- 网格布局 grid(1)
目录 网格布局 grid(1) 实现方式 对容器设置的属性 行高与列宽的设置 单元格的间距 内容的位置 表格在容器的位置 兼容问题 网格布局 grid(1) 实现方式 display:grid 也可成 ...
- PTA-1003 我要通过!
1003 我要通过!https://pintia.cn/problem-sets/994805260223102976/problems/994805323154440192 “答案正确”是自动判题系 ...
- python中可变类型和不可变类型数据的复制
常见的复制方式有以下5种第1种:通过等号[=]复制 - 不论可变还是不可变数据类型,通过[=]复制后都指向同一个内存地址: - 改变复制后的数据(例子中的anotherStr,anotherList) ...
- AcWing 1013. 机器分配
//分组背包 for物品 for体积 for 决策 #include <iostream> using namespace std; ; int n, m; int w[N][N]; in ...
- 编码 - 设置 win10 下 cmd 编码格式
概述 cmd 编码格式修改 背景 之前尝试过修改 gitbash(mingw) 的 Character Set 这次尝试修改一下 cmd 的编码格式 准备 os win10.1903 1. 查看 当前 ...
- PP: Pattern Trails: visual analysis of pattern transitions in subspaces
Problem: 1. We can't find patterns in full attribute space, and patterns may only be found in smalle ...
- 后台异常 - Content is not allowed in prolog
问题原因 解析XML报的错,XML拼的不对