poj2706Connect(极限大模拟)

| 收藏本文 下载本文 作者:浪漫主义狗

下面是小编为大家准备的poj2706Connect(极限大模拟)(共含6篇),欢迎阅读借鉴。同时,但愿您也能像本文投稿人“浪漫主义狗”一样,积极向本站投稿分享好文章。

poj2706Connect(极限大模拟)

篇1:poj2706Connect(极限大模拟)

ConnectTime Limit:1000MSMemory Limit:65536KTotal Submissions:1148Accepted:375

Description

Figure 1Figure 2Figure 3aFigure 3bFigure 4

Your task is to decide if a specified sequence of moves in the board game Twixt ends with a winning move.

In this version of the game, different board sizes may be specified. Pegs are placed on a board at integer coordinates in the range [0, N]. Players Black and White use pegs of their own colZ?www.2cto.com/kf/ware/vc/“ target=”_blank“ class=”keylink“>vci4gQmxhY2sgYWx3YXlzIHN0YXJ0cyBhbmQgdGhlbiBhbHRlcm5hdGVzIHdpdGggV2hpdGUsIHBsYWNpbmcgYSBwZWcKIGF0IG9uZSB1bm9jY3VwaWVkIHBvc2l0aW9uICh4LHkpLiBCbGFjaw==”s endzones are where x equals 0 or N, and White‘s endzones are where y equals 0 or N. Neither player may place a peg in the other player‘s endzones. After each play the latest position is connected by a segment to every position with a peg of the same color that is a chess knight‘s move away (2 away in one coordinate and 1 away in the other), provided that a new segment will touch no segment already added, except at an endpoint. Play stops after a winning move, which is when a player‘s segments complete a connected path between the player‘s endzones.

For example Figure 1 shows a board with N=4 after the moves (0,2), (2,4), and (4,2). Figure 2 adds the next move (3,2). Figure 3a shows a poor next move of Black to (2,3). Figure 3b shows an alternate move for Black to (2,1) which would win the game.

Figure 4 shows the board with N=7 after Black wins in 11 moves:

(0, 3), (6, 5), (3, 2), (5, 7), (7, 2), (4, 4), (5, 3), (5, 2), (4, 5), (4, 0), (2, 4).

Input

The input contains from 1 to 20 datasets followed by a line containing only two zeroes, “0 0”. The first line of each dataset contains the maximum coordinate N and the number of total moves M where 3< N< 21, 4< M< 250, and M is odd. The rest of the dataset contains a total of M coordinate pairs, with one or more pairs per line. All numbers on a line will be separated by a space. M being odd means that Black will always be the last player. All data will be legal. There will never be a winning move before the last move.

Output

The output contains one line for each data set: “yes” if the last move is a winning move and “no” otherwise.

Sample Input

4 50 2 2 4 4 2 3 2 2 34 50 2 2 4 4 2 3 2 2 17 110 3 6 5 3 2 5 7 7 2 4 45 3 5 2 4 5 4 0 2 40 0

Sample Output

noyesyes

Source

Mid-Central USA

黑白棋的游戏,在n*n的棋盘上,黑棋先手,且最后一步是黑棋,当黑棋从x=0连接的到x=n,时黑棋获胜,问最后一步是不是致胜的一步

每个点都可以和它周围的八个点连接,类似象棋中的马,但是在连接两个点的时候,在连线之间不能有其他的连线(包括黑棋自身的连线)。所以在连接一条线的时候,要判断其他的可能会切割这条线的九条线是否存在。

先判断不包含最后一步的黑棋能不能胜利,再判断加上最后一步后能不能获胜,如果开始不能获胜,后来获胜,那么输出yes,否则,输出no

