2019牛客暑期多校训练营(第四场)----D-triples I

首先发出题目链接:
链接:https://ac.nowcoder.com/acm/contest/884/D
来源:牛客网
涉及:位运算

点击这里回到2019牛客暑期多校训练营解题—目录贴


题目如下:
在这里插入图片描述
在这里插入图片描述
代码如下:

#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
vector<ll> vec1, vec2;
int t;
ll a;
int main(){
	scanf("%d", &t);
	while(t--){
		vec1.clear();
		vec2.clear();
		scanf("%lld", &a);
		if(a % 3 == 0){
			printf("1 %lld\n", a);
			continue;
		}
		for(int i = 0; i <= 60; i++){
			ll tmp = (1ll << i);
			if(a & tmp){
				if(tmp % 3 == 1)	vec1.push_back(tmp);
				if(tmp % 3 == 2)	vec2.push_back(tmp);
			}
		}
		if(a % 3 == 1){	
			if(vec1.size() >= 2){
				printf("2 %lld %lld\n", a - vec1[0], a - vec1[1]);
			} else if(vec1.size() == 1){
				printf("2 %lld %lld\n", a - vec1[0], vec1[0] + vec2[0]);
			} else if(vec1.size() == 0){
				ll tmp1 = vec2[0] + vec2[1], tmp2 = vec2[1] + vec2[2], tmp3 = vec2[2] + vec2[0];
				printf("3 %lld %lld %lld\n", a - tmp1, a - tmp2, a - tmp3);
			}
		}else{
			if(vec2.size() >= 2){
				printf("2 %lld %lld\n", a - vec2[0], a - vec2[1]);
			} else if(vec2.size() == 1){
				printf("2 %lld %lld\n", a - vec2[0], vec1[0] + vec2[0]);
			} else if(vec2.size() == 0){
				ll tmp1 = vec1[0] + vec1[1], tmp2 = vec1[1] + vec1[2], tmp3 = vec1[2] + vec1[0];
				printf("3 %lld %lld %lld\n", a - tmp1, a - tmp2, a - tmp3);
			}	
		}
	}
	return 0;
} 
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页