UVA 539 - The Settlers of Catan(深搜 回溯)

cvat-develop.zip CVAT的ZIP压缩包 立即下载

The Settlers of Catan 

Within Settlers 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

Input 

The input file will contain one or more test cases.

The first line of each test case contains two integers: the number of nodes n ( $2 \le n \le 25$) and the number of edges m ( $1 \le m \le 25$). The next m lines describe the m edges. Each edge is given by the numbers of the two nodes connected by it. Nodes are numbered from 0 to n-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 for n and m.

Output 

For each test case, print the length of the longest road on a single line.

Sample Input 

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

Sample Output 

2
12

================================

分别从每个点开始深搜,得到最大长度


#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int n,m,ans,vis[33][33];

void dfs(int point,int sum)
{
    for(int i=0;i<n;i++)
    {
        if(vis[point][i])
        {
            vis[point][i]=vis[i][point]=0;
            dfs(i,sum+1);
            vis[point][i]=vis[i][point]=1;
        }
    }
    if(sum>ans) ans=sum;
    return;
}

int main()
{
    int x,y;
    while(~scanf("%d%d",&n,&m))
    {
        if(n==0&&m==0) break;
        ans=-1;
        memset(vis,0,sizeof(vis));
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&x,&y);
            vis[x][y]=vis[y][x]=1;
        }
        for(int i=0;i<n;i++)
        {
            dfs(i,0);
        }
        printf("%d\n",ans);
    }
    return 0;
}


通过python+openCV实现对图片中箭头方向的判断 摘要: 针对YOLOv8算法在箭头方向识别效果不佳的问题,提出了一种基于OpenCV的解决方案。该方法通过图像预处理、轮廓分析、几何特征提取(凸包、质心、外接矩形)和方向向量计算,准确判断箭头的上下左右方向。代码示例展示了从图像读取到方向识别的完整流程,并提供了优化建议(如调整二值化阈值、处理多轮廓)。该方案在Windows11+Python3.12+OpenCV环境下验证有效,适用于需要简单几何特征分析的箭头方向检测场景。 阅读详情

相关推荐

泛微E9表单建模查询列表勾选后带入流程明细表中

注意:参照下图各项配置,否则会有问题。

泛微二次开发后端知识总结 5309

UVaOJ539 - The Settlers of Catan

539 - The Settlers of Catan Time limit: 3.000 seconds Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities

c随遇er安的专栏 622

从INCA到Excel:手把手教你移植汽车标定数据的查表插值算法(附源码)

本文详细介绍了如何将汽车标定数据从INCA平台移植到Excel,实现查表插值算法的完整迁移。通过解析INCA MAP数据结构,设计Excel环境下的双线性插值算法,并提供VBA和C#两种实现方案,帮助工程师高效处理标定数据。文章包含实用代码示例和性能优化技巧,适用于ECU开发与标定场景。

weixin_29313239的博客 410

SZU:D89 The Settlers of Catan

Judge Info Memory Limit: 65536KB Case Time Limit: 3000MS Time Limit: 3000MS Judger: Number Only Judger Description Within Settlers of Catan, the 1995 German game of the year, players at...

weixin_30657999的博客 137

激光条纹中心提取——Steger

激光条纹中心提取-Steger 好久没有记录了,记录一下今天学习的内容,据说Steger在激光条纹中心提取上神一般的存在。文章和代码都分享给大家了哈,其中有四个文件,3个C++,一个python,python一个抠图文件,3个c++包含背景图+原图, 单张图提取, 多张图提取。 分享代码 #include <opencv2\core.hpp> #include <opencv2\highgui.hpp> #include <opencv2\imgproc.hpp> #i

CharmsLUO的博客 5380

Eureka常见面试题总结

