加载中…
个人资料
abentu
abentu
  • 博客等级:
  • 博客积分:0
  • 博客访问:16,180
  • 关注人气:4
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
相关博文
推荐博文
谁看过这篇博文
加载中…
正文 字体大小:

poj3760-魔兽世界(2)

(2010-06-06 20:24:03)
标签:

杂谈

代码的后一半:

 

int clr(int i,int j)
{
 w[i][j].id = 0;
 w[i][j].hp = 0;
 w[i][j].ap = 0;
 w[i][j].type = 0;
 w[i][j].step = 0;
 w[i][j].kill = 0;
 return 0;
}

int train()
{
 int j;
 j = pA % 5;
 j = oA[j];
 if (eA >= inithp[j])
 {
  eA -= inithp[j];
  pA ++;
  p01(0,pA,j);
  w[0][0].id = pA;
  w[0][0].hp = inithp[j];
  w[0][0].ap = initap[j];
  w[0][0].type = j;
  w[0][0].step = 0;
  w[0][0].kill = 0;
 }

 j = pB % 5;
 j = oB[j];
 if (eB >= inithp[j])
 {
  eB -= inithp[j];
  pB ++;
  p01(1,pB,j);
  w[1][n+1].id = pB;
  w[1][n+1].hp = inithp[j];
  w[1][n+1].ap = initap[j];
  w[1][n+1].type = j;
  w[1][n+1].step = 0;
  w[1][n+1].kill = 0;
 }

 return 0;
}

int move()
{
 int i;

 for (i = n;i >= 0;i --)
 {
  w[0][i+1] = w[0][i];
  if (w[0][i+1].hp > 0)
   w[0][i+1].step ++;
 }

 clr(0,0);

 for (i = 1;i <= n+1;i ++)
 if (w[0][i].hp > 0 && w[0][i].type == 2 && w[0][i].step > 0 && w[0][i].step % 2 == 0)
 {
  w[0][i].hp -= 9;
  if (w[0][i].hp <= 0)
   w[0][i].hp = 1;
  w[0][i].ap += 20;
 }


 for (i = 1;i <= n+1;i ++)
 {
  w[1][i-1] = w[1][i];
  if (w[1][i-1].hp > 0)
   w[1][i-1].step ++;
 }

 clr(1,n+1);

 for (i = n;i >= 0;i --)
 if (w[1][i].hp > 0 && w[1][i].type == 2 && w[1][i].step > 0 && w[1][i].step % 2 == 0)
 {
  w[1][i].hp -= 9;
  if (w[1][i].hp <= 0)
   w[1][i].hp = 1;
  w[1][i].ap += 20;
 }
 
 if (w[1][0].hp > 0)
 {
  p09(1,w[1][0].id,w[1][0].hp,w[1][0].ap,w[1][0].type,0);
  clr(1,0);
  flag[0] ++;
 }

 if (flag[0] >= 2)
  p10(0);

 for (i = 1;i <= n;i ++)
 {
  if (w[0][i].hp > 0)
   p02(0,w[0][i].id,w[0][i].hp,w[0][i].ap,w[0][i].type,i);
  if (w[1][i].hp > 0)
   p02(1,w[1][i].id,w[1][i].hp,w[1][i].ap,w[1][i].type,i);
 }

 if (w[0][n+1].hp > 0)
 {
  p09(0,w[0][n+1].id,w[0][n+1].hp,w[0][n+1].ap,w[0][n+1].type,1);
  clr(0,n+1);
  flag[n+1] ++;
 }

 if (flag[n+1] >= 2)
  p10(1);

 return 0;
}

int produce()
{
 int i;
 for (i = 1;i <= n;i ++)
  e[i] += 10;
 return 0;
}

int take()
{
 int i;
 for (i = 1;i <= n;i ++)
 {
  if (w[0][i].hp > 0 && w[1][i].hp <= 0 && e[i] > 0)
  {
   p07(0,w[0][i].id,w[0][i].type,e[i]);
   eA += e[i];
   e[i] = 0;
  }
  else if (w[0][i].hp <= 0 && w[1][i].hp > 0 && e[i] > 0)
  {
   p07(1,w[1][i].id,w[1][i].type,e[i]);
   eB += e[i];
   e[i] = 0;
  }
 }

 return 0;
}

int judge[N];

