题意:

给你一个数,希望你能用最少的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. 从零开始入门 K8s | Kubernetes 调度和资源管理

    作者 | 子誉  蚂蚁金服高级技术专家 关注"阿里巴巴云原生"公众号,回复关键词"入门",即可下载从零入门 K8s 系列文章 PPT. Kubernetes 调 ...

  2. Open_Read_Write函数基本使用

    先来一个小插曲,我们知道read函数等是系统调用函数,应该在第二页的手册里头,可是我man 2 read的时候却找不到,由此到/usr/sharead/man/man2目录下查看的时候发现此目录为空, ...

  3. $\LaTeX$数学公式大全7

    $7\ Arrow\ Symbols$ $\leftarrow$ \leftarrow $\Leftarrow$ \Leftarrow $\rightarrow$ \rightarrow $\Righ ...

  4. 网络爬虫技术实现java依赖库整理输出

    网络爬虫技术实现java依赖库整理输出 目录 1       简介... 2 1.1      背景介绍... 2 1.2      现有方法优缺点对比... 2 2       实现方法... 2 ...

  5. From 7.8 To 7.14

    From 7.8 To 7.14 大纲 学科 英语的话每天早上背单词, 争取每天做一篇完型, 一篇阅读, 一篇短文填空, 一篇改错, 一篇七选五??? 似乎太多了, 先试一下吧 语文的话, 尝试翻译一 ...

  6. C语言博客作业00

    对网络专业的了解 我一直觉得计算机是个很神奇的东西,就像大脑中有思想一样,在一个有形的芯片中能储存着无形的数据.它们的存储方式是什么?读取方式又是什么?为什么2个数字能产生如此巨大的信息?为什么点击鼠 ...

  7. SRS之HLS部署实例源码分析

    1. 综述 SRS 关于 HLS 的具体配置可见: HLS部署实例 SRS 关于 hls 的配置文件内容如下: listen 1935; max_connections 1000; daemon of ...

  8. 石川es6课程---7、数组

    石川es6课程---7.数组 一.总结 一句话总结: ^ 主要就map(映射:一个对一个),reduce(汇总:一堆出来一个),filter  过滤器,forEach 循环(迭代) 四个方法 ^ 使用 ...

  9. idea启动报Plugin Error错误的解决办法(亲测有效)

    今天在idea工作时,idea崩溃自动关闭,再打开时报Plugin Error,tomcat无法启动,于是上网查询,看到这个办法,成功解决了我的问题: 找到IDEA的配置文件夹下的disabled_p ...

  10. 前端使用pdf.js预览pdf文件,超级简单

    现在的浏览器基本都支持直接把pdf文件拖到浏览器就可以打开了,不用安装额外的插件.但是不同的浏览器显示的页面不一样.如果我们想在网页上统一预览pdf怎样实现呢? Mozilla开源了一个插件pdf.j ...