Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8109   Accepted: 3551   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers a…
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she's done. If s…
题目链接:http://poj.org/problem?id=1041 思路:懒得写了,直接copy吧:对于一个图可以从一个顶点沿着边走下去,每个边只走一次,所有的边都经过后回到原点的路.一个无向图存在欧拉回路的充要条件是每个顶点的度是偶数, 对于有向图存在欧拉回路的条件是每个顶点的出度等于入度(就是出去的边数等于进来的边数).根据这个首先判断存在欧拉回路不, 如果存在然后用DFS去找欧拉回路.DFS的思想等效于先找一个环,然后对环上所有点递归DFS,并且把这些递归产生的路插入这个环中. 实际上…
题意: Bessie 最近做了农场看守,他每天晚上的工作就是巡视农场并且保证没有坏人破坏农场.从谷仓出发去巡视,并且最终回到谷仓. Bessie 视力不是很好,不能像其他农场的看守一样,对农场的每一条连接不同场地的路走一遍就可以发现是不是有异常情况,他需要每条路都走两遍,并且这两边必须是不同的方向,因为他觉得自己应该不会两次都忽略农场中的异常情况. 每块地之间一定会由至少一条路相连.现在的任务就是帮他制定巡视路线.前提假设一定存在满足题意的路径. 输入: 第一行输入两个数N(2 <= N <=…
题目链接:https://www.luogu.com.cn/problem/P1378 题目中给出矩形的长宽和一些点,可以在每个点放油滴,油滴会扩展,直到触碰到矩形的周边或者其他油滴的边缘,求出剩余面积的最小值,就是求油滴面积的最大值.策略是dfs加上回溯,暴力求解. 代码如下: #include<bits/stdc++.h> using namespace std; typedef unsigned int ui; typedef long long ll; typedef unsigned…
题目链接:http://poj.org/problem?id=2230 题目大意:给你n个点m条边,Bessie希望能走过每条边两次,且两次的方向相反,让你输出以点的形式输出路径. 解题思路:其实就是输出有向图的欧拉路,只是让你以点的形式输出.建图的时候,输入a,b直接建立(a,b)和(b,a)正反两条边,然后dfs递归遍历即可.注意输出点的位置:在边遍历完之后输出,原理暂时还没搞懂. 代码: #include<iostream> #include<cstdio> #include…
Watchcow Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9974 Accepted: 4307 Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoer…
Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she's done. If s…
Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, makes her patrol, and then returns to the barn when she'…
Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 5258   Accepted: 2206   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no ev…
关键是每条边必须走两遍,重复建边即可,因为确定了必然存在 Euler Circuit ,所以所有判断条件都不需要了. 注意:我是2500ms跑过的,鉴于这道题ac的code奇短,速度奇快,考虑解法应该不唯一. #include<cstdio> #include<cstring> #include<vector> #include<stack> #include<algorithm> #define rep(i,a,b) for(int i=a;i…
主题链接: http://poj.org/problem? id=2230 Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6055   Accepted: 2610   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk ac…
POJ 3050 题意: 1.5*5的方阵中,随意挑一格,记住这个格子的数字 2.可以上下左右走,走5次,每走一次记录下所走格子的数字 3.经过以上步骤,把所得6个数字连起来,形成一串数字.求共可以形成多少种不同的数字串 思路: 网格大小只有5*5,用穷举法,不会超时. 这里利用了stl中的set容器来防止重复.最终只要输出set的size就是结果. 注意dfs回溯时的编程规范 #include<iostream> #include<algorithm> #include<s…
[题目链接] http://poj.org/problem?id=2230 [算法] 欧拉回路 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #inclu…
Watchcow Time Limit: 3000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 223064-bit integer IO format: %lld      Java class name: Main   Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to wa…
把26个小写字母当成点,每个单词就是一条边. 然后就是求欧拉路径. #include<cstdio> #include<iostream> #include<algorithm> #include<cstring> #include<cmath> #include<queue> #include<map> using namespace std; #define MOD 1000000007 const int INF=0…
Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 8800   Accepted: 3832   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no ev…
Watchcow Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6336   Accepted: 2743   Special Judge Description Bessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no ev…
题意:给你n个字符串,每个字符串可以和另一个字符串连接的前提是,前一个字符串的尾字符等于后一个字符串的首字符,问你存不存在欧拉通路并输出 解题思路:基本标准流程,建图:把一个字符串可以看作一条首字符指向尾字符的一条边,因为这道题需要输出字典序最小的,那么得先给他排序,按照字典序从小到大排,因为我用前向星存图,所以首字符相同的,按尾字符从大到小排 建完图后查看是否存在欧拉路径,如果存在,就输出,输出用dfs回溯的方法输出的: 代码: #include<iostream> #include<…
这类题是最简单的了都是一个套路,不像动态规划一类题一个套路,没做过就是不会也极难想出来. 一.BFS 解决的问题:用来初始点解决到指定点的最短路径问题,因为图的每一层上的点到初始点的距离相同.(注意是无权图) 在程序实现 BFS 时需要考虑以下问题: 队列:用来存储每一轮遍历得到的节点: 标记:对于遍历过的节点,应该将它标记,防止重复遍历. 下面这两个题都是比较典型的广度优先题 1091. 二进制矩阵中的最短路径 这题笔者超时了百思不得其解. class Solution { public in…
题目链接 357. 计算各个位数不同的数字个数 题意: 给定一个非负整数 n,计算各位数字都不同的数字 x 的个数,其中 0 ≤ x < 10n . 示例: 输入: 2 输出: 91 解释: 答案应为除去 11,22,33,44,55,66,77,88,99 外,在 [0,100) 区间内的所有数字. 思路 法1:DFS+回溯 前导0单独处理,其余位置按0~9顺序每次插入,用一个数组vis[10]记录已经用过的数字 法2:数学 设f[i]表示i位数的有效数字,比如f[1]=10,f[2]=9*9…
  冰壶2.0 题目大意:就是给你一个冰壶和一个地图,地图上有石头,冰壶只能沿着x方向和y方向运动,并且要一直运动直到撞到石头为止,并且沿着此方向撞过来会把挡住的石头撞没,冰壶在停的时候可以扔出去一次,最多只能扔10次,问你冰壶能否到指定点? 这一题原题非常长,需要很细心地读题(比如我一开始的时候就是没看到只能扔10次,导致好几次tle),而且这一题一开始我还做复杂了,一开始的时候用的是dfs+dp去储存最短距离,可是我发现冰壶会撞烂石头,所以储存最短距离是不行的,所以只能直接dfs了 直接df…
Door Man Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 2476 Accepted: 1001 Description You are a butler in a large mansion. This mansion has so many rooms that they are merely referred to by number (room 0, 1, 2, 3, etc-). Your master is…
题意:给你一个图,有N个点,M条边,这M条边有的是单向的,有的是双向的. 问你能否找出一条欧拉回路,使得每条边都只经过一次! 分析: 下面转自别人的题解: 把该图的无向边随便定向,然后计算每个点的入度和出度.如果有某个点出入度之差为奇数,那么肯定不存在欧拉回路.因为欧拉回路要求每点入度 = 出度,也就是总度数为偶数,存在奇数度点必不能有欧拉回路. 好了,现在每个点入度和出度之差均为偶数.那么将这个偶数除以2,得x.也就是说,对于每一个点,只要将x条边改变方向(入>出就是变入,出>入就是变出),…
图的深度遍历 Time Limit: 1000MS Memory limit: 65536K 题目描述 请定一个无向图,顶点编号从0到n-1,用深度优先搜索(DFS),遍历并输出.遍历时,先遍历节点编号小的. 输入 输入第一行为整数n(0 < n < 100),表示数据的组数. 对于每组数据,第一行是两个整数k,m(0 < k < 100,0 < m < k*k),表示有m条边,k个顶点. 下面的m行,每行是空格隔开的两个整数u,v,表示一条连接u,v顶点的无向边. 输…
红与黑 题目大意:一个人在一个矩形的房子里,可以走黑色区域,不可以走红色区域,从某一个点出发,他最多能走到多少个房间? 不多说,DFS深搜即可,水题 注意一下不要把行和列搞错就好了,我就是那样弄错过一次哈哈哈哈 #include <stdio.h> #include <stdlib.h> #define MAX_N 20 static int dp[MAX_N][MAX_N]; static int startx; static int starty; static int ans…
好吧前几天一直没更新博客,主要是更新博客的确是要耗费一点精力 北大教你数水坑 最近更新博客可能就是一点旧的东西和一些水题,主要是最近对汇编感兴趣了嘻嘻嘻 这一题挺简单的,没什么难度,简单深搜 #include <stdio.h> #include <stdlib.h> typedef int Postion; ][]; static int N, M; void DFS(Postion, Postion); int main(void) { ; while (~scanf(&quo…
分析: 基础的欧拉路算法,变化在于要求每条边正向和反向各走一遍. 链式前向星构图,只要标记走过的单向边,边找边输出即可. code #include <iostream> #include <cstdio> using namespace std; struct node { int v, ne; } edge[100009]; int head[10009], vis[100009], cnt = 1; int n, m, x, y; void addedge (int u, i…
Product-->Scheme-->editeScheme中:Auguments中Environment Variable中 Scheme中添加环境变量 "OS_ACTIVITY_MODE" 并将它的值设为:disable iOS 10真机调试的话,会屏蔽掉NSLog.如果NSLog宏定义是这样的话:#define NSLog(format, ...) NSLog(format, ## __VA_ARGS__)在完成OS_ACTIVITY_MODE设置后会发现真机调试时N…
题目链接 : poj2230 大致题意: 有一个人每晚要检查牛场,牛场内有m条路,他担心会有遗漏,就每条路检查两次,且每次的方向不同,要求你打印他行走的路径(必须从1开始),打印一条即可. 思路分析 输入n条边,要求每条边都要走两次,每次的方向不同.那么就可以看成是有向图,把一条边分成两条边,就可以直接打印结果.但是这题还有一个陷阱,m最大为50000,n最大为10000,如果直接采用邻接矩阵数组放不下,那么我的方法就是利用一个动态数组存储结构体. struct node { int key;…