题意:

给你一个数,希望你能用最少的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. Android_activity实现一个简单的新建联系表

    项目展示: 第一个Activity用于显示联系人信息 第二个Activity输入联系人信息 要求: 运行“新建联系人”程序,结果如下图所示: 点击“新建联系人”按钮,打开输入信息界面并输入姓名.公司. ...

  2. pyton3的数字操作你都会用吗?

    '''数字数据类型用于存储数值.数据类型是不允许改变的,这就意味着如果改变数字数据类型的值,将重新分配空间. 1.del(用于删除一些数字对象的引用) 2.整形(int)通常被称为是整形或者整数,是正 ...

  3. RBAC 权限模型

    RBAC 0 模型 最基本的 MySQL 脚本,没有建立外键约束. /* Navicat Premium Data Transfer Source Server Type : MySQL Source ...

  4. koa 项目实战(四)注册接口和调试工具(postman)

    1.安装模块 npm install koa-bodyparser --save npm install bcryptjs --save 2.引入模块 根目录/app.js const bodyPar ...

  5. PMML辅助机器学习算法上线

    在机器学习用于产品的时候,我们经常会遇到跨平台的问题.比如我们用Python基于一系列的机器学习库训练了一个模型,但是有时候其他的产品和项目想把这个模型集成进去,但是这些产品很多只支持某些特定的生产环 ...

  6. Orcal nvl函数

    NVL(E1, E2)的功能为:如果E1为NULL,则函数返回E2,否则返回E1本身.但此函数有一定局限,所以就有了NVL2函数. 拓展:NVL2函数:Oracle/PLSQL中的一个函数,Oracl ...

  7. Win10删除文件显示删除确认对话框

    1.右键单击“回收站”图标:2.在弹出属性窗口中,点击“属性”选项:3.在“回收站”窗口中,在选项“显示删除确认对话框”前面打钩,并单击“确定”按钮:

  8. httpClient模仿Basic Auth

    httpclient代码调用如下: @GetMapping("loginTest") public String httpClientWithBasicAuth() { Strin ...

  9. spring boot系列(五)spring boot 配置spring data jpa (查询方法)

    接着上面spring boot系列(四)spring boot 配置spring data jpa 保存修改方法继续做查询的测试: 1 创建UserInfo实体类,代码和https://www.cnb ...

  10. linux常用命令(9)nl命令

    nl命令在linux系统中用来计算文件中行号.nl 可以将输出的文件内容自动的加上行号!其默认的结果与 cat -n 有点不太一样, nl 可以将行号做比较多的显示设计,包括位数与是否自动补齐 0 等 ...