![](https://img-blog.csdnimg.cn/20201014180756754.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法竞赛入门经典-第7章 暴力求解法
lab104_yifan
这个作者很懒,什么都没留下…
展开
-
UVA 539 The Settlers of Catan
UVA 539 The Settlers of Catan 题意 输入n, 再输入n组数据,每组数据有两个节点,表示两点可以相连,每两个可以相连的节点长度为1,找出该图中最长的路径输出值, 注意:节点可以重复经过, 边不能重复 思路 直接dfs,每个节点都进行一次dfs,找出每个借点连接的最大路径,然后进行比较输出最大的那个 代码 #include #incl原创 2013-07-09 08:48:13 · 1484 阅读 · 1 评论 -
UVA 301 Transportation 。。有点需要思考的回溯、、
UVA 301 Transportation Transportation Ruratania is just entering capitalism and is establishing new enterprising activities in many fields including transport. The transp原创 2013-07-20 23:56:00 · 1775 阅读 · 0 评论 -
UVA639 Don't Get Rooked
UVA639 Don't Get Rooked 类似八皇后问题,不过中间多了障碍物。。 深搜回溯,标记放过的点,。然后利用标记的点进行判断能不能放入。 #include #include int n; char map[10][10]; int vis[10][10]; int max; void dfs(int num) { if (max < num原创 2013-07-20 20:37:26 · 1040 阅读 · 0 评论 -
UVA 10344 23 out of 5
UVA 10344 23 out of 5 找23点。。用深搜。。直到找到23点为止。。 每个数字有3种情况 + - * 找到5个数字就判断。。 #include using namespace std; #include #include int num[5]; int judge; void dfs(int star, int sum) { if原创 2013-07-20 20:39:40 · 1009 阅读 · 0 评论 -
UVA 216 Getting in Line
UVA 216 Getting in Line 深搜回溯,找出最短的路径。。搜索过程中保存下路径。最后输出。。 其实也可以用全排列的next_permutation 暴力找出最短。。 #include #include #include int n; double x[10], y[10]; int vis[10]; int lu[10]; int minlu[10];原创 2013-07-20 20:35:30 · 1060 阅读 · 0 评论 -
UVA 10474 Where is the Marble?
UVA 10474 Where is the Marble? 很水的一题。直接从小到大排序好,然后看要找哪个,找过去找出位置即可。。。 还有一种方法,计数排序时间复杂度更低。。不过这题数据量不大没问题 #include #include #include using namespace std; int n, m; int a[10005], b[10005]原创 2013-07-20 20:25:45 · 1911 阅读 · 0 评论 -
uva729 The Hamming Distance Problem
uva729 The Hamming Distance Problem 全排列水题 存1的时候要注意位置。。。 刚开始因为这个不小心wa了 #include using namespace std; #include #include int t; int n, h; int i; char sb[25]; int main() { scanf("%d", &原创 2013-07-20 20:21:23 · 1141 阅读 · 0 评论 -
uva10098 Generating Fast, Sorted Permutation
uva10098 Generating Fast, Sorted Permutation 全排列水题 #include using namespace std; #include #include int t; int i; char sb[25]; int main() { scanf("%d", &t); getchar(); while (t --) {原创 2013-07-20 20:19:31 · 1209 阅读 · 0 评论 -
uva146 ID Codes
uva146 ID Codes 全排列的水题。 next_permutation 水过。。。 #include using namespace std; #include #include char sb[25]; int main() { while(gets(sb) != NULL && sb[0] != '#') { if(next_permutation(原创 2013-07-20 20:16:59 · 1180 阅读 · 0 评论 -
UVA 11205 The broken pedometer 果断还是暴力吧。。。
UVA 11205 The broken pedometer 这题题意一开始还理解错了。后来才知道是输出最少开几个灯,能表示所有数字。。 一开始的想法是深搜。。把每一种情况找出来求出最少的。。结果很悲剧啊 超时了无数次。。。 后来换思路。。用暴力。。大概思路 灯可能是开着或者关着的, 题目中灯为P盏,一盏灯有2种状态,按这样来考虑的话 一共只要枚举 2^p次 而p最多为15,原创 2013-07-18 01:56:30 · 2301 阅读 · 1 评论 -
UVA 10167 Birthday Cake
UVA 10167 Birthday Cake 切蛋糕,保证一刀切后,两边樱桃数相同, 切过去的方程Ax+By = 0 可能有很多条, 输出一条即可 很水啊。。直接暴力水过 #include #include int n; int x[105], y[105]; int a, b; int shang , xia; int judge; int main() {原创 2013-07-18 01:52:47 · 1296 阅读 · 0 评论 -
UVA 331 Mapping the Swaps
UVA 331 Mapping the Swaps 题意。给一串数字。求其冒泡排序(最少次数的)方案的种数。。 标准的深搜回溯 每次交换值后进行一次judge。如果从小到大了,就种数加1. #include #include int min; int n; int num[5]; int judge() { for(int i = 0; i原创 2013-07-20 20:42:36 · 1028 阅读 · 0 评论