#include#include#include#include using namespace std ;int vis[500] ;int Map[25][25] , c[500][500] ;//ºÚΪ1£¬°×Ϊ-1queueque ;void solve1(int i,int j,int n,int temp){ if( (i-1) >= 0 && (i+1)< n && (j-1) >= 0 && c[ (i-1)*n+j ][ (i+1)*n+(j-1) ] != 0 ) return ; if( (i-1) >= 0 && (j-2) >= 0 && (i+1)< n && (j-1) >= 0 && c[ (i-1)*n+(j-2) ][ (i+1)*n+(j-1) ] != 0 ) return ; if( (j-3) >= 0 && (i+1)< n && (j-1) >= 0 && c[ i*n+(j-3) ][ (i+1)*n+(j-1) ] != 0 ) return ; if( (j-1) >= 0 && (i+1)< n && (j+1)< n && c[ i*n+(j-1) ][ (i+1)*n+(j+1) ] != 0 ) return ; if( (j-1) >= 0 && (i+2)< n && c[ i*n+(j-1) ][ (i+2)*n+j ] != 0 ) return ; if( (j-1) >= 0 && (i+2)< n && (j-2) >= 0 && c[ i*n+(j-1) ][ (i+2)*n+(j-2) ] != 0 ) return ; if( (i-1) >= 0 && (j-1) >= 0 && (i+1)< n && c[ (i-1)*n+(j-1) ][ (i+1)*n+j ] != 0 ) return ; if( (i+1)< n && (j-2) >= 0 && c[ (i+1)*n+j ][ i*n+(j-2) ] != 0 ) return ; if( (j-2) >= 0 && (i+2)< n && (j-1) >= 0 && c[ i*n+(j-2) ][ (i+2)*n+(j-1) ] != 0 ) return ; c[ i*n+j ][ (i+1)*n+(j-2) ] = c[ (i+1)*n+(j-2) ][ i*n+j ] = temp ; return ;}void solve2(int u,int v,int n,int temp){ if( (u-1) >= 0 && (v-1) >= 0 ) { if( (u+1)< n && c[ (u-1)*n+(v-1) ][ (u+1)*n+v ] != 0 ) return ; if( (u+1)< n && (v-2) >= 0 && c[ (u-1)*n+(v-1) ][ (u+1)*n+(v-2) ] != 0 ) return ; if( (v-3) >= 0 && c[ (u-1)*n+(v-1) ][ u*n+(v-3) ] != 0 ) return ; } if( (v-1) >= 0 ) { if( (u-1) >= 0 && (v+1)< n && c[ u*n+(v-1) ][ (u-1)*n+(v+1) ] != 0 ) return ; if( (u-2) >= 0 && c[ u*n+(v-1) ][ (u-2)*n+v ] != 0 ) return ; if( (u-2) >= 0 && (v-2) >= 0 && c[ u*n+(v-1) ][ (u-2)*n+(v-2) ] != 0 ) return ; } if( (u+1)< n && (v-1) >= 0 && (u-1) >= 0 && c[ (u+1)*n+(v-1) ][ (u-1)*n+v ] != 0 ) return ; if( (u-1) >= 0 && (v-2) >= 0 && c[ (u-1)*n+v ][ u*n+(v-2) ] != 0 ) return ; if( (v-2) >= 0 && (u-2) >= 0 && (v-1) >= 0 && c[ u*n+(v-2) ][ (u-2)*n+(v-1) ] != 0 ) return ; c[ u*n+v ][ (u-1)*n+(v-2) ] = c[ (u-1)*n+(v-2) ][ u*n+v ] = temp ; return ;}void solve3(int u,int v,int n,int temp){ if( (u+1)< n ) { if( (u-1) >= 0 && (v-1) >= 0 && c[ (u+1)*n+v ][ (u-1)*n+(v-1) ] != 0 ) return ; if( (v-2) >= 0 && c[ (u+1)*n+v ][ u*n+(v-2) ] != 0 ) return ; if( (u+2)< n && (v-2) >= 0 && c[ (u+1)*n+v ][ (u+2)*n+(v-2) ] != 0 ) return ; } if( (u+1)< n && (v-1) >= 0 ) { if( (v+1)< n && c[ (u+1)*n+(v-1) ][ u*n+(v+1) ] != 0 ) return ; if( (u+2)< n && (v+1)< n && c[ (u+1)*n+(v-1) ][ (u+2)*n+(v+1) ] != 0 ) return ; if( (u+3)< n && c[ (u+1)*n+(v-1) ][ (u+3)*n+v ] != 0 ) return ; } if( (u+1)< n && (v+1)< n && (v-1) >= 0 && c[ (u+1)*n+(v+1) ][ u*n+(v-1) ] != 0 ) return ; if( (v-1) >= 0 && (u+2)< n && c[ u*n+(v-1) ][ (u+2)*n+v ] != 0 ) return ; if( (u+2)< n && (u+1)< n && (v-2) >= 0 && c[ (u+2)*n+v ][ (u+1)*n+(v-2) ] != 0 ) return ; c[ u*n+v ][ (u+2)*n+(v-1) ] = c[ (u+2)*n+(v-1) ][ u*n+v ] = temp ; return ;}void solve4(int u,int v,int n,int temp){ if( (u-1) >= 0 ) { if( (u-2) >= 0 && (v-2) >= 0 && c[ (u-1)*n+v ][ (u-2)*n+(v-2) ] != 0 ) return ; if( (v-2) >= 0 && c[ (u-1)*n+v ][ u*n+(v-2) ] != 0 ) return ; if( (u+1)< n && (v-1) >= 0 && c[ (u-1)*n+v ][ (u+1)*n+(v-1) ] != 0 ) return ; } if( (u-1) >= 0 && (v-1) >= 0 ) { if( (u-3) >= 0 && c[ (u-1)*n+(v-1) ][ (v-3)*n+v ] != 0 ) return ; if( (u-2) >= 0 && (v+1)< n && c[ (u-1)*n+(v-1) ][ (u-2)*n+(v+1) ] != 0 ) return ; if( (v+1)< n && c[ (u-1)*n+(v-1) ][ u*n+(v+1) ] != 0 ) return ; } if( (u-1) >= 0 && (v+1)< n && (v-1) >= 0 && c[ (u-1)*n+(v+1) ][ u*n+(v-1) ] != 0 ) return ; if( (v-1) >= 0 && (u-2) >= 0 && c[ u*n+(v-1) ][ (u-2)*n+v ] != 0 ) return ; if( (u-2) >= 0 && (v-2) >= 0 && c[ (u-2)*n+v ][ (u-1)*n+(v-2) ] != 0 ) return ; c[ u*n+v ][ (u-2)*n+(v-1) ] = c[ (u-2)*n+(v-1) ][ u*n+v ] = temp ; return ;}int bfs(int u,int n){ int v , i , j ; while( !que.empty ) que.pop() ; vis[u] = 1 ; que.push(u) ; while( !que.empty() ) { u = que.front() ; que.pop() ; if( u >= (n-1)*n )return 1 ; for(i = 0 ; i< n*n ; i++) {if( c[u][i] == 1 && vis[i] == 0 ){ vis[i] = 1 ; que.push(i) ;} } } return 0 ;}void solve(int temp,int n){ int u , v ; scanf(“%d %d”, &u, &v) ; Map[u][v] = temp ; if( (u+1)< n && (v-2) >= 0 && Map[u][v] == Map[u+1][v-2] ) solve1(u,v,n,temp); if( (u-1) >= 0 && (v+2)< n && Map[u][v] == Map[u-1][v+2] ) solve1(u-1,v+2,n,temp) ; if( (u-1) >= 0 && (v-2) >= 0 && Map[u][v] == Map[u-1][v-2] ) solve2(u,v,n,temp) ; if( (u+1)< n && (v+2)< n && Map[u][v] == Map[u+1][v+2] ) solve2(u+1,v+2,n,temp) ; if( (u+2)< n && (v-1) >= 0 && Map[u][v] == Map[u+2][v-1] ) solve3(u,v,n,temp) ; if( (u-2) >= 0 && (v+1)< n && Map[u][v] == Map[u-2][v+1] ) solve3(u-2,v+1,n,temp) ; if( (u-2) >= 0 && (v-1) >= 0 && Map[u][v] == Map[u-2][v-1] ) solve4(u,v,n,temp) ; if( (u+2)< n && (v+1)< n && Map[u][v] == Map[u+2][v+1] ) solve4(u+2,v+1,n,temp) ;}int main(){ int n , m , x , y , u , v , temp , i , j ; while( scanf(“%d %d”, &n, &m) != EOF ) { if( m == 0 && n == 0 ) break ; n++ ; memset(Map,0,sizeof(vis)) ; memset(c,0,sizeof(c)) ; temp = 1 ; m-- ; while( m-- ) {solve(temp,n) ;temp = -temp ; } int k1 = 0 , k2 = 0 ; memset(vis,0,sizeof(vis)) ; for(j = 0 ; j< n ; j++) {if( Map[0][j] == 1 && vis[j] == 0 ){ k1 = bfs(j,n) ; if( k1 == 1 ) break ;} } solve(temp,n) ; memset(vis,0,sizeof(vis)) ; for(j = 0 ; j< n ; j++) {if( Map[0][j] == 1 && vis[j] == 0 ){ k2 = bfs(j,n) ; if( k2 == 1 ) break ;} } if( k1 == 0 && k2 == 1)printf(“yesn”) ; elseprintf(“non”) ; } return 0;}

