Triangle War(POJ 1085)

原创 2011年01月07日 17:18:00

问题描述:

Triangle War is a two-player game played on the following triangular grid: 
 
Two players, A and B, take turns filling in any dotted line connecting two dots, with A starting first. Once a line is filled, it cannot be filled again. If the line filled by a player completes one or more triangles, she owns the completed triangles and she is awarded another turn (i.e. the opponent skips a turn). The game ends after all dotted lines are filled in, and the player with the most triangles wins the game. The difference in the number of triangles owned by the two players is not important. 

For example, if A fills in the line between 2 and 5 in the partial game on the left below: 
 
Then, she owns the triangle labelled A and takes another turn to fill in the line between 3 and 5. B can now own 3 triangles (if he wishes) by filling in the line between 2 and 3, then the one between 5 and 6, and finally the one between 6 and 9. B would then make one more move before it is A's turn again. 
In this problem, you are given a number of moves that have already been made. From the partial game, you should determine which player will win assuming that each player plays a perfect game from that point on. That is, assume that each player always chooses the play that leads to the best possible outcome for himself/herself.

 

关于输入:

You will be given a number of games in the input. The first line of input is a positive integer indicating the number of games to follow. Each game starts with an integer 6 <= m <= 18 indicating the number of moves that have been made in the game. The next m lines indicate the moves made by the two players in order, each of the form i j (with i < j) indicating that the line between i and j is filled in that move. You may assume that all given moves are legal.

 

关于输出:

For each game, print the game number and the result on one line as shown below. If A wins, print the sentence "A wins." If B wins, print "B wins."

 

例子输入:

 

4 

6
2 4
4 5
5 9
3 6
2 5
3 5
7
2 4
4 5
5 9
3 6
2 5
3 5
7 8
6
1 2
2 3
1 3
2 4
2 5
4 5
10
1 2
2 5
3 6
5 8
4 7
6 10
2 4
4 5
4 8
7 8
例子输出:
Game 1: B wins. 

Game 2: A wins.
Game 3: A wins.
Game 4: B wins.
解题代码:

 

版权声明:本文为博主原创文章,未经博主允许不得转载。

Spark组件之GraphX学习14--TriangleCount实例和分析

更多代码请见:https://github.com/xubo245/SparkLearning 1解释 统计图中的Triangle,并返回 源码: /* * Licensed t...
  • bob601450868
  • bob601450868
  • 2016年05月04日 18:51
  • 1576

【LeetCode-面试算法经典-Java实现】【120-Triangle(三角形)】

【120-Triangle(三角形)】【LeetCode-面试算法经典-Java实现】【所有题目目录索引】原题  Given a triangle, find the minimum path sum...
  • DERRANTCM
  • DERRANTCM
  • 2015年08月14日 06:13
  • 2348

关于TRIANGLE二维三角网格生成器在windows下的配置说明

最近需要用到三角网格生成的一些东西,所以就把TRIANGLE这个库编译了一下,发现编译过程还是稍微有些纠结,于是就想到写下来,希望以后有些童鞋看到少走一些弯路。      首先非常感谢eryar的帮助...
  • shlkl99
  • shlkl99
  • 2014年06月18日 21:21
  • 1891

博弈搜索练习-极大极小值搜索+AlphaBeta剪枝--POJ 1085-Triangle War/三角点格棋

Triangle War Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3066   Accepted: 120...
  • qq_38597315
  • qq_38597315
  • 2017年07月12日 11:16
  • 101

【DP】 POJ 1085 Triangle War

状态用二进制压缩存储,然后记忆化搜索就可以了。。。 #include #include #include #include #include #include #include...
  • blankcqk
  • blankcqk
  • 2015年02月09日 11:28
  • 256

Poj 1085 Triangle War (极大极小搜索)

题目链接:http://poj.org/problem?id=1085   题意:两个人轮流在九个小正三角形组成的大三角形上面选取边,如果当前选择的边刚好为某些三角形最后一个未选取的边,则该玩家得...
  • dooder_daodao
  • dooder_daodao
  • 2011年08月12日 20:40
  • 2346

POJ1085 The Triangle War: 记忆化搜索

根本不知道怎么下手,后面看了别人的博客: http://blog.csdn.net/urecvbnkuhbh_54245df/article/details/5846776 POJ 1085 Th...
  • qq_34494458
  • qq_34494458
  • 2017年04月27日 17:36
  • 98

POJ 1085 Triangle War(博弈,極大極小搜索+alpha_beta剪枝)

转载请注明出处,谢谢 http://blog.csdn.net/ACM_cxlove?viewmode=contents           by---cxlove 題目:給出10個點,總共有1...
  • ACM_cxlove
  • ACM_cxlove
  • 2012年09月19日 17:52
  • 3670

POJ 1085 Triangle War 极小极大值算法+α-β剪枝

用极小极大值算法解决比较直观,但是效率太低,即使使用了α-β剪枝,效率仍然很低,勉强ACCEPT,因为这种方法本质上是深度搜索,会有大量的重复计算,如果像DP那样将计算过的状态记录下来,则还有进一步优...
  • mimo9527
  • mimo9527
  • 2011年02月28日 18:15
  • 1350

poj 1085 Triangle War 1568 Find the Winning Move 极大极小搜索 alpha-beta剪枝

一,极大极小搜索及alpha-beta剪枝
  • gwq5210
  • gwq5210
  • 2015年09月14日 16:29
  • 602
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Triangle War(POJ 1085)
举报原因:
原因补充:

(最多只允许输入30个字)