点击关注我的博客原文 Eureka是Netflix组件的一个子模块,也是核心模块之一。云端服务发现,一个基于 REST 的服务,用于定位服务,以实现云端中间层服务发现和故障转移(来源springcloud中文网的介绍:https://www.springcloud.cc/)。下图总结了Eureka服务端(以下简称服务端)与Eureka客户端(以下简称客户端)之间协同工作的流程: 流程说明:...

u012105931的博客 2万+

HOJ 1455 The Settlers of Catan

The Settlers of Catan My Tags   (Edit)   Source : University of Ulm Internal Contest 1998   Time limit : 1 sec   Memory limit : 32 M Su

We Can 619

Veeam Backup 13 通过UI界面高效备份VMware ESXi虚拟机的完整指南

本文提供了一份使用Veeam Backup 13图形化界面高效备份VMware ESXi虚拟机的完整指南。内容涵盖从环境准备、添加vCenter/ESXi主机、配置备份存储库,到创建备份任务、设置保留策略与计划,以及执行备份和验证成功的关键步骤。通过直观的UI操作,管理员可以轻松实现虚拟机数据的可靠保护与快速恢复。

weixin_29322553的博客 438

The Settlers of Catan

题目描述在1995年的德国游戏“卡坦定居者”中,玩家试图通过在未知的荒野中修建道路,定居点和城市来统治岛屿。 你被一家软件公司雇佣,这家软件公司决定开发这款游戏的电脑版本,并选择实施游戏的一项特殊规则:  游戏结束时,建造最长公路的玩家获得两个额外的胜利点。 这里的问题是玩家通常建立复杂的道路网络,而不仅仅是一条线性路径。因此,确定最长的道路不是微不足道的(尽管人类玩家通常会立即看到它)。 与原始...

qq_41486817的博客 318

Yolov5s/Yolov8s网络结构图

yolov8、yolov5网络结构图

Goodness2020的博客 9925

CCC数字钥匙Release 3实战:如何用BLE/UWB实现无钥匙进入(附避坑指南)

本文深入解析CCC数字钥匙Release 3标准下BLE/UWB无钥匙进入系统的开发实践,涵盖硬件选型、安全测距协议、时序同步等关键环节,并提供实战调试技巧与安全攻防案例。特别针对BLE芯片配置、UWB模块选型等常见陷阱给出解决方案,帮助开发者高效实现厘米级精度的数字钥匙系统。

weixin_29326909的博客 255

The Settlers of Catan UVA

Within Settlers 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 softw...

weixin_44824383的博客 214

三个原则判定电源环路稳定性

环路稳定性测试接线图如图2所示,将信号电阻(Inserted Resistor )接入电源的环路控制电路中,注入一特定幅度和频率范围的扫频干扰信号(OUT),当干扰信号达到一定的幅度时,环路系统便对干扰信号有所响应,然后使用频率响应分析仪对电源环路输出端(CH2)和电源环路干扰信号注入端(CH1)同时进行比值跟踪测量,则可以得出频率与增益和相位的关系曲线图——波特曲线图(Bode Plot Graph),如图1所示。相位裕度,增益裕度,穿越频率,如图(波特图)所示。相位容限即相位裕度,增益容限即增益裕度。

经营范围: CTA、SRRC、CCC、移动、电信、联通入库 3739

UVa 539 The Settlers of Catan

本文探讨了在无向图中寻找最长路径的问题,其中节点度不超过3且边数不超过25。通过深度优先搜索(DFS)策略,从每个节点出发遍历所有可能的路径,使用边标记避免重复访问。由于图的规模有限且度数约束,搜索效率可接受。代码实现中,使用邻接矩阵存储图结构,并通过递归DFS计算最长路径的边数。对于每个测试用例,输出最长路径的长度。该算法在给定约束下能够有效解决问题。

寂静山林 338

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

UVA - 539 The Settlers of Catan (回溯水题)

The Settlers of Catan  Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wilde

小G的ACM之路 906

Data-Structures-and-Algorithm-Analysis-in-Java.pdf

作者: Weiss, Mark A. 出版社: Addison Wesley Data Structures and Algorithm Analysis in Java is an “advanced algorithms” book that fits between traditional CS2 and Algorithms Analysis courses. In the old ACM Curriculum Guidelines, this course was known as CS7. This text is for readers who want to learn good programming and algorithm analysis skills simultaneously so that they can develop such programs with the maximum amo...

UVa 539 - The Settlers of Catan

题目链接:UVa 539 - The Settlers of Catan 简单回溯,注意一下题目给的是无向边。 #include #include #include //#define test using namespace std; const int MAX_N = 25 + 5; int vis[MAX_N][MAX_N]; int G[MAX_N][MAX_N]; int m

fobdddf的专栏 675

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

UVa 539 - The Settlers of Catan, 简单回溯

539 - The Settlers of Catan 3761 54.91% 1773 93.06% 题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_proble

D_Double's Journey 1435

[回溯]The Settlers of Catan UVA539

回溯求图中最长的路径。

九问的烦恼 1303

UVA 539 The Settlers of Catan

UVA 539 The Settlers of Catan题目大意:第一行输入n个城市和m条路,下面m行输入m条路连接那些城市,求一条经过最多路的路径长度解题思路:把每个点作为初始位置回溯#include <stdio.h> #include <iostream> #include <string.h> using namespace std; int n, m; int road[30][30];

ZeroLH00的博客 350

UVA - 539 The Settlers of Catan

The Settlers of Catan  Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wil

七夜 996

UVa 539 & POJ 2258 - The Settlers of Catan

传送门UVa 539  & POJ 2258 - The Settlers of Catan

一只冰熊 1006

uva 539 The Settlers of Catan(回溯)

uva 539 The Settlers of Catan Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wilder

总有那么一群人喜欢盯着我的博客看,估计这是他们见过最长的博客名,我必须得告诉他们博客名最长可以写多长 660

UVa 539 - The Settlers of Catan 递归回溯

The Settlers of Catan  Within Settlers of Catan, the 1995 German game of the year, players attempt to dominate an island by building roads, settlements and cities across its uncharted wilde

GodLike 1349

Uva 539 The Settlers of Catan

在给定的点中找一条最长路,每条便只能走一次!回溯水过~~ #include #include #include #include #include #include using namespace std; int vis[26][26]; int n,

Xiao_Peng 324

uva 539 - The Settlers of Catan(搜索)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=108&page=show_problem&problem=480 #include #include #include using namespace std; const int MAX_N = 25; int n, m; in

NightWind 687

The Settlers of Catan UVA539

The Settlers of Catan 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...

473687880 240
上一篇: UVA 639 - Don't Get Rooked(深搜)
下一篇: UVA 301 - Transportation
coco430
博客等级 码龄14年 9粉丝 107原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值