WithinSettlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wilderness.
You are employed by a software company that just has decided to develop a computer version of this game, and you are chosen to implement one of the game's special rules:
When the game ends, the player who built the longest road gains two extra victory points.
The problem here is that the players usually build complex road networks and not just one linear path. Therefore, determining the longest road is not trivial (although human players usually see it immediately).
Compared to the original game, we will solve a simplified problem here: You are given a set of nodes (cities) and a set of edges (road segments) of length 1 connecting the nodes. The longest road is defined as the longest path within the network that doesn't
use an edge twice. Nodes may be visited more than once, though.
Example: The following network contains a road of length 12.
o o -- o o
\ / \ /
o -- o o -- o
/ \ / \
o o -- o o -- o
\ /
o -- o
The input file will contain one or more test cases.
The first line of each test case contains two integers: the number of nodesn(
)
and the number of edgesm(
). The nextmlines describe themedges. Each edge is given by the
numbers of the two nodes connected by it. Nodes are numbered from 0 ton-1. Edges are undirected. Nodes have degrees of three or less. The network is not neccessarily connected.
Input will be terminated by two values of 0 fornandm.
For each test case, print the length of the longest road on a single line.
3 2
0 1
1 2
15 16
0 2
1 2
2 3
3 4
3 5
4 6
5 7
6 8
7 8
7 9
8 10
9 11
10 12
11 12
10 13
12 14
0 0
2
12
Miguel A. Revilla
1999-01-11
求图中的一条最长路径,又是回溯。
#include<iostream>
#include<cstring>
using namespace std;
int grid[30][30],vis[30][30];
int len,maxlen,n;
void dfs(int posx,int posy)
{
len++;
int i,j,k;
for(i=0;i<n;i++)
{
if(grid[posy][i]==1&&vis[posy][i]==0&&i!=posx)
{
vis[posy][i]=1;
vis[i][posy]=1;
dfs(posy,i);
len--;
vis[posy][i]=0;
vis[i][posy]=0;
}
}
if(len>maxlen) maxlen=len;
}
int main()
{
int m;
while(cin>>n>>m&&(n!=0||m!=0))
{
memset(grid,0,sizeof(grid));
memset(vis,0,sizeof(vis));
int i,j;
for(i=0;i<m;i++)
{
int x,y;
cin>>x>>y;
grid[x][y]=grid[y][x]=1;
}
maxlen=0;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
if(grid[i][j]&&vis[i][j]==0)
{
memset(vis,0,sizeof(vis));
len=0;
vis[i][j]=1;
vis[j][i]=1;
dfs(i,j);
}
}
}
cout<<maxlen<<endl;
}
return 0;
}
分享到:
相关推荐
colonizers, 在"The Settlers of Catan" Teuber的上 Colonizers 基于流行的棋盘游戏 "catan"( 以前是"catan的Settlers")的HTML5多人游戏,由克劳斯 Teuber 。工作在多个设备( 台式机,平板电脑和移动电话) 。 在本地...
本文将深入探讨一个特别的开源项目——Java Settlers of Catan,这是经典桌面游戏“卡坦岛定居者”在Java平台上的实现。这个项目不仅允许玩家在数字环境中体验卡坦岛的乐趣,还引入了计算机AI对手,增强了游戏的可玩...
Catan纸牌接龙定居者是克劳斯·特伯(Klaus Teuber)流行的棋盘游戏“ The Cattlers of Catan”或“ Die Siedler Von Catan”的Java版本。 该项目使您可以与计算机AI玩棋盘游戏。
《Settlers-of-Catan: C++实现的命令行版》 该项目是使用C++编程语言,面向对象编程(OOP)技术实现的一款基于经典棋盘游戏《卡坦岛》(Settlers of Catan)的模拟游戏。《卡坦岛》是一款策略性的桌面游戏,玩家在...
《数字版Catan:探索JavaScript实现的棋盘游戏魅力》 Catan,又称《卡坦岛》,是一款广受欢迎的策略类棋盘游戏,由德国设计师Kosmos在1995年推出。游戏以资源管理和领土建设为核心,玩家通过交易、建造、扩张,竞争...
当Catan板有焦点时,按住ALT_C,这将使OptionPane出现并允许取消。 至于我想谈论的游戏新增内容,我为游戏实现了一个类别系统,这使其难度更大(它是可选的;如果您要使用标准游戏,请选择定居者类别)以及可能影响...
JSettlers2是用Java编写的卡坦岛定居者棋盘游戏的基于Web的版本。 该客户端-服务器系统支持人和/或AI机器人之间的多个同时游戏。 最初由Robert S Thomas撰写,是AI论文... sourceforge CVS的历史可以追溯到2012-09-28。
在“ The Settlers Online”中使用您喜欢的地图,而无需在选项卡或应用程序之间切换。 TSOW是用于“ The Settlers Online”游戏的小部件。 它使您无需查看选项卡或应用程序即可查看自己的冒险地图。 此扩展名是游戏...
This project intends to create a remake of the famous strategy game "The Settlers 3" published by Blue Byte in 1998. The project is developed in Java and runs on PC (Windows/Linux), Mac and Android. ...
在“The Settlers Online”中使用您最喜爱的地图,而无需在选项卡或应用程序之间切换。 TSOW是用于“ The Settlers Online”游戏的小部件。 它使您无需查看选项卡或应用程序即可查看自己的冒险地图。 此扩展名是游戏...
对出色的经典回合制棋盘游戏 Settlers of Catan 的现代改编,玩家竞相收集资源和胜利点以赢得比赛。 Github 工作流程 Master 随时准备部署到 Heroku 功能分支上的功能 由队友审查的拉取请求 团队动力 敏捷 在需要时...
《定居者II》文档 随着时间的流逝,本文档可以有望解释游戏使用的文件格式中的每个字节。 在撰写本文时,我们知道创建完美的WLD / SWD映射所需的一切。 也可以替换原始游戏中的现有图形,尽管仍然没有开源工具可以...
吉打定居者关于K'tah的定居者是一款回合制多人视频棋盘游戏,灵感来自Catan的Settlers和K'tah的游戏系列! 这是LMU计算机科学和动画部门之间的共同努力,其开发团队由四个LMU班级的2021名学生组成。 K'tah的定居者以...
Mobile Catan,作为一个开源项目,是经典桌面游戏“Settlers of Catan”的移动版本,专为MIDP 1.0(Mobile Information Device Profile)设计,适配早期的移动设备。这个项目不仅提供了在小型屏幕上体验策略游戏的...
该项目最初是The Settlers II.net地图生成器,但随着时间的推移,它将得到更好的抽象,以便地图生成器部分成为独立模块,也可用于其他游戏和项目。 该项目的当前状态在上运行 您可以在各自的站点上阅读有关更多信息...
"android开发"暗示了这些源代码可能与在Android平台上构建应用有关,而"settlers5tw"可能是项目或应用的名称,可能与《Settlers》系列游戏的第五部作品《The Settlers: Heritage of Kings》的台湾版本有关。...
定居者 本项目拟对Blue Byte 1998年出版的著名策略游戏《定居者3》进行翻拍。该项目采用Java开发,运行于PC(Windows/Linux)、Mac和Android上。 更多信息可以在项目网站 警告:Alpha 状态 该游戏目前处于alpha状态...
通天塔 Web 扩展强制使用与您的浏览器相同的语言! 如何? 通过简单地将一种语言翻译成另一种语言......... 那不是字符串替换吗? 查看源代码。 ... 你可以一键安装 Babel(或者很快就能安装)。...Babel 需要在许多网站上...
Settlers IV脚本编辑器 启动S4Editor.exe时启动的一个小窗口。 将旧的MapGenerator.dll重命名为MapGenerator2.dll,然后将此程序(也称为MapGenerator.dll)拖到S4 / Editor /文件夹中,然后关闭。
小指 Web扩展使收藏品易于查找! 什么? 小指取代 与 怎么样? 它将重定向浏览器发出的某些请求(请参阅 )。 有关详细信息,请查看 。 哪里? 一键即可安装Pinky。 用法 ...如果你真的喜欢...