总是有一个程序的bug没找到

时间:2023-12-05 14:36:44
 算法训练 Lift and Throw  
时间限制:3.0s   内存限制:256.0MB
问题描述
  给定一条标有整点(1, 2, 3, ...)的射线. 定义两个点之间的距离为其下标之差的绝对值.
  Laharl, Etna, Flonne一开始在这条射线上不同的三个点, 他们希望其中某个人能够到达下标最大的点.
  每个角色只能进行下面的3种操作, 且每种操作不能每人不能进行超过一次.
  1.移动一定的距离
  2.把另一个角色高举过头
  3.将举在头上的角色扔出一段距离
  每个角色有一个movement range参数, 他们只能移动到没有人的位置, 并且起点和终点的距离不超过movement range.
  如果角色A和另一个角色B距离为1, 并且角色B没有被别的角色举起, 那么A就能举起B. 同时, B会移动到A的位置,B原来所占的位置变为没有人的位置. 被举起的角色不能进行任何操作, 举起别人的角色不能移动.同时, 每个角色还有一个throwing range参数, 即他能把举起的角色扔出的最远的距离. 注意, 一个角色只能被扔到没有别的角色占据的位置. 我们认为一个角色举起另一个同样举起一个角色的角色是允许的. 这种情况下会出现3个人在同一个位置的情况. 根据前面的描述, 这种情况下上面的两个角色不能进行任何操作, 而最下面的角色可以同时扔出上面的两个角色. 你的任务是计算这些角色能够到达的位置的最大下标, 即最大的数字x, 使得存在一个角色能够到达x.
输入格式
  输入共三行, 分别为Laharl, Etna, Floone的信息.
  每一行有且仅有3个整数, 描述对应角色的初始位置, movement range, throwing range.
  数据保证3个角色的初始位置两两不相同且所有的数字都在1到10之间.</div>
输出格式
  仅有1个整数, 即Laharl, Etna, Flonne之一能到达的最大距离.
样例输入
9 3 3
4 3 1
2 3 3
样例输出
15
样例说明
  一开始Laharl在位置9, Etna在位置4, Flonne在位置2.
  首先, Laharl移动到6.
  然后Flonne移动到位置5并且举起Etna.
  Laharl举起Flonne将其扔到位置9.
  Flonne把Etna扔到位置12.
  Etna移动到位置15.
我想的思路是一人有三种操作,分别是移动,举起旁边的,扔自己上面的。三个人就是九种。
然后九种操作进行深度搜索。
样例给过了,但提交只有两组数据对了。
做了两晚上都没调好,我感觉我的思路应该没有错误。
 如果你有思路,希望告知我。
递归的程序虽然比较好想,但是稍微一复杂根本就没法调bug啊,很容易迷失在不知第几层。。。
 #include <iostream>
