题意:

给你一个数,希望你能用最少的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. js对象及初识面向对象(4)

    一.什么是对象? 对象是包含了属性和方法的集合体 二.什么是面向对象? 面向对象是一种编程思想,在JS当中利用原型来阐述这种思想的编程方法 三.构建对象: 1.内置对象: String   Math  ...

  2. 局域网与internet

    凡是由能彼此通信的设备组成的网络就叫互联网,即使仅有两台机器(计算机.手机等),不论用何种技术使其彼此通信,都叫互联网, 所以,互联网有广域网.城域网及局域网之分. 国际标准的互联网写法是intern ...

  3. 邻居子系统输出 之 neigh_output、neigh_hh_output

    概述 ip层在构造好ip头,检查完分片之后,会调用邻居子系统的输出函数neigh_output进行输出,输出分为有二层头缓存和没有两种情况,有缓存时调用neigh_hh_output进行快速输出,没有 ...

  4. Web存储机制—sessionStorage,localStorage使用方法

    Web存储机制,在这里主要聊有关于Web Storage API提供的存储机制,通过该机制,浏览器可以安全地存储键值对,比使用cookie更加直观.接下来简单的了解如何使用这方面的技术. 基本概念 W ...

  5. mysql密码忘记更改

    忘记mysql的密码是一件不好的事,通常我们会把密码记住,或者是存在文档中,避免忘记,如果忘记了密码可以参照下方方法来更改,这个操作需要重启mysql. 首先我们在my.cnf文件中的[mysqld] ...

  6. koa 基础(十七)原生 JS 中的类、静态方法、继承

    1.app.js /** * 原生 JS 中的类.静态方法.继承 * es5中的类和静态方法 */ function Person(name, age) { // 构造函数里面的方法和属性 this. ...

  7. 使用 Itext 生成PDF字节数组(文件流不落地)

    package com.ulic.gis.customerCenter.controller; import java.io.ByteArrayOutputStream; import java.io ...

  8. vue echarts圆角阴影效果

    series: [ { name: '销量', type: 'bar', data: [5, 20, 36, 10, 10, 20], itemStyle: { normal: { barBorder ...

  9. JDBC插入数据,获取自增长值

    package com.loaderman.demo.c_auto; public class Dept { private int id; private String deptName; publ ...

  10. Proxmox

    vmware: vmware 12 pro proxmox 下载地址 往下会比较麻烦一点,这里就不做展示了(仅供参考)