ABC343E 题解

题目传送门。

PS:比赛时题目数据过弱,把我的错误做法放过去了,感谢@CheZiHe929 提供的 hack

错误代码可以看这里

思路

固定第一个立方体位置不动,那么第二个立方体三个坐标从 [7,7][-7,7] 枚举,第三个立方体也一样。

正确性证明

  • 如果两个立方体完全不相交,那么完全可以移动到相切的位置。例如:(0,0,0)(0,0,0)(0,1145141919810,0)(0,1145141919810,0) 完全等价于 (0,0,0)(0,0,0)(0,7,0)(0,7,0)

  • 如果两个立方体相切,在 [7,7][-7,7] 范围内可以满足所有的相切情况。

因此,该算法在实际上是可以找到答案的。

时间复杂度

第一个立方体 O(1)\operatorname{O}(1),后面两个需要 156=1139062515^6=11390625 的时间复杂度,完全可以跑得过。

Code

#include<bits/stdc++.h>
using namespace std;
int f1(int a1,int b1,int c1,int a2,int b2,int c2) {
	int res=1;
	res*=max(0,min(a1,a2)+7-max(a1,a2));
	res*=max(0,min(b1,b2)+7-max(b1,b2));
	res*=max(0,min(c1,c2)+7-max(c1,c2));
	return res;
}
int f2(int a1,int b1,int c1,int a2,int b2,int c2,int a3,int b3,int c3) {
	int res=1;
	res*=max(0,min(min(a1,a2),a3)+7-max(max(a1,a2),a3));
	res*=max(0,min(min(b1,b2),b3)+7-max(max(b1,b2),b3));
	res*=max(0,min(min(c1,c2),c3)+7-max(max(c1,c2),c3));
	return res;
}
int a,b,c;
int main() {
	scanf("%d%d%d",&a,&b,&c);
	if(a+2*b+3*c!=1029) {
		printf("No");
		return 0;
	}
	int x[4],y[4],z[4],rx;
	int x2,y2,z2,x3,y3,z3;
	for(x2=-7; x2<=7; x2++) {
		for(y2=-7; y2<=7; y2++) {
			for(z2=-7; z2<=7; z2++) {
				for(x3=-7; x3<=7; x3++) {
					for(y3=-7; y3<=7; y3++) {
						for(z3=-7; z3<=7; z3++) {
							int three= f2(0,0,0,x2,y2,z2,x3,y3,z3);
							int ab= f1(0,0,0,x2,y2,z2),
							    bc= f1(x2,y2,z2,x3,y3,z3),
							    ac= f1(0,0,0,x3,y3,z3);
							int two=bc+ac+ab-3*three;
							if(two==b&&three==c){
								printf("Yes\n0 0 0 %d %d %d %d %d %d",x2,y2,z2,x3,y3,z3);
								exit(0);
							}
						}
					}
				}
			}
		}
	}
	cout<<"No";
	return 0;
}
posted @   Weslie_qwq  阅读(2)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】
点击右上角即可分享
微信分享提示