#include <cstdio> using namespace std; typedef struct node{
int loca;
int moverange;
int throwrange;
};
struct node a[];
int w[]={};
int is_move[]={};
int is_lift[]={};
int is_throw[]={};
int is_belifted[]={};
int ans=;
int step[]={}; int dfs();
//第一个人的第一种操作,移动
void fun11(){
if(!is_move[]){
int t=a[].loca+a[].moverange;
for(int i=a[].loca-a[].moverange; i<=t; i++){
if(!w[i] && i>=){
int t1=w[a[].loca];
int t2=a[].loca;
int t3=is_move[];
w[a[].loca]=;
w[i]=;
a[].loca=i;
is_move[]=;
dfs();
w[a[].loca]=t1;
w[i]=;
a[].loca=t2;
is_move[]=t3;
} }
}
}
//第一个人的第二种操作,举起两边的
void fun12(){
for(int i=;i<=;i++){
if(w[a[].loca-]==i){
int t1=w[a[].loca-];
int t2=is_belifted[i];
int t3=is_lift[]; w[a[].loca-]=;
is_belifted[i]=;
is_lift[]=i;
dfs(); w[a[].loca-]=t1;
is_belifted[i]=t2;
is_lift[]=t3;
}
if(w[a[].loca+]==i){
int t1=w[a[].loca+];
int t2=is_belifted[i];
int t3=is_lift[];
w[a[].loca+]=;
is_belifted[i]=;
is_lift[]=i;
dfs();
w[a[].loca+]=t1;
is_belifted[i]=t2;
is_lift[]=t3;
}
}
}
//第一个人的第三种操作,扔自己上面的
void fun13(){
if(!is_throw[] && is_lift[]!=){
for(int i=a[].loca-a[].throwrange; i<=a[].loca+a[].throwrange; i++){
if(!w[i] && i>=){
int t1=w[a[].loca];
int t2=w[i];
int t3=a[].loca;
int t4=is_throw[];
w[a[].loca]=;
w[i]=is_lift[];
a[].loca=i;
is_throw[]=;
dfs();
w[a[].loca]=t1;
w[i]=t2;
a[].loca=t3;
is_throw[]=t4;
} }
}
} //第二个人的第一种操作,移动
void fun21(){
if(!is_move[]){
int t=a[].loca+a[].moverange;
for(int i=a[].loca-a[].moverange; i<=t; i++){
if(!w[i] && i>=){
int t1=w[a[].loca];
int t2=a[].loca;
int t3=is_move[];
w[a[].loca]=;
w[i]=;
a[].loca=i;
is_move[]=;
dfs();
w[a[].loca]=t1;
w[i]=;
a[].loca=t2;
is_move[]=t3;
} }
}
}
//第二个人的第二种操作,举起两边的
void fun22(){
for(int i=;i<=;i++){
if(w[a[].loca-]==i){
int t1=w[a[].loca-];
int t2=is_belifted[i];
int t3=is_lift[];
w[a[].loca-]=;
is_belifted[i]=;
is_lift[]=i;
dfs();
w[a[].loca-]=t1;
is_belifted[i]=t2;
is_lift[]=t3;
}
if(w[a[].loca+]==i){
int t1=w[a[].loca+];
int t2=is_belifted[i];
int t3=is_lift[];
w[a[].loca+]=;
is_belifted[i]=;
is_lift[]=i;
dfs();
w[a[].loca+]=t1;
is_belifted[i]=t2;
is_lift[]=t3;
}
}
}
//第二个人的第三种操作,扔自己上面的
void fun23(){
if(!is_throw[] && is_lift[]!=){
for(int i=a[].loca-a[].throwrange; i<=a[].loca+a[].throwrange; i++){
if(!w[i] && i>=){
int t1=w[a[].loca];
int t2=w[i];
int t3=a[].loca;
int t4=is_throw[];
w[a[].loca]=;
w[i]=is_lift[];
a[].loca=i;
is_throw[]=;
dfs();
w[a[].loca]=t1;
w[i]=t2;
a[].loca=t3;
is_throw[]=t4;
} }
}
}
//第三个人的第一种操作,移动
void fun31(){
if(!is_move[]){
int t=a[].loca+a[].moverange;
for(int i=a[].loca-a[].moverange; i<=t; i++){
if(!w[i] && i>=){
int t1=w[a[].loca];
int t2=a[].loca;
int t3=is_move[];
w[a[].loca]=;
w[i]=;
a[].loca=i;
is_move[]=;
dfs();
w[a[].loca]=t1;
w[i]=;
a[].loca=t2;
is_move[]=t3;
} }
}
}
//第三个人的第二种操作,举起两边的
void fun32(){
for(int i=;i<=;i++){
if(w[a[].loca-]==i){
int t1=w[a[].loca-];
int t2=is_belifted[i];
int t3=is_lift[];
w[a[].loca-]=;
is_belifted[i]=;
is_lift[]=i;
dfs();
w[a[].loca-]=t1;
is_belifted[i]=t2;
is_lift[]=t3;
}
if(w[a[].loca+]==i){
int t1=w[a[].loca-];
int t2=is_belifted[i];
int t3=is_lift[];
w[a[].loca+]=;
is_belifted[i]=;
is_lift[]=i;
dfs();
w[a[].loca+]=t1;
is_belifted[i]=t2;
is_lift[]=t3;
}
}
}
//第三个人的第三种操作,扔自己上面的
void fun33(){
if(!is_throw[] && is_lift[]!=){
for(int i=a[].loca-a[].throwrange; i<=a[].loca+a[].throwrange; i++){
if(!w[i] && i>=){
int t1=w[a[].loca];
int t2=w[i];
int t3=a[].loca;
int t4=is_throw[];
w[a[].loca]=;
w[i]=is_lift[];
a[].loca=i;
is_throw[]=;
dfs();
w[a[].loca]=t1;
w[i]=t2;
a[].loca=t3;
is_throw[]=t4;
} }
}
} int dfs(){
ans=max(ans,a[].loca);
ans=max(ans,a[].loca);
ans=max(ans,a[].loca);
//if(is_move[1]==1&&is_move[2]==1&&is_move[3]==1&&is_throw[1]==1&&is_throw[2]==1&&is_throw[3]==0||is_throw[1]==1&&is_throw[2]==0&&is_throw[3]==1||is_throw[1]==0&&is_throw[2]==1&&is_throw[3]==1){
// return 0;
//}else{
for(int i=;i<=;i++){
if(!step[i]){
switch(i){
case :step[]=;fun11();step[]=;break;
case :step[]=;fun12();step[]=;break;
case :step[]=;fun13();step[]=;break;
case :step[]=;fun21();step[]=;break;
case :step[]=;fun22();step[]=;break;
case :step[]=;fun23();step[]=;break;
case :step[]=;fun31();step[]=;break;
case :step[]=;fun32();step[]=;break;
case :step[]=;fun33();step[]=;break;
}
} }
return ;
//} } int main()
{
for(int i=;i<=;i++){
scanf("%d %d %d",&a[i].loca,&a[i].moverange,&a[i].throwrange);
}
dfs();
printf("%d\n",ans);
return ;
}