题意:

给你一个数,希望你能用最少的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的更多相关文章

  1. 平面割线平分点(构造)--牛客第三场-- Magic Line

    题意: 给你n个点的坐标,让你给出两个点,这两个点的连线可以平分这些点. 思路: 先按y的大小排序,在按x的小排序,再搞一下就行了.如下图: #include <bits/stdc++.h> ...

  2. 分层最短路(牛客第四场)-- free

    题意: 给你边权,起点和终点,有k次机会把某条路变为0,问你最短路是多长. 思路: 分层最短路模板题.题目有点坑(卡掉了SPFA,只能用dijkstra跑的算法). #include<iostr ...

  3. %300为0的个数(牛客第四场)-- number

    题意: 给你一串数,问你如题. 思路: 我不是这样的作法,从后往前,先取00,再算%3==0的个数,往前推的时候有递推关系: #define IOS ios_base::sync_with_stdio ...

  4. 笛卡尔树--牛客第四场(sequence)

    思路: O(n)建一颗笛卡尔树,再O(n)dfs向上合并答案就行了. #define IOS ios_base::sync_with_stdio(0); cin.tie(0); #include &l ...

  5. 线性基求交(线段树)--牛客第四场(xor)

    题意: 给你n个基,q个询问,每个询问问你能不能 l~r 的所有基都能表示 x . 思路: 建一颗线性基的线段树,up就是求交的过程,按照线段树区间查询的方法进行check就可以了. #define ...

  6. 最短meeting路线(树的直径)--牛客第四场(meeting)

    题意: 给你一棵树,树上有些点是有人的,问你选一个点,最短的(最远的那个人的距离)是多少. 思路: 其实就是树的直径,两遍dfs,dfs第二遍的时候遇到人就更新直径就行了,ans是/2,奇数的话+1. ...

  7. 牛客第三场多校 H Diff-prime Pairs

    链接:https://www.nowcoder.com/acm/contest/141/H来源:牛客网 Eddy has solved lots of problem involving calcul ...

  8. 牛客网第二场Jfarm(随机化+二维前缀和)

    链接:https://www.nowcoder.com/acm/contest/140/J 来源:牛客网 White Rabbit has a rectangular farmland of n*m. ...

  9. 牛客网第一场E题 Removal

    链接:https://www.nowcoder.com/acm/contest/139/E 来源:牛客网 Bobo has a sequence of integers s1, s2, ..., sn ...

随机推荐

  1. zabbix服务端接收的数据类型,便于编写脚本向服务端提交数据

    1.数据类型1:zabbix_agent执行脚本提交字典 UserParameter=tcp_port_listen,/usr/local/zabbix/share/script/get_game_p ...

  2. 简单的SSRF的学习

    自己眼中的SSRF 成因 服务端允许了 可以向其他服务器请求获取一些数据 通过各种协议 http https file等(外网服务器所在的内网进行端口的扫描指纹的识别等) 一SSRF配合redis未授 ...

  3. 关于开发APP接口版本不兼容的问题

    关于 APP接口版本兼容的问题. iOS和android 要不断开发新版本,很多服务端开发都是在以前接口的逻辑上进行修改. 新的APP和接口开发后,接口如何兼容老的APP? 有的公司 每次发布完APP ...

  4. SRS之RTMP handshake

    1. SrsRtmpServer::handshake 位于 srs_rtmp_stack.cpp. int SrsRtmpServer::handshake() { int ret = ERROR_ ...

  5. MAMP 环境下安装Redis扩展

    1. 下载对应版本的 php 源码,(当前使用版本是 php5.6.30 )版本号最后一位有点区别不影响链接:http://php.net/get/php-5.6.31.tar.bz2/from/a/ ...

  6. itertools模块中的product方法

    itertools模块中的product方法 itertools.product(*iterables[, repeat]) 笛卡尔积 创建一个迭代器,生成表示item1,item2等中的项目的笛卡尔 ...

  7. RestAssured

    配置MAVEN <dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-ass ...

  8. n个骰子可能的点数和

    让后面的点数比前面的大 package touzi; public class Touzi { public static void main(String[] args) { // TODO Aut ...

  9. 使用EasyPrint实现不预览直接打印功能_非JS打印

    插件地址 github 下载插件,安装后将在注册表中添加EasyPrint的协议 随后可以在开始->运行中输入EasyPrint://1&test 进行测试  参数分为两部分使用[&am ...

  10. PHP中获取当前页面的完整URL、PHP URL处理、获取不带扩展名的文件名

    javascript实现: top.location.href 顶级窗口的地址this.location.href 当前窗口的地址 PHP实现 #测试网址: http://localhost/blog ...