解题报告:HDU_6139 Galaxy at War (阶梯博弈)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_32570675/article/details/77433971

题目链接

题意:

一张n*m的表格上有一些格子有一些水晶球,两个人轮流进行游戏

每次选择一个有水晶球的格子,选择其中至少一个水晶球将它左移或者下移,不能出界

还有一些格子上有M(Meditations)或者P(pollutant sources),对应的作用为

当你选择的格子上有M时,若你选择移动 t 个水晶球,那么会将2*t 个水晶球平分到可以移动到的格子内

当t个水晶被移动到有P的格子上时,t 变成 [t/2] (向下取整)

(n,m)处一定有P,(n-1,m)处一定有M

任意含M(x,y)和含P(a,b)的格子的位置关系满足式子的值为奇数


无法操作的玩家输掉比赛,给定局势,询问先手胜负态


思路:

先分析给出的位置关系的式子,可以发现所有含有M的格子和含有P的格子的奇偶关系不同

如果没有M和P的设定,这个问题就是一个简单的阶梯博弈,只用考虑离终点的距离为奇数的点

含有P的位置离终点的距离一定为偶数,所有对答案没有影响

含有M的位置离终点的距离一定为奇数,它每次会将一个奇数步上的 t 变成偶数步上的2*t

一定可以选择其中的 t 重新移动到奇数步上,所以对答案同样没有影响

所以答案就是所有距离终点奇数步的格子的水晶数异或值


代码:

#include<cstdio>
using namespace std;

int n,m,T,k,x,y,w;
int main()
{
   scanf("%d",&T);
   while(T--){
      scanf("%d%d%d",&n,&m,&k);
      int ans = 0 , t = (n^m);
      while(k--){
         scanf("%d%d%d",&x,&y,&w);
         if((x^y^t)&1)ans^=w;
      }scanf("%d",&k);while(k--)scanf("%*d%*d");
      scanf("%d",&k);while(k--)scanf("%*d%*d");
      printf("%s\n",ans?"win":"lose");
   }return 0;
}



阅读更多

Galaxy War

08-24

In order to count the monsters from another dimension, many stars in galaxy joint the Association Counter Monsters (ACM). They built many bidirectional tunnels to exchange messages. They built some tunnels so that any circle in the graph formed by the tunnel network, whose length is larger than 3, had at least one chord. A chord is an edge connecting two non-adjacent points in the cycle.nnOne day, the Chief of ACM asked you to draw a map of the stars in ACM. In the map, the two endpoint of any tunnel must have different colors. For security reason, the more methods of drawing the map, the better. So the Chief asked you how many methods there were if he provided you n colors.nnGiven you all the tunnels among the stars, your task is to answer the Chief's question as soon as possible.nnInputnnThe input contains several test cases.nnFor each case, the first line contains two integers n (2 <= n <= 1000), m, indicating the number of stars in ACM and the number of tunnels. The following m lines contain two integers each, indicating the stars that tunnel connects. The stars are numbered from 1 to n. No tunnel connects a star to itself, and no two stars are connected with more than one tunnel. Then an integer P (0 < P <= 1000), the number of the Chief's questions, follows. The following P lines contain 2 integers C (0 < C <= 1000000000), M (0 < M <= 1000000000), each, meaning that the Chief provides you C colors, and that you should output the number of methods module M.nnOutputnnFor each quest, output the answer in one line.nnSample Inputnn4 5n1 2n2 3n3 4n4 1n1 3n2n2 10n3 10nSample Outputnn0n6

没有更多推荐了,返回首页