篇2:极限

极限

极限jí xiàn[释义]

①(名)最高的限度。轮船的载重已经达到了~。(作宾语)

②(名)数学上的一个概念;如果变量x逐渐变化;趋近于定量唬患此们的差的.绝对值可以小于任何已知的正数时;定量唤凶霰淞x的极限;可写成x→唬换limx=弧

[构成]  偏正式:极(限

篇3:话说极限

我有一个朋友,叫做极限。每当我骄傲的时候,他总会告诉我:“不行,你差得还很远,要不断地加油才行!”听了他的话,我便会不由自主地低下头,审视自己的盲目、狂傲。

我有一个敌人,叫做极限。我非常地恨他,因为每当我在用尽全力向前冲刺,想要超他的时候,他往往毫不留情地将我推倒在地,然后用轻蔑的语气讽刺道:“你想超过我吗?别妄想了!等到下辈子吧!”看着他狂妄的眼神,我快被心中的怒火吞噬了,然而我却不能说什么,人微言轻,失败的我只能在心中默默地为自己流泪。

我有一位严厉的导师,叫做极限。他总是用“失败”这把刚劲的教鞭,鞭策着我前进,尤其是在我迷茫不知何去何从时,他总会将目标清楚地摆在我的眼前。虽然他很严厉,但同时他又十分仁慈,他总会在我即将崩溃的时候将我领回正轨,在我被自己的征服欲逼疯之前,令我冷静下来。

我还有一个毕生追求的目标,就是突破极限。然而这个目标对我来说就像是一个美妙的梦——我可以去幻想,但终究无法实现。并非是因为我不努力,而是因为极限实在像一个魔怪,总是站在我的肩上,使我奋尽全力登上东岳之顶,天姥之巅,却还有更高的位置。我想比它站得高,然后便不停地攀登,直到累得昏倒,才停下来做个好梦。

唉,极限,我该对你说什么呢?我不知道自己应该去爱你,还是去恨你。我爱你,因为你没有让我失去目标;我恨你,因为我总无法完完全全地超越你。我曾恶毒地诅咒过你,但你没有介意,仍然像一位导师和好友,鞭策着我前进。为此,我对你由衷地敬佩。可是如果你觉得这样,就可以把你那暴虐的本性表露出来,对我肆意侮辱,那么你就大错特错了。即使我摔倒了,也会再次爬起来,鼓起勇气,继续前进;我会在摔倒时吸取教训,我会从你的身上取走那些能够令我强大的魔力,然后,在同你并驾齐驱的时候,我将体会到胜利的甜蜜,而你也会尝尝失败的痛苦滋味。

好吧,极限,我的敌人,就让我向你挑战!同时,也让我把爱献给你——

【亮点透析】

本文的立意角度出新,作者将极限拟人化。全文围绕极限是“我”的敌人、导师、目标三个方面展开,这就避免了论证的枯燥,读来有新鲜感。

篇4:极限之旅

有一天,我死了。那一刻,我哭了,我随着自己的灵魂走出我冰冷的身体,我想:我无法爱了,我的爱已到心头。

我独自飘荡着,没有目的地,一味地飘呀飘,我羡慕世上的每一个生灵,哪怕是一棵小草,因为它在爱。它爱孕育它的大地,它爱滋润它的雨水,它爱陪伴它的花朵,它爱……它始终在爱,它不停地在爱,我宁愿化为一棵小草。

我走在拥挤的人群中,没人看得到我,没人感受得到我,我好想让每一个从我身旁走过人知道,我爱他们!我办不到。我感到从未有过的孤独与痛苦。爱真的会给人力量,而我再也不具备这种力量。

忽然间,我看见我的家人在为我哭泣。于是,我不再哭泣,我惊讶地发现,他们因为爱在哭泣,他们知道我的爱!我无声地欢呼着:“我的爱并没停止!”

我不再羡慕那小草,因为它不如我爱得深。我不再注意身边的人群,因为我知道其实我并不孤单。

我沿着我人生的足迹,找寻我的爱。原来我爱的花依然那么美,花的芳香中散发着我的爱。我的日记本躺在我子女的身上,它在替我传播着我的爱。我的子女用我的口气在教导着他们的孩子,他们在延续我的爱。环顾四周,我的爱无处不在。

为什么我的爱仍在?

我想是因为我曾以爱得那么深。我记起我对一切都倾注了我数不尽的爱。一切都被我的爱烙上永不褪灭的痕迹。它经得起所有的磨难,更经得起时间的考验,任何事物都挡不住我的爱,尽管我死了。

有一天,我死了。

那一刻,我笑了,因为我的爱无极限。

--600字

篇5:飞越极限

飞越极限,是我在方特看的项目中最为刺激惊险的一个。

我们被导游带进一个狭长的走廊,走廊左侧是一排可以容纳七个人的座位,走廊右侧似乎是门,两扇门之间还有珠穆朗玛峰的图片。在导游的指挥下,我们依次坐上了走廊左边类似飞机舱的座位,系上安全带,扶好从高空中缓缓落下的把手。忽然,灯光灭了,我们知道,极限之旅就要开始了!(语文迷 zuowen.JY135.com)

身下的座位向前移动,大约1米左右又停了下来,紧接着,有阵阵寒风扑面而来,而眼前原本漆黑的世界也忽然变得明亮起来。映入眼帘的是一片蔚蓝的天空,而脚下原本踏踏实实的地也忽然悬空了,忽而是高大的自由女神像正高举火炬,忽而是雪山连绵的珠穆朗玛峰,忽而是神秘莫测的埃及金字塔,狮身人面像忠诚地守护着它……几分钟的时间,我们已经飞跃了很多地方,飞越极限已经落下帷幕。但是,我似乎感觉得到———呼啸的海浪,还在扑打着岸边,清爽的凉风,依旧吹着脸……

极限挑战,惊险刺激。我坚信,终有一日,我会真的驾驶着飞船,飞到许多今天的人类无法涉足的地方去!

上一篇:月有清辉 下一篇:太阳花的笑容 相关推荐 点亮我心中的那盏灯作文600字 我为自己点赞作文600字 友谊,爱一般的香气 一路走来,感谢有你演讲稿 做一个有教养的人作文600字 这次,我没有放弃 一道美丽的风景作文600字 人生路上温暖多作文800字 最好的我们 老师的另一面作文700字 触动了我的心灵作文600字_12篇 《法官妈妈》观后感700字

篇6:挑战极限

挑战极限

挑战极限正文:

一枚小小的鸡蛋,怕什么?我能把吞进肚子里。但是,如果把一枚鸡蛋从四楼上往下扔,不让蛋壳粉碎,可能吗?废话!怎么可能?除非你把蛋抓住自个儿往下跳,不过鸡蛋没碎,倒是人粉身碎骨了!

哼!我就不相信就没有办法制服不了?瞧,今天组织的<<鸡蛋历险记>>,我、陈瑶、廖奕玲、刘芮格整整商量了一中午,三个臭皮匠还顶不过一个诸葛亮?笑话!虽然笨人用笨招,把箱子放海绵,一层又一层,但是实验还是成功了,不过失败的那个蛋已经吞进了我的肚子里了。

下午,同学们都带了为自己的宝贝鸡蛋装的“摔不坏”设备,不过大都千篇 一律的选择降落伞式。看来降落伞的人气指数还蛮高的!

时间飞逝,两节课后,大会开始了!我们给这个鸡蛋设备取名于“鸡蛋自杀”。第一个是罗璐和宋璐做的,只见那似导弹一般的`装制一头扎进人海里,可怜我的同桌罗璐吃下了她那不胜之果。第二个做的平常,大多都猜导烂,居然出乎意料......接下来,连连战败。到了我们组了,唐老师扔下来,李永健 居然用手抱,大家都说犯规,我的牙咬得格格响,这个厌恶,我真想上去打他几拳!好解心头之恨!第二放下来时,又被男生扔来扔去,鸡蛋面目全非......

比赛结束了,也许这只是一个小小的挑战,也许将来还有更多大浪等待迎接我的。

挑战极限、挑战自我、挑战每时每刻!

心理极限作文

挑战极限作文

垂直极限观后感

快乐极限作文

定义证明二重极限

《垂直极限》观后感600字

关于极限作文七年级

突破极限的瞬间作文

挑战极限超越自我优秀作文

追求极限的河作文

poj2706Connect(极限大模拟)(共6篇)

欢迎下载DOC格式的poj2706Connect(极限大模拟),但愿能给您带来参考作用!
推荐度: 推荐 推荐 推荐 推荐 推荐
点击下载文档 文档为doc格式
点击下载本文文档