3的倍数 或运算构造x(牛客第四场)-- triples I
题意:
给你一个数,希望你能用最少的3的倍数或运算成它,让你输出答案。
思路:
进制%3有规律,1、2、4、8、16%3是1、2、1、2、1 ...
利用这一点分情况取一些位合成一些数就是答案了。
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#include <cstdio>//sprintf islower isupper
#include <cstdlib>//malloc exit strcat itoa system("cls")
#include <iostream>//pair
#include <fstream>
#include <bitset>
//#include <map>
//#include<unordered_map>
#include <vector>
#include <stack>
#include <set>
#include <string.h>//strstr substr
#include <string>
#include <time.h>//srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9;
#include <cmath>
#include <deque>
#include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less
#include <vector>//emplace_back
//#include <math.h>
//#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor
#include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare)
using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation
#define fo(a,b,c) for(register int a=b;a<=c;++a)
#define fr(a,b,c) for(register int a=b;a>=c;--a)
#define mem(a,b) memset(a,b,sizeof(a))
#define pr printf
#define sc scanf
void swapp(int &a,int &b);
double fabss(double a);
int maxx(int a,int b);
int minn(int a,int b);
int Del_bit_1(int n);
int lowbit(int n);
int abss(int a);
//const long long INF=(1LL<<60);
const double E=2.718281828;
const double PI=acos(-1.0);
const int inf=(1LL<<);
const double ESP=1e-;
const int mod=(int)1e9+;
const int N=(int)1e6+; int _1[],_2[]; int main()
{
int sum=;
int T;
sc("%d",&T);
while(T--)
{
long long a;
int cnt1=,cnt2=;
sc("%lld",&a);
if(a%==)
{
pr("1 %lld\n",a);
continue;
}
fr(i,,)
{
if((a>>i)&)
{
if(i%==)
_1[++cnt1]=i;
else
_2[++cnt2]=i;
}
}
int tcnt1=cnt1,tcnt2=cnt2;
long long ans1=,ans2=;
int temp=;
if(cnt1&&cnt2)
{
ans1+=(1LL<<_1[cnt1--]);
ans1+=(1LL<<_2[cnt2--]);
fo(i,,cnt1)
ans2+=(1LL<<_1[i]),temp+=;
fo(i,,cnt2)
ans2+=(1LL<<_2[i]),temp+=;
if(temp%==)
ans2+=(1LL<<_2[tcnt2]);
if(temp%==)
ans2+=(1LL<<_1[tcnt1]);
}
else if(cnt1==&&cnt2)
{
ans1+=(1LL<<_2[cnt2--]);
ans1+=(1LL<<_2[cnt2--]);
ans1+=(1LL<<_2[cnt2--]);
fo(i,,cnt2)
ans2+=(1LL<<_2[i]);
if(ans2%==)
ans2+=(1LL<<_2[tcnt2]);
else if(ans2%==)
ans2+=(1LL<<_2[tcnt2]),ans2+=(1LL<<_2[tcnt2-]);
}
else if(cnt1&&cnt2==)
{
ans1+=(1LL<<_1[cnt1--]);
ans1+=(1LL<<_1[cnt1--]);
ans1+=(1LL<<_1[cnt1--]);
fo(i,,cnt1)
ans2+=(1LL<<_1[i]);
if(ans2%==)
ans2+=(1LL<<_1[tcnt1])+(1LL<<_1[tcnt1-]);
else if(ans2%==)
ans2+=(1LL<<_1[tcnt1]);
}
pr("2 %lld %lld\n",ans1,ans2);
}
return ;
} /**************************************************************************************/ int maxx(int a,int b)
{
return a>b?a:b;
} void swapp(int &a,int &b)
{
a^=b^=a^=b;
} int lowbit(int n)
{
return n&(-n);
} int Del_bit_1(int n)
{
return n&(n-);
} int abss(int a)
{
return a>?a:-a;
} double fabss(double a)
{
return a>?a:-a;
} int minn(int a,int b)
{
return a<b?a:b;
}
3的倍数 或运算构造x(牛客第四场)-- triples I的更多相关文章
- 平面割线平分点(构造)--牛客第三场-- Magic Line
题意: 给你n个点的坐标,让你给出两个点,这两个点的连线可以平分这些点. 思路: 先按y的大小排序,在按x的小排序,再搞一下就行了.如下图: #include <bits/stdc++.h> ...
- 分层最短路(牛客第四场)-- free
题意: 给你边权,起点和终点,有k次机会把某条路变为0,问你最短路是多长. 思路: 分层最短路模板题.题目有点坑(卡掉了SPFA,只能用dijkstra跑的算法). #include<iostr ...
- %300为0的个数(牛客第四场)-- number
题意: 给你一串数,问你如题. 思路: 我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系: #define IOS ios_base::sync_with_stdio ...
- 笛卡尔树--牛客第四场(sequence)
思路: O(n)建一颗笛卡尔树,再O(n)dfs向上合并答案就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include &l ...
- 线性基求交(线段树)--牛客第四场(xor)
题意: 给你n个基,q个询问,每个询问问你能不能 l~r 的所有基都能表示 x . 思路: 建一颗线性基的线段树,up就是求交的过程,按照线段树区间查询的方法进行check就可以了. #define ...
- 最短meeting路线(树的直径)--牛客第四场(meeting)
题意: 给你一棵树,树上有些点是有人的,问你选一个点,最短的(最远的那个人的距离)是多少. 思路: 其实就是树的直径,两遍dfs,dfs第二遍的时候遇到人就更新直径就行了,ans是/2,奇数的话+1. ...
- 牛客第三场多校 H Diff-prime Pairs
链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...
- 牛客网第二场Jfarm(随机化+二维前缀和)
链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 White Rabbit has a rectangular farmland of n*m. ...
- 牛客网第一场E题 Removal
链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...
随机推荐
- codeforces269B
Greenhouse Effect CodeForces - 269B Emuskald is an avid horticulturist and owns the world's longest ...
- log4j 多进程配置要注意的
多进程写日志文件 方法一: 解决log4j公用配置文件,多进程同时写同一个log文件,因存在操作系统pv操作问题, 导致部分日志丢失.解决方案是不同的进程写不同的log文件 测试于:Log4j 1.2 ...
- 两次取反 !!a 的作用
两次取反的作用 让a的结果只能是false或者是true:如果a是0:两次取反当然是false:如果a是null:两次取反是false:如果a是undefined:两次取法是false:其余的比如 a ...
- 极光推送报错time_to_live value should be a non-negative integertime_to_live value should be a non-negative integer
文件中修改
- 编译内核时报错./include/net/sch_generic.h:535:28: error: inlining failed in call to always_inline 'qdisc_pkt_len': indirect function call with a yet undetermined callee static inline unsigned int qdisc_pkt_
直接修改头文件include/net/sch_generic.h中的qdisc_pkt_len函数 将static inline unsigned int qdisc_pkt_len修改为: stat ...
- JNI使用常见错误
1. java.lang.UnsatisfiedLinkError: Couldn't load hello: **findLibrary returned null** 解决方案: * 如果处理器平 ...
- 百度AI接口---身份证识别Demo
题记:自己是做java web的,但是本人以前接触并学习很多图像的知识,所以对图像很敏感.下面以百度的一个接口,实现身份证识别案例 1.需要百度开发者AppID.SecretKey .API Key. ...
- mips调试
0x01 环境搭建 由于我们通常的操作系统指令集都是x86的,所以无法跑MIPS程序.这时候就需要装QEMU来模拟,QEMU通过源码编译较为复杂,我们又没有特殊的需求,所以直接使用ubuntu的APT ...
- Redis 持久化配置(兼论瞎翻译的问题)
redis.conf 文件中配置 save 默认配置项: save save save 查了好几个地方都是这么说的: 第一句的意思:15分钟内修改了一个键就保存??? 往 Redis 里加了一个值,重 ...
- 在Linux上安装Python3.7.1
一.安装依赖环境 输入命令:yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readlin ...