POJ 1979 题解】的更多相关文章

Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 31722   Accepted: 17298 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a…
POJ 1979 Red and Black (红与黑) Time Limit: 1000MS    Memory Limit: 30000K Description 题目描述 There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to…
地址 http://poj.org/problem?id=1979 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't mo…
http://poj.org/problem?id=1979 #include <cstdio> #include <cstring> using namespace std; const int maxn = 21; bool vis[maxn][maxn]; char maz[maxn][maxn]; int n,m; const int dx[4] = {1,-1,0,0}; const int dy[4] = {0,0,1,-1}; int ans; bool in(int…
  fengyun@fengyun-server:~/learn/acm/poj$ cat 1979.cpp #include<cstdio> #include<iostream> #include<string> #include<algorithm> #include<iterator> #include<sstream>//istringstream #include<cstring> #include<que…
1.链接地址: http://bailian.openjudge.cn/practice/1979 http://poj.org/problem?id=1979 2.题目: 总时间限制: 1000ms 内存限制: 65536kB 描述 There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile.…
题目链接:http://poj.org/problem?id=1979 思路分析:使用DFS解决,与迷宫问题相似:迷宫由于搜索方向只往左或右一个方向,往上或下一个方向,不会出现重复搜索: 在该问题中往四个方向搜索,会重复搜索,所以使用vis表来标记访问过的点,避免重复搜索. 代码如下: #include <iostream> using namespace std; ; int vis[MAX_N][MAX_N]; char map[MAX_N][MAX_N]; int red_count,…
题目链接:http://poj.org/problem?id=1979 #include<cstring> #include<iostream> using namespace std; ,h=,sum=; ][]; void DFS(int p,int q) { &&p<h&&q>=&&q<n) { sum++; aa[p][q]='#'; } else return ; DFS(p-,q); DFS(p+,q);…
题目地址: http://poj.org/problem?id=1979  或者  https://vjudge.net/problem/OpenJ_Bailian-2816 Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 46793   Accepted: 25201 Description There is a rectangular room, covered with square ti…
传送门: poj:http://poj.org/problem?id=1979 zoj:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1165 题目大意: 给你初始坐标,标记为'#'的格子不能走,求你能走的所有格子的个数(能走的为'.',初始坐标用'@'表示) 思路: 一看直接DFS就好了嘛.... 好几天没刷题了,回到家来水一发先~ #include<cstdio> #include<cstring> con…
题目 题意: $ yyf $ 一开始在 $ 1 $ 号节点他要通过一条有 $ n $ 个地雷的道路,每次前进他有 $ p $ 的概率前进一步,有 $ 1-p $ 的概率前进两步,问他不领盒饭的概率. 对于这道题我们可以考虑 $ dp $ ,我们可以设计状态 $ f[i] $ 表示安全通过 $ i $的概率,那么我们可以得到状态转移方程 $ f[i]=p* f[i-1]+(1-p)* f[i-2] $ $ f[x_i]=0 $ 然后我们可以看到 $ x \in [1, 100000000] $如果…
题意 $ T $ 组数据,每组数据给一个长度 $ N $ 的序列,要求一段连续的子序列的和大于 $ S $,问子序列最小长度为多少. 输入样例 2 10 15 5 1 3 5 10 7 4 9 2 8 5 11 1 2 3 4 5 输出样例 2 3 解析 我们很容易发现对于这题我们可以二分答案,先找出一个初始长度,判断是否存在合法序列,如果存在缩小长度,如果不存在加长长度. 时间复杂度 $ O(nlogn) $ 代码 #include<cstdio> #include<algorithm…
题目 Given a list of N integers with absolute values no larger than \(10^{15}\), find a non empty subset of these numbers which minimizes the absolute value of the sum of its elements. In case there are multiple subsets, choose the one with fewer eleme…
DP中环形处理 对于DP中存在环的情况,大致有两种处理的方法: 对于很多的区间DP来说,很常见的方法就是把原来的环从任意两点断开(注意并不是直接删掉这条边),在复制一条一模一样的链在这条链的后方,当做线性问题来解,即可实现时间复杂度降维. 情况一:将原来的环从任意两点断开,再当做线性问题来解.情况二:添加一些特殊条件,将断开的前后强行连接起来.两种情况取其中的最优解即可.亦可以实现时间复杂度的降维. 本篇博客将对于第一种情况进行分析. 根据一道例题来探讨. POJ 1179 Polygon 题目…
#include<iostream> #include<cstdio> #include<queue> #include<algorithm> #include<cstring> using namespace std; #define MAXN 21 struct node { int x; int y; }; int n,m,g[MAXN][MAXN]; bool vis[MAXN][MAXN]; ]={,-,,}; ]={,,,-}; in…
标准DFS,统计遍历过程中遇到的黑点个数 #include<cstdio> #include<vector> #include<queue> #include<string> #include<map> #include<iostream> #include<cstring> #include<algorithm> using namespace std; typedef long long LL; const…
Post Office Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18835   Accepted: 10158 Description There is a straight highway with villages alongside the highway. The highway is represented as an integer axis, and the position of each vill…
Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 78114   Accepted: 24667 Description Farmer John has been informed of the location of a fugitive cow and wants to catch her immediately. He starts at a point N (0 ≤ N ≤ 100,00…
Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27520   Accepted: 10776 Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be fille…
Lake Counting 描述 Due to recent rains, water has pooled in various places in Farmer John's field, which is represented by a rectangle of N x M (1 <= N <= 100; 1 <= M <= 100) squares. Each square contains either water ('W') or dry land ('.'). Fa…
这是一道比较水的DPS的题目 题意就是求你可以走到的黑色的地板砖的块数,@代表你的起点,也是黑色的地板砖,#代表白色的,则说明你不能走,这就是一个广搜的题目 思路也很简单,如果你周围的那块地板是黑色的,而且之前没有走过,那就可以往那个地板砖走. 还有这道题的那个初始化很重要,不然很可能会WA. #include <stdio.h> #include <iostream> #include <string.h> using namespace std; int ans;…
红与黑 题目大意:一个人在一个矩形的房子里,可以走黑色区域,不可以走红色区域,从某一个点出发,他最多能走到多少个房间? 不多说,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…
[问题描述] 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只能见到窗口的K个数,每次窗体向右移动一位,如下表: [样例输入] 8 3 1 3 -1 -3 5 3 6 7 [样例输出] -1 -3 -3 -3 3 3 3 3 5 5 6 7 [解题思路] 首先,不难想到用枚举的办法,对于每一个区间,枚举其中的最大值和最小值,但对于n<=1000000的数据来说,枚举必定超时,因此我们可以用到队列来进行优化. 我们取前k个数中的最大值和最小值,放入两个队列中,设放最大值的为k,…
一开始理解错题意了,以为是走过的砖不能再重复走,最多能走多少个黑砖,结果写的递归陷入死循环...后来才明白原来可以重复走,问可以到达的磁砖数. #include <iostream> #include <string.h> #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; int w,h,num,ans; ][];//存储地图的信息,为0代…
Problem Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can mo…
题意:有红色和黑色的格子,只能走黑色的,问从起始位置出发,最多能走到达多少块黑色格子. 分析:相当于走迷宫,黑色格子是路,红色格子是墙,每次到达一个未到达过的格子时计数,原点也算是一个.每次可以走上下左右四个方向,用深度优先遍历从原点起始,一直到遍历所有能到达的格子.需要注意的是,不要重复走同一个格子,可以采取数组标记已走过的格子,但这里只需简单将已走过的格子标记为红色就可以达到目的,因为红色的格子也不可走. C++代码: #include <cstdio> ; ; //输入 int W; i…
Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only…
Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 27891   Accepted: 15142 Description There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a…
题目描述 给定A,B,求A^B的所有因数的和,再MOD 9901 输入 一行两个整数 A 和 B. 输出 一行,一个整数 样例输入 2 3 样例输出 15 提示 对于100%的数据满足:0 <= A,B <= 50000000 这道题首先要想到有一个因数和公式 f[a] = ( 1 + p1 + p1^2 + .... + p1^q1 ) * ( 1 + p2 + p2^2 + .... + p2^q2 ) * ...... * ( 1 + pn + pn^2 +.....+ pn^qn )…
Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions:46898   Accepted: 12204 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man…