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 ...
随机推荐
- Qt Gui 第一章~第二章
一.Qt启动 qmake -project; 创建xxx.pro qmake xxx.pro; 生成makefile文件 make:构建该程序,生成可执行文件 运行程序:windows:xxx:mac ...
- 2020牛客寒假算法基础集训营3 G.牛牛的Link Power II (树状数组维护前缀和)
https://ac.nowcoder.com/acm/contest/3004/G 发现每个“1”对于它本身位置产生的影响贡献为0,对前面的“1”有产生贡献,对后面的"1"也产生 ...
- 第一次个人编程作业·寒假
这个作业属于哪个课程 https://edu.cnblogs.com/campus/fzzcxy/SE/ 这个作业要求在哪里 https://edu.cnblogs.com/campus/fzzcxy ...
- R parallel包实现多线程1
并行执行 Yes! Well done! Socket clusters are initialized without variables, so a_global_var wasn't found ...
- configparser模块简介
https://www.cnblogs.com/plf-Jack/p/11170284.html
- Java 中的 匿名类
什么是内部类? 在一个类中定义另一个类,这样定义的类称为内部类.包含内部类的类称为内部类的外部类. 如果想要通过一个类来使用另一个类,可以定义为内部类. 内部类的外部类的成员变量在内部类仍然有效,内部 ...
- The number of set(位运算+状态dp)一道十分美妙的题目哦!!!!!!
Given you n sets.All positive integers in sets are not less than 1 and not greater than m.If use the ...
- Ubuntu, 更新Sourses.list
1.备份原文件 sudo cp /etc/apt/sources.list /etc/apt/sources_list.bak 2.加载文件 vim:vim sourses.list ubuntu d ...
- 数据库 concat 与 ||
mysql中用concat,oracle中concat和||都有,都是做字符串拼接的 oracle简单实例: 1.建表 CREATE TABLE tab1 (col1 VARCHAR2(6), col ...
- c数据结构 -- 使用链表实现计数
#include <stdio.h> #include <stdlib.h> typedef struct _node{ int value; struct _node *ne ...