int fight()
{
 memset(judge,0,sizeof(judge));

 int i,j,hp0,hp1;
 for (i = 1;i <= n;i ++)
 if (w[0][i].hp > 0 && w[1][i].hp > 0)
 {
  if (flag[i] >= 9)
   j = 0;
  else if (flag[i] <= -9)
   j = 1;
  else
   j = (i + 1) % 2;

  hp0 = w[0][i].hp;
  hp1 = w[1][i].hp;
  
  p03(j,w[j][i].id,w[j][i].hp,w[j][i].ap,w[j][i].type,i,1-j,w[1-j][i].id,w[1-j][i].type);
  w[1-j][i].hp -= w[j][i].ap;
  if (w[1-j][i].hp > 0 && w[1-j][i].type != 1)
  {
   p04(1-j,w[1-j][i].id,w[1-j][i].type,i,j,w[j][i].id,w[j][i].type);
   w[j][i].hp -= (w[1-j][i].ap / 2);
  }

  if (w[0][i].hp <= 0)
  {
   judge[i] = -1;
   p05(0,w[0][i].id,w[0][i].type,i);
   w[1][i].kill ++;
   if (w[1][i].kill % 2 == 0 && w[1][i].type == 4)
   {
    w[1][i].hp += w[1][i].hp;
    w[1][i].ap += w[1][i].ap;
   }
   if (w[0][i].type == 3)
    w[1][i].hp += hp0;
   clr(0,i);
  }

  if (w[1][i].hp <= 0)
  {
   judge[i] = 1;
   p05(1,w[1][i].id,w[1][i].type,i);
   w[0][i].kill ++;
   if (w[0][i].kill % 2 == 0 && w[0][i].type == 4)
   {
    w[0][i].hp += w[0][i].hp;
    w[0][i].ap += w[0][i].ap;
   }
   if (w[1][i].type == 3)
    w[0][i].hp += hp1;
   clr(1,i);
  }

  if (w[0][i].hp > 0 && w[1][i].hp > 0)
   judge[i] = 2;


  if (w[j][i].hp > 0 && w[j][i].type == 0)
   p06(j,w[j][i].id,w[j][i].type,i);

  if (judge[i] == 1)
   p07(0,w[0][i].id,w[0][i].type,e[i]);
  else if (judge[i] == -1)
   p07(1,w[1][i].id,w[1][i].type,e[i]);

  if (judge[i] == 1)
  {
   j = flag[i];
   switch(j)
   {
   case 10:
    break;
   case 9:
    flag[i] = 10;
    break;
   case 1:
    flag[i] = 10;
    p08(0,i);
    break;
   case 0:
    flag[i] = 1;
    break;
   case -1:
    flag[i] = 1;
    break;
   case -9:
    flag[i] = 10;
    p08(0,i);
    break;
   case -10:
    flag[i] = -9;
    break;
   default:
    break;
   }
  }

  if (judge[i] == -1)
  {
   j = flag[i];
   switch(j)
   {
   case 10:
    flag[i] = 9;
    break;
   case 9:
    flag[i] = -10;
    p08(1,i);
    break;
   case 1:
    flag[i] = -1;
    break;
   case 0:
    flag[i] = -1;
    break;
   case -1:
    flag[i] = -10;
    p08(1,i);
    break;
   case -9:
    flag[i] = -10;
   case -10:
    break;
   default:
    break;
   }
  }
  
  if (judge[i] == 2)
  {
   j = flag[i];
   switch(j)
   {
   case 10:
    break;
   case 9:
    flag[i] = 10;
    break;
   case 1:
    flag[i] = 0;
    break;
   case 0:
    break;
   case -1:
    flag[i] = 0;
    break;
   case -9:
    flag[i] = -10;
    break;
   case -10:
    break;
   default:
    break;
   }
  }

 }

 for (i = n;i >= 1;i --)
 {
  if (eA < 8)
   break;
  if (judge[i] == 1)
  {
   eA -= 8;
   w[0][i].hp += 8;
  }
 }

 for (i = 1;i <= n;i ++)
 {
  if (eB < 8)
   break;
  if (judge[i] == -1)
  {
   eB -= 8;
   w[1][i].hp += 8;
  }
 }

 for (i = 1;i <= n;i ++)
 {
  if (judge[i] == 1)
  {
   eA += e[i];
   e[i] = 0;
  }
  else if (judge[i] == -1)
  {
   eB += e[i];
   e[i] = 0;
  }
 }


 return 0;
}


int report()
{
 p11(0,eA);
 p11(1,eB);
 return 0;
}

int init()
{
 memset(w,0,sizeof(w));
 memset(flag,0,sizeof(flag));
 memset(e,0,sizeof(e));
 eA = 0;
 eB = 0;
 pA = 0;
 pB = 0;

 scanf("%d%d%d",&m,&n,&t);
 int i;
 for (i = 0;i <= 4;i ++)
  scanf("%d",&inithp[i]);
 for (i = 0;i <= 4;i ++)
  scanf("%d",&initap[i]);

 eA = m;
 eB = m;

 return 0;
}

int solve()
{
 for (time = 0;time <= t;time += 10)
 {
  hour = time / 60;
  min = time % 60;
  min = min / 10;
  switch(min)
  {
  case 0:
   train();
   break;
  case 1:
   move();
   break;
  case 2:
   produce();
   break;
  case 3:
   take();
   break;
  case 4:
   fight();
   break;
  case 5:
   report();
   break;
  default:
   break;
  }

  if (flag[0] >= 2 || flag[n+1] >= 2)
   break;
 }

 return 0;
}


int main()
{
 scanf("%d",&cases);
 int i;
 for (i = 1;i <= cases;i ++)
 {
  printf("Case:%d\n",i);
  init();
  solve();
 }
 return 0;
}

0

阅读 评论 收藏 转载 喜欢 打印举报/Report
  • 评论加载中,请稍候...
发评论

    发评论

    以上网友发言只代表其个人观点,不代表新浪网的观点或立场。

      

    新浪BLOG意见反馈留言板 欢迎批评指正

    新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 会员注册 | 产品答疑

    新浪公司 版权所有