- 浏览: 121821 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
leelege:
让一切GenericDao都去死吧
自己写的一个Hibernate CURD的封装 -
liuxuejin:
不用泛型的飘过,个人觉得没有什么必要,因为增删查的代码(简单的 ...
自己写的一个Hibernate CURD的封装 -
java113096:
finallygo 写道icanfly 写道ricoyu 写道 ...
自己写的一个Hibernate CURD的封装 -
jiluo093:
http://jiluo093.iteye.com/blog/ ...
自己写的一个Hibernate CURD的封装 -
piao_bo_yi:
Dev|il 写道yin_bp 写道Dev|il 写道dnst ...
自己写的一个Hibernate CURD的封装
Reversi
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 591 Accepted Submission(s): 251
Problem Description
Reversi, also called Othello, is a two-sided game.
Each of the two sides corresponds to one player; they are referred to here as light and dark after the sides of Othello pieces, but "heads" and "tails" would identify them equally as well, so long as each marker has sufficiently distinctive sides.
Originally, Reversi did not have a defined starting position. Later it adopted Othello's rules, which state that the game begins with four markers placed in a square in the middle of the grid, two facing light-up, two pieces with the dark side up. The dark player makes the first move.
Dark must place a piece with the dark side up on the board, in such a position that there exists at least one straight (horizontal, vertical, or diagonal) occupied line between the new piece and another dark piece, with one or more contiguous light pieces between them. In the below situation, dark has the following options indicated by transparent pieces:
After placing the piece, dark turns over (flips, captures) all light pieces lying on a straight line between the new piece and any anchoring dark pieces. All reversed pieces now show the dark side, and dark can use them in later moves—unless light has reversed them back in the meantime. In other words, a valid move is one where at least one piece is reversed.
If dark decided to put a piece in the topmost location (all choices are strategically equivalent at this time), one piece gets turned over, so that the board appears thus:
Now light plays. This player operates under the same rules, with the roles reversed: light lays down a light piece, causing a dark piece to flip. Possibilities at this time appear thus (indicated by transparent pieces):
Light takes the bottom left option and reverses one piece:
Players take alternate turns. If one player cannot make a valid move, play passes back to the other player. When neither player can move, the game ends. This occurs when the grid has filled up, or when one player has no more pieces on the board, or when neither player can legally place a piece in any of the remaining squares. The player with the most pieces on the board at the end of the game wins.
Now after several rounds, it’s dark’s turn. Can you figure out the largest number of light pieces he can turn over?
Input
The first line contains one integer T representing the number of test cases.
For each test case, there’re 8 lines. Each line contains 8 characters (D represents dark, L represents light, * represents nothing here).
Every two adjacent cases are separated by a blank line.
Output
For each test case, in one line print the case number and the largest number of light pieces the dark player can turn over. If he can’t put one piece in any position, then print 0.
Please follow the format of the sample output.
Sample Input
3
********
********
********
***LD***
***DL***
********
********
********
********
********
**DLL***
**DLLL**
**DLD***
********
********
********
********
********
*D******
*DLLD***
***LL***
**D*D***
********
********
Sample Output
Case 1: 1
Case 2: 3
Case 3: 0
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3368
AC代码:
Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 591 Accepted Submission(s): 251
Problem Description
Reversi, also called Othello, is a two-sided game.
Each of the two sides corresponds to one player; they are referred to here as light and dark after the sides of Othello pieces, but "heads" and "tails" would identify them equally as well, so long as each marker has sufficiently distinctive sides.
Originally, Reversi did not have a defined starting position. Later it adopted Othello's rules, which state that the game begins with four markers placed in a square in the middle of the grid, two facing light-up, two pieces with the dark side up. The dark player makes the first move.
Dark must place a piece with the dark side up on the board, in such a position that there exists at least one straight (horizontal, vertical, or diagonal) occupied line between the new piece and another dark piece, with one or more contiguous light pieces between them. In the below situation, dark has the following options indicated by transparent pieces:
After placing the piece, dark turns over (flips, captures) all light pieces lying on a straight line between the new piece and any anchoring dark pieces. All reversed pieces now show the dark side, and dark can use them in later moves—unless light has reversed them back in the meantime. In other words, a valid move is one where at least one piece is reversed.
If dark decided to put a piece in the topmost location (all choices are strategically equivalent at this time), one piece gets turned over, so that the board appears thus:
Now light plays. This player operates under the same rules, with the roles reversed: light lays down a light piece, causing a dark piece to flip. Possibilities at this time appear thus (indicated by transparent pieces):
Light takes the bottom left option and reverses one piece:
Players take alternate turns. If one player cannot make a valid move, play passes back to the other player. When neither player can move, the game ends. This occurs when the grid has filled up, or when one player has no more pieces on the board, or when neither player can legally place a piece in any of the remaining squares. The player with the most pieces on the board at the end of the game wins.
Now after several rounds, it’s dark’s turn. Can you figure out the largest number of light pieces he can turn over?
Input
The first line contains one integer T representing the number of test cases.
For each test case, there’re 8 lines. Each line contains 8 characters (D represents dark, L represents light, * represents nothing here).
Every two adjacent cases are separated by a blank line.
Output
For each test case, in one line print the case number and the largest number of light pieces the dark player can turn over. If he can’t put one piece in any position, then print 0.
Please follow the format of the sample output.
Sample Input
3
********
********
********
***LD***
***DL***
********
********
********
********
********
**DLL***
**DLLL**
**DLD***
********
********
********
********
********
*D******
*DLLD***
***LL***
**D*D***
********
********
Sample Output
Case 1: 1
Case 2: 3
Case 3: 0
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3368
AC代码:
#include <iostream> using namespace std; char map[10][10]; //八个方向 int dir[8][2] = {{0, 1}, {0, -1},{1, 0},{-1, 0},{1, 1},{-1, -1},{1, -1},{-1, 1}}; void dfs(int x, int y, int d, int num, int &sum) { int i; if(x < 0 || x > 7 || y < 0 || y > 7) return; if(d == 8) //这个d值可以随便 { for(i = 0; i < 8; i++) dfs(x + dir[i][0], y + dir[i][1], i, num, sum); }else { if(map[x][y] == '*') return; //如果为*表示无法消除 else if(map[x][y] == 'D') //如果为D代表已经找到这条线上的所有点 { sum += num; return; }else dfs(x + dir[d][0], y + dir[d][1], d, num + 1, sum); //如果是L就一直超这个方向搜索下去 } } int solve() { int max = 0, i, j, sum; for(i = 0; i < 8; i++) for(j = 0; j < 8; j++) { sum = 0; if(map[i][j] == '*') { dfs(i, j, 8, 0, sum); if(sum > max) max = sum; } } return max; } int main() { int t, i, ans, c = 0; cin>>t; while(t--) { for(i = 0; i < 8; i++) cin>>map[i]; ans = solve(); printf("Case %d: %d\n",++c,ans); } return 0; }
发表评论
-
求n个元素集合的子集(幂集)或n个元素的组合
2011-10-21 13:19 3122回溯法是设计递归过程的一种重要方法,它的求解过程是遍历一个状态 ... -
螺旋矩阵
2011-10-19 13:26 957给一个正整数n,输出一个n*n的螺旋矩阵 螺旋矩阵可以是逆时针 ... -
HDU2896(病毒侵袭)
2011-09-26 13:46 861病毒侵袭 Time Limit: 2000/1 ... -
HDU2060(Snooker)
2011-09-17 19:20 866Snooker Time Limit: 1000/1000 M ... -
HDU1166(敌兵布阵)
2011-09-17 12:55 803敌兵布阵 Time Limit: 2000/1000 MS ( ... -
HDU1754 I Hate It
2011-09-16 23:40 1024参考资料:http://www.cppblog.com/MiY ... -
HDU1686Oulipo
2011-09-14 22:15 805Oulipo Time Limit: 3000/1000 MS ... -
HDU2100Lovekey
2011-09-12 17:16 691Lovekey Time Limit: 3000/1000 M ... -
HDU1010Tempter of the Bone
2011-09-11 23:02 524Tempter of the Bone Time Limit: ... -
求一个集合的全排列
2011-09-11 14:49 776#include <iostream> usin ... -
HDU1175连连看
2011-09-09 23:24 753连连看 Time Limit: 20000/10000 MS ... -
HDU1711Number Sequence
2011-09-09 13:09 713Number Sequence Time Limit: 100 ... -
HDU1097A hard puzzle
2011-09-06 22:46 820A hard puzzle Time Limit: 2000/ ... -
HDU1004Let the Balloon Rise
2011-09-06 09:44 510Let the Balloon Rise Time Limit ... -
HDU2061Treasure the new start, freshmen!
2011-08-24 14:06 986Treasure the new start, freshme ... -
HDU2251Seinfeld
2011-08-24 13:39 877Seinfeld Time Limit: 2000/1000 ... -
HDU2083简易版之最短距离
2011-08-22 15:30 892简易版之最短距离 Time Limit: 1000/1000 ... -
HDU2093考试排名
2011-08-12 09:58 840考试排名 Time Limit: 1000/1 ... -
HDU2057A + B Again
2011-08-12 00:09 890A + B Again Time Limit: 1000/10 ... -
HDU2068RPG的错排
2011-08-10 22:45 729RPG的错排 Time Limit: 1000/1000 MS ...
相关推荐
whu四月月赛一题的解题报告和源代码。欢迎大家下载。
HDU的1250,主要是利用高精度加法,但是代码有点繁琐,效率不是很高
HDU1059的代码
杭电ACMhdu1163
hdu1001解题报告
hdu 1574 passed sorce
HDU的一题........HDU DP动态规
hdu acm 教案 搜索入门 hdu acm 教案 搜索入门
hdu2101AC代码
搜索 dfs 解题代码 hdu1241
hdu acm 教案 动态规划(1) hdu acm 教案 动态规划(1)
hdu 5007 Post Robot 字符串枚举。 暴力一下就可以了。
ACM HDU题目分类,我自己总结的大概只有十来个吧
HDU最全ac代码
hdu 1166线段树代码
hdu动态规划算法集锦
hdu题目分类
hdu-acm源代码(上百题)hdu-acm源代码、hdu-acm源代码hdu-acm源代码
自己做的HDU ACM已经AC的题目
HDU图